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§
Sourceconst CONTENT_TYPE: &'static str
const CONTENT_TYPE: &'static str
HTTP content type identifying this serialization format.
Required Associated Types§
Sourcetype EncodeItem: ?Sized
type EncodeItem: ?Sized
Message type accepted by the encoder.
Sourcetype DecodeItem
type DecodeItem
Owned message type returned by the decoder.
Required Methods§
Sourcefn encode(
&mut self,
item: &Self::EncodeItem,
destination: &mut Vec<u8>,
) -> Result<(), Self::Error>
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.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".