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

Array length handling when serializing messages

asked 2018-10-17 09:25:04 -0500

Vicente Penades gravatar image

I am trying to code a rosbag serializer, and I am trying to generate code from the messages, like https://github.com/ros/genmsg

I noticed there's an inconsitency in how to handle unbounded array lengths.

In some cases, it is assumed the array elements are preceded with the length of the array: CameraInfo

In some others, the length is calculated from other properties of the message: Image, PointCloud2

Then there's cases in which it's not clear if the length needs to be handled based on the length of the whole message itself: CompressedImage.

So, are these cases handled manually? or is there some sort of non obvious rule?

I have noticed that in the definitions of some unbounded arrays, it is stated that the length needs to be computed from other parameters.

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2018-10-17 09:55:34 -0500

Dirk Thomas gravatar image

The serialization logic only considers the length of the actual array.

Any other fields in a message containing such length information are additionally information and might (or might not) match the actual data. They are serialized independently.

edit flag offensive delete link more
0

answered 2018-10-17 10:25:29 -0500

Vicente Penades gravatar image

Keep in mind I am trying to programatically generate source code from the MSG files.

When handling image.msg the data field is defined as this:

   uint8[] data          # actual matrix data, size is (step * rows)

And, for a 4 x 4 image at 1 byte/pixel this is what I get from the file:

0 0 0 0

But when handling CameraInfo I find this:

  # The distortion parameters, size depending on the distortion model.
  # For "plumb_bob", the 5 parameters are: (k1, k2, t1, t2, k3).
  float64[] D

But this is what I get from the file:

 5 0 0 0 0 0

So both are variable length arrays, but one stores the length in the file and the other doesn't

So based on this information, I think it is not possible to generate serialization code from the MSG files unless I am missing something...

edit flag offensive delete link more

Comments

The serialization code needs to serialize the length of the dynamic array first and then the items of the array. The fact that other fields in the message indicate lengths is not relevant to the (de-)serializer.

Dirk Thomas gravatar image Dirk Thomas  ( 2018-10-17 10:30:17 -0500 )edit

it is not possible to generate serialization code from the MSG files

Since the msg files are the only input and ROS is able to serialize and deserialize messages just fine it is obviously sufficient.

Dirk Thomas gravatar image Dirk Thomas  ( 2018-10-17 10:32:24 -0500 )edit

I think it is not possible to generate serialization code from the MSG files

This is an interesting statement seeing as the whole of ROS (or at least the communication parts of it) are built on top of just that (ie: generating (de)serialisation code from .msg files).

gvdhoorn gravatar image gvdhoorn  ( 2018-10-17 12:46:15 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2018-10-17 09:25:04 -0500

Seen: 371 times

Last updated: Oct 17 '18