MCAPChannel

class osi_utilities.tracefile.mcap_channel.MCAPChannel(mcap_writer)[source]

Bases: object

Helper for writing OSI messages to an external MCAP writer.

Use this when you already have a mcap.writer.Writer instance and want to add OSI channels/messages to it.

Usage:

from mcap.writer import Writer
with open("output.mcap", "wb") as f:
    writer = Writer(f)
    writer.start()
    channel = MCAPChannel(writer)
    channel.add_channel("ground_truth", GroundTruth)
    channel.write_message(gt_msg, "ground_truth")
    writer.finish()
Parameters:

mcap_writer (McapRawWriter)

add_channel(topic, message_class, metadata=None)[source]

Register an OSI channel with the external writer.

Parameters:
  • topic (str) – Channel topic name.

  • message_class (type[Message]) – The protobuf message class.

  • metadata (dict[str, str] | None) – Optional channel metadata.

Returns:

The channel ID.

Return type:

int

write_message(message, topic)[source]

Write an OSI message to a registered channel.

Parameters:
  • message (Message) – The protobuf message.

  • topic (str) – The channel topic.

Returns:

True on success.

Return type:

bool

static prepare_required_file_metadata()[source]

Prepare required net.asam.osi.trace metadata.

Return type:

dict[str, str]