Doing import std_msgs.msg.String
or from std_msgs.msg import String
imports a generated Python class.
The typesupport for the String
type exists on a metaclass: String.__class__._TYPE_SUPPORT
.
This value starts as None
.
It later becomes a pycapsule (with no name) when someone calls String.__class__.__import_type_support__()
.
This is done in rclpy
by check_for_type_support(msg_type)
.
It's called by the Node in create_...()
.
Afterwards inside C code the function rclpy_common_get_type_support(pymsg_type)
. blindly assumes _TYPE_SUPPORT
is a pycapsule.
The pointer from that capsule is passed to rcl_thing_init()
.
Rclpy can deserialize a ROS message to a Python instance using rclpy_deserialize()
.
It does this in these steps:
- Get the type support for the message type being deserialized
- Create some kind of instance of the message type.
- It's a
void *
returned by a function stored in a pycapsuleString.__class__._CREATE_ROS_MESSAGE
. - It's the C type support for the message. The python type support converts to/from the C type support
- It's a
- Call
rmw_deserialize()
to populate that message. - Convert the C message type to a python type
- It calls a function in a pycapsule
String.__class__._CONVERT_FROM_PY
to convert fromvoid *
toPyObject *
.
- It calls a function in a pycapsule
rclpy
can serialize a Python message to bytes using rclpy_serialize()
.
It does so using these steps: