Working with ROS 1 Messages

Writer Example

import sys

from mcap_ros1.writer import Writer
from std_msgs.msg import String


with open(sys.argv[1], "wb") as f:
    ros_writer = Writer(f)
    for i in range(0, 10):
        ros_writer.write_message("/chatter", String(data=f"string message {i}"))
    ros_writer.finish()

Reader Example

import sys

from mcap_ros1.reader import read_ros1_messages


def main():
    for msg in read_ros1_messages(sys.argv[1]):
        print(
            f"{msg.topic} [{msg.log_time}] ({type(msg.ros_msg).__name__}): {msg.ros_msg.data}"
        )


if __name__ == "__main__":
    main()