ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

How to serialize C++ objects containing ROS messages

asked 2014-06-18 19:44:54 -0500

sned gravatar image

Hello I have the following class I'd like to serialize:

class Foo
{  int x;
   std::vector<double> bars;
   moveit_msgs::RobotState _startState;

in the absence of any ROS/MoveIt components, I am able to serialize out/in using the Boost serialization library. I resume that if all I had was the moveit message type then I could use the move_it serialization described on MessagesSerializationAndAdaptingTypes (assuming moveit_msgs are serializable by ROS?). But when I have a class containing both then I am not sure what to do. How do I go about serializing it now? I am using ROS Groovy


edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted

answered 2014-10-01 21:30:15 -0500

tfoote gravatar image

In ROS you cannot serialize and send arbitrary datatypes, you need to use ROS message datatypes. Some libraries provide custom mappings from native datatypes to ROS message-serialized formats. But you need a target ROS message format.

More on messages here:

edit flag offensive delete link more

answered 2014-10-02 01:23:32 -0500

ahendrix gravatar image

I assume you're using boost::serialization

ROS message don't implement boost::serialization::Serializable, so you'll need to implement a serialize() function as described here:

ROS already has serializers for messages, so you may be able to use those to implement the boost serialization. I'm not aware of much documentation about how to call the ROS serializers in C++. the best place to start is probably the source:

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2014-06-18 19:44:54 -0500

Seen: 2,440 times

Last updated: Oct 02 '14