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 2037
"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*******@gmai l.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***@brunningo nline.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 "Alternativ ely, 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
application scope as well. The other data types appear to have been
unharmed. All session level data remained unharmed as well. The data
in the arrays seemed to have disappeared all of the sudden. No IIS
restarts, for example, were performed. Is...
|
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 high-level functions, too, e.g. dbWriteTable can
automatically build a MySQL table and write a table of R data
into it.
|
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 ASP.Net 1.1 (unfortunately 2.0 isn't an option right now) and I'm
working on the design of a security framework for other developers in our
organization to use.
We have a handful of different types of users that are contained in an enum
called...
|
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
recent thread.
I want to know why this descrimination is in place. Can't all the
variables be initialised to NULL automatically by the compiler? This
would make programming a little easier.
|
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 to make ask my question by example. Let's say I'm a
sales company I'm selling products to customers. Okay?
I have these tables (databases) and fields and I have these questions.
I have created these tables in VB.NET Database Connections IDE...
| |
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 style (within the loop, obviously).
The loop deals with an array:
// this is aligned at cache line boundaries
|
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 than the descriptions of
OOP I've read in making a case. Ie., what objective
data/studies/research indicates that a particular problem can be solved
more quickly by the programmer, or that the solution is more efficient
in execution time/memory...
|
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 another program. I have been using _open and _write to export the data but I have been having problems implementing _read.
I will give a simple example of what I want to do.
The following code creates a file and stores it in some location....
|
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)
{
int i;
int level;
Dq<Node *> Q;
Node *tmp;
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |