Skip to main content

Codec

Trait Codec 

Source
pub trait Codec {
    type SendItem;
    type SendError;
    type RecvItem;
    type RecvError;

    // Required methods
    fn encoder(
        &self,
    ) -> Box<dyn TypedEncoder<Self::SendItem, Error = Self::SendError> + Send + Sync>;
    fn decoder(
        &self,
    ) -> Box<dyn TypedDecoder<Item = Self::RecvItem, Error = Self::RecvError> + Send + Sync>;
}
Expand description

Represents a specific encoding and decoding scheme for one side of a connection.

The codec defines what messages the user is spected to send to the other side, as well as the messages that are expected to be received from the other side.

The encoders and decoders generated by the Codec handle any optional transformations, such as compression, as configured during protocol negotiation.

Required Associated Types§

Source

type SendItem

The type of message that is sent to the other side.

Source

type SendError

The type of error that is returned if encoding fails.

Source

type RecvItem

The type of message that is expected to be received from the other side.

Source

type RecvError

The type of error that is returned if decoding fails.

Required Methods§

Source

fn encoder( &self, ) -> Box<dyn TypedEncoder<Self::SendItem, Error = Self::SendError> + Send + Sync>

Generates a new encoder for encoding messages to be sent to the other side of the connection.

Source

fn decoder( &self, ) -> Box<dyn TypedDecoder<Item = Self::RecvItem, Error = Self::RecvError> + Send + Sync>

Generates a new decoder for encoding messages to be sent to the other side of the connection.

Implementors§