Skip to main content

EncodingEncoder

Struct EncodingEncoder 

Source
pub struct EncodingEncoder<'buf, E: BufferEncoding> { /* private fields */ }
Expand description

Stateful cursor over a &mut [u8] wire buffer that writes decoded bytes through E: BufferEncoding. Constructed by MctpMedium::serialize and handed to the caller’s message_writer closure so the closure cannot bypass the encoding.

Implementations§

Source§

impl<'buf, E: BufferEncoding> EncodingEncoder<'buf, E>

Source

pub fn new(buf: &'buf mut [u8]) -> Self

Wrap a wire-byte buffer for stateful encoding-mediated writes.

Source

pub fn write(&mut self, byte: u8) -> Result<(), EncodeError>

Write one decoded byte. Advances the wire cursor by the encoding’s per-byte wire footprint. Returns EncodeError::BufferFull when the underlying wire buffer cannot fit the encoded representation.

Source

pub fn write_all(&mut self, bytes: &[u8]) -> Result<(), EncodeError>

Write a contiguous slice of decoded bytes; aborts on the first encode error. Equivalent to a for &b in bytes { self.write(b)? } loop, but more concise at call sites that just splat a byte slice.

Source

pub fn wire_position(&self) -> usize

Wire bytes written so far (the size of the produced wire frame).

Source

pub fn remaining_wire(&self) -> usize

Wire bytes remaining in the underlying buffer.

Auto Trait Implementations§

§

impl<'buf, E> Freeze for EncodingEncoder<'buf, E>

§

impl<'buf, E> RefUnwindSafe for EncodingEncoder<'buf, E>
where E: RefUnwindSafe,

§

impl<'buf, E> Send for EncodingEncoder<'buf, E>
where E: Send,

§

impl<'buf, E> Sync for EncodingEncoder<'buf, E>
where E: Sync,

§

impl<'buf, E> Unpin for EncodingEncoder<'buf, E>
where E: Unpin,

§

impl<'buf, E> UnsafeUnpin for EncodingEncoder<'buf, E>

§

impl<'buf, E> !UnwindSafe for EncodingEncoder<'buf, E>

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.