I have buffer/payload of integers where every 4 bytes is a field which i need to extract.
I have a pointer pointing to the buffer. Now I have to extract 4 bytes and assign it to variable until I reach the end of buffer.
The pointer is uint8_t pointer to the buf and buf is a buffer object whose details are encapsulated.
What is the best and the most elegant way to do this?
I am coding in c++. Any suggestions is appreciated.
I have buffer/payload of integers where every 4 bytes is a field which i
Share
If the integers in your buffer are word-aligned, you could try:
Otherwise, perhaps safer and more preferable:
BTW: make sure you don’t have a problem with endianess (i.e. both your machine and the machine that saved those ints must have the same endianess for this to work, otherwise you need to compensate). You’re relying on your specific implementation of C++ here.