Skip to main content

Codec

Trait Codec 

Source
pub trait Codec {
    type EncodeItem: ?Sized;
    type DecodeItem;
    type Error: Error;

    const CONTENT_TYPE: &'static str;

    // Required methods
    fn encode(
        &mut self,
        item: &Self::EncodeItem,
        destination: &mut Vec<u8>,
    ) -> Result<(), Self::Error>;
    fn decode(
        &mut self,
        payload: &[u8],
    ) -> Result<Self::DecodeItem, Self::Error>;
}
Expand description

Encodes and decodes message payloads independently of gRPC wire framing.

A codec may retain reusable serialization state. Implementations do not need to be thread safe. Payloads exclude the five-byte gRPC frame prefix, and the transport is responsible for compression and message size limits.

Required Associated Constants§

Source

const CONTENT_TYPE: &'static str

HTTP content type identifying this serialization format.

Required Associated Types§

Source

type EncodeItem: ?Sized

Message type accepted by the encoder.

Source

type DecodeItem

Owned message type returned by the decoder.

Source

type Error: Error

Serialization or deserialization failure.

Required Methods§

Source

fn encode( &mut self, item: &Self::EncodeItem, destination: &mut Vec<u8>, ) -> Result<(), Self::Error>

Appends one serialized message to destination.

The caller may reuse the buffer between messages. An implementation may leave partially appended bytes on failure; callers must discard them.

§Errors

Returns an implementation-defined error when the message cannot be encoded.

Source

fn decode(&mut self, payload: &[u8]) -> Result<Self::DecodeItem, Self::Error>

Decodes exactly one message payload.

§Errors

Returns an implementation-defined error when the payload is invalid for this codec, including unsupported trailing bytes where applicable.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§

Source§

impl Codec for PayloadCodec

Source§

const CONTENT_TYPE: &'static str = "application/grpc"

Source§

type EncodeItem = Vec<u8>

Source§

type DecodeItem = Vec<u8>

Source§

type Error = Status

Source§

impl<E, D> Codec for ProstCodec<E, D>
where E: Message, D: Message + Default,

Source§

const CONTENT_TYPE: &'static str = Self::CONTENT_TYPE

Source§

type EncodeItem = E

Source§

type DecodeItem = D

Source§

type Error = ProstCodecError