aws_smithy_runtime_api/client/
ser_de.rs1use crate::box_error::BoxError;
9use crate::client::interceptors::context::{Error, Input, Output};
10use crate::client::orchestrator::{HttpRequest, HttpResponse, OrchestratorError};
11use crate::impl_shared_conversions;
12use aws_smithy_types::config_bag::{ConfigBag, Storable, StoreReplace};
13use std::fmt;
14use std::sync::Arc;
15
16pub trait SerializeRequest: Send + Sync + fmt::Debug {
18 fn serialize_input(&self, input: Input, cfg: &mut ConfigBag) -> Result<HttpRequest, BoxError>;
27}
28
29#[derive(Clone, Debug)]
33pub struct SharedRequestSerializer(Arc<dyn SerializeRequest>);
34
35impl SharedRequestSerializer {
36 pub fn new(serializer: impl SerializeRequest + 'static) -> Self {
38 Self(Arc::new(serializer))
39 }
40}
41
42impl SerializeRequest for SharedRequestSerializer {
43 fn serialize_input(&self, input: Input, cfg: &mut ConfigBag) -> Result<HttpRequest, BoxError> {
44 self.0.serialize_input(input, cfg)
45 }
46}
47
48impl Storable for SharedRequestSerializer {
49 type Storer = StoreReplace<Self>;
50}
51
52impl_shared_conversions!(convert SharedRequestSerializer from SerializeRequest using SharedRequestSerializer::new);
53
54pub trait DeserializeResponse: Send + Sync + fmt::Debug {
66 #[deprecated(
75 note = "Implement `deserialize_streaming_with_config` instead. This method will be removed in a future release."
76 )]
77 fn deserialize_streaming(
78 &self,
79 response: &mut HttpResponse,
80 ) -> Option<Result<Output, OrchestratorError<Error>>> {
81 let _ = response;
82 None
83 }
84
85 fn deserialize_streaming_with_config(
90 &self,
91 response: &mut HttpResponse,
92 _cfg: &ConfigBag,
93 ) -> Option<Result<Output, OrchestratorError<Error>>> {
94 #[allow(deprecated)]
95 self.deserialize_streaming(response)
96 }
97
98 #[deprecated(
103 note = "Implement `deserialize_nonstreaming_with_config` instead. This method will be removed in a future release."
104 )]
105 fn deserialize_nonstreaming(
106 &self,
107 response: &HttpResponse,
108 ) -> Result<Output, OrchestratorError<Error>> {
109 self.deserialize_nonstreaming_with_config(response, &ConfigBag::base())
110 }
111
112 fn deserialize_nonstreaming_with_config(
119 &self,
120 response: &HttpResponse,
121 _cfg: &ConfigBag,
122 ) -> Result<Output, OrchestratorError<Error>> {
123 #[allow(deprecated)]
124 self.deserialize_nonstreaming(response)
125 }
126}
127
128#[derive(Debug)]
132pub struct SharedResponseDeserializer(Arc<dyn DeserializeResponse>);
133
134impl SharedResponseDeserializer {
135 pub fn new(serializer: impl DeserializeResponse + 'static) -> Self {
137 Self(Arc::new(serializer))
138 }
139}
140
141#[allow(deprecated)]
142impl DeserializeResponse for SharedResponseDeserializer {
143 fn deserialize_nonstreaming(
144 &self,
145 response: &HttpResponse,
146 ) -> Result<Output, OrchestratorError<Error>> {
147 self.0.deserialize_nonstreaming(response)
148 }
149
150 fn deserialize_nonstreaming_with_config(
151 &self,
152 response: &HttpResponse,
153 cfg: &ConfigBag,
154 ) -> Result<Output, OrchestratorError<Error>> {
155 self.0.deserialize_nonstreaming_with_config(response, cfg)
156 }
157
158 fn deserialize_streaming(
159 &self,
160 response: &mut HttpResponse,
161 ) -> Option<Result<Output, OrchestratorError<Error>>> {
162 self.0.deserialize_streaming(response)
163 }
164
165 fn deserialize_streaming_with_config(
166 &self,
167 response: &mut HttpResponse,
168 cfg: &ConfigBag,
169 ) -> Option<Result<Output, OrchestratorError<Error>>> {
170 self.0.deserialize_streaming_with_config(response, cfg)
171 }
172}
173
174impl Storable for SharedResponseDeserializer {
175 type Storer = StoreReplace<Self>;
176}
177
178impl_shared_conversions!(convert SharedResponseDeserializer from DeserializeResponse using SharedResponseDeserializer::new);