# Publish generic message

Hello,

I have a question regarding generic ROS message publishing.

I would like to serialize/deserialize ROS messages without knowing the message type and write/read them into/from my specific file format (not bag).

Writing and serialization part can be easily done, by investigating the rosbag recorder implementation.
With the aid of the SubscriptionCallbackHelperT, I am able to subscribe to MessageEvents, which contains message in type of topic_tools::ShapeShifter. These messages can be serialized with the ros::serialization::serialize method. After that, they can be freely written to any file format.

The problem is with the read and publish part. I can get my serialized message from my format, but I am unable to create a generic message from it and publish.
As an example, I see that the rosbag player gets MessageInstaces from the bag file, which can be published via advertised publishers.
Publishers here advertised their topics and types in string representation via AdvertiseOptions, so this is a possible generic way. In this solution, the Publisher still requires a message with a correct type (or MessageInstace) for the publish method.

Maybe some casting to topic_tools::ShapeShifter or MessageInstance type would solve the issue, but I only have a byte array with the serialized message data and no compile time available type information for the deserialization.

I would like to avoid type introspection packages as additional dependencies and solve this in the ROS way.

Does anybody know, how to overcome this problem.