Ask Your Question
0

I am unable to serialize and deserialize ros msgs.. Please Help

asked 2012-09-20 06:01:49 -0600

Ammar gravatar image

updated 2012-09-20 10:33:40 -0600

Lorenz gravatar image

Hello Community, I am using the ros::serialization library to serialize a ros msg type into a buffer. However when I pass the same buffer to a deserialize function it gives me the following error.

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

Could someone please help me in figuring this out? I literally copied both ros::serialization and ros::deserialization from the ROS wiki under roscpp. Any help is appreciated. Thanks Ammar

EDIT: Here is the code -

void Trader::serialize_task(const multiagent_coordination_msgs::TaskToken& my_task){
    namespace ser = ros::serialization;
    multiagent_coordination_msgs::Agent my_agent;
    uint32_t serial_size = ros::serialization::serializationLength(my_task);

    boost::shared_array<uint8_t> buffer(new uint8_t[serial_size]);

    ser::OStream stream(buffer.get(), serial_size);
    ser::serialize(stream, my_task);

    deserialize_task(buffer);
}

void Trader::deserialize_task(const boost::shared_array<uint8_t>& my_buffer){
    namespace ser = ros::serialization;

    multiagent_coordination_msgs::TaskToken my_task;

    uint32_t serial_size = ros::serialization::serializationLength(my_task);
    boost::shared_array<uint8_t> buffer(new uint8_t[serial_size]);

    ser::IStream stream(buffer.get(), serial_size);
    ser::deserialize(stream, my_task);
}
edit retag flag offensive close merge delete

Comments

It would help to see your code.

Lorenz gravatar imageLorenz ( 2012-09-20 06:40:41 -0600 )edit

3 Answers

Sort by ยป oldest newest most voted
1

answered 2012-09-21 10:22:47 -0600

Ammar gravatar image

I actually ended using 'pickle' in Python to do the same thing. It took away those 2 functions for literally 2 lines in code. I am sure the serialize_data in roscpp has more sophisticated purposes. However all I was trying to do was create a byte stream and send it out over a network. Then deserialize it into the data structure on the other end. For anyone else attempting similar tasks: I would highly suggesting looking at pickle.dumps and pickle.loads in Python.

edit flag offensive delete link more
0

answered 2012-09-20 10:29:52 -0600

Lorenz gravatar image

updated 2012-09-20 10:31:15 -0600

In deserialize_task, you create the IStream on the local variable buffer, not the parameter my_buffer that contains the actual serialized data. Also, I would pass the buffer size used for serialization to deserialize_task. A freshly generated empty message object might require less memory than a filled message so using the message length of the newly created message might be wrong.

edit flag offensive delete link more
0

answered 2014-12-11 00:27:40 -0600

akki gravatar image

i have work on serialization between arduino and ros . but,i am understand perfectly how to work both side. can any one help me pls.

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: 2012-09-20 06:01:49 -0600

Seen: 2,189 times

Last updated: Sep 21 '12