Skip to main content

EnvelopeCodec

Trait EnvelopeCodec 

Source
pub trait EnvelopeCodec: Send + Sync {
    // Required methods
    fn decode(&self, frame: &[u8]) -> Result<Inbound, CodecError>;
    fn encode(
        &self,
        msg: Outbound<'_>,
        out: &mut Vec<u8>,
    ) -> Result<(), CodecError>;
    fn encode_inbound(
        &self,
        msg: Inbound,
        out: &mut Vec<u8>,
    ) -> Result<(), CodecError>;
    fn decode_outbound<'a>(
        &self,
        frame: &'a [u8],
    ) -> Result<Outbound<'a>, CodecError>;
}
Expand description

The protocol-envelope codec: frame bytes ↔ the logical message set. Layered above (and nesting) the record-value JsonCodec, so the wire format stays pluggable; decode/encode keep the record value as an opaque Payload sliced from / spliced into the frame.

Symmetric, so one codec object serves both engines: decode/encode are the server direction (read requests / write replies) and encode_inbound / decode_outbound the client direction.

Required Methods§

Source

fn decode(&self, frame: &[u8]) -> Result<Inbound, CodecError>

Decode one frame into a logical Inbound message (server reads a request).

Source

fn encode(&self, msg: Outbound<'_>, out: &mut Vec<u8>) -> Result<(), CodecError>

Encode a logical Outbound message, appending its bytes to out (server writes a reply/event).

Source

fn encode_inbound( &self, msg: Inbound, out: &mut Vec<u8>, ) -> Result<(), CodecError>

Encode a logical Inbound message, appending its bytes to out (client writes a request). The dual of decode.

Source

fn decode_outbound<'a>( &self, frame: &'a [u8], ) -> Result<Outbound<'a>, CodecError>

Decode one frame into a logical Outbound message (client reads a reply/event). The dual of encode; the result borrows the frame (Outbound’s sub/topic are &str slices into it).

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§