eclipse-ecal / rosidl_typesupport_protobuf

Middleware agnostic ros2 static typesupport which uses Protobuf for serialization/deserialization.
Apache License 2.0
49 stars 15 forks source link

Publishing protobuf Messages in ros #35

Open Oszimilian opened 5 months ago

Oszimilian commented 5 months ago

Hello, I am not sure if I have understood this library correctly. I have a Ros node that receives protobuf messages. These messages contain a lot of deserialized messages. I want to put these messages into ros space. This means that each proto message needs to be converted into a ros message. Is this the use case for this library?

FlorianReimold commented 5 months ago

The goal of this library is serialize ROS messages with protobuf.

In ROS2, the ROS library / API itself doesn't define a data transport or a data serialization (even though it ships with a default one). The RMW (Ros Middleware Layer) needs to serialize the Ros Messages to a format that they can transmit. This is done via rosidl_typesupport packages. There are many of those packages. This one uses protobuf for serialization. It was initially developed for the rmw_ecal. eCAL doesn't really care about the data serialization, as it only transports binary blobs. However, as eCAL and Protobuf work well together, we developed the rosidl_typesupport_protobuf, which can serialize the ros messages to a binary buffer via protobuf.

If you have a serialized protobuf message in an std::string, etc. , you don't need this typesupport. You rather need to obtain the original .proto file for that message and use protoc to generate the cpp / python etc. class structure for that that message. You can then call DeserializeFromString to parse your binary blob and make if fill your class. You can now copy the data to your ROS messages. Usually it's faster to do that by hand (maybe some AI tools like ChatGPT can help here, too). However if you really have a lot of messages or the message format changes often, you can check the code in this repo, as the typesupport also generated some glue code converting from protobuf classes to the ROS message API. You could use it as a template to do some autocode generation.