Skip to main content

aws_sdk_iot/protocol_serde/
shape_create_billing_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_billing_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_billing_group::CreateBillingGroupOutput,
9    crate::operation::create_billing_group::CreateBillingGroupError,
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_billing_group::CreateBillingGroupError::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_billing_group::CreateBillingGroupError::unhandled(generic)),
19    };
20
21    let _error_message = generic.message().map(|msg| msg.to_owned());
22    Err(match error_code {
23        "InternalFailureException" => crate::operation::create_billing_group::CreateBillingGroupError::InternalFailureException({
24            #[allow(unused_mut)]
25            let mut tmp = {
26                #[allow(unused_mut)]
27                let mut output = crate::types::error::builders::InternalFailureExceptionBuilder::default();
28                output = crate::protocol_serde::shape_internal_failure_exception::de_internal_failure_exception_json_err(_response_body, output)
29                    .map_err(crate::operation::create_billing_group::CreateBillingGroupError::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        "InvalidRequestException" => crate::operation::create_billing_group::CreateBillingGroupError::InvalidRequestException({
39            #[allow(unused_mut)]
40            let mut tmp = {
41                #[allow(unused_mut)]
42                let mut output = crate::types::error::builders::InvalidRequestExceptionBuilder::default();
43                output = crate::protocol_serde::shape_invalid_request_exception::de_invalid_request_exception_json_err(_response_body, output)
44                    .map_err(crate::operation::create_billing_group::CreateBillingGroupError::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        "ResourceAlreadyExistsException" => crate::operation::create_billing_group::CreateBillingGroupError::ResourceAlreadyExistsException({
54            #[allow(unused_mut)]
55            let mut tmp = {
56                #[allow(unused_mut)]
57                let mut output = crate::types::error::builders::ResourceAlreadyExistsExceptionBuilder::default();
58                output = crate::protocol_serde::shape_resource_already_exists_exception::de_resource_already_exists_exception_json_err(
59                    _response_body,
60                    output,
61                )
62                .map_err(crate::operation::create_billing_group::CreateBillingGroupError::unhandled)?;
63                let output = output.meta(generic);
64                output.build()
65            };
66            if tmp.message.is_none() {
67                tmp.message = _error_message;
68            }
69            tmp
70        }),
71        "ThrottlingException" => crate::operation::create_billing_group::CreateBillingGroupError::ThrottlingException({
72            #[allow(unused_mut)]
73            let mut tmp = {
74                #[allow(unused_mut)]
75                let mut output = crate::types::error::builders::ThrottlingExceptionBuilder::default();
76                output = crate::protocol_serde::shape_throttling_exception::de_throttling_exception_json_err(_response_body, output)
77                    .map_err(crate::operation::create_billing_group::CreateBillingGroupError::unhandled)?;
78                let output = output.meta(generic);
79                output.build()
80            };
81            if tmp.message.is_none() {
82                tmp.message = _error_message;
83            }
84            tmp
85        }),
86        _ => crate::operation::create_billing_group::CreateBillingGroupError::generic(generic),
87    })
88}
89
90#[allow(clippy::unnecessary_wraps)]
91pub fn de_create_billing_group_http_response(
92    _response_status: u16,
93    _response_headers: &::aws_smithy_runtime_api::http::Headers,
94    _response_body: &[u8],
95) -> std::result::Result<
96    crate::operation::create_billing_group::CreateBillingGroupOutput,
97    crate::operation::create_billing_group::CreateBillingGroupError,
98> {
99    Ok({
100        #[allow(unused_mut)]
101        let mut output = crate::operation::create_billing_group::builders::CreateBillingGroupOutputBuilder::default();
102        output = crate::protocol_serde::shape_create_billing_group::de_create_billing_group(_response_body, output)
103            .map_err(crate::operation::create_billing_group::CreateBillingGroupError::unhandled)?;
104        output._set_request_id(::aws_types::request_id::RequestId::request_id(_response_headers).map(str::to_string));
105        output.build()
106    })
107}
108
109pub fn ser_create_billing_group_input(
110    input: &crate::operation::create_billing_group::CreateBillingGroupInput,
111) -> ::std::result::Result<::aws_smithy_types::body::SdkBody, ::aws_smithy_types::error::operation::SerializationError> {
112    let mut out = String::new();
113    let mut object = ::aws_smithy_json::serialize::JsonObjectWriter::new(&mut out);
114    crate::protocol_serde::shape_create_billing_group_input::ser_create_billing_group_input_input(&mut object, input)?;
115    object.finish();
116    Ok(::aws_smithy_types::body::SdkBody::from(out))
117}
118
119pub(crate) fn de_create_billing_group(
120    _value: &[u8],
121    mut builder: crate::operation::create_billing_group::builders::CreateBillingGroupOutputBuilder,
122) -> ::std::result::Result<
123    crate::operation::create_billing_group::builders::CreateBillingGroupOutputBuilder,
124    ::aws_smithy_json::deserialize::error::DeserializeError,
125> {
126    let mut tokens_owned = ::aws_smithy_json::deserialize::json_token_iter(crate::protocol_serde::or_empty_doc(_value)).peekable();
127    let tokens = &mut tokens_owned;
128    ::aws_smithy_json::deserialize::token::expect_start_object(tokens.next())?;
129    loop {
130        match tokens.next().transpose()? {
131            Some(::aws_smithy_json::deserialize::Token::EndObject { .. }) => break,
132            Some(::aws_smithy_json::deserialize::Token::ObjectKey { key, .. }) => match key.to_unescaped()?.as_ref() {
133                "billingGroupArn" => {
134                    builder = builder.set_billing_group_arn(
135                        ::aws_smithy_json::deserialize::token::expect_string_or_null(tokens.next())?
136                            .map(|s| s.to_unescaped().map(|u| u.into_owned()))
137                            .transpose()?,
138                    );
139                }
140                "billingGroupId" => {
141                    builder = builder.set_billing_group_id(
142                        ::aws_smithy_json::deserialize::token::expect_string_or_null(tokens.next())?
143                            .map(|s| s.to_unescaped().map(|u| u.into_owned()))
144                            .transpose()?,
145                    );
146                }
147                "billingGroupName" => {
148                    builder = builder.set_billing_group_name(
149                        ::aws_smithy_json::deserialize::token::expect_string_or_null(tokens.next())?
150                            .map(|s| s.to_unescaped().map(|u| u.into_owned()))
151                            .transpose()?,
152                    );
153                }
154                _ => ::aws_smithy_json::deserialize::token::skip_value(tokens)?,
155            },
156            other => {
157                return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(format!(
158                    "expected object key or end object, found: {other:?}"
159                )))
160            }
161        }
162    }
163    if tokens.next().is_some() {
164        return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
165            "found more JSON tokens after completing parsing",
166        ));
167    }
168    Ok(builder)
169}