Re: ctypes structure with a variable-size field at the end
Thomas Heller <[email protected]>
| Newsgroups | gmane.comp.python.ctypes |
|---|---|
| Message-ID | <[email protected]> |
gatch breizh schrieb:
> Hi,
>
> I would like to know how to write a ctypes::Structure with a variable-size
> field at the end.
> It occurs in many protocols to have a data field with a size early defined.
> I have been searching a solution through the web (very usual question) for a
> while but without any success ...
>
> Attempt #1: Append a new field to the list _fields_ does NOT work...
> <code>
> class LV(Structure):
> _fields_ = [('Length', c_ushort)]
>
> lv = LV()
> lv.Length = 5
> lv._fields_.append(('Value', c_ubyte * 5) # ==> added but not usable
> <end of code>
>
> Attempt #2: use of ctypes.resize() seems to fail for ctypes.Structure
>
> First, is it possible? if so, how to write it?
> I Hope someone could help me!
> Thanks.
>
> .: Gatch, Python 2.5.4, CTypes 1.0.3
Do you want to *create* such a structure in Python, or do you want do retrieve
something from such a structure that you received from somewhere?
--
Thanks,
Thomas
------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the
lucky parental unit. See the prize list and enter to win:
http://p.sf.net/sfu/thinkgeek-promo