pub trait BufferEncoding {
// Required methods
fn write_byte(wire_buf: &mut [u8], byte: u8) -> Result<usize, EncodeError>;
fn read_byte(wire_buf: &[u8]) -> Result<(u8, usize), DecodeError>;
fn wire_size_of(decoded: &[u8]) -> usize;
}Expand description
Stateless byte-stuffing transform. Implementors define how a single logical (payload) byte maps to one or more wire bytes (encode) and how a wire-byte prefix maps back to a single payload byte (decode).
All methods are associated functions — there is no self and no
struct state. Callers own the buffers and the read/write cursors.
Required Methods§
Sourcefn write_byte(wire_buf: &mut [u8], byte: u8) -> Result<usize, EncodeError>
fn write_byte(wire_buf: &mut [u8], byte: u8) -> Result<usize, EncodeError>
Encode one logical payload byte into wire_buf starting at
index 0. Returns the number of wire bytes written (1 for plain,
2 for an escape sequence). The caller advances their write
cursor by the returned count.
Sourcefn read_byte(wire_buf: &[u8]) -> Result<(u8, usize), DecodeError>
fn read_byte(wire_buf: &[u8]) -> Result<(u8, usize), DecodeError>
Decode the next logical payload byte from wire_buf starting at
index 0. Returns (decoded_byte, wire_bytes_consumed). The
caller advances their read cursor by wire_bytes_consumed.
Sourcefn wire_size_of(decoded: &[u8]) -> usize
fn wire_size_of(decoded: &[u8]) -> usize
Wire-byte footprint of decoded under this encoding. Must equal
the sum of write_byte(_, b) lengths for each b in decoded.
NO default impl: every encoding declares its sizing rule
explicitly.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.