Re: [ctypes-users] Re: Byte ordering
by Bob Ippolito other posts by this author
Nov 8 2005 11:35AM messages near this date
[ctypes-users] Re: Byte ordering
|
Re: [ctypes-users] Re: Byte ordering
On Nov 8, 2005, at 9:59 AM, Thomas Heller wrote:
> Nicolas Pinault <nicolasp@[...].com> writes:
>
> > Hello,
> >
> > I need to access data structures which are in big-endian format. I
> > would like to be able to declare and use Structures which manage this
> > automaticaly.
> > A keyword could say the structure contains big-endian data. When
> > accessing this structure fields, byte ordering would be done
> > automaticaly.
>
> This is not the first time this request comes up, although
> personally I
> never had a need for it.
>
> First, there are some 'Struct' modules that I know of which are
> based on
> the standard Python struct module, and so can handle different byte
> orders. (Bob Ippolito has something called ptypes, iirc, and Just van
> Rossum has sstruct, but I'm less sure on the name of the latter).
> Neither of them is compatible with ctypes, afaik.
This is the ptypes that Thomas is referring to (defaults to big endian):
http://svn.red-bean.com/bob/py2app/trunk/src/macholib/ptypes.py
This is an example of structures defined with it:
http://svn.red-bean.com/bob/py2app/trunk/src/macholib/mach_o.py
The MachOHeader class in this file shows how you could set up the
endian stuff:
http://svn.red-bean.com/bob/py2app/trunk/src/macholib/MachO.py
This code successfully reads and writes Mach-O headers of big and
little endian, in either 32 or 64 bit flavors. Note that several
Mach-O headers can be in a single file (a fat binary -- or Universal
Binary in Mac OS X terminology), so this code can read/write
different endians in the same file. Endian is controlled at per-
structure granularity (each struct is written by a single struct.pack).
-bob
-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
ctypes-users mailing list
ctypes-users@[...].net
https://lists.sourceforge.net/lists/listinfo/ctypes-users
Thread:
Thomas Heller
Bob Ippolito
Thomas Heller
|