ROS serialization&deserialization [URGENT]
Hi guys ! I want to serialize and deserialize ROS messages in order to send them over UDP to make other stuff. I've already managed to do serialization like so:
/// \brief serializes an interAgentInfo message to send over UDP as a string
/// of bytes.
/// \param msg - pointer to interAgentInfo object to be serialized
/// \param packet - uint8_t vector containing the serialized message
void serializeInterAgentInfo(interAgentInfo *msg, uint8_t **packet, uint32_t *packet_size)
{
pthread_mutex_lock (&message_mutex); //Lock mutex
uint32_t serial_size = ros::serialization::serializationLength( *msg );
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;
pthread_mutex_unlock (&message_mutex); //Unlock mutex
}
The deserialization would also be easy if i had a "normal" message. The message interAgentInfo has some variable sized vectors. I don't seem to find any helpful documentation anywhere to solve my problem. I can't either get strlen() of the generated packet as i was expecting doing ...
Any hints guys ?
Thanks in advance to you all,
Pedro