Skip to main content

StreamWriter

Struct StreamWriter 

Source
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>

Source

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.

Source

pub fn version(&self) -> u32

Negotiated stream protocol version.

Source

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.

Source

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.

Trait Implementations§

Source§

impl<W: Debug + Write> Debug for StreamWriter<W>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<W> Freeze for StreamWriter<W>
where W: Freeze,

§

impl<W> RefUnwindSafe for StreamWriter<W>
where W: RefUnwindSafe,

§

impl<W> Send for StreamWriter<W>
where W: Send,

§

impl<W> Sync for StreamWriter<W>
where W: Sync,

§

impl<W> Unpin for StreamWriter<W>
where W: Unpin,

§

impl<W> UnsafeUnpin for StreamWriter<W>
where W: UnsafeUnpin,

§

impl<W> UnwindSafe for StreamWriter<W>
where W: UnwindSafe,

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

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 T
where U: TryFrom<T>,

Source§

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.