Skip to main content

ResizableBufferSink

Struct ResizableBufferSink 

Source
pub struct ResizableBufferSink<'a, Unit> { /* private fields */ }
Expand description

A byte-oriented backward-writing sink over a ResizableBuffer.

This is a safe implementation of Microsoft’s ResizableBufferSink: units are serialized to little-endian bytes and written into the byte buffer from the end toward the start. The write position is tracked as a byte count from the buffer end; growth relocates existing content to the new buffer’s end (matching Microsoft’s newBuffer.last(content.size())).

Note: this type does not implement the Sink trait (which requires returning &[Unit], impossible safely over a byte buffer). Use it with the low-level raw encoders via a manual write loop, or use VecSink when trait-based sinks are required.

Implementations§

Source§

impl<'a, Unit> ResizableBufferSink<'a, Unit>

Source

pub fn new(buffer: &'a mut dyn ResizableBuffer) -> Self

Create a sink over the given buffer.

Source

pub fn encoded_bytes(&self) -> &[u8]

The encoded bytes (written region, in write order).

Source

pub fn reset(&mut self)

Reset the write pointer, discarding content.

Source

pub fn len(&self) -> usize

Number of bytes written.

Source

pub fn is_empty(&self) -> bool

Whether nothing has been written.

Source§

impl<'a> ResizableBufferSink<'a, u8>

Source

pub fn write_u8(&mut self, unit: u8)

Write a single byte.

Source§

impl<'a> ResizableBufferSink<'a, u32>

Source

pub fn write_u32(&mut self, unit: u32)

Write a single u32 unit (little-endian).

Auto Trait Implementations§

§

impl<'a, Unit> !RefUnwindSafe for ResizableBufferSink<'a, Unit>

§

impl<'a, Unit> !Send for ResizableBufferSink<'a, Unit>

§

impl<'a, Unit> !Sync for ResizableBufferSink<'a, Unit>

§

impl<'a, Unit> !UnwindSafe for ResizableBufferSink<'a, Unit>

§

impl<'a, Unit> Freeze for ResizableBufferSink<'a, Unit>

§

impl<'a, Unit> Unpin for ResizableBufferSink<'a, Unit>
where Unit: Unpin,

§

impl<'a, Unit> UnsafeUnpin for ResizableBufferSink<'a, Unit>

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, 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.