mcap.writer module¶
- class mcap.writer.CompressionType(value)[source]¶
Bases:
Enum
An enumeration.
- LZ4 = 2¶
- NONE = 1¶
- ZSTD = 3¶
- class mcap.writer.IndexType(value)[source]¶
Bases:
Flag
Determines what indexes should be written to the MCAP file. If in doubt, choose ALL.
- ALL = 30¶
- ATTACHMENT = 2¶
- CHUNK = 4¶
- MESSAGE = 8¶
- METADATA = 16¶
- NONE = 1¶
- class mcap.writer.Writer(output: str | IO[Any] | BufferedWriter, chunk_size: int = 1048576, compression: CompressionType = CompressionType.ZSTD, index_types: IndexType = IndexType.ALL, repeat_channels: bool = True, repeat_schemas: bool = True, use_chunking: bool = True, use_statistics: bool = True, use_summary_offsets: bool = True, enable_crcs: bool = True, enable_data_crcs: bool = False)[source]¶
Bases:
object
Writes MCAP data.
- Parameters:
output – A filename or stream to write to.
chunk_size – The maximum size of individual data chunks in a chunked file.
compression – Compression to apply to chunk data, if any.
index_types – Indexes to write to the file. See IndexType for possibilities.
repeat_channels – Repeat channel information at the end of the file.
repeat_schemas – Repeat schemas at the end of the file.
use_chunking – Group data in chunks.
use_statistics – Write statistics record.
use_summary_offsets – Write summary offset records.
- add_attachment(create_time: int, log_time: int, name: str, media_type: str, data: bytes)[source]¶
Adds an attachment to the file.
- Parameters:
log_time – Time at which the attachment was recorded.
create_time – Time at which the attachment was created. If not available, must be set to zero.
name – Name of the attachment, e.g “scene1.jpg”.
media_type – Media Type (e.g “text/plain”).
data – Attachment data.
- add_message(channel_id: int, log_time: int, data: bytes, publish_time: int, sequence: int = 0)[source]¶
Adds a new message to the file. If chunking is enabled the message will be added to the current chunk.
- Parameters:
channel_id – The id of the channel to which the message should be added.
sequence – Optional message counter assigned by publisher.
log_time – Time at which the message was recorded as nanoseconds since a user-understood epoch (i.e unix epoch, robot boot time, etc.).
publish_time – Time at which the message was published as nanoseconds since a user-understood epoch (i.e unix epoch, robot boot time, etc.).
data – Message data, to be decoded according to the schema of the channel.
- add_metadata(name: str, data: Dict[str, str])[source]¶
Adds key-value metadata to the file.
- Parameters:
name – A name to associate with the metadata.
data – Key-value metadata.
- finish()[source]¶
Writes any final indexes, summaries etc to the file. Note that it does not close the underlying output stream.
- register_channel(topic: str, message_encoding: str, schema_id: int, metadata: Dict[str, str] = {}) int [source]¶
Registers a new message channel. Returns the numeric id of the new channel.
- Parameters:
schema_id – The schema for messages on this channel. A schema_id of 0 indicates there is no schema for this channel.
topic – The channel topic.
message_encoding – Encoding for messages on this channel. See the list of well-known message encodings for common values.
metadata – Metadata about this channel.
- register_schema(name: str, encoding: str, data: bytes)[source]¶
Registers a new message schema. Returns the new integer schema id.
- Parameters:
name – An identifier for the schema.
encoding – Format for the schema. See the list of well-known schema encodings for common values. An empty string indicates no schema is available.
data – Schema data. Must conform to the schema encoding. If encoding is an empty string, data should be 0 length.
- start(profile: str = '', library: str = 'python mcap 1.2.1')[source]¶
Starts writing to the output stream.
- Parameters:
profile – The profile is used for indicating requirements for fields throughout the file (encoding, user_data, etc).
library – Free-form string for writer to specify its name, version, or other information for use in debugging.