facontidavide / ros_type_introspection

Deserialize ROS messages that are unknown at compilation time
MIT License
61 stars 30 forks source link

Serialize a message? #28

Closed rhaschke closed 5 years ago

rhaschke commented 5 years ago

Is there also a way to serialize a message from RenamedValues, i.e. the reverse process of parsing?

facontidavide commented 5 years ago

I need more context to answer this question. Serialization and deserialization need a schema, as it is called in most of serialization libraries. In ROS a schema is the MessageDefinition.

When you want to serialize message, which schema are you using? Will it be a ROS message or your own?

For example, let's say that you deserialized a JointState.

Now you are telling me that you want to "serialize it back". What do you mean exactly?

If your answer is "just re-publish the very same message as I received as a JointState" than it is easy using ShapeShifter.

rhaschke commented 5 years ago

Let's keep the example of a JointState msg. I received the message, deserialized it with your lib, now modified some values in the data structures provided by the deserialization output. This modified output should now be serialized again (of course using the same message definition) and published.

facontidavide commented 5 years ago

Good news: I can do this and I can create an example that show you how. Bad news: it is impossible to change the size of any vector, including strings.

In my use case, I was changing the timestamp, so no problem:

https://github.com/facontidavide/PlotJuggler/blob/master/plugins/ROS/TopicPublisherROS/statepublisher_rostopic.cpp#L189-L209

If you want to change values of a Pose, Point, Quaternion, Time, values in a covariance matrix, or any other type with fixed size, than it is OK.

Adding generic serialization capabilities to this library would require a lot of work, and I am not planning to work on this.

Unless, of course, there is a client that really need this and is willing to sponsor its development ;)

rhaschke commented 5 years ago

The PlotJuggler example, you are referring to, actually uses ROS serialization/deserialization methods for the compile-time-known Header type. In my case, the type would not be known at compile time. Would this still be possible?

facontidavide commented 5 years ago

Would this still be possible?

Out of the box? No.

I can imagine how this can be done, but only if we never change the size of any array/string.

Saving somewhere the offset in memory for each field, if should be possible to rewrite an area of the serialized memory in place, and later you can republish it using ShapeShifter.

rhaschke commented 5 years ago

Would this still be possible?

Out of the box? No.

That's a pity. Thanks a lot anyways. I'm sure your work will be useful for me in another context in the future.

facontidavide commented 5 years ago

If you need this feature or, in general, if you need this library to be adapted to your needs, you may want to consider the possibility to hire me as freelancer to modify the original code. Whenever an open source is sponsored, I am happy to offer rates well below the standard in our industry.

If you are interested, you can contact me at davide.faconti@gmail.com

facontidavide commented 5 years ago

I just pushed a branch related to this issue, just in case...

rhaschke commented 5 years ago

Thanks for this offer, but I can't pay software development myself. I would be happy to be paid for my open-source activity as well ;-)