pub trait Codec:
Send
+ Sync
+ 'static {
// Required methods
fn encoder_content_type(&self, accept: Option<&str>) -> String;
fn encode<T: Message + Serialize>(
&self,
val: &T,
mime: Option<&str>,
) -> Result<Bytes, GatewayError>;
fn decode<T: Message + Default + DeserializeOwned>(
&self,
buf: &[u8],
mime: Option<&str>,
) -> Result<T, GatewayError>;
}Expand description
Defines how to encode and decode gRPC messages to/from HTTP bodies.
This trait abstracts the serialization logic, enabling the gateway to support various wire formats.
Required Methods§
Sourcefn encoder_content_type(&self, accept: Option<&str>) -> String
fn encoder_content_type(&self, accept: Option<&str>) -> String
Returns the content type that this codec will use for encoding.
§Parameters
accept: TheAcceptheader value from the request, if any.
Sourcefn encode<T: Message + Serialize>(
&self,
val: &T,
mime: Option<&str>,
) -> Result<Bytes, GatewayError>
fn encode<T: Message + Serialize>( &self, val: &T, mime: Option<&str>, ) -> Result<Bytes, GatewayError>
Sourcefn decode<T: Message + Default + DeserializeOwned>(
&self,
buf: &[u8],
mime: Option<&str>,
) -> Result<T, GatewayError>
fn decode<T: Message + Default + DeserializeOwned>( &self, buf: &[u8], mime: Option<&str>, ) -> Result<T, GatewayError>
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.