API Reference
Complete reference for MCAP logging APIs in Cerulion Core.For a quick start guide with examples, see the Quickstart page.
Quick Reference
| Method | Description | Category |
|---|---|---|
create() | Create a new MCAP recorder | Initialization |
register_channel() | Register a topic/channel for logging | Setup |
log_message() | Log a message to the MCAP file | Recording |
record_from_subscriber() | Record from a subscriber (standalone) | Recording |
finish() | Close the MCAP file gracefully | Cleanup |
as_arc() | Wrap recorder in Arc for sharing | Utilities |
enable_mcap_logging() | Enable logging on pub/sub | Integration |
Configuration
McapRecorderConfig
McapRecorderConfig
Description
Configuration struct for MCAP recorder settings.Fields
Optional compression setting. Can be
None, Some(Compression::Lz4), or Some(Compression::Zstd).Optional schema registry for automatic schema lookup when registering channels.
Optional list of topic patterns to include. If None, all topics are included (unless excluded).
Optional list of topic patterns to exclude from recording.
Example
Notes
Topic filtering via
McapRecorderConfig is currently defined in the API but not yet fully integrated into the recorder creation. This feature is planned for future implementation.Initialization
create()
create()
Signature
Description
Creates a new MCAP recorder that writes to a file with automatic background writing. The recorder automatically starts a background thread for asynchronous message writing to avoid blocking your application.Parameters
Path to the MCAP file to create (e.g.,
"log.mcap"). The directory must exist.Optional compression setting:
None- No compression (fastest, larger files)Some(Compression::Lz4)- LZ4 compression (balanced)Some(Compression::Zstd)- Zstandard compression (best compression)
Optional schema registry for automatic schema lookup when registering channels with message types.
Returns
Examples
Notes
The recorder automatically starts a background thread for asynchronous message writing to avoid blocking your application.
Channel Management
register_channel()
register_channel()
Signature
Description
Registers a channel (topic) with optional schema for logging. Channels are automatically registered when usinglog_message() if not already registered, but manual registration is useful when you want to specify a schema upfront.Parameters
Topic name to register. Should follow standard naming conventions (e.g.,
"sensors/imu").Optional message type name for schema lookup. If provided and a schema registry is configured, the recorder will attempt to load the schema for this message type.
Message encoding format. Common values:
"raw"- Raw binary data (no schema)"protobuf"- Protocol Buffers encoding"json"- JSON encoding"cdr"- CDR encoding (ROS2)
Returns
Examples
Notes
Channels are automatically registered when using
log_message() if not already registered. Manual registration is useful when you want to specify a schema upfront.Recording Messages
log_message()
log_message()
Signature
Description
Logs a message to the MCAP file asynchronously. Messages are queued and written by a background thread, so this call returns quickly without blocking your application.Parameters
Topic name for the message. The channel will be auto-registered if not already registered.
Message data as a byte vector. Should match the encoding specified during channel registration.
Optional timestamp in nanoseconds since Unix epoch. If
None, the current time is used automatically.Returns
Examples
Notes
record_from_subscriber()
record_from_subscriber()
Signature
Description
Records messages from a subscriber, wrapping its receive loop (standalone recorder pattern). This method automatically registers the channel if not already registered and polls the subscriber for messages.Parameters
Subscriber to record messages from. The subscriber should already be created and connected.
Topic name for the MCAP channel. This is the topic name that will appear in the MCAP file.
Mutable closure that returns
true to continue recording or false to stop. Called periodically during the recording loop.Returns
Example
Notes
This method automatically registers the channel if not already registered and polls the subscriber for messages. It’s a convenience method for standalone recording scenarios.
Cleanup
finish()
finish()
Signature
Description
Finishes writing and closes the MCAP file gracefully. This method signals the background thread to shut down, waits for all queued messages to be written, and then closes the file.Returns
Example
Notes
The
finish() method consumes the recorder. If you don’t call it explicitly, the file will be closed automatically when the recorder is dropped, but errors during cleanup won’t be reported.Utilities
as_arc()
as_arc()
Signature
Description
Wraps the recorder in anArc for sharing across threads or multiple publishers/subscribers. This is a convenience method for when you need to share the recorder.Returns
Shared reference to the recorder that can be cloned and shared across threads.
Example
See Also
enable_mcap_logging()- For enabling logging on publishers/subscribers
Integration
enable_mcap_logging()
enable_mcap_logging()
Publisher Signature
Subscriber Signature
Description
Enables MCAP logging on a publisher or subscriber. Once enabled, all messages published or received will be automatically logged to the provided recorder.Parameters
Shared reference to an MCAP recorder. All messages published/received will be automatically logged to this recorder.
Examples
Notes
The recorder must be wrapped in
Arc to allow sharing across multiple publishers/subscribers. Use as_arc() for convenience.Compression Options
MCAP supports optional compression to reduce file size.Compression Types
Speed: Fastest
Compression Ratio: 1:1 (no compression)
Best For: Real-time logging, fast storage, systems with limited CPU
Compression Ratio: 1:1 (no compression)
Best For: Real-time logging, fast storage, systems with limited CPU
Speed: Fast
Compression Ratio: 2-3:1 typical
Best For: Balanced real-time logging with moderate compression
Compression Ratio: 2-3:1 typical
Best For: Balanced real-time logging with moderate compression
Speed: Slower
Compression Ratio: 3-5:1 typical
Best For: Archival storage, offline analysis, maximizing storage efficiency
Compression Ratio: 3-5:1 typical
Best For: Archival storage, offline analysis, maximizing storage efficiency
Examples
Performance Comparison
For a typical sensor data stream (100 Hz, 1KB messages):| Compression | File Size | CPU Usage | Latency Impact |
|---|---|---|---|
| None | 360 MB | 0.1% | < 1 μs |
| LZ4 | 120 MB | 2.5% | ~10 μs |
| Zstandard | 72 MB | 8.5% | ~50 μs |
Topic Filtering
TheMcapRecorderConfig supports topic filtering through include and exclude patterns.
Filter Patterns
Filter patterns support simple string matching:- Exact match:
"sensors/imu"matches only that topic - Substring match:
"sensors/*"matches topics containing “sensors/“
Configuration
Filter Logic
- Exclude First: If a topic matches any exclude pattern, it’s excluded
- Include Check: If include patterns are specified, topic must match at least one
- Default Behavior: If no include patterns specified, all topics are included (unless excluded)
Examples
Schema Registry Integration
MCAP can use an existing schema registry for automatic schema lookup.Purpose
Schema registry integration is useful when:- Logging ROS2 messages via RCL Hooks
- Ensuring proper schema registration for ROS2 message types
- Maintaining compatibility with ROS2 tooling
- Automatic schema conversion from YAML to JSON format
Schema Registry Parameter
Example
Schema registry integration is optional. For Cerulion-native message types, schemas are automatically registered when channels are created. The recorder automatically converts YAML schemas to JSON format for MCAP.
Background Writing
The MCAP recorder uses a background thread for asynchronous message writing to avoid blocking your application.How It Works
When you call
log_message(), messages are queued in memory with minimal overheadA dedicated thread processes the queue and writes messages to disk in batches
Your application continues without waiting for disk I/O operations
The
finish() method or Drop implementation ensures all queued messages are written before closingPerformance Benefits
log_message() typically returns in microseconds, with no disk I/O blockingBatched writes improve disk performance and reduce system call overhead
Real-time publishers/subscribers aren’t affected by disk speed or filesystem latency
Example
Error Handling
All MCAP logging functions returnResult types for comprehensive error handling.