Skip to main content

Codec

Trait Codec 

pub trait Codec:
    Send
    + Sync
    + 'static {
    type Encode: Send + Sync + 'static;
    type Decode: Send + Sync + 'static;
    type Encoder: Encoder<Item = Self::Encode, Error = Status> + Send + Sync + 'static;
    type Decoder: Decoder<Item = Self::Decode, Error = Status> + Send + Sync + 'static;

    // Required methods
    fn encoder(&mut self) -> Self::Encoder;
    fn decoder(&mut self) -> Self::Decoder;
}
Available on crate features grpc and http and std only.
Expand description

Trait that knows how to encode and decode gRPC messages.

§Content type

rama-grpc always sends and accepts application/grpc, on both the client and the server, regardless of the codec in use. There is no per-codec subtype (such as application/grpc+proto or application/grpc+json) and no content type negotiation: the codec is chosen by the generated stub, not by the peer.

A consequence is that a client and a server which are wired up with different codecs for the same path do not fail the handshake, they mis-decode each other’s messages instead. Make sure both ends of a route are generated with the same codec.

Required Associated Types§

type Encode: Send + Sync + 'static

The encodable message.

type Decode: Send + Sync + 'static

The decodable message.

type Encoder: Encoder<Item = Self::Encode, Error = Status> + Send + Sync + 'static

The encoder that can encode a message.

type Decoder: Decoder<Item = Self::Decode, Error = Status> + Send + Sync + 'static

The decoder that can decode a message.

Required Methods§

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

Fetch the encoder.

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

Fetch the decoder.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§

§

impl<F, T, U> Codec for SerdeCodec<F, T, U>
where F: SerdeFormat, T: Serialize + Send + Sync + 'static, U: DeserializeOwned + Send + Sync + 'static,

§

type Encode = T

§

type Decode = U

§

type Encoder = SerdeEncoder<F, T>

§

type Decoder = SerdeDecoder<F, U>

§

impl<T, U> Codec for ProstCodec<T, U>
where T: Message + Send + 'static, U: Message + Default + Send + 'static,

§

type Encode = T

§

type Decode = U

§

type Encoder = ProstEncoder<T>

§

type Decoder = ProstDecoder<U>