Re: ctypes structure with a variable-size field at the end
Mads Kiilerich <[email protected]>
| Newsgroups | gmane.comp.python.ctypes |
|---|---|
| Message-ID | <[email protected]> |
gatch breizh wrote, On 06/15/2010 11:12 AM: > 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 ... > It might be possible to do with some clever tricks, but I would say: C don't have variable-size fields, but it allows you to work with such "fields" through careful pointer manipulations and careful reading within the bounds. I would use the same approach with ctypes. For example by finding the address where the field starts and cast it to a c_char*length array. /Mads ------------------------------------------------------------------------------ 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