mcap_protobuf.reader module¶
the mcap_protobuf.reader
module is deprecated. For similar functionality,
instantiate the mcap.reader.McapReader
with a
mcap_protobuf.decoder.DecoderFactory
instance, eg:
>>> from mcap.reader import make_reader
>>> from mcap_protobuf.decoder import DecoderFactory
>>> reader = make_reader(open("proto.mcap", "rb"), decoder_factories=[DecoderFactory()])
>>> for schema_, channel_, message_, proto_msg in reader.iter_decoded_messages():
>>> print(proto_msg)
MyProtoClass(data="hello")
MyProtoClass(data="goodbye")
- 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.
publish_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: str | bytes | PathLike[str] | McapReader | IO[bytes], topics: Iterable[str] | None = None, start_time: int | datetime | None = None, end_time: int | datetime | None = 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
andreverse
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 themcap_protobuf.decoder.Decoder
class.