pub struct StreamWriter<W: Write> { /* private fields */ }Expand description
TLV-framed encoder for the btrfs send stream. Construct with
StreamWriter::new (writes the stream header), then call
StreamWriter::write_command for each command. Drop or call
StreamWriter::finish to release the inner writer.
Symmetric with crate::StreamReader — round trips of every
StreamCommand variant are unit-tested.
Implementations§
Source§impl<W: Write> StreamWriter<W>
impl<W: Write> StreamWriter<W>
Sourcepub fn new(inner: W, version: u32) -> Result<Self>
pub fn new(inner: W, version: u32) -> Result<Self>
Wrap inner and write the 17-byte stream header
(magic + version). version must be 1, 2, or 3.
§Errors
Returns an error on version == 0 || version > 3, or if the
underlying writer fails.
Sourcepub fn finish(self) -> Result<W>
pub fn finish(self) -> Result<W>
Flush and unwrap the inner writer. The caller is responsible
for sending an explicit StreamCommand::End terminator
beforehand if the consumer expects one (kernel-emitted
streams always terminate with End).
§Errors
Returns an error if flushing fails.
Sourcepub fn write_command(&mut self, cmd: &StreamCommand) -> Result<()>
pub fn write_command(&mut self, cmd: &StreamCommand) -> Result<()>
Encode cmd as a framed TLV command and write it to the
underlying writer. The frame’s CRC32C (raw, init=0) is
computed over the header (with the CRC field zeroed) and
payload, matching the parser’s verification.
§Errors
Returns an error if any individual attribute exceeds the 16-bit length field’s range, the total payload exceeds the 32-bit length field’s range, or the underlying writer fails.