Ask Your Question
0

roscpp - Convert uint8[] into a known struct

asked 2013-08-12 11:38:56 -0500

Hendrik Wiese gravatar image

Hi folks,

I've got a universal message type for all kinds of data that comes in through a UDP socket. This message just contains a fixed size array of uint8[16].

What I would like to do is to convert the uint8 array into a pre-defined struct. I know what the struct has to look like so if I just had a usual C array of chars I'd just do a cast. But IIRC that doesn't work with a uint8[] since it is a more complex type of array.

So how do I do that? How do I kind of unmarshall that uint8 array into a struct?

Thanks a lot!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2013-08-12 12:02:52 -0500

Hendrik Wiese gravatar image

Got it working. It's really just as simple as

typedef struct {
  char a;
  float b;
  char c;
} stc;

And later...

stc* d = (stc*)&msg.data;

Since the other side of the line does packing and converting endianness I had to take care of having all the uint8 in the right place before doing this.

It's working. Thanks anyway!

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2013-08-12 11:38:56 -0500

Seen: 540 times

Last updated: Aug 12 '13