Trait Decode

Source
pub trait Decode {
    type Item;
    type Error;

    // Required method
    fn decode(
        &mut self,
        buffer: &mut [u8],
    ) -> (usize, DecodeResult<Self::Item, Self::Error>);
}
Expand description

Trait for values that can be decoded from a byte buffer

Required Associated Types§

Source

type Item

The item being decoded

Source

type Error

The error that may arise from a decode operation

Note that this should not be returned in the event of an unexpected end-of-buffer. Instead, a DecodeResult::UnexpectedEnd should be used.

Required Methods§

Source

fn decode( &mut self, buffer: &mut [u8], ) -> (usize, DecodeResult<Self::Item, Self::Error>)

Attempt to decode a value from the buffer

Returns the number of bytes consumed from the buffer, along with a DecodeResult with either an item, error, or “need more bytes.”

Note that the “bytes consumed” return value should only be non-zero if either the buffer contains a full frame, or if internal buffering is employed.

Implementors§