module documentation
The Decoder: one live ROS2 message instance becomes one message dataclass.
It runs on the event loop. rclpy objects use numpy.ndarray and array.array containers and nested generated objects, none of which may cross into the server half. Each becomes a plain Python value:
- a container of bytes (uint8 or byte, fixed or not) becomes bytes;
- every other container becomes a tuple;
- a nested message becomes its own message dataclass;
- a byte scalar, which rclpy hands over as a one-byte bytes, becomes an int.
messages.is_byte_container decides the first case, so the dataclass annotation and the decoded value agree. The per-field plan is cached per message dataclass.
| Function | decode |
Convert one live ROS2 message instance into an instance of its message dataclass. |
| Function | _as |
Return a container of bytes as bytes. |
| Function | _as |
Return a byte scalar (a one-byte bytes in rclpy) as an integer. |
| Function | _element |
Return the decoder for a scalar, or None when the value already needs no work. |
| Function | _field |
Return the function that turns one rclpy field value into its plain Python value. |
| Function | _plan |
Return the field-name and field-decoder pairs for a message dataclass, in field order. |
| Function | _unchanged |
Return the value as it came (rclpy already hands over a builtin). |
Return a container of bytes as bytes.
rclpy hands over a numpy.ndarray for a fixed uint8 array, array.array('B') for a uint8 sequence and a list of one-byte bytes for an octet sequence.
def _element_decoder(element:
ElementType, nested: type[ Message] | None) -> Callable[ [ Any], Any] | None:
¶
Return the decoder for a scalar, or None when the value already needs no work.