2

What I want to know is if I have a defined structured object with known parameters and a known order. I want to parse a binary blob into this structure in a generic way.

For example, I know that my file is a binary file of this structure

typedef struct { 
 uint frCompressedSize;
 uint frUncompressedSize;
 ushort frFileNameLength;
 ushort frExtraFieldLength;
 char frFileName[ frFileNameLength ];
 uchar frExtraField[ frExtraFieldLength ];
 uchar frData[ frCompressedSize ];
 } ZIPFILERECORD;

Is there a better way to do this than reading in individual fields at a time in a hard coded manner? In my real code the structure has almost 100 parameters so the hardcoded method is not my first choice.

Any Ideas?

thanks!

asked Feb 25, 2013 at 19:30
0

1 Answer 1

3

You are looking for the python struct library

answered Feb 25, 2013 at 20:15
Sign up to request clarification or add additional context in comments.

1 Comment

This got me half way there, I had to break up the structure into two parts, since the last 3 parameter sizes relied on the values read in on the top paremters. Dividing it up into several struct.unpack calls solved my problem in much less than the hardcoded parsing I thougth I was going to have to do. thanks!

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.