On Sun, 19 Jun 2005, Josiah Carlson wrote:
Keith Dart kdart@kdart.com wrote:
Therefore, I would like to ask here if anyone has already started something like this? If not, I will go ahead and do it (if I have time).
If all you need to do is read or write C-like types to or from memory, you should spend some time looking through the 'struct' module if you haven't already.
I know about 'struct'. However, it will just convert to Python "native" types. C unsigned become Python longs.
u = struct.pack("I", 0xfffffffe) struct.unpack("I", u) (4294967294L,)
In SNMP, for example, a Counter32 is basically an unsigned int, defined as "IMPLICIT INTEGER (0..4294967295)". One cannot efficiently translate and use that type in native Python. Currently, I have defined an "unsigned" type as a subclass of long, but I don't think that would be speed or storage efficient.
On the other hand, adding my own type won't help with the ioctl() problem, since it won't know about it.