Skip to main content

Encoder

Trait Encoder 

pub trait Encoder {
    type Item;
    type Error: From<Error>;

    // Required method
    fn encode(
        &mut self,
        item: Self::Item,
        dst: &mut EncodeBuf<'_>,
    ) -> Result<(), Self::Error>;

    // Provided method
    fn buffer_settings(&self) -> BufferSettings { ... }
}
Available on crate features grpc and http and std only.
Expand description

Encodes gRPC message types

Required Associated Types§

type Item

The type that is encoded.

type Error: From<Error>

The type of encoding errors.

The type of unrecoverable frame encoding errors.

Required Methods§

fn encode( &mut self, item: Self::Item, dst: &mut EncodeBuf<'_>, ) -> Result<(), Self::Error>

Encodes a message into the provided buffer.

Only the message payload is to be written, gRPC framing is handled for you.

Codecs used by generated stubs have Status as their error type. The convention, as followed by the built-in prost codec, is to map a serialisation failure with Status::from_error_generic, which inspects the source chain and otherwise results in crate::Code::Unknown.

Provided Methods§

fn buffer_settings(&self) -> BufferSettings

Controls how rama-grpc creates and expands encode buffers.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§

§

impl<F, T> Encoder for SerdeEncoder<F, T>
where F: SerdeFormat, T: Serialize,

§

type Item = T

§

type Error = Status

§

impl<T> Encoder for ProstEncoder<T>
where T: Message,

§

type Item = T

§

type Error = Status