I am looking for any example library by analyzing binary msg in C ++. Most people request reading a binary file or data received on a socket, but I just have a set of binary messages that I need to decode. Someone said boost :: spirit , but I could not find a suitable example for my needs.
As an example: 9A690C12E077033811FFDFFEF07F042C1CE0B704381E00B1FEFFF78004A92440
where the first 8 bits are the preamble, the next 6 bits are the msg identifier (integer from 0 to 63), the next 212 bits are data, and the last 24 bits are CRC24.
So, in this case msg 26, I have to get this data from 212 data bits:
- 4-bit integer value
- 4-bit integer value
- 9 bit floating point value from 0 to 63.875, where LSB is 0.125
- 4-bit integer value
EDIT: I need to work at the bit level, so memcpy is not a good solution, as it copies a few bytes. To get the first 4-bit integer value, I have to get 2 bits from the byte, and 2 more bits from the next byte, shift each pair and make up. What I'm asking for is a more elegant way to extract values, because I have about 20 different messages and you want a general solution for analyzing them at the bit level.
And so on.
Do you know os any library that can easily achieve this?
I also found another Q / A that uses static_cast. I thought it over, and for every person recommending this approach, there is another warning about the installations. Since I already have my message, I donβt know if this warning applies to me or just for socket communication.
EDIT: boost: dynamic_bitset looks promising. Any help to use?
source share