aws_smithy_json/protocol/
aws_rest_json_1.rs1use crate::codec::{JsonCodec, JsonCodecSettings};
17use aws_smithy_schema::http_protocol::HttpBindingProtocol;
18use aws_smithy_schema::{Schema, ShapeId};
19use aws_smithy_types::config_bag::ConfigBag;
20
21static PROTOCOL_ID: ShapeId = ShapeId::from_static("aws.protocols", "restJson1", "");
22
23#[derive(Debug)]
29pub struct AwsRestJsonProtocol {
30 inner: HttpBindingProtocol<JsonCodec>,
31}
32
33impl AwsRestJsonProtocol {
34 pub fn new() -> Self {
36 let codec = JsonCodec::new(
37 JsonCodecSettings::builder()
38 .use_json_name(true)
39 .default_timestamp_format(aws_smithy_types::date_time::Format::EpochSeconds)
40 .build(),
41 );
42 Self {
43 inner: HttpBindingProtocol::new(PROTOCOL_ID, codec, "application/json"),
44 }
45 }
46
47 pub fn inner(&self) -> &HttpBindingProtocol<JsonCodec> {
49 &self.inner
50 }
51}
52
53impl Default for AwsRestJsonProtocol {
54 fn default() -> Self {
55 Self::new()
56 }
57}
58
59impl aws_smithy_schema::protocol::ClientProtocolInner for AwsRestJsonProtocol {
60 type Request = aws_smithy_runtime_api::http::Request;
61 type Response = aws_smithy_runtime_api::http::Response;
62
63 fn protocol_id(&self) -> &ShapeId {
64 self.inner.protocol_id()
65 }
66
67 fn serialize_request(
68 &self,
69 input: &dyn aws_smithy_schema::serde::SerializableStruct,
70 input_schema: &Schema,
71 endpoint: &str,
72 cfg: &ConfigBag,
73 ) -> Result<aws_smithy_runtime_api::http::Request, aws_smithy_schema::serde::SerdeError> {
74 self.inner
75 .serialize_request(input, input_schema, endpoint, cfg)
76 }
77
78 fn deserialize_response<'a>(
79 &self,
80 response: &'a aws_smithy_runtime_api::http::Response,
81 output_schema: &Schema,
82 cfg: &ConfigBag,
83 ) -> Result<
84 Box<dyn aws_smithy_schema::serde::ShapeDeserializer + 'a>,
85 aws_smithy_schema::serde::SerdeError,
86 > {
87 self.inner
88 .deserialize_response(response, output_schema, cfg)
89 }
90
91 fn payload_codec(&self) -> Option<&dyn aws_smithy_schema::codec::DynCodec> {
92 self.inner.payload_codec()
93 }
94
95 fn update_endpoint(
96 &self,
97 request: &mut aws_smithy_runtime_api::http::Request,
98 endpoint: &aws_smithy_types::endpoint::Endpoint,
99 cfg: &ConfigBag,
100 ) -> Result<(), aws_smithy_schema::serde::SerdeError> {
101 self.inner.update_endpoint(request, endpoint, cfg)
102 }
103}