pub trait ClientProtocol<Req = Request, Res = Response>:
Send
+ Sync
+ Debug {
// Required methods
fn protocol_id(&self) -> &ShapeId<'static>;
fn serialize_request(
&self,
input: &dyn SerializableStruct,
input_schema: &Schema<'_>,
endpoint: &str,
cfg: &ConfigBag,
) -> Result<Req, SerdeError>;
fn deserialize_response<'a>(
&self,
response: &'a Res,
output_schema: &Schema<'_>,
cfg: &'a ConfigBag,
) -> Result<Box<dyn ShapeDeserializer + 'a>, SerdeError>;
fn parse_error_metadata(
&self,
response: &Res,
cfg: &ConfigBag,
) -> Result<ErrorMetadataBuilder, SerdeError>;
fn deserialize_error_response<'a>(
&self,
response: &'a Res,
cfg: &'a ConfigBag,
) -> Result<Box<dyn ShapeDeserializer + 'a>, SerdeError>;
fn update_endpoint(
&self,
request: &mut Req,
endpoint: &Endpoint,
cfg: &ConfigBag,
) -> Result<(), SerdeError>;
fn payload_codec(&self) -> Option<&dyn DynCodec>;
fn event_stream_media_type(&self) -> Option<&str>;
fn parse_event_stream_error_metadata(
&self,
payload: &[u8],
) -> Result<ErrorMetadataBuilder, SerdeError>;
}Expand description
Object-safe view of ClientProtocolInner parameterized over concrete
request / response types.
This is what callers hold behind dyn, for example,
SharedClientProtocol stores Arc<dyn ClientProtocol<Req, Res>> so the
protocol can be swapped at runtime. The generic Req / Res parameters
default to HTTP so existing call sites remain source-compatible.
Every ClientProtocolInner gets ClientProtocol for free via a blanket
impl; implementors should write ClientProtocolInner only.
Required Methods§
Sourcefn protocol_id(&self) -> &ShapeId<'static>
fn protocol_id(&self) -> &ShapeId<'static>
Returns the Smithy shape ID of this protocol.
Sourcefn serialize_request(
&self,
input: &dyn SerializableStruct,
input_schema: &Schema<'_>,
endpoint: &str,
cfg: &ConfigBag,
) -> Result<Req, SerdeError>
fn serialize_request( &self, input: &dyn SerializableStruct, input_schema: &Schema<'_>, endpoint: &str, cfg: &ConfigBag, ) -> Result<Req, SerdeError>
Serializes an operation input into a request message.
See ClientProtocolInner::serialize_request for the invariant an implementor must uphold:
the protocol owns its own framing headers and request path, and endpoint is advisory.
Sourcefn deserialize_response<'a>(
&self,
response: &'a Res,
output_schema: &Schema<'_>,
cfg: &'a ConfigBag,
) -> Result<Box<dyn ShapeDeserializer + 'a>, SerdeError>
fn deserialize_response<'a>( &self, response: &'a Res, output_schema: &Schema<'_>, cfg: &'a ConfigBag, ) -> Result<Box<dyn ShapeDeserializer + 'a>, SerdeError>
Deserializes a response message, returning a boxed ShapeDeserializer.
Sourcefn parse_error_metadata(
&self,
response: &Res,
cfg: &ConfigBag,
) -> Result<ErrorMetadataBuilder, SerdeError>
fn parse_error_metadata( &self, response: &Res, cfg: &ConfigBag, ) -> Result<ErrorMetadataBuilder, SerdeError>
Extracts canonical error metadata from a response.
See ClientProtocolInner::parse_error_metadata for the contract.
Sourcefn deserialize_error_response<'a>(
&self,
response: &'a Res,
cfg: &'a ConfigBag,
) -> Result<Box<dyn ShapeDeserializer + 'a>, SerdeError>
fn deserialize_error_response<'a>( &self, response: &'a Res, cfg: &'a ConfigBag, ) -> Result<Box<dyn ShapeDeserializer + 'a>, SerdeError>
Returns a ShapeDeserializer positioned at the body of an error
response — inside the protocol’s error envelope, where applicable.
See ClientProtocolInner::deserialize_error_response for the contract.
Sourcefn update_endpoint(
&self,
request: &mut Req,
endpoint: &Endpoint,
cfg: &ConfigBag,
) -> Result<(), SerdeError>
fn update_endpoint( &self, request: &mut Req, endpoint: &Endpoint, cfg: &ConfigBag, ) -> Result<(), SerdeError>
Updates a previously serialized request with a resolved endpoint.
Sourcefn payload_codec(&self) -> Option<&dyn DynCodec>
fn payload_codec(&self) -> Option<&dyn DynCodec>
Returns the codec used for payload (de)serialization, if any.
Sourcefn event_stream_media_type(&self) -> Option<&str>
fn event_stream_media_type(&self) -> Option<&str>
The media type used to label a structured event-stream payload, if any.
See ClientProtocolInner::event_stream_media_type for why this is a
protocol-level fact rather than a codec-level one.
Sourcefn parse_event_stream_error_metadata(
&self,
payload: &[u8],
) -> Result<ErrorMetadataBuilder, SerdeError>
fn parse_event_stream_error_metadata( &self, payload: &[u8], ) -> Result<ErrorMetadataBuilder, SerdeError>
Extracts canonical error metadata from an event-stream exception frame’s
payload.
See ClientProtocolInner::parse_event_stream_error_metadata for the
contract and for why the payload’s envelope must be parsed by the protocol
selected at runtime.