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: http://dvd.sourcefor...fo/packhdr.html
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.