Re: ctypes structure with a variable-size field at the end
gatch breizh <[email protected]>
| Newsgroups | gmane.comp.python.ctypes |
|---|---|
| Message-ID | <[email protected]> |
Hi Thomas.
Glad to talk to you.
I have got a C struct from *somewhere* that I want to convert to python:
<C code>
typedef struct
{
UINT32 Length; /* In bytes */
UINT8 Value[];
} tLV;
<end of C code>
Thanks
Gael
2010/6/16 Thomas Heller <[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
> _______________________________________________
> ctypes-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/ctypes-users
>
------------------------------------------------------------------------------
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
_______________________________________________
ctypes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ctypes-users