Skip to main content

AwsJsonRpcProtocol

Struct AwsJsonRpcProtocol 

Source
pub struct AwsJsonRpcProtocol { /* private fields */ }
Expand description

AWS JSON RPC protocol (awsJson1_0 / awsJson1_1).

Implementations§

Source§

impl AwsJsonRpcProtocol

Source

pub fn aws_json_1_0() -> Self

Creates an AWS JSON 1.0 protocol instance.

The X-Amz-Target prefix defaults to the Smithy service shape name from the config bag; use Self::with_target_prefix to override it.

Source

pub fn aws_json_1_1() -> Self

Creates an AWS JSON 1.1 protocol instance.

The X-Amz-Target prefix defaults to the Smithy service shape name from the config bag; use Self::with_target_prefix to override it.

Source

pub fn with_target_prefix(self, target_prefix: impl Into<String>) -> Self

Overrides the prefix of the X-Amz-Target header.

By default the prefix is the Smithy service shape name, read from the [ServiceShapeName] config-bag entry that generated clients store regardless of which protocol they were generated for. That default exists because a customer selecting this protocol through Config::builder().protocol(..) has no way to know the shape name, and an incorrect X-Amz-Target is unroutable.

Override it when a service’s target prefix is not its shape name.

Note this is not the sdkId carried by Metadata::service — an sdkId may contain spaces ("JSON RPC 10") and is not a valid header value here.

Source

pub fn with_default_namespace(self, namespace: impl Into<String>) -> Self

Configures the default Smithy namespace used to resolve relative shape IDs in JSON __type discriminator fields. Forwarded to JsonCodecSettings::default_namespace on the codec wrapped by this protocol.

AWS JSON 1.0 / 1.1 services typically emit relative __type values (the shape name without a namespace prefix). Code-generated clients call this method with the service shape’s namespace so that crate::codec::JsonDeserializer::read_discriminated_document can produce a fully-qualified discriminator.

Unlike the X-Amz-Target prefix, this is a response-parsing concern rather than request shaping — nothing on the serialization path reads it, because a serializer must always emit an absolute shape ID.

Setting it explicitly overrides the default, which is the ServiceShapeNamespace config-bag entry that generated clients store regardless of which protocol they were generated for. A caller selecting this protocol at runtime therefore gets relative __type resolution without having to know the model’s namespace; previously it had to be set by hand or discriminators stayed relative, which made the type registry silently miss the shape.

The fallback is applied per response because JsonCodec holds an Arc<JsonCodecSettings> that create_deserializer clones by pointer, so there is nowhere to store the resolved value on an immutable protocol. That costs ~46 ns per response and only when no explicit namespace was configured. The internal codec_with_bag_namespace helper in protocol/mod.rs carries the measurement and the memoization option if it ever matters.

Trait Implementations§

Source§

impl ClientProtocolInner for AwsJsonRpcProtocol

Source§

fn serialize_request( &self, input: &dyn SerializableStruct, input_schema: &Schema<'_>, _endpoint: &str, cfg: &ConfigBag, ) -> Result<Request, SerdeError>

Serializes an awsJson1_0 / awsJson1_1 request.

_endpoint is deliberately ignored: both protocols fix the request path at /, so the route is a function of the protocol rather than of the operation, and a path computed by codegen for a different protocol must not leak through when this protocol is selected at runtime via Config::builder().protocol(..). apply_http_endpoint merges the scheme and authority afterwards.

The assertion belongs here rather than in [HttpRpcProtocol] because only the concrete protocol knows whether its route is constant — RpcV2CborProtocol legitimately passes HttpRpcProtocol a computed /service/{service}/operation/{operation} route.

Source§

fn parse_error_metadata( &self, response: &Response, _cfg: &ConfigBag, ) -> Result<Builder, SerdeError>

Extracts canonical error metadata from an awsJson1_0 / awsJson1_1 response.

awsJson protocols carry the error code in the __type (or legacy code) field of the JSON body, with X-Amzn-Errortype taking priority. The error message comes from message, Message, or errorMessage body keys.

Per the ClientProtocolInner::parse_error_metadata contract the request id is not populated here — the orchestrator’s request-id pipeline attaches it separately.

deserialize_error_response is not overridden: awsJson has no error envelope, so the default (which forwards to deserialize_response against prelude::DOCUMENT) is already correct — the body root IS the error body.

Source§

fn event_stream_media_type(&self) -> Option<&str>

This protocol labels structured event-stream payloads application/json.

Must stay in agreement with the code generator’s eventStreamMessageContentType for this protocol (AwsJson.kt:95), which supplies the fallback when a protocol declares no media type.

Source§

fn parse_event_stream_error_metadata( &self, payload: &[u8], ) -> Result<Builder, SerdeError>

Parses the same JSON error envelope as ClientProtocolInner::parse_error_metadata, from an event-stream frame’s payload rather than an HTTP response body. An event-stream frame has no HTTP headers, so an empty header map is passed; the discriminator comes from the payload’s __type.

Source§

type Request = Request

The protocol’s request message type (e.g., http::Request).
Source§

type Response = Response

The protocol’s response message type (e.g., http::Response).
Source§

fn protocol_id(&self) -> &ShapeId<'static>

Returns the Smithy shape ID of this protocol.
Source§

fn deserialize_response<'a>( &self, response: &'a Response, output_schema: &Schema<'_>, cfg: &'a ConfigBag, ) -> Result<Box<dyn ShapeDeserializer + 'a>, SerdeError>

Deserializes a response message, returning a boxed [ShapeDeserializer] that supplies every member of output_schema this protocol carries in the response. Read more
Source§

fn payload_codec(&self) -> Option<&dyn DynCodec>

Returns the codec used for payload (de)serialization, if any. Read more
Source§

fn update_endpoint( &self, request: &mut Request, endpoint: &Endpoint, cfg: &ConfigBag, ) -> Result<(), SerdeError>

Updates a previously serialized request with a resolved endpoint. Read more
§

fn deserialize_error_response<'a>( &self, response: &'a Self::Response, 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. Read more
Source§

impl Debug for AwsJsonRpcProtocol

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<P> ClientProtocol<<P as ClientProtocolInner>::Request, <P as ClientProtocolInner>::Response> for P
where P: ClientProtocolInner,

§

fn protocol_id(&self) -> &ShapeId<'static>

Returns the Smithy shape ID of this protocol.
§

fn serialize_request( &self, input: &dyn SerializableStruct, input_schema: &Schema<'_>, endpoint: &str, cfg: &ConfigBag, ) -> Result<<P as ClientProtocolInner>::Request, SerdeError>

Serializes an operation input into a request message. Read more
§

fn deserialize_response<'a>( &self, response: &'a <P as ClientProtocolInner>::Response, output_schema: &Schema<'_>, cfg: &'a ConfigBag, ) -> Result<Box<dyn ShapeDeserializer + 'a>, SerdeError>

Deserializes a response message, returning a boxed [ShapeDeserializer].
§

fn parse_error_metadata( &self, response: &<P as ClientProtocolInner>::Response, cfg: &ConfigBag, ) -> Result<Builder, SerdeError>

Extracts canonical error metadata from a response. Read more
§

fn deserialize_error_response<'a>( &self, response: &'a <P as ClientProtocolInner>::Response, 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. Read more
§

fn update_endpoint( &self, request: &mut <P as ClientProtocolInner>::Request, endpoint: &Endpoint, cfg: &ConfigBag, ) -> Result<(), SerdeError>

Updates a previously serialized request with a resolved endpoint.
§

fn payload_codec(&self) -> Option<&dyn DynCodec>

Returns the codec used for payload (de)serialization, if any.
§

fn event_stream_media_type(&self) -> Option<&str>

The media type used to label a structured event-stream payload, if any. Read more
§

fn parse_event_stream_error_metadata( &self, payload: &[u8], ) -> Result<Builder, SerdeError>

Extracts canonical error metadata from an event-stream exception frame’s payload. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more