ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

How to know where the next variable begins in a serialized message?

asked 2011-06-20 20:46:57 -0500

pparescasellas gravatar image

updated 2011-06-21 04:04:10 -0500

kwc gravatar image

Hey everybody,

In the last few weeks I've been trying to serialize any ROS message received in some kind of listener node that's subscribed to all the existent topics. Once every message is serialized (using ros::serialize) I get an Ostream full of bytes. I need to deserialize this Ostream byte by byte (without using ros::deserialize) to rebuild all the containing data of any message and put the information into some xml-like format. My idea is to call __getMessageDefinition() (which is deprecated...) for each message to obtain the .msg definition so I get something like:

float64[6] a
float64[]  b
float64[]  x
int32      c

Once I have this information, I know that the first 8 bytes of the Ostream are a[0], the next 8 are a[1], etc. And the last 4 bytes belong to c. The problem would be solved if it wasn't for vectors without specified length and strings.

So my question is, how can I know how many bytes belong to a certain variable? In the example above, how can I know where b ends and x starts? There should be a way to do this right?

Thanks!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2011-06-21 01:53:17 -0500

Lorenz gravatar image

updated 2011-06-21 04:46:34 -0500

You can learn more about message definitions and the corresponding data types here.

The message slots are serialized into the binary buffer that is transmitted in the same order as specified in the message definition. You can have a look at the corresponding code in the generated message headers and, for primitive types, at the file roscpp_serialization/include/ros/serialized_message.h

edit flag offensive delete link more

Question Tools

Stats

Asked: 2011-06-20 20:46:57 -0500

Seen: 551 times

Last updated: Jun 21 '11