1 + | // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
|
2 + | #[allow(clippy::unnecessary_wraps)]
|
3 + | pub async fn de_streaming_operation_with_optional_data_http_request<B>(
|
4 + | #[allow(unused_variables)] request: ::http::Request<B>,
|
5 + | ) -> std::result::Result<
|
6 + | crate::input::StreamingOperationWithOptionalDataInput,
|
7 + | ::aws_smithy_legacy_http_server::protocol::rpc_v2_cbor::rejection::RequestRejection,
|
8 + | >
|
9 + | where
|
10 + | B: ::aws_smithy_legacy_http_server::body::HttpBody + Send,
|
11 + | B: Into<::aws_smithy_types::byte_stream::ByteStream>,
|
12 + | B::Data: Send,
|
13 + | ::aws_smithy_legacy_http_server::protocol::rpc_v2_cbor::rejection::RequestRejection:
|
14 + | From<<B as ::aws_smithy_legacy_http_server::body::HttpBody>::Error>,
|
15 + | {
|
16 + | Ok({
|
17 + | #[allow(unused_mut)]
|
18 + | let mut input =
|
19 + | crate::input::streaming_operation_with_optional_data_input::Builder::default();
|
20 + | #[allow(unused_variables)]
|
21 + | let ::aws_smithy_runtime_api::http::RequestParts {
|
22 + | uri, headers, body, ..
|
23 + | } = ::aws_smithy_runtime_api::http::Request::try_from(request)?.into_parts();
|
24 + | if let Some(value) = {
|
25 + | let mut receiver = crate::protocol_serde::shape_streaming_operation_with_optional_data_input::de_events_payload(&mut body.into().into_inner())?;
|
26 + | if let Some(_initial_event) = receiver
|
27 + | .try_recv_initial(::aws_smithy_legacy_http::event_stream::InitialMessageType::Request)
|
28 + | .await
|
29 + | .map_err(
|
30 + | |ev_error| ::aws_smithy_legacy_http_server::protocol::rpc_v2_cbor::rejection::RequestRejection::ConstraintViolation(
|
31 + | #[allow(clippy::useless_conversion)]
|
32 + | format!("{ev_error}").into()
|
33 + | )
|
34 + | )? {
|
35 + | input = crate::protocol_serde::shape_streaming_operation_with_optional_data::de_streaming_operation_with_optional_data(_initial_event.payload(), input)?;
|
36 + | }
|
37 + | Some(receiver)
|
38 + | } {
|
39 + | input = input.set_events(value)
|
40 + | }
|
41 + | input.build()?
|
42 + | })
|
43 + | }
|
44 + |
|
45 + | #[allow(clippy::unnecessary_wraps)]
|
46 + | pub fn ser_streaming_operation_with_optional_data_http_response(
|
47 + | #[allow(unused_variables)] output: crate::output::StreamingOperationWithOptionalDataOutput,
|
48 + | ) -> std::result::Result<
|
49 + | ::aws_smithy_legacy_http_server::response::Response,
|
50 + | ::aws_smithy_legacy_http_server::protocol::rpc_v2_cbor::rejection::ResponseRejection,
|
51 + | > {
|
52 + | Ok({
|
53 + | #[allow(unused_mut)]
|
54 + | let mut builder = ::http::Response::builder();
|
55 + | builder = ::aws_smithy_legacy_http::header::set_response_header_if_absent(
|
56 + | builder,
|
57 + | ::http::header::CONTENT_TYPE,
|
58 + | "application/vnd.amazon.eventstream",
|
59 + | );
|
60 + | builder = ::aws_smithy_legacy_http::header::set_response_header_if_absent(
|
61 + | builder,
|
62 + | ::http::header::HeaderName::from_static("smithy-protocol"),
|
63 + | "rpc-v2-cbor",
|
64 + | );
|
65 + | let http_status: u16 = 200;
|
66 + | builder = builder.status(http_status);
|
67 + | let body = ::aws_smithy_legacy_http_server::body::boxed(
|
68 + | ::aws_smithy_legacy_http_server::body::Body::wrap_stream({
|
69 + | let error_marshaller = crate::event_stream_serde::EventsErrorMarshaller::new();
|
70 + | let marshaller = crate::event_stream_serde::EventsMarshaller::new();
|
71 + | let signer = ::aws_smithy_eventstream::frame::NoOpSigner {};
|
72 + | {
|
73 + | use ::futures_util::StreamExt;
|
74 + | let payload = ::bytes::Bytes::from(crate::protocol_serde::shape_streaming_operation_with_optional_data_output::ser_streaming_operation_with_optional_data_output_output_output(&output)?);
|
75 + | let initial_message =
|
76 + | crate::event_stream_serde::initial_response_from_payload(payload);
|
77 + | let mut buffer = ::std::vec::Vec::new();
|
78 + | ::aws_smithy_eventstream::frame::write_message_to(
|
79 + | &initial_message,
|
80 + | &mut buffer,
|
81 + | )
|
82 + | .expect("Failed to write initial message");
|
83 + | let initial_message_stream =
|
84 + | futures_util::stream::iter(vec![Ok(buffer.into())]);
|
85 + | let adapter =
|
86 + | output
|
87 + | .events
|
88 + | .into_body_stream(marshaller, error_marshaller, signer);
|
89 + | initial_message_stream.chain(adapter)
|
90 + | }
|
91 + | }),
|
92 + | );
|
93 + | builder.body(body)?
|
94 + | })
|
95 + | }
|
96 + |
|
97 + | #[allow(clippy::unnecessary_wraps)]
|
98 + | pub fn ser_streaming_operation_with_optional_data_http_error(
|
99 + | error: &crate::error::StreamingOperationWithOptionalDataError,
|
100 + | ) -> std::result::Result<
|
101 + | ::aws_smithy_legacy_http_server::response::Response,
|
102 + | ::aws_smithy_legacy_http_server::protocol::rpc_v2_cbor::rejection::ResponseRejection,
|
103 + | > {
|
104 + | Ok({
|
105 + | match error {
|
106 + | crate::error::StreamingOperationWithOptionalDataError::ValidationException(output) => {
|
107 + | let payload = crate::protocol_serde::shape_validation_exception::ser_validation_exception_error(output)?;
|
108 + | #[allow(unused_mut)]
|
109 + | let mut builder = ::http::Response::builder();
|
110 + | builder = ::aws_smithy_legacy_http::header::set_response_header_if_absent(
|
111 + | builder,
|
112 + | ::http::header::CONTENT_TYPE,
|
113 + | "application/vnd.amazon.eventstream",
|
114 + | );
|
115 + | builder = ::aws_smithy_legacy_http::header::set_response_header_if_absent(
|
116 + | builder,
|
117 + | ::http::header::HeaderName::from_static("smithy-protocol"),
|
118 + | "rpc-v2-cbor",
|
119 + | );
|
120 + | let content_length = payload.len();
|
121 + | builder = ::aws_smithy_legacy_http::header::set_response_header_if_absent(
|
122 + | builder,
|
123 + | ::http::header::CONTENT_LENGTH,
|
124 + | content_length,
|
125 + | );
|
126 + | builder
|
127 + | .status(400)
|
128 + | .body(::aws_smithy_legacy_http_server::body::to_boxed(payload))?
|
129 + | }
|
130 + | }
|
131 + | })
|
132 + | }
|
133 + |
|
134 + | pub(crate) fn de_streaming_operation_with_optional_data(
|
135 + | value: &[u8],
|
136 + | mut builder: crate::input::streaming_operation_with_optional_data_input::Builder,
|
137 + | ) -> ::std::result::Result<
|
138 + | crate::input::streaming_operation_with_optional_data_input::Builder,
|
139 + | ::aws_smithy_cbor::decode::DeserializeError,
|
140 + | > {
|
141 + | #[allow(clippy::match_single_binding)]
|
142 + | fn pair(
|
143 + | mut builder: crate::input::streaming_operation_with_optional_data_input::Builder,
|
144 + | decoder: &mut ::aws_smithy_cbor::Decoder,
|
145 + | ) -> ::std::result::Result<
|
146 + | crate::input::streaming_operation_with_optional_data_input::Builder,
|
147 + | ::aws_smithy_cbor::decode::DeserializeError,
|
148 + | > {
|
149 + | builder = match decoder.str()?.as_ref() {
|
150 + | "optionalData" => {
|
151 + | ::aws_smithy_cbor::decode::set_optional(builder, decoder, |builder, decoder| {
|
152 + | Ok(builder.set_optional_data(Some(decoder.string()?)))
|
153 + | })?
|
154 + | }
|
155 + | _ => {
|
156 + | decoder.skip()?;
|
157 + | builder
|
158 + | }
|
159 + | };
|
160 + | Ok(builder)
|
161 + | }
|
162 + |
|
163 + | let decoder = &mut ::aws_smithy_cbor::Decoder::new(value);
|
164 + |
|
165 + | match decoder.map()? {
|
166 + | None => loop {
|
167 + | match decoder.datatype()? {
|
168 + | ::aws_smithy_cbor::data::Type::Break => {
|
169 + | decoder.skip()?;
|
170 + | break;
|
171 + | }
|
172 + | _ => {
|
173 + | builder = pair(builder, decoder)?;
|
174 + | }
|
175 + | };
|
176 + | },
|
177 + | Some(n) => {
|
178 + | for _ in 0..n {
|
179 + | builder = pair(builder, decoder)?;
|
180 + | }
|
181 + | }
|
182 + | };
|
183 + |
|
184 + | if decoder.position() != value.len() {
|
185 + | return Err(
|
186 + | ::aws_smithy_cbor::decode::DeserializeError::expected_end_of_stream(decoder.position()),
|
187 + | );
|
188 + | }
|
189 + |
|
190 + | Ok(builder)
|
191 + | }
|