pub struct Writer<'a, W: Write + Seek> { /* private fields */ }
Expand description
Implementations§
source§impl<'a, W: Write + Seek> Writer<'a, W>
impl<'a, W: Write + Seek> Writer<'a, W>
pub fn new(writer: W) -> McapResult<Self>
sourcepub fn add_channel(&mut self, chan: &Channel<'a>) -> McapResult<u16>
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()
sourcepub fn write(&mut self, message: &Message<'a>) -> McapResult<()>
pub fn write(&mut self, message: &Message<'a>) -> McapResult<()>
Write the given message (and its provided channel, if needed).
sourcepub fn write_to_known_channel(
&mut self,
header: &MessageHeader,
data: &[u8]
) -> McapResult<()>
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.
pub fn attach(&mut self, attachment: &Attachment<'_>) -> McapResult<()>
pub fn write_metadata(&mut self, metadata: &Metadata) -> McapResult<()>
sourcepub fn flush(&mut self) -> McapResult<()>
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.)
sourcepub fn finish(&mut self) -> McapResult<()>
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.