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::ClientProtocol for AwsRestJsonProtocol {
60 fn protocol_id(&self) -> &ShapeId {
61 self.inner.protocol_id()
62 }
63
64 fn serialize_request(
65 &self,
66 input: &dyn aws_smithy_schema::serde::SerializableStruct,
67 input_schema: &Schema,
68 endpoint: &str,
69 cfg: &ConfigBag,
70 ) -> Result<aws_smithy_runtime_api::http::Request, aws_smithy_schema::serde::SerdeError> {
71 self.inner
72 .serialize_request(input, input_schema, endpoint, cfg)
73 }
74
75 fn deserialize_response<'a>(
76 &self,
77 response: &'a aws_smithy_runtime_api::http::Response,
78 output_schema: &Schema,
79 cfg: &ConfigBag,
80 ) -> Result<
81 Box<dyn aws_smithy_schema::serde::ShapeDeserializer + 'a>,
82 aws_smithy_schema::serde::SerdeError,
83 > {
84 self.inner
85 .deserialize_response(response, output_schema, cfg)
86 }
87}