mcap_protobuf.reader module

the mcap_protobuf.reader module provides high-level protobuf message reading capability. For more low-level control, consider using the underlying mcap_protobuf.decoder.Decoder and mcap.reader.McapReader objects directly.

class mcap_protobuf.reader.McapProtobufMessage(proto_msg: Any, message: Message, channel: Channel)[source]

Bases: object

Contains a single protobuf message and associated metadata from an MCAP file.

Variables:
  • proto_msg – the decoded protobuf message.

  • sequence_count – the message sequence count if included in the MCAP, or 0 otherwise.

  • topic – the topic that the message was published on.

  • channel_metadata – the metadata associated with this protobuf topic, if any.

  • log_time_ns – the time this message was logged by the recorder, as a POSIX nanosecond timestamp.

  • log_time_ns – the time this message was published, as a POSIX nanosecond timestamp.

property log_time: datetime

The timestamp representing when this message was logged by the recorder.

property publish_time: datetime

The timestamp representing when this message was published.

mcap_protobuf.reader.read_protobuf_messages(source: Union[str, bytes, PathLike, McapReader, IO[bytes]], topics: Optional[Iterable[str]] = None, start_time: Optional[Union[int, datetime]] = None, end_time: Optional[Union[int, datetime]] = None, log_time_order: bool = True, reverse: bool = False) Iterator[McapProtobufMessage][source]

High-level generator that reads protobuf messages out of an MCAP.

Parameters:
  • source – some source of MCAP file data. Supply a stream of bytes, an McapReader instance, or the path to a valid MCAP file in the filesystem.

  • topics – an optional list of topics to read from the MCAP file.

  • start_time – if not None, messages logged before this time will not be included.

  • end_time – if not None, messages logged at this timestamp or after will not be included.

  • log_time_order – if True, messages will be yielded in ascending log time order. If False, messages will be yielded in the order they appear in the MCAP file.

  • reverse – if both log_time_order and reverse are True, messages will be yielded in descending log time order.

Yields:

an McapProtobufMessage instance for each protobuf message in the MCAP file.

Note

this generator assumes the source MCAP contains only Protobuf-encoded messages. If you need to decode protobuf messages from a file containing other encodings, use the mcap.reader.McapReader.iter_messages() function to iterate through Message records in your MCAP, and decode the protobuf messages with the mcap_protobuf.decoder.Decoder class.