Skip to main content

Crate mcap

Crate mcap 

Source
Expand description

A library for manipulating Foxglove MCAP files, both reading:

use std::{fs, io::BufReader};

fn read_it() -> mcap::McapResult<()> {
    // Streams one record at a time, so memory scales with the largest record (or chunk),
    // not the file. Each message is linked to its channel and schema.
    let file = BufReader::new(fs::File::open("in.mcap")?);
    for message in mcap::io::MessageReader::new(file) {
        println!("{:?}", message?);
        // Or whatever else you'd like to do...
    }
    Ok(())
}

See sans_io::LinearReader for raw records, sans_io::IndexedReader for random access through the summary, and sans_io::SummaryReader for the summary alone. The read readers take a byte slice and suit data already in memory.

or writing:

use std::{collections::BTreeMap, fs, io::BufWriter};

use anyhow::Result;

use mcap::{Channel, records::MessageHeader, Writer};

fn write_it() -> Result<()> {
    // To set the profile or compression options, see mcap::WriteOptions.
    let mut out = Writer::new(
        BufWriter::new(fs::File::create("out.mcap")?)
    )?;

    // Channels and schemas are automatically assigned ID as they're serialized,
    // and automatically deduplicated with `Arc` when deserialized.
    let channel_id = out.add_channel(0, "cool stuff", "application/octet-stream", &BTreeMap::new())?;

    out.write_to_known_channel(
        &MessageHeader {
            channel_id,
            sequence: 25,
            log_time: 6,
            publish_time: 24
        },
        &[1, 2, 3]
    )?;
    out.write_to_known_channel(
        &MessageHeader {
            channel_id,
            sequence: 32,
            log_time: 23,
            publish_time: 25
        },
        &[3, 4, 5]
    )?;

    out.finish()?;

    Ok(())
}

Re-exports§

pub use read::parse_record;
pub use read::MessageStream;
pub use read::Summary;
pub use write::WriteOptions;
pub use write::Writer;

Modules§

io
Blocking std::io adapters for the sans-io readers.
read
Read MCAP data from a byte slice already in memory.
records
Raw records parsed from an MCAP file
sans_io
Read MCAP files from any source of bytes
write
Write MCAP files

Structs§

Attachment
An attachment and its metadata in an MCAP file
Channel
Describes a channel which Messages are published to in an MCAP file
Message
An event in an MCAP file, published to a Channel
Schema
Describes a schema used by one or more Channels in an MCAP file

Enums§

Compression
Compression options for chunks of channels, schemas, and messages in an MCAP file
McapError

Constants§

LIBRARY_IDENTIFIER
Default Header.library identifier for the Rust MCAP library.
MAGIC
Magic bytes for the MCAP format
VERSION
Crate version for the Rust MCAP library.

Type Aliases§

McapResult