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

ros::desrialize messages

asked 2018-10-04 06:15:37 -0500

dforer gravatar image

updated 2018-10-04 06:16:15 -0500

Hello. I'm building a system based on ros messages (not using ros message transferring system, only its messages). I'm using python zmq system to send ros messages, and cpp zmq to receive it. On the sending side I'm using this code to serialize the msg:

    s1 = StringIO()
    s.serialize(s1)
    socket.send_multipart(s1.buflist)

which s is of type ros message type.

On the receiving side i'm using :

ros::serialization::IStream s(m.message_start, m.num_bytes - (m.message_start - m.buf.get()));

deserialize(s, message);

which message is ros message type and m is of type ros::SerializedMessage, and deserialize is ros's deserialize function

I manage to deserialize alot of ros's messages(std msgs and my own created messages) but some I cannot deserialize and get the following error:

terminate called after throwing an instance of 'ros::serialization::StreamOverrunException' what(): Buffer Overrun

How come I can deserialize some of them and some not, considering all of them are ros like messages?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2018-10-04 08:10:21 -0500

There are some strange things in you code which may be causing problems sometimes. I would expect you to be getting compiler warnings from them too.

m.num_bytes - (m.message_start - m.buf.get())

This expression in the definition of s is very unusual. You're doing arithmetic with pointers and a size_t this is not recommended. You're subtracting the pointer for the shared_array data from the pointer to the message, they are probably the same address most of the time which will make this term zero however they may occasionally be different. In this case you're calculating the difference between these two pointers in memory a largely meaningless value. What was the purpose of this piece of code?

I would recommend using this and seeing if it helps:

ros::serialization::IStream s(m.message_start, m.num_bytes);

It might help to print out some debugging information containing the size of the message so you can see if this causes the crash or not too.

Hope this helps.

edit flag offensive delete link more

Comments

Thanks. I have done some debugging printing and out that m.message_star returns nothing. I guess this might be the problem isn't it? I will just add that m.num_bytes does return the correct size.

dforer gravatar image dforer  ( 2018-10-04 09:56:16 -0500 )edit

m initializion looks like that:

   memcpy (serialized_msg.buf.get(),zmq_msg_data(&original_msg), serialized_msg.num_bytes);

    serialized_msg.message_start = serialized_msg.buf.get();
dforer gravatar image dforer  ( 2018-10-04 09:57:35 -0500 )edit

If m.message_start is zero then you'll almost certainly get a negative buffer length which may be causing your problem.

PeteBlackerThe3rd gravatar image PeteBlackerThe3rd  ( 2018-10-04 11:29:20 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2018-10-04 06:15:37 -0500

Seen: 1,047 times

Last updated: Oct 04 '18