MessageBodyDecoder

Trait MessageBodyDecoder 

Source
pub trait MessageBodyDecoder {
    // Required methods
    fn is_complete(&self) -> bool;
    fn decode(&mut self, data: &mut BytesMut) -> Result<Option<Bytes>, Error>;
    fn decode_eof(
        &mut self,
        data: &mut BytesMut,
    ) -> Result<Option<Bytes>, Error>;
}
Expand description

Common trait for message body decoders. The decoder must not consume any more data once the message body is complete.

The trait is basically a copy of the Decoder trait from tokio-util. However, there are no type parameters, so that the structs implementing this trait can be treated as trait objects.

There is one additional method named is_complete which returns true if a message body has been successfully decoded. The decoder is expected to decode at most one message body. Once a message body is decoded, the decoder must not consume any more data.

The decode_eof method should return an error if the body cannot be completed.

Required Methods§

Source

fn is_complete(&self) -> bool

Returns true if the last chunk of the message body was decoded.

Source

fn decode(&mut self, data: &mut BytesMut) -> Result<Option<Bytes>, Error>

Decode a given chunk of data.

Source

fn decode_eof(&mut self, data: &mut BytesMut) -> Result<Option<Bytes>, Error>

Process end of stream.

Implementors§