Sign in to follow this  
fanaticlatic

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:

[CODE]
00 00 01 BA 7F FF FF 8A D4 01 86 66 CF F8
[/CODE]

Should fill these variables in my packed structure:
[CODE]
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;
[/CODE]

The masks should be like the purple values shown here: [url="http://dvd.sourceforge.net/dvdinfo/packhdr.html"]http://dvd.sourcefor...fo/packhdr.html[/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.

hinchy

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