aws_sdk_mediapackagev2/protocol_serde/
shape_create_channel.rs

1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2#[allow(clippy::unnecessary_wraps)]
3pub fn de_create_channel_http_error(
4    _response_status: u16,
5    _response_headers: &::aws_smithy_runtime_api::http::Headers,
6    _response_body: &[u8],
7) -> std::result::Result<crate::operation::create_channel::CreateChannelOutput, crate::operation::create_channel::CreateChannelError> {
8    #[allow(unused_mut)]
9    let mut generic_builder = crate::protocol_serde::parse_http_error_metadata(_response_status, _response_headers, _response_body)
10        .map_err(crate::operation::create_channel::CreateChannelError::unhandled)?;
11    generic_builder = ::aws_types::request_id::apply_request_id(generic_builder, _response_headers);
12    let generic = generic_builder.build();
13    let error_code = match generic.code() {
14        Some(code) => code,
15        None => return Err(crate::operation::create_channel::CreateChannelError::unhandled(generic)),
16    };
17
18    let _error_message = generic.message().map(|msg| msg.to_owned());
19    Err(match error_code {
20        "AccessDeniedException" => crate::operation::create_channel::CreateChannelError::AccessDeniedException({
21            #[allow(unused_mut)]
22            let mut tmp = {
23                #[allow(unused_mut)]
24                let mut output = crate::types::error::builders::AccessDeniedExceptionBuilder::default();
25                output = crate::protocol_serde::shape_access_denied_exception::de_access_denied_exception_json_err(_response_body, output)
26                    .map_err(crate::operation::create_channel::CreateChannelError::unhandled)?;
27                let output = output.meta(generic);
28                output.build()
29            };
30            if tmp.message.is_none() {
31                tmp.message = _error_message;
32            }
33            tmp
34        }),
35        "ConflictException" => crate::operation::create_channel::CreateChannelError::ConflictException({
36            #[allow(unused_mut)]
37            let mut tmp = {
38                #[allow(unused_mut)]
39                let mut output = crate::types::error::builders::ConflictExceptionBuilder::default();
40                output = crate::protocol_serde::shape_conflict_exception::de_conflict_exception_json_err(_response_body, output)
41                    .map_err(crate::operation::create_channel::CreateChannelError::unhandled)?;
42                let output = output.meta(generic);
43                output.build()
44            };
45            if tmp.message.is_none() {
46                tmp.message = _error_message;
47            }
48            tmp
49        }),
50        "InternalServerException" => crate::operation::create_channel::CreateChannelError::InternalServerException({
51            #[allow(unused_mut)]
52            let mut tmp = {
53                #[allow(unused_mut)]
54                let mut output = crate::types::error::builders::InternalServerExceptionBuilder::default();
55                output = crate::protocol_serde::shape_internal_server_exception::de_internal_server_exception_json_err(_response_body, output)
56                    .map_err(crate::operation::create_channel::CreateChannelError::unhandled)?;
57                let output = output.meta(generic);
58                output.build()
59            };
60            if tmp.message.is_none() {
61                tmp.message = _error_message;
62            }
63            tmp
64        }),
65        "ResourceNotFoundException" => crate::operation::create_channel::CreateChannelError::ResourceNotFoundException({
66            #[allow(unused_mut)]
67            let mut tmp = {
68                #[allow(unused_mut)]
69                let mut output = crate::types::error::builders::ResourceNotFoundExceptionBuilder::default();
70                output = crate::protocol_serde::shape_resource_not_found_exception::de_resource_not_found_exception_json_err(_response_body, output)
71                    .map_err(crate::operation::create_channel::CreateChannelError::unhandled)?;
72                let output = output.meta(generic);
73                output.build()
74            };
75            if tmp.message.is_none() {
76                tmp.message = _error_message;
77            }
78            tmp
79        }),
80        "ServiceQuotaExceededException" => crate::operation::create_channel::CreateChannelError::ServiceQuotaExceededException({
81            #[allow(unused_mut)]
82            let mut tmp = {
83                #[allow(unused_mut)]
84                let mut output = crate::types::error::builders::ServiceQuotaExceededExceptionBuilder::default();
85                output = crate::protocol_serde::shape_service_quota_exceeded_exception::de_service_quota_exceeded_exception_json_err(
86                    _response_body,
87                    output,
88                )
89                .map_err(crate::operation::create_channel::CreateChannelError::unhandled)?;
90                let output = output.meta(generic);
91                output.build()
92            };
93            if tmp.message.is_none() {
94                tmp.message = _error_message;
95            }
96            tmp
97        }),
98        "ThrottlingException" => crate::operation::create_channel::CreateChannelError::ThrottlingException({
99            #[allow(unused_mut)]
100            let mut tmp = {
101                #[allow(unused_mut)]
102                let mut output = crate::types::error::builders::ThrottlingExceptionBuilder::default();
103                output = crate::protocol_serde::shape_throttling_exception::de_throttling_exception_json_err(_response_body, output)
104                    .map_err(crate::operation::create_channel::CreateChannelError::unhandled)?;
105                let output = output.meta(generic);
106                output.build()
107            };
108            if tmp.message.is_none() {
109                tmp.message = _error_message;
110            }
111            tmp
112        }),
113        "ValidationException" => crate::operation::create_channel::CreateChannelError::ValidationException({
114            #[allow(unused_mut)]
115            let mut tmp = {
116                #[allow(unused_mut)]
117                let mut output = crate::types::error::builders::ValidationExceptionBuilder::default();
118                output = crate::protocol_serde::shape_validation_exception::de_validation_exception_json_err(_response_body, output)
119                    .map_err(crate::operation::create_channel::CreateChannelError::unhandled)?;
120                let output = output.meta(generic);
121                output.build()
122            };
123            if tmp.message.is_none() {
124                tmp.message = _error_message;
125            }
126            tmp
127        }),
128        _ => crate::operation::create_channel::CreateChannelError::generic(generic),
129    })
130}
131
132#[allow(clippy::unnecessary_wraps)]
133pub fn de_create_channel_http_response(
134    _response_status: u16,
135    _response_headers: &::aws_smithy_runtime_api::http::Headers,
136    _response_body: &[u8],
137) -> std::result::Result<crate::operation::create_channel::CreateChannelOutput, crate::operation::create_channel::CreateChannelError> {
138    Ok({
139        #[allow(unused_mut)]
140        let mut output = crate::operation::create_channel::builders::CreateChannelOutputBuilder::default();
141        output = crate::protocol_serde::shape_create_channel::de_create_channel(_response_body, output)
142            .map_err(crate::operation::create_channel::CreateChannelError::unhandled)?;
143        output._set_request_id(::aws_types::request_id::RequestId::request_id(_response_headers).map(str::to_string));
144        crate::serde_util::create_channel_output_output_correct_errors(output)
145            .build()
146            .map_err(crate::operation::create_channel::CreateChannelError::unhandled)?
147    })
148}
149
150pub fn ser_create_channel_headers(
151    input: &crate::operation::create_channel::CreateChannelInput,
152    mut builder: ::http::request::Builder,
153) -> std::result::Result<::http::request::Builder, ::aws_smithy_types::error::operation::BuildError> {
154    if let ::std::option::Option::Some(inner_1) = &input.client_token {
155        let formatted_2 = inner_1.as_str();
156        let header_value = formatted_2;
157        let header_value: ::http::HeaderValue = header_value.parse().map_err(|err| {
158            ::aws_smithy_types::error::operation::BuildError::invalid_field(
159                "client_token",
160                format!("`{}` cannot be used as a header value: {}", &header_value, err),
161            )
162        })?;
163        builder = builder.header("x-amzn-client-token", header_value);
164    }
165    Ok(builder)
166}
167
168pub fn ser_create_channel_input(
169    input: &crate::operation::create_channel::CreateChannelInput,
170) -> ::std::result::Result<::aws_smithy_types::body::SdkBody, ::aws_smithy_types::error::operation::SerializationError> {
171    let mut out = String::new();
172    let mut object = ::aws_smithy_json::serialize::JsonObjectWriter::new(&mut out);
173    crate::protocol_serde::shape_create_channel_input::ser_create_channel_input_input(&mut object, input)?;
174    object.finish();
175    Ok(::aws_smithy_types::body::SdkBody::from(out))
176}
177
178pub(crate) fn de_create_channel(
179    value: &[u8],
180    mut builder: crate::operation::create_channel::builders::CreateChannelOutputBuilder,
181) -> ::std::result::Result<
182    crate::operation::create_channel::builders::CreateChannelOutputBuilder,
183    ::aws_smithy_json::deserialize::error::DeserializeError,
184> {
185    let mut tokens_owned = ::aws_smithy_json::deserialize::json_token_iter(crate::protocol_serde::or_empty_doc(value)).peekable();
186    let tokens = &mut tokens_owned;
187    ::aws_smithy_json::deserialize::token::expect_start_object(tokens.next())?;
188    loop {
189        match tokens.next().transpose()? {
190            Some(::aws_smithy_json::deserialize::Token::EndObject { .. }) => break,
191            Some(::aws_smithy_json::deserialize::Token::ObjectKey { key, .. }) => match key.to_unescaped()?.as_ref() {
192                "Arn" => {
193                    builder = builder.set_arn(
194                        ::aws_smithy_json::deserialize::token::expect_string_or_null(tokens.next())?
195                            .map(|s| s.to_unescaped().map(|u| u.into_owned()))
196                            .transpose()?,
197                    );
198                }
199                "ChannelGroupName" => {
200                    builder = builder.set_channel_group_name(
201                        ::aws_smithy_json::deserialize::token::expect_string_or_null(tokens.next())?
202                            .map(|s| s.to_unescaped().map(|u| u.into_owned()))
203                            .transpose()?,
204                    );
205                }
206                "ChannelName" => {
207                    builder = builder.set_channel_name(
208                        ::aws_smithy_json::deserialize::token::expect_string_or_null(tokens.next())?
209                            .map(|s| s.to_unescaped().map(|u| u.into_owned()))
210                            .transpose()?,
211                    );
212                }
213                "CreatedAt" => {
214                    builder = builder.set_created_at(::aws_smithy_json::deserialize::token::expect_timestamp_or_null(
215                        tokens.next(),
216                        ::aws_smithy_types::date_time::Format::EpochSeconds,
217                    )?);
218                }
219                "Description" => {
220                    builder = builder.set_description(
221                        ::aws_smithy_json::deserialize::token::expect_string_or_null(tokens.next())?
222                            .map(|s| s.to_unescaped().map(|u| u.into_owned()))
223                            .transpose()?,
224                    );
225                }
226                "ETag" => {
227                    builder = builder.set_e_tag(
228                        ::aws_smithy_json::deserialize::token::expect_string_or_null(tokens.next())?
229                            .map(|s| s.to_unescaped().map(|u| u.into_owned()))
230                            .transpose()?,
231                    );
232                }
233                "IngestEndpoints" => {
234                    builder = builder.set_ingest_endpoints(crate::protocol_serde::shape_ingest_endpoint_list::de_ingest_endpoint_list(tokens)?);
235                }
236                "InputSwitchConfiguration" => {
237                    builder = builder.set_input_switch_configuration(
238                        crate::protocol_serde::shape_input_switch_configuration::de_input_switch_configuration(tokens)?,
239                    );
240                }
241                "InputType" => {
242                    builder = builder.set_input_type(
243                        ::aws_smithy_json::deserialize::token::expect_string_or_null(tokens.next())?
244                            .map(|s| s.to_unescaped().map(|u| crate::types::InputType::from(u.as_ref())))
245                            .transpose()?,
246                    );
247                }
248                "ModifiedAt" => {
249                    builder = builder.set_modified_at(::aws_smithy_json::deserialize::token::expect_timestamp_or_null(
250                        tokens.next(),
251                        ::aws_smithy_types::date_time::Format::EpochSeconds,
252                    )?);
253                }
254                "OutputHeaderConfiguration" => {
255                    builder = builder.set_output_header_configuration(
256                        crate::protocol_serde::shape_output_header_configuration::de_output_header_configuration(tokens)?,
257                    );
258                }
259                "Tags" => {
260                    builder = builder.set_tags(crate::protocol_serde::shape_tag_map::de_tag_map(tokens)?);
261                }
262                _ => ::aws_smithy_json::deserialize::token::skip_value(tokens)?,
263            },
264            other => {
265                return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(format!(
266                    "expected object key or end object, found: {:?}",
267                    other
268                )))
269            }
270        }
271    }
272    if tokens.next().is_some() {
273        return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
274            "found more JSON tokens after completing parsing",
275        ));
276    }
277    Ok(builder)
278}