2

I am new to data serialization in c++, I searched for examples but I was not really successful. My goal is to be able to send and receive a pcl point cloud over tcp in c++. I am familiar with ROS, but now I cannot use it in the server. I have to send point cloud through ethernet to a client machine, where I am free to use ROS.

I tried Python with ZeroMQ configured to send the point cloud in numpy array. The message contained a json markdown with the array shape and then another message contained the array. If i am correct, in c++ I should serialize my pcl::PointCloud<pcl::PointXYZ> cloud object to be able to send it somehow. In case of c++ I cannot find it possible to send array shape as markdown. Is it possible in c++ to send this cloud object similar as in zmq? Or is there a more handy approach to this problem?

update: In cpp, I read the point cloud from camera, into pcl::PointCloud<pcl::PointXYZ> object. My goal is to send somehow this data through tcp and be able to reconstruct into a similar point cloud object preferably in cpp.

Martzi
  • 43
  • 7
  • What should the serialized data look like? Can you update your answer with an example of the Python/C++ datatypes and the serialized data? – rveerd Feb 01 '21 at 15:17
  • Yes, i updated. I should encode pcl::PointCloud before sending with zmq, and be able to decode into the same type. – Martzi Feb 01 '21 at 15:30

1 Answers1

1

C++ does not provide a standard method to serialize and deserialize data.

You can implement this yourself for simple cases.

For more complex cases you can use a library, such as protocol buffers or Boost serialization.

You can also use a text-based format "on the wire", such as XML or JSON.

rveerd
  • 3,620
  • 1
  • 14
  • 30
  • Thanks, I also looked around and find [this](https://stackoverflow.com/a/234740) helpful answer about serialization. In my case I cannot modify the pcd structure so if I am right, I have to use your mentioned boost or protobuf library?As I inspect pcd, there are `operator<<` defined. Does it really make easier this serialization [in this form](https://pointclouds.org/documentation/common_2include_2pcl_2point__cloud_8h_source.html) or do I need to write a serialization/deserialization from scratch, related to pcl data structure? Another q: If i use zmq in c++, do I still need to serialize? – Martzi Feb 01 '21 at 16:49
  • You do not need to modify any existing structure. You can create functions to write data from the object to a stream and to read data from a stream and re-create the object. ZeroMQ does not provide serialization. – rveerd Feb 01 '21 at 18:05