What's your choice when handle complicated C structures.

Ò

Ò»Ê×Ê«

Hi all,

Recently I am writing a small network application with python.

The protocol is binary based and defined in c header files.

Now I'm using the upack function of 'struct' module, but it's really
annoying to write fmt strings for complicated structures.

What will be your choice when handling binary structures?
 
D

Diez B. Roggisch

一首诗 said:
Hi all,

Recently I am writing a small network application with python.

The protocol is binary based and defined in c header files.

Now I'm using the upack function of 'struct' module, but it's really
annoying to write fmt strings for complicated structures.

What will be your choice when handling binary structures?

You can try gccxml + ctypes instead.

Diez
 
D

Daniel Fetchinson

Recently I am writing a small network application with python.
The protocol is binary based and defined in c header files.

Now I'm using the upack function of 'struct' module, but it's really
annoying to write fmt strings for complicated structures.

What will be your choice when handling binary structures?

I would write a couple of wrapper functions around unpack of struct so
that the actual unpacking is less annoying but otherwise would
continue using the same approach as what you describe.

Cheers,
Daniel
 
G

Glenn Linderman


Interesting. It seems to be a bit more capable around the edges than
unpack, and certainly has a friendlier looking syntax, but I wonder how
the performance compares to unpack, for the cases they both handle?
Seems like for cases they both handle, it could be beneficial to compile
to the equivalent unpack for speed?

Containers look nice, but it seems it would be nice to allow multiple
targets: Containers, dicts (with a special entry giving the order of the
fields, perhaps, for reconstruction; maybe that is what a container is,
already?), namedtuples, all seem to be reasonable alternative targets,
with different usage tradeoffs, of course.
 
R

Robert Kern

一首诗 said:
Hi all,

Recently I am writing a small network application with python.

The protocol is binary based and defined in c header files.

Now I'm using the upack function of 'struct' module, but it's really
annoying to write fmt strings for complicated structures.

What will be your choice when handling binary structures?

I use numpy and its nested dtypes. But then, I use numpy for damn near everything.

http://numpy.scipy.org/

Construct also looks appropriate.

http://construct.wikispaces.com/

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,123
Latest member
Layne6498
Top