ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A
Ask Your Question

ros::desrialize messages

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

dforer gravatar image

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

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()

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

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

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


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 -0600 )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 -0600 )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 -0600 )edit

Your Answer

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

Add Answer

Question Tools



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

Seen: 879 times

Last updated: Oct 04 '18