Skip to main content

aws_smithy_cbor/
protocol.rs

1/*
2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 * SPDX-License-Identifier: Apache-2.0
4 */
5
6//! RPC v2 CBOR protocol implementation.
7
8use crate::codec::{CborCodec, CborCodecSettings};
9use aws_smithy_runtime_api::http::{Request, Response};
10use aws_smithy_schema::http_protocol::HttpRpcProtocol;
11use aws_smithy_schema::protocol::ClientProtocolInner;
12use aws_smithy_schema::serde::{SerdeError, SerializableStruct, ShapeDeserializer};
13use aws_smithy_schema::{shape_id, Schema, ShapeId};
14use aws_smithy_types::config_bag::ConfigBag;
15
16/// RPC v2 CBOR protocol (`smithy.protocols#rpcv2Cbor`).
17#[derive(Debug)]
18pub struct RpcV2CborProtocol {
19    inner: HttpRpcProtocol<CborCodec>,
20}
21
22impl RpcV2CborProtocol {
23    /// Creates a new RPC v2 CBOR protocol instance.
24    pub fn new() -> Self {
25        Self {
26            inner: HttpRpcProtocol::new(
27                shape_id!("smithy.protocols", "rpcv2Cbor"),
28                CborCodec::new(CborCodecSettings::default()),
29                "application/cbor",
30            ),
31        }
32    }
33}
34
35impl Default for RpcV2CborProtocol {
36    fn default() -> Self {
37        Self::new()
38    }
39}
40
41impl ClientProtocolInner for RpcV2CborProtocol {
42    type Request = Request;
43    type Response = Response;
44
45    fn protocol_id(&self) -> &ShapeId {
46        self.inner.protocol_id()
47    }
48
49    fn serialize_request(
50        &self,
51        input: &dyn SerializableStruct,
52        input_schema: &Schema,
53        endpoint: &str,
54        cfg: &ConfigBag,
55    ) -> Result<Request, SerdeError> {
56        self.inner
57            .serialize_request(input, input_schema, endpoint, cfg)
58    }
59
60    fn deserialize_response<'a>(
61        &self,
62        response: &'a Response,
63        output_schema: &Schema,
64        cfg: &ConfigBag,
65    ) -> Result<Box<dyn ShapeDeserializer + 'a>, SerdeError> {
66        self.inner
67            .deserialize_response(response, output_schema, cfg)
68    }
69
70    fn payload_codec(&self) -> Option<&dyn aws_smithy_schema::codec::DynCodec> {
71        self.inner.payload_codec()
72    }
73
74    fn update_endpoint(
75        &self,
76        request: &mut Request,
77        endpoint: &aws_smithy_types::endpoint::Endpoint,
78        cfg: &ConfigBag,
79    ) -> Result<(), SerdeError> {
80        self.inner.update_endpoint(request, endpoint, cfg)
81    }
82}