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