ros::serialization deserialize error

asked 2020-07-13 04:25:08 -0500

dapt 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.

environment OS: Ubuntu 18.04 LTS Linux s35 4.15.0-106-generic #107-Ubuntu SMP Thu Jun 4 11:27:52 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux ROS: ROS1 melodic I am using turtlebot3 burger.

I want to serialize sensor_msgs::LaserScan::ConstPtr msg. After serializing with ros::seriaklization and sending to the server, another node receives it from the server and deserializes it.

I serialized msg of sensor_msgs::LaserScan::ConstPtr with such function.

void serializeconverter(sensor_msgs::LaserScan::ConstPtr msg, uint8_t **packet, uint32_t *packet_size)
   uint32_t serial_size = ros::serialization::serializationLength(msg);
   boost::shared_array<uint8_t> serialization_buffer;
   serialization_buffer.reset( new uint8_t[serial_size]);
   ros::serialization::OStream stream( serialization_buffer.get(), serial_size );
   ros::serialization::serialize( stream, msg);
   (*packet) = serialization_buffer.get();
   (*packet_size) = serial_size;

I am creating a function to deserialize the uint8 array data created by serializeconverter(). The 1st argument gets the serialized uint8 array, the 2nd argument gets the msg pointer as the return value, and the 3rd argument gets the size of the 1st argument.

void deserializeconverter(uint8_t *packet, sensor_msgs::LaserScan::ConstPtr *msg, uint32_t packet_size){
    ros::serialization::IStream istream(packet, packet_size);
    ros::serialization::Serializer<std_msgs::String>::read(istream, *msg); //[A]

I thought I could do this, but in the line [A]

terminate called after throwing an instance of'ros::serialization::StreamOverrunException'

Has happened.

There are few documents about ros::serialization, I have seen other Q&A, but I do not know the cause. I don't know what is wrong. Could you tell me?

edit retag flag offensive close merge delete