When does ros calls serialize::read()
write()
methods? when message is publishing, does it call serialization::write
internally? and If I am subscribing to particular type on receiver side, does it call instantiate()
or read()
method? Lets assume when I publish rosbag::MessageInstance
from publisher, and I am subscribed to MsgType
, does it call instantiate()
? how does it convert ros:MessageInstance
to MsgType
?
Originally posted by debonair on ROS Answers with karma: 17 on 2019-02-12
Post score: 0
Original comments
Comment by gregbowers on 2023-06-27:
In ROS, the ros::serialization::read() method is used for deserialization, converting serialized data into a ROS message object. On the other hand, the ros::serialization::write() method is used for serialization, converting a ROS message object into a byte stream.
When you publish a message, ROS internally calls ros::serialization::write() to serialize the message before sending it over the network.
When you subscribe to a particular message type, ROS internally calls the instantiate() method of the message type to create an instance of that message type. Then, it calls the ros::serialization::read() method to deserialize the received byte stream into the instantiated message object.
If you publish a rosbag::MessageInstance from a publisher and subscribe to MsgType on the receiver side, ROS will internally call instantiate() to create an instance of MsgType. Then it will call ros::serialization::read() to deserialize the rosbag::MessageInstance into the MsgType object.
This allows