pub trait Decoder {
    type Item;
    type Error: From<Error>;

    // Required method
    fn decode(
        &mut self,
        src: &mut BytesMut
    ) -> Result<Option<Self::Item>, Self::Error>;

    // Provided method
    fn decode_eof(
        &mut self,
        src: &mut BytesMut
    ) -> Result<Option<Self::Item>, Self::Error> { ... }
}
Expand description

Decoding of frames via buffers, for use with FramedRead.

Required Associated Types§

source

type Item

The type of items returned by decode

source

type Error: From<Error>

The type of decoding errors.

Required Methods§

source

fn decode( &mut self, src: &mut BytesMut ) -> Result<Option<Self::Item>, Self::Error>

Decode an item from the src BytesMut into an item

Provided Methods§

source

fn decode_eof( &mut self, src: &mut BytesMut ) -> Result<Option<Self::Item>, Self::Error>

Called when the input stream reaches EOF, signaling a last attempt to decode

Notes

The default implementation of this method invokes the Decoder::decode method.

Implementors§

source§

impl Decoder for BytesCodec

§

type Item = Bytes

§

type Error = Error

source§

impl Decoder for LengthCodec

§

type Item = Bytes

§

type Error = Error

source§

impl Decoder for LinesCodec

§

type Item = String

§

type Error = Error

source§

impl<Enc, Dec> Decoder for CborCodec<Enc, Dec>
where for<'de> Dec: Deserialize<'de> + 'static, for<'de> Enc: Serialize + 'static,

Decoder impl parses cbor objects from bytes

§

type Item = Dec

§

type Error = CborCodecError

source§

impl<Enc, Dec> Decoder for JsonCodec<Enc, Dec>
where for<'de> Dec: Deserialize<'de> + 'static, for<'de> Enc: Serialize + 'static,

Decoder impl parses json objects from bytes

§

type Item = Dec

§

type Error = JsonCodecError