Struct mcap::write::Writer

source ·
pub struct Writer<'a, W: Write + Seek> { /* private fields */ }
Expand description

Writes an MCAP file to the given writer.

Users should call finish() to flush the stream and check for errors when done; otherwise the result will be unwrapped on drop.

Implementations§

source§

impl<'a, W: Write + Seek> Writer<'a, W>

source

pub fn new(writer: W) -> McapResult<Self>

source

pub fn add_channel(&mut self, chan: &Channel<'a>) -> McapResult<u16>

Adds a channel (and its provided schema, if any), returning its ID.

Useful with subequent calls to write_to_known_channel()

source

pub fn write(&mut self, message: &Message<'a>) -> McapResult<()>

Write the given message (and its provided channel, if needed).

source

pub fn write_to_known_channel( &mut self, header: &MessageHeader, data: &[u8] ) -> McapResult<()>

Write a message to an added channel, given its ID.

This skips hash lookups of the channel and schema if you already added them.

source

pub fn attach(&mut self, attachment: &Attachment<'_>) -> McapResult<()>

source

pub fn write_metadata(&mut self, metadata: &Metadata) -> McapResult<()>

source

pub fn flush(&mut self) -> McapResult<()>

Finishes the current chunk, if we have one, and flushes the underlying writer.

We finish the chunk to guarantee that the file can be streamed by future readers at least up to this point. (The alternative is to just flush the writer mid-chunk. But if we did that, and then writing was suddenly interrupted afterwards, readers would have to try to recover a half-written chunk, probably with an unfinished compresion stream.)

Note that lossless compression schemes like LZ4 and Zstd improve as they go, so larger chunks will tend to have better compression. (Of course, this depends heavily on the entropy of what’s being compressed! A stream of zeroes will compress great at any chunk size, and a stream of random data will compress terribly at any chunk size.)

source

pub fn finish(&mut self) -> McapResult<()>

Finishes any current chunk and writes out the rest of the file.

Subsequent calls to other methods will panic.

Trait Implementations§

source§

impl<'a, W: Write + Seek> Drop for Writer<'a, W>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'a, W> RefUnwindSafe for Writer<'a, W>where W: RefUnwindSafe,

§

impl<'a, W> Send for Writer<'a, W>where W: Send,

§

impl<'a, W> !Sync for Writer<'a, W>

§

impl<'a, W> Unpin for Writer<'a, W>where W: Unpin,

§

impl<'a, W> UnwindSafe for Writer<'a, W>where W: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.