roboto.formats.mcap.decoded_message#
Module Contents#
- class roboto.formats.mcap.decoded_message.DecodedMessage(msg, fields, accessor_cache=None)#
Facade for values returned from message decoders.
Provides a unified interface for working with decoded messages regardless of their original encoding format or source. Handles the conversion of decoded message data into dictionary format suitable for analysis and processing.
A decoded message is a nested
dict/ sequence / scalar value: JSON channels and the sharedmcap_codecdecoder (which handles the ROS1, ROS2/CDR, and IDL encodings) both materialize todict, so one dictionary interface serves every encoding.This class filters that decoded value down to the specified fields and presents it through a consistent dictionary interface.
- Parameters:
msg (Any)
fields (collections.abc.Sequence[roboto.formats.fields.FieldSelection])
accessor_cache (Optional[roboto.formats.mcap.accessor.AccessorCache])
- static is_path_match(attrib, field_path)#
Check if an attribute path matches or is a parent of a field path.
Determines whether a given attribute path should be included when filtering message data based on the specified fields.
- Parameters:
attrib (str) – Attribute path to check (e.g., “pose.position”).
field_path (str) – Target field path (e.g., “pose.position.x”).
- Returns:
True if the attribute matches or is a parent of the field path.
- Return type:
bool
Examples
>>> DecodedMessage.is_path_match("pose", "pose.position.x") True >>> DecodedMessage.is_path_match("pose.position", "pose.position.x") True >>> DecodedMessage.is_path_match("pose.position.x", "pose.position.x") True >>> DecodedMessage.is_path_match("velocity", "pose.position.x") False
- to_dict()#
Convert the decoded message to a dictionary format.
Extracts and organizes message data into a dictionary structure, including only the attributes that match the specified fields.
- Returns:
Dictionary containing the filtered message data with attribute names as keys.
- Return type:
dict
Examples
>>> # Assuming fields include "pose.position.x" and "velocity" >>> decoded_msg = DecodedMessage(ros_message, fields) >>> data_dict = decoded_msg.to_dict() >>> print(data_dict) {'pose': {'position': {'x': 1.5}}, 'velocity': 2.0}