Skip to main content

ByteWriter

Struct ByteWriter 

Source
pub struct ByteWriter<'a> { /* private fields */ }
Expand description

Destination of an encoding.

A writer either appends to a Vec<u8> or only counts octets (ByteWriter::counter), which is how encoded lengths are computed with the very same code that encodes.

Typed encoders cannot return errors; the rare failures (an array with more than i32::MAX elements) are recorded with ByteWriter::fail and reported by ByteWriter::status.

Implementations§

Source§

impl<'a> ByteWriter<'a>

Source

pub fn new(buffer: &'a mut Vec<u8>) -> Self

Starts a new outermost value at the current end of buffer.

Source

pub fn counter() -> ByteWriter<'static>

A writer that stores nothing and only counts the octets written.

Source

pub fn position(&self) -> usize

Octets written since the start of the outermost value.

Source

pub fn align(&mut self, boundary: usize)

Writes zero octets until the position is a multiple of boundary.

Source

pub fn put_u8(&mut self, octet: u8)

Writes one octet.

Source

pub fn put_slice(&mut self, octets: &[u8])

Writes octets as they are.

Source

pub fn put_count(&mut self, count: usize)

Writes the element count of a variable array (HLAinteger32BE, no alignment is performed).

A count above i32::MAX records EncoderError::TooManyElements.

Source

pub fn fail(&mut self, error: EncoderError)

Records that the value being written cannot be encoded. The first error wins.

Source

pub fn status(&self) -> Result<(), EncoderError>

Err with the first recorded error, Ok if the encoding is sound so far.

Trait Implementations§

Source§

impl<'a> Debug for ByteWriter<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> !UnwindSafe for ByteWriter<'a>

§

impl<'a> Forget for ByteWriter<'a>

§

impl<'a> Freeze for ByteWriter<'a>
where &'a mut Vec<u8>: Freeze, &'static str: Freeze, *const u8 is !null: Freeze, PhantomData<u8>: Freeze,

§

impl<'a> Move for ByteWriter<'a>

§

impl<'a> RefUnwindSafe for ByteWriter<'a>

§

impl<'a> Send for ByteWriter<'a>
where RawVecInner: Send, &'static str: Send,

§

impl<'a> Sync for ByteWriter<'a>
where RawVecInner: Sync,

§

impl<'a> Unpin for ByteWriter<'a>
where &'a mut Vec<u8>: Unpin, &'static str: Unpin, *const u8 is !null: Unpin,

§

impl<'a> UnsafeUnpin for ByteWriter<'a>
where &'a mut Vec<u8>: UnsafeUnpin, &'static str: UnsafeUnpin, *const u8 is !null: UnsafeUnpin, PhantomData<u8>: UnsafeUnpin,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.