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

Revision history [back]

click to hide/show revision 1
initial version

I made a quick work around, don't know if you will propose a better way, but here it is. In the message interAgentInfo i've put a uint16 as the first member of the message and named it packet_size.

When doing serialization, i compute :

uint32_t serial_size = ros::serialization::serializationLength( *msg );

This allows to fill in :

msg.packet_size = serial_size;

Then i serialize and send the message over UDP. On the reception side, to get the packet size, i first deserialize just the first member of the whole message, packet_size, to get the whole packet size.

/// \brief deserializes a string of bytes into a interAgentInfo message
/// \param packet - uint8_t vector containing message to deserialize
/// \param msg - pointer to interAgentInfo destination object
void deserializeInterAgentInfo(uint8_t *packet, interAgentInfo *msg)
   std_msgs::UInt16 packet_size;
   ros::serialization::IStream psize_stream(packet, 2);
   ros::serialization::deserialize(psize_stream, packet_size);
   ros::serialization::IStream istream(packet,;
   ros::serialization::deserialize(istream, *msg);

This way, from the first two bytes i get the size of the whole packet, and then i can deserialize the whole message.