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>
impl<'buf, E: BufferEncoding> EncodingEncoder<'buf, E>
Sourcepub fn new(buf: &'buf mut [u8]) -> Self
pub fn new(buf: &'buf mut [u8]) -> Self
Wrap a wire-byte buffer for stateful encoding-mediated writes.
Sourcepub fn write(&mut self, byte: u8) -> Result<(), EncodeError>
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.
Sourcepub fn write_all(&mut self, bytes: &[u8]) -> Result<(), EncodeError>
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.
Sourcepub fn wire_position(&self) -> usize
pub fn wire_position(&self) -> usize
Wire bytes written so far (the size of the produced wire frame).
Sourcepub fn remaining_wire(&self) -> usize
pub fn remaining_wire(&self) -> usize
Wire bytes remaining in the underlying buffer.