A little comments of ctypes and construct.

一首诗 newptcai at gmail.com
Fri Nov 21 03:28:51 EST 2008


Hi all,

Recently I asked a question on this group:


>> What's your choice when handle complicated C structures.

I got these suggestion:

1) try construct

2) try ctypes

----------------

I spend half a day on construct and here's my conclusion:

1. It really good for parse(unpack) data structures.

But

1. It's not that good for pack.
2. From the documents and example, can not find out how to describe
nested struct array.

for example:

typedef struct _Point
{
   int x;
   int y;
} Point;

typedef struct _Shape
{
  int z;
  Point ap[2];
}Shape;

Can not find out how to describe this..


----------------

Then I tried ctypes.

1. It works fine for pack

BUT:

1. I can not figure out how to unpack.  The examples I googled doesn't
work on my computer.

http://markmail.org/message/44tu6rm4nejxgbdd

2. BigEndianStructure can not be nested.  So.  If you need bid endian,
you got bad luck.

So, both of them are not ideal solution to pack and unpack
sophisticated C style data structures.

----------------

BTW:  Some one suggested that I should use struct.Struct and
namedtuple.

I skimmed the document, but can't find a clear way to handle nested
structures.



More information about the Python-list mailing list