mcap_ros1.writer module

class mcap_ros1.writer.Writer(output: str | IO[Any] | BufferedWriter, chunk_size: int = 1048576, compression: CompressionType = CompressionType.ZSTD, enable_crcs: bool = True)[source]

Bases: object

add_attachment(create_time: int, log_time: int, name: str, media_type: str, data: bytes)[source]

Writes an attachment to an MCAP 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_metadata(name: str, data: Dict[str, str])[source]

Writes metadata to an MCAP file.

Parameters:
  • name – the name of the metadata.

  • data – a dictionary of metadata key-value pairs.

finish()[source]

Finishes writing to the MCAP stream. This must be called before the stream is closed.

write_message(topic: str, message: Any, log_time: int | None = None, publish_time: int | None = None, sequence: int = 0)[source]

Writes a message to the MCAP stream, automatically registering schemas and channels as needed.

Parameters:
  • topic – The topic of the message.

  • message – The message to write.

  • log_time – The time at which the message was logged as a nanosecond UNIX timestamp. Will default to the current time if not specified.

  • publish_time – The time at which the message was published as a nanosecond UNIX timestamp. Will default to log_time if not specified.

  • sequence – An optional sequence number.