FrameCodec

Trait FrameCodec 

Source
pub trait FrameCodec:
    Send
    + Sync
    + 'static {
    type Frame: Send + Sync + 'static;
    type Decoder: Decoder<Item = Self::Frame, Error = Error> + Send;
    type Encoder: Encoder<Self::Frame, Error = Error> + Send;

    // Required methods
    fn decoder(&self) -> Self::Decoder;
    fn encoder(&self) -> Self::Encoder;
    fn frame_payload(frame: &Self::Frame) -> &[u8] ;
    fn wrap_payload(payload: Vec<u8>) -> Self::Frame;
    fn max_frame_length(&self) -> usize;

    // Provided method
    fn correlation_id(_frame: &Self::Frame) -> Option<u64> { ... }
}
Expand description

Trait for pluggable frame codecs supporting different wire protocols.

Implementors define their own Frame type (for example, a struct carrying transaction identifiers) and provide decoder/encoder instances.

Required Associated Types§

Source

type Frame: Send + Sync + 'static

Frame type produced by decoding.

Source

type Decoder: Decoder<Item = Self::Frame, Error = Error> + Send

Decoder type for this codec.

Source

type Encoder: Encoder<Self::Frame, Error = Error> + Send

Encoder type for this codec.

Required Methods§

Source

fn decoder(&self) -> Self::Decoder

Create a Tokio decoder for this codec.

Source

fn encoder(&self) -> Self::Encoder

Create a Tokio encoder for this codec.

Source

fn frame_payload(frame: &Self::Frame) -> &[u8]

Extract the message payload bytes from a frame.

Source

fn wrap_payload(payload: Vec<u8>) -> Self::Frame

Wrap serialized payload bytes into a frame for sending.

Source

fn max_frame_length(&self) -> usize

Maximum frame length this codec will accept.

Provided Methods§

Source

fn correlation_id(_frame: &Self::Frame) -> Option<u64>

Extract correlation ID for request/response matching.

Returns None for protocols without correlation (for example, RESP).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl FrameCodec for LengthDelimitedFrameCodec

Source§

type Frame = Bytes

Source§

type Decoder = LengthDelimitedDecoder

Source§

type Encoder = LengthDelimitedEncoder