I receive some bytes and then I want to cast to typedef struct
with correspondent values.
My typedef struct
is:
typedef struct SomethingHeader {
uint8_t PV;
uint8_t messageID;
uint32_t stID;
} ;
I receive the array with values:
somePDU[0] = {char} 2 [0x2]
somePDU[1] = {char} 6 [0x6]
somePDU[2] = {char} 41 [0x29]
somePDU[3] = {char} -90 [0xa6]
somePDU[4] = {char} 28 [0x1c]
somePDU[5] = {char} -93 [0xa3]
somePDU[6] = {char} 55 [0x37]
somePDU[7] = {char} -50 [0xce]
somePDU[8] = {char} 0 [0x]
....
When I use reinterpret_cast<SomethingHeader*>(somePDU)
, on the watch debug mode I see:
PV = 2 [0x2]
messageID = 6 [0x6]
stID = -835214564 [0xce37a31c]
The reinterpret_cast
jumps two bytes: somePDU[2]
and somePDU[3]
, but I needed, because my expected value is 698797623 (0x29a6ce37)
It seems to me that the reinterpret_cast
only works well every 4 bytes (or with structures that occupy 4 bytes in a row).
How can I force the reinterpret_cast
not to skip those two bytes?