1 + | // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
|
2 + | #[non_exhaustive]
|
3 + | #[derive(Debug)]
|
4 + | pub struct EventStreamErrorMarshaller;
|
5 + |
|
6 + | impl EventStreamErrorMarshaller {
|
7 + | pub fn new() -> Self {
|
8 + | EventStreamErrorMarshaller
|
9 + | }
|
10 + | }
|
11 + | impl ::aws_smithy_eventstream::frame::MarshallMessage for EventStreamErrorMarshaller {
|
12 + | type Input = crate::types::error::EventStreamError;
|
13 + | fn marshall(
|
14 + | &self,
|
15 + | _input: Self::Input,
|
16 + | ) -> std::result::Result<::aws_smithy_types::event_stream::Message, ::aws_smithy_eventstream::error::Error> {
|
17 + | let mut headers = Vec::new();
|
18 + | headers.push(::aws_smithy_types::event_stream::Header::new(
|
19 + | ":message-type",
|
20 + | ::aws_smithy_types::event_stream::HeaderValue::String("exception".into()),
|
21 + | ));
|
22 + | let payload = match _input {
|
23 + | crate::types::error::EventStreamError::ErrorEvent(inner) => {
|
24 + | headers.push(::aws_smithy_types::event_stream::Header::new(":exception-type", ::aws_smithy_types::event_stream::HeaderValue::String("error".into())));
|
25 + | headers.push(::aws_smithy_types::event_stream::Header::new(":content-type", ::aws_smithy_types::event_stream::HeaderValue::String("application/json".into())));
|
26 + | crate::protocol_serde::shape_error_event::ser_error_event_error(&inner)
|
27 + | .map_err(|err| ::aws_smithy_eventstream::error::Error::marshalling(format!("{err}")))?
|
28 + | }
|
29 + | crate::types::error::EventStreamError::Unhandled(_inner) => return Err(
|
30 + | ::aws_smithy_eventstream::error::Error::marshalling("Cannot serialize `EventStream::Unknown` for the request. The `Unknown` variant is intended for responses only. It occurs when an outdated client is used after a new enum variant was added on the server side.".to_owned())
|
31 + | ),
|
32 + | }
|
33 + | ;
|
34 + | Ok(::aws_smithy_types::event_stream::Message::new_from_parts(headers, payload))
|
35 + | }
|
36 + | }
|
37 + |
|
38 + | #[non_exhaustive]
|
39 + | #[derive(Debug)]
|
40 + | pub struct EventStreamMarshaller;
|
41 + |
|
42 + | impl EventStreamMarshaller {
|
43 + | pub fn new() -> Self {
|
44 + | EventStreamMarshaller
|
45 + | }
|
46 + | }
|
47 + | impl ::aws_smithy_eventstream::frame::MarshallMessage for EventStreamMarshaller {
|
48 + | type Input = crate::types::EventStream;
|
49 + | fn marshall(&self, input: Self::Input) -> std::result::Result<::aws_smithy_types::event_stream::Message, ::aws_smithy_eventstream::error::Error> {
|
50 + | let mut headers = Vec::new();
|
51 + | headers.push(::aws_smithy_types::event_stream::Header::new(
|
52 + | ":message-type",
|
53 + | ::aws_smithy_types::event_stream::HeaderValue::String("event".into()),
|
54 + | ));
|
55 + | let payload = match input {
|
56 + | Self::Input::Headers(inner) => {
|
57 + | headers.push(::aws_smithy_types::event_stream::Header::new(":event-type", ::aws_smithy_types::event_stream::HeaderValue::String("headers".into())));
|
58 + | if let Some(value) = inner.boolean_header {
|
59 + | headers.push(
|
60 + | ::aws_smithy_types::event_stream::Header::new("booleanHeader", ::aws_smithy_types::event_stream::HeaderValue::Bool(value))
|
61 + | );
|
62 + | }
|
63 + | if let Some(value) = inner.byte_header {
|
64 + | headers.push(
|
65 + | ::aws_smithy_types::event_stream::Header::new("byteHeader", ::aws_smithy_types::event_stream::HeaderValue::Byte(value))
|
66 + | );
|
67 + | }
|
68 + | if let Some(value) = inner.short_header {
|
69 + | headers.push(
|
70 + | ::aws_smithy_types::event_stream::Header::new("shortHeader", ::aws_smithy_types::event_stream::HeaderValue::Int16(value))
|
71 + | );
|
72 + | }
|
73 + | if let Some(value) = inner.int_header {
|
74 + | headers.push(
|
75 + | ::aws_smithy_types::event_stream::Header::new("intHeader", ::aws_smithy_types::event_stream::HeaderValue::Int32(value))
|
76 + | );
|
77 + | }
|
78 + | if let Some(value) = inner.long_header {
|
79 + | headers.push(
|
80 + | ::aws_smithy_types::event_stream::Header::new("longHeader", ::aws_smithy_types::event_stream::HeaderValue::Int64(value))
|
81 + | );
|
82 + | }
|
83 + | if let Some(value) = inner.blob_header {
|
84 + | headers.push(
|
85 + | ::aws_smithy_types::event_stream::Header::new("blobHeader", ::aws_smithy_types::event_stream::HeaderValue::ByteArray(value.into_inner().into()))
|
86 + | );
|
87 + | }
|
88 + | if let Some(value) = inner.string_header {
|
89 + | headers.push(
|
90 + | ::aws_smithy_types::event_stream::Header::new("stringHeader", ::aws_smithy_types::event_stream::HeaderValue::String(value.into()))
|
91 + | );
|
92 + | }
|
93 + | if let Some(value) = inner.timestamp_header {
|
94 + | headers.push(
|
95 + | ::aws_smithy_types::event_stream::Header::new("timestampHeader", ::aws_smithy_types::event_stream::HeaderValue::Timestamp(value))
|
96 + | );
|
97 + | }
|
98 + | Vec::new()
|
99 + | }
|
100 + | Self::Input::BlobPayload(inner) => {
|
101 + | headers.push(::aws_smithy_types::event_stream::Header::new(":event-type", ::aws_smithy_types::event_stream::HeaderValue::String("blobPayload".into())));
|
102 + | headers.push(::aws_smithy_types::event_stream::Header::new(":content-type", ::aws_smithy_types::event_stream::HeaderValue::String("application/octet-stream".into())));
|
103 + | if let Some(inner_payload) = inner.payload {
|
104 + | inner_payload.into_inner()
|
105 + | }
|
106 + | else {
|
107 + | Vec::new()
|
108 + | }
|
109 + | }
|
110 + | Self::Input::StringPayload(inner) => {
|
111 + | headers.push(::aws_smithy_types::event_stream::Header::new(":event-type", ::aws_smithy_types::event_stream::HeaderValue::String("stringPayload".into())));
|
112 + | headers.push(::aws_smithy_types::event_stream::Header::new(":content-type", ::aws_smithy_types::event_stream::HeaderValue::String("text/plain".into())));
|
113 + | if let Some(inner_payload) = inner.payload {
|
114 + | inner_payload.into_bytes()
|
115 + | }
|
116 + | else {
|
117 + | Vec::new()
|
118 + | }
|
119 + | }
|
120 + | Self::Input::StructurePayload(inner) => {
|
121 + | headers.push(::aws_smithy_types::event_stream::Header::new(":event-type", ::aws_smithy_types::event_stream::HeaderValue::String("structurePayload".into())));
|
122 + | headers.push(::aws_smithy_types::event_stream::Header::new(":content-type", ::aws_smithy_types::event_stream::HeaderValue::String("application/json".into())));
|
123 + | if let Some(inner_payload) = inner.payload {
|
124 + | crate::protocol_serde::shape_structure_payload_event::ser_payload_payload(&inner_payload)
|
125 + | .map_err(|err| ::aws_smithy_eventstream::error::Error::marshalling(format!("{err}")))?
|
126 + | }
|
127 + | else {
|
128 + | unimplemented!("TODO(EventStream): Figure out what to do when there's no payload")
|
129 + | }
|
130 + | }
|
131 + | Self::Input::UnionPayload(inner) => {
|
132 + | headers.push(::aws_smithy_types::event_stream::Header::new(":event-type", ::aws_smithy_types::event_stream::HeaderValue::String("unionPayload".into())));
|
133 + | headers.push(::aws_smithy_types::event_stream::Header::new(":content-type", ::aws_smithy_types::event_stream::HeaderValue::String("application/json".into())));
|
134 + | if let Some(inner_payload) = inner.payload {
|
135 + | crate::protocol_serde::shape_union_payload_event::ser_payload_payload(&inner_payload)
|
136 + | .map_err(|err| ::aws_smithy_eventstream::error::Error::marshalling(format!("{err}")))?
|
137 + | }
|
138 + | else {
|
139 + | unimplemented!("TODO(EventStream): Figure out what to do when there's no payload")
|
140 + | }
|
141 + | }
|
142 + | Self::Input::HeadersAndExplicitPayload(inner) => {
|
143 + | headers.push(::aws_smithy_types::event_stream::Header::new(":event-type", ::aws_smithy_types::event_stream::HeaderValue::String("headersAndExplicitPayload".into())));
|
144 + | if let Some(value) = inner.header {
|
145 + | headers.push(
|
146 + | ::aws_smithy_types::event_stream::Header::new("header", ::aws_smithy_types::event_stream::HeaderValue::String(value.into()))
|
147 + | );
|
148 + | }
|
149 + | headers.push(::aws_smithy_types::event_stream::Header::new(":content-type", ::aws_smithy_types::event_stream::HeaderValue::String("application/json".into())));
|
150 + | if let Some(inner_payload) = inner.payload {
|
151 + | crate::protocol_serde::shape_headers_and_explicit_payload_event::ser_payload_payload(&inner_payload)
|
152 + | .map_err(|err| ::aws_smithy_eventstream::error::Error::marshalling(format!("{err}")))?
|
153 + | }
|
154 + | else {
|
155 + | unimplemented!("TODO(EventStream): Figure out what to do when there's no payload")
|
156 + | }
|
157 + | }
|
158 + | Self::Input::HeadersAndImplicitPayload(inner) => {
|
159 + | headers.push(::aws_smithy_types::event_stream::Header::new(":event-type", ::aws_smithy_types::event_stream::HeaderValue::String("headersAndImplicitPayload".into())));
|
160 + | if let Some(value) = inner.header {
|
161 + | headers.push(
|
162 + | ::aws_smithy_types::event_stream::Header::new("header", ::aws_smithy_types::event_stream::HeaderValue::String(value.into()))
|
163 + | );
|
164 + | }
|
165 + | Vec::new()
|
166 + | }
|
167 + | Self::Input::Unknown => return Err(
|
168 + | ::aws_smithy_eventstream::error::Error::marshalling("Cannot serialize `EventStream::Unknown` for the request. The `Unknown` variant is intended for responses only. It occurs when an outdated client is used after a new enum variant was added on the server side.".to_owned())
|
169 + | )
|
170 + | }
|
171 + | ;
|
172 + | Ok(::aws_smithy_types::event_stream::Message::new_from_parts(headers, payload))
|
173 + | }
|
174 + | }
|
175 + |
|
176 + | #[non_exhaustive]
|
177 + | #[derive(Debug)]
|
178 + | pub struct EventStreamUnmarshaller;
|
179 + |
|
180 + | impl EventStreamUnmarshaller {
|
181 + | pub fn new() -> Self {
|
182 + | EventStreamUnmarshaller
|
183 + | }
|
184 + | }
|
185 + | impl ::aws_smithy_eventstream::frame::UnmarshallMessage for EventStreamUnmarshaller {
|
186 + | type Output = crate::types::EventStream;
|
187 + | type Error = crate::types::error::EventStreamError;
|
188 + | fn unmarshall(
|
189 + | &self,
|
190 + | message: &::aws_smithy_types::event_stream::Message,
|
191 + | ) -> std::result::Result<::aws_smithy_eventstream::frame::UnmarshalledMessage<Self::Output, Self::Error>, ::aws_smithy_eventstream::error::Error>
|
192 + | {
|
193 + | let response_headers = ::aws_smithy_eventstream::smithy::parse_response_headers(message)?;
|
194 + | match response_headers.message_type.as_str() {
|
195 + | "event" => {
|
196 + | match response_headers.smithy_type.as_str() {
|
197 + | "headers" => {
|
198 + | let mut builder = crate::types::builders::HeadersEventBuilder::default();
|
199 + | for header in message.headers() {
|
200 + | match header.name().as_str() {
|
201 + | "booleanHeader" => {
|
202 + | builder = builder.set_boolean_header(Some(::aws_smithy_eventstream::smithy::expect_bool(header)?));
|
203 + | }
|
204 + | "byteHeader" => {
|
205 + | builder = builder.set_byte_header(Some(::aws_smithy_eventstream::smithy::expect_byte(header)?));
|
206 + | }
|
207 + | "shortHeader" => {
|
208 + | builder = builder.set_short_header(Some(::aws_smithy_eventstream::smithy::expect_int16(header)?));
|
209 + | }
|
210 + | "intHeader" => {
|
211 + | builder = builder.set_int_header(Some(::aws_smithy_eventstream::smithy::expect_int32(header)?));
|
212 + | }
|
213 + | "longHeader" => {
|
214 + | builder = builder.set_long_header(Some(::aws_smithy_eventstream::smithy::expect_int64(header)?));
|
215 + | }
|
216 + | "blobHeader" => {
|
217 + | builder = builder.set_blob_header(Some(::aws_smithy_eventstream::smithy::expect_byte_array(header)?));
|
218 + | }
|
219 + | "stringHeader" => {
|
220 + | builder = builder.set_string_header(Some(::aws_smithy_eventstream::smithy::expect_string(header)?));
|
221 + | }
|
222 + | "timestampHeader" => {
|
223 + | builder = builder.set_timestamp_header(Some(::aws_smithy_eventstream::smithy::expect_timestamp(header)?));
|
224 + | }
|
225 + | // Event stream protocol headers start with ':'
|
226 + | name => {
|
227 + | if !name.starts_with(':') {
|
228 + | ::tracing::trace!("Unrecognized event stream message header: {}", name);
|
229 + | }
|
230 + | }
|
231 + | }
|
232 + | }
|
233 + | Ok(::aws_smithy_eventstream::frame::UnmarshalledMessage::Event(
|
234 + | crate::types::EventStream::Headers(builder.build()),
|
235 + | ))
|
236 + | }
|
237 + | "blobPayload" => {
|
238 + | let mut builder = crate::types::builders::BlobPayloadEventBuilder::default();
|
239 + | let content_type = response_headers.content_type().unwrap_or_default();
|
240 + | if content_type != "application/octet-stream" {
|
241 + | return Err(::aws_smithy_eventstream::error::Error::unmarshalling(format!(
|
242 + | "expected :content-type to be 'application/octet-stream', but was '{content_type}'"
|
243 + | )));
|
244 + | }
|
245 + | builder = builder.set_payload(Some(::aws_smithy_types::Blob::new(message.payload().as_ref())));
|
246 + | Ok(::aws_smithy_eventstream::frame::UnmarshalledMessage::Event(
|
247 + | crate::types::EventStream::BlobPayload(builder.build()),
|
248 + | ))
|
249 + | }
|
250 + | "stringPayload" => {
|
251 + | let mut builder = crate::types::builders::StringPayloadEventBuilder::default();
|
252 + | let content_type = response_headers.content_type().unwrap_or_default();
|
253 + | if content_type != "text/plain" {
|
254 + | return Err(::aws_smithy_eventstream::error::Error::unmarshalling(format!(
|
255 + | "expected :content-type to be 'text/plain', but was '{content_type}'"
|
256 + | )));
|
257 + | }
|
258 + | builder = builder.set_payload(Some(
|
259 + | ::std::str::from_utf8(message.payload())
|
260 + | .map_err(|_| ::aws_smithy_eventstream::error::Error::unmarshalling("message payload is not valid UTF-8"))?
|
261 + | .to_owned(),
|
262 + | ));
|
263 + | Ok(::aws_smithy_eventstream::frame::UnmarshalledMessage::Event(
|
264 + | crate::types::EventStream::StringPayload(builder.build()),
|
265 + | ))
|
266 + | }
|
267 + | "structurePayload" => {
|
268 + | let mut builder = crate::types::builders::StructurePayloadEventBuilder::default();
|
269 + | builder = builder.set_payload(Some(
|
270 + | crate::protocol_serde::shape_payload_structure::de_payload_structure_payload(&message.payload()[..]).map_err(|err| {
|
271 + | ::aws_smithy_eventstream::error::Error::unmarshalling(format!("failed to unmarshall payload: {err}"))
|
272 + | })?,
|
273 + | ));
|
274 + | Ok(::aws_smithy_eventstream::frame::UnmarshalledMessage::Event(
|
275 + | crate::types::EventStream::StructurePayload(builder.build()),
|
276 + | ))
|
277 + | }
|
278 + | "unionPayload" => {
|
279 + | let mut builder = crate::types::builders::UnionPayloadEventBuilder::default();
|
280 + | builder = builder.set_payload(Some(
|
281 + | crate::protocol_serde::shape_payload_union::de_payload_union_payload(&message.payload()[..]).map_err(|err| {
|
282 + | ::aws_smithy_eventstream::error::Error::unmarshalling(format!("failed to unmarshall payload: {err}"))
|
283 + | })?,
|
284 + | ));
|
285 + | Ok(::aws_smithy_eventstream::frame::UnmarshalledMessage::Event(
|
286 + | crate::types::EventStream::UnionPayload(builder.build()),
|
287 + | ))
|
288 + | }
|
289 + | "headersAndExplicitPayload" => {
|
290 + | let mut builder = crate::types::builders::HeadersAndExplicitPayloadEventBuilder::default();
|
291 + | builder = builder.set_payload(Some(
|
292 + | crate::protocol_serde::shape_payload_structure::de_payload_structure_payload(&message.payload()[..]).map_err(|err| {
|
293 + | ::aws_smithy_eventstream::error::Error::unmarshalling(format!("failed to unmarshall payload: {err}"))
|
294 + | })?,
|
295 + | ));
|
296 + | for header in message.headers() {
|
297 + | match header.name().as_str() {
|
298 + | "header" => {
|
299 + | builder = builder.set_header(Some(::aws_smithy_eventstream::smithy::expect_string(header)?));
|
300 + | }
|
301 + | // Event stream protocol headers start with ':'
|
302 + | name => {
|
303 + | if !name.starts_with(':') {
|
304 + | ::tracing::trace!("Unrecognized event stream message header: {}", name);
|
305 + | }
|
306 + | }
|
307 + | }
|
308 + | }
|
309 + | Ok(::aws_smithy_eventstream::frame::UnmarshalledMessage::Event(
|
310 + | crate::types::EventStream::HeadersAndExplicitPayload(builder.build()),
|
311 + | ))
|
312 + | }
|
313 + | "headersAndImplicitPayload" => {
|
314 + | let mut builder = crate::types::builders::HeadersAndImplicitPayloadEventBuilder::default();
|
315 + | for header in message.headers() {
|
316 + | match header.name().as_str() {
|
317 + | "header" => {
|
318 + | builder = builder.set_header(Some(::aws_smithy_eventstream::smithy::expect_string(header)?));
|
319 + | }
|
320 + | // Event stream protocol headers start with ':'
|
321 + | name => {
|
322 + | if !name.starts_with(':') {
|
323 + | ::tracing::trace!("Unrecognized event stream message header: {}", name);
|
324 + | }
|
325 + | }
|
326 + | }
|
327 + | }
|
328 + | builder = crate::protocol_serde::shape_headers_and_implicit_payload_event::de_headers_and_implicit_payload_event_json_err(
|
329 + | &message.payload()[..],
|
330 + | builder,
|
331 + | )
|
332 + | .map_err(|err| ::aws_smithy_eventstream::error::Error::unmarshalling(format!("failed to unmarshall: {err}")))?;
|
333 + | Ok(::aws_smithy_eventstream::frame::UnmarshalledMessage::Event(
|
334 + | crate::types::EventStream::HeadersAndImplicitPayload(builder.build()),
|
335 + | ))
|
336 + | }
|
337 + | _unknown_variant => Ok(::aws_smithy_eventstream::frame::UnmarshalledMessage::Event(
|
338 + | crate::types::EventStream::Unknown,
|
339 + | )),
|
340 + | }
|
341 + | }
|
342 + | "exception" => {
|
343 + | let generic = match crate::protocol_serde::parse_event_stream_error_metadata(message.payload()) {
|
344 + | Ok(builder) => builder.build(),
|
345 + | Err(err) => {
|
346 + | return Ok(::aws_smithy_eventstream::frame::UnmarshalledMessage::Error(
|
347 + | crate::types::error::EventStreamError::unhandled(err),
|
348 + | ))
|
349 + | }
|
350 + | };
|
351 + | if response_headers.smithy_type.as_str() == "error" {
|
352 + | let mut builder = crate::types::error::builders::ErrorEventBuilder::default();
|
353 + | builder = crate::protocol_serde::shape_error_event::de_error_event_json_err(&message.payload()[..], builder)
|
354 + | .map_err(|err| ::aws_smithy_eventstream::error::Error::unmarshalling(format!("failed to unmarshall error: {err}")))?;
|
355 + | builder.set_meta(Some(generic));
|
356 + | return Ok(::aws_smithy_eventstream::frame::UnmarshalledMessage::Error(
|
357 + | crate::types::error::EventStreamError::ErrorEvent(builder.build()),
|
358 + | ));
|
359 + | }
|
360 + | Ok(::aws_smithy_eventstream::frame::UnmarshalledMessage::Error(
|
361 + | crate::types::error::EventStreamError::generic(generic),
|
362 + | ))
|
363 + | }
|
364 + | value => {
|
365 + | return Err(::aws_smithy_eventstream::error::Error::unmarshalling(format!(
|
366 + | "unrecognized :message-type: {value}"
|
367 + | )));
|
368 + | }
|
369 + | }
|
370 + | }
|
371 + | }
|