mcap.reader module¶
High-level classes for reading content out of MCAP data sources.
- class mcap.reader.DecodedMessageTuple(schema: Schema | None, channel: Channel, message: Message, decoded_message: Any)[source]¶
- Bases: - tuple- Yielded from every iteration of - iter_decoded_messages().- decoded_message: Any¶
- Alias for field number 3 
 
- class mcap.reader.McapReader(decoder_factories: Iterable[DecoderFactory] = ())[source]¶
- Bases: - ABC- Reads data out of an MCAP file, using the summary section where available to efficiently read only the parts of the file that are needed. - Parameters:
- decoder_factories – An iterable of - DecoderFactoryinstances which can provide decoding functionality to- iter_decoded_messages().
 - abstract get_summary() Summary | None[source]¶
- Reads the (optional) summary section from the MCAP file. 
 - abstract iter_attachments() Iterator[Attachment][source]¶
- Iterates through attachment records in the MCAP. 
 - iter_decoded_messages(topics: Iterable[str] | None = None, start_time: int | None = None, end_time: int | None = None, log_time_order: bool = True, reverse: bool = False) Iterator[DecodedMessageTuple][source]¶
- iterates through messages in an MCAP, decoding their contents. - Parameters:
- topics – if not None, only messages from these topics will be returned. 
- start_time – an integer nanosecond timestamp. if provided, messages logged before this timestamp are not included. 
- end_time – an integer nanosecond timestamp. if provided, messages logged at or after this timestamp are not 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_orderand- reverseare True, messages will be yielded in descending log time order.
 
 
 - abstract iter_messages(topics: Iterable[str] | None = None, start_time: int | None = None, end_time: int | None = None, log_time_order: bool = True, reverse: bool = False) Iterator[Tuple[Schema | None, Channel, Message]][source]¶
- iterates through the messages in an MCAP. - Parameters:
- topics – if not None, only messages from these topics will be returned. 
- start_time – an integer nanosecond timestamp. if provided, messages logged before this timestamp are not included. 
- end_time – an integer nanosecond timestamp. if provided, messages logged at or after this timestamp are not 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_orderand- reverseare True, messages will be yielded in descending log time order.
 
 
 
- class mcap.reader.NonSeekingReader(stream: IO[bytes], validate_crcs: bool = False, decoder_factories: Iterable[DecoderFactory] = (), record_size_limit: int | None = 4294967296)[source]¶
- Bases: - McapReader- an McapReader for reading out of non-seekable data sources, such as a pipe or socket. - Parameters:
- stream – a file-like object for reading the source data from. 
- validate_crcs – if - True, will validate chunk and data section CRC values.
- decoder_factories – An iterable of - DecoderFactoryinstances which can provide decoding functionality to- iter_decoded_messages().
- record_size_limit – An upper bound to the size of MCAP records that this reader will attempt to load in bytes, defaulting to 4 GiB. If this reader encounters a record with a greater length, it will throw an - RecordLengthLimitExceedederror. Setting to- Noneremoves the limit, but can allow corrupted MCAP files to trigger a MemoryError exception.
 
 - get_summary() Summary | None[source]¶
- Returns a Summary object containing records from the (optional) summary section. 
 - iter_attachments() Iterator[Attachment][source]¶
- Iterates through attachment records in the MCAP. 
 - iter_messages(topics: Iterable[str] | None = None, start_time: int | None = None, end_time: int | None = None, log_time_order: bool = True, reverse: bool = False) Iterator[Tuple[Schema | None, Channel, Message]][source]¶
- Iterates through the messages in an MCAP. - Parameters:
- topics – if not None, only messages from these topics will be returned. 
- start_time – an integer nanosecond timestamp. if provided, messages logged before this timestamp are not included. 
- end_time – an integer nanosecond timestamp. if provided, messages logged at or after this timestamp are not 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_orderand- reverseare True, messages will be yielded in descending log time order.
 
 - Warning - setting log_time_order to True on a non-seekable stream will cause the entire content of the MCAP to be loaded into memory. 
 
- class mcap.reader.SeekingReader(stream: IO[bytes], validate_crcs: bool = False, decoder_factories: Iterable[DecoderFactory] = (), record_size_limit: int | None = 4294967296)[source]¶
- Bases: - McapReader- an McapReader for reading out of seekable data sources. - Parameters:
- stream – a file-like object for reading the source data from. 
- validate_crcs – if - True, will validate Chunk CRCs for any chunks read. This class does not validate the data section CRC in the DataEnd record because it is designed not to read the entire data section when reading messages. To read messages while validating the data section CRC, use- NonSeekingReader.
- decoder_factories – An iterable of - DecoderFactoryinstances which can provide decoding functionality to- iter_decoded_messages().
- record_size_limit – An upper bound to the size of MCAP records that this reader will attempt to load in bytes, defaulting to 4 GiB. If this reader encounters a record with a greater length, it will throw an - RecordLengthLimitExceedederror. Setting to- Noneremoves the limit, but can allow corrupted MCAP files to trigger a MemoryError exception.
 
 - iter_attachments() Iterator[Attachment][source]¶
- Iterates through attachment records in the MCAP. 
 - iter_messages(topics: Iterable[str] | None = None, start_time: int | None = None, end_time: int | None = None, log_time_order: bool = True, reverse: bool = False) Iterator[Tuple[Schema | None, Channel, Message]][source]¶
- iterates through the messages in an MCAP. - Parameters:
- topics – if not None, only messages from these topics will be returned. 
- start_time – an integer nanosecond timestamp. if provided, messages logged before this timestamp are not included. 
- end_time – an integer nanosecond timestamp. if provided, messages logged at or after this timestamp are not 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_orderand- reverseare True, messages will be yielded in descending log time order.
 
 
 
- mcap.reader.make_reader(stream: IO[bytes], validate_crcs: bool = False, decoder_factories: Iterable[DecoderFactory] = ()) McapReader[source]¶
- constructs the appropriate McapReader implementation for this data source.