How can I handle low-level data types in Python?
What I want to do is writing an interface to a C daemon which waits for
stuff like unsigned ints on a socket. For example, I need to craft and
decode data structures that look like this:
32-bit unsigned int MSG_LENGTH
32-bit unsigned int MSG_CODE
64-bit signed int DATA
32-bit length + utf-8 characters STRING_DATA
etc.
What's the right way to do this in Python? 7 2014
"dementrio" wrote: What I want to do is writing an interface to a C daemon which waits for stuff like unsigned ints on a socket. For example, I need to craft and decode data structures that look like this:
32-bit unsigned int MSG_LENGTH 32-bit unsigned int MSG_CODE 64-bit signed int DATA 32-bit length + utf-8 characters STRING_DATA etc.
What's the right way to do this in Python? http://docs.python.org/lib/module-struct.html
</F>
On 15 Feb 2006 04:07:37 -0800, dementrio <de*******@gmail.com> wrote: How can I handle low-level data types in Python? What I want to do is writing an interface to a C daemon which waits for stuff like unsigned ints on a socket. For example, I need to craft and decode data structures that look like this:
32-bit unsigned int MSG_LENGTH 32-bit unsigned int MSG_CODE 64-bit signed int DATA 32-bit length + utf-8 characters STRING_DATA etc.
What's the right way to do this in Python?
Look at the struct module.
--
Cheers,
Simon B, si***@brunningonline.net, http://www.brunningonline.net/simon/blog/
Thanks for the hint!
However now I have another problem - endianness (the client runs on
powerpc, the server on x86). I found that simply reversing the stuff I
recv() works, but is there any cleaner way for taking care of this?
dementrio wrote: Thanks for the hint!
However now I have another problem - endianness (the client runs on powerpc, the server on x86). I found that simply reversing the stuff I recv() works, but is there any cleaner way for taking care of this?
Have you actually _read_ the struct documentation?
"""
Alternatively, the first character of the format string can be used to
indicate the byte order, size and alignment of the packed data, according
to the following table:
....
"""
Diez
"dementrio" wrote: However now I have another problem - endianness (the client runs on powerpc, the server on x86). I found that simply reversing the stuff I recv() works, but is there any cleaner way for taking care of this? http://docs.python.org/lib/module-struct.html
(see the second table, the one that has "byte order" and "size and
alignment" in the heading)
</F>
dementrio wrote: Thanks for the hint!
However now I have another problem - endianness (the client runs on powerpc, the server on x86). I found that simply reversing the stuff I recv() works, but is there any cleaner way for taking care of this? http://docs.python.org/lib/module-struct.html
and search for "Alternatively, the first character of the format string
can be used to indicate the byte order"
Daniel
> Have you actually _read_ the struct documentation?
Ok, sorry about that. Somehow I managed to notice only that "By
default, C numbers are represented in the machine's native format and
byte order".
Now I'm just going to RTFM and stay silent. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Activator8 |
last post by:
In our application, we have noticed on two rare occasion where the
data stored in application level arrays has disappeared. We have 3
application level arrays, and many other data types stored at...
|
by: York |
last post by:
Hi,
R language has very high-level IO functions, its read.table can read a
total .csv file and recogonize the types of each column. write.table can
do the reverse.
R's MySQL interface has...
|
by: Nathan |
last post by:
I've spent a good part of the afternoon searching Google and the newsgroups
for some sort of answer - so I apologize if I'm asking something that has
already been asked and answered.
I'm using...
|
by: Madhav |
last post by:
Hi all,
I did not understand why do the global vars are
initialized to NULL where as the block level variables have random
values? I know that the C standard requires this as was mentioned in a...
|
by: mesut |
last post by:
Mybe it's a stupid question but :
I'm starting to learn VB.NET. I have some basic skills. I'm from
Mainframe world and I have same question to make my DATABASES (tables
and relation)
I would like...
|
by: Jacek Dziedzic |
last post by:
Hi!
I'm trying to squeeze a few clock cycles from a tight
loop that profiling shows to be a bottleneck in my program.
I'm at a point where the only thing that matters is
execution speed, not...
|
by: Chris Carlen |
last post by:
Hi:
From what I've read of OOP, I don't get it. I have also found some
articles profoundly critical of OOP. I tend to relate to these articles.
However, those articles were no more objective...
|
by: emaghero |
last post by:
Greetings and Salutations,
I am currently doing some file I/0 on data that I have and I do not wish to use fstream. I have data stored in its untranslated binary format and I want to read it into...
|
by: gskbond |
last post by:
Following is my logic to traverse level by level an mway search tree....
(Yeah I finally used templates to implement a queue... :) )
void mWayTree:: TraverseLevelOrder(Node *root,int lvl)
{...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
| |