Skip to main content

Decoder

Trait Decoder 

Source
pub trait Decoder {
    type Item: Debug;
    type Error: Debug;

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

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

Splits a byte stream into frames.

Required Associated Types§

Source

type Item: Debug

The type of decoded frames.

Source

type Error: Debug

The type of unrecoverable frame decoding errors.

If an individual message is ill-formed but can be ignored without interfering with the processing of future messages, it may be more useful to report the failure as an Item.

Required Methods§

Source

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

Attempts to decode a frame from the buffered input.

Returns Ok(Some(item)) after removing exactly one frame’s bytes from the front of src, and Ok(None) if src does not hold a complete frame yet. On None the partial frame must stay in src, it is passed in again together with the input that arrives next.

This is called repeatedly while it returns frames, and may be called with an empty buffer.

Provided Methods§

Source

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

Attempts to decode a frame once the transport reached a clean EOF.

The peer closed its write half and no further input will arrive, so this is the decoder’s chance to produce a frame from whatever is left in src, or to report a truncated one as an error. Once the transport is at EOF it is used instead of decode for every decode attempt, it may be called again after it returned None, and with an empty buffer.

The default implementation calls decode.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

§

impl Decoder for Codec

§

fn decode(&self, src: &mut BytesMut) -> Result<Option<Frame>, FrameError>

Decodes a frame.

This method is intentionally de-generified and outlined because it is very large.

§

type Item = Frame

§

type Error = FrameError

Source§

impl<T> Decoder for Rc<T>
where T: Decoder,

Source§

type Item = <T as Decoder>::Item

Source§

type Error = <T as Decoder>::Error

Source§

fn decode( &self, src: &mut BytesMut, ) -> Result<Option<<Rc<T> as Decoder>::Item>, <Rc<T> as Decoder>::Error>

Source§

fn decode_eof( &self, src: &mut BytesMut, ) -> Result<Option<<Rc<T> as Decoder>::Item>, <Rc<T> as Decoder>::Error>

Implementors§