On Sat, Dec 20, 2008, Ravi Kondamuru wrote:
>I am trying to use xstruct module to unpack a varaible size record with the
>following structure.
>
>struct nameid {
> u32bits len /* total length */
>u32bits id;
>char name; /* name variable length */
>}
>
>As can be seen the length of the name = len - (sizeof(len) + sizeof(id)).
>
>How do I use xstruct or struct to unpack such a structure?
>
>n = xstruct.structdef(xstruct.little_endian, [
> ('len', (xstruct. unsigned_long, 1)),
> ('id', (xstruct.unsigned_long, 1)),
> ('name', (xstruct.string, <?>)),
>])
>
>xstruct seems to expect the exact len to be specified in structdef. Is there
>a way to tell it to go till the end of the buffer passed?
I haven't done this in python yet, but when handling things like
this in C and perl, I have done it with two reads, the first to
get the length, the second to read the data with that length.
Bill
--
INTERNET: [email protected] Bill Campbell; Celestial Software LLC
URL: http://www.celestial.com/ PO Box 820; 6641 E. Mercer Way
Voice: (206) 236-1676 Mercer Island, WA 98040-0820
Fax: (206) 232-9186
Independent self-reliant people would be a counterproductive anachronism
in the collective society of the future where people will be defined by
their associations. 1896 John Dewey, educational philosopher, proponent
of modern public schools.
_______________________________________________
Tutor maillist - [email protected]
http://mail.python.org/mailman/listinfo/tutor