I am new to python and have tried searching for help prior to posting.
I have binary file that contains a number of values I need to parse. Each value has a hex header of two bytes and a third byte that gives a size of the data in that record to parse. The following is an example:
\x76\x12\x0A\x08\x00\x00\x00\x00\x00\x00\x00\x00
The \x76\x12
is the record marker and \x0A
is the number of bytes to be read next.
This data always has the two byte marker and a third byte size. However the data to be parsed is variable and the record marker increments as follows: \x76\x12
and \x77\x12
and so on until \x79\x12
where is starts again.
This is just example data for the use of this posting.
Many Thanks for any help or pointers.
Is something like this what you want?
This will treat the data as a raw string (to ignore '\' escape character and split into a list
output: ['', 'x76', 'x12', 'x0A', 'x08', 'x00', 'x00', 'x00', 'x00', 'x00', 'x00', 'x00', 'x00']
You can then iterate through the values you are interested in and convert them to decimal if required: