Sign in to follow this  

bit stream to structure

Recommended Posts

fanaticlatic    473
Hi all,

I am wondering what the best practice is for placing a series of bits and bytes read in from a file/external source into a packed structure.

For example the program header from an mpeg stream:

00 00 01 BA 7F FF FF 8A D4 01 86 66 CF F8

Should fill these variables in my packed structure:
uint32 sync_bytes;
unsigned mask1 : 2;
unsigned system_clock_ref1 : 3;
unsigned mask2 : 1;
unsigned system_clock_ref2 : 15;
unsigned mask3 : 1;
unsigned system_clock_ref3 : 15;
unsigned mask4 : 1;
unsigned system_ext : 9;
unsigned mask5 : 1;
unsigned mux_rate : 22;
unsigned mask6 : 2;
unsigned reserved : 5;
unsigned stuffing_length : 3;

The masks should be like the purple values shown here: [url=""][/url]

I think I am going wrong with the endianness of the system.

I have also thought about serialisation of the data and literally stepping through each bit, this seems overly cautious and slow.

I'd be happy to hear any thoughts on this.

Thanks in advance.


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this