aws_sdk_backupgateway/protocol_serde/
shape_get_gateway.rs

1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2#[allow(clippy::unnecessary_wraps)]
3pub fn de_get_gateway_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::get_gateway::GetGatewayOutput, crate::operation::get_gateway::GetGatewayError> {
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::get_gateway::GetGatewayError::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::get_gateway::GetGatewayError::unhandled(generic)),
16    };
17
18    let _error_message = generic.message().map(|msg| msg.to_owned());
19    Err(match error_code {
20        "ResourceNotFoundException" => crate::operation::get_gateway::GetGatewayError::ResourceNotFoundException({
21            #[allow(unused_mut)]
22            let mut tmp = {
23                #[allow(unused_mut)]
24                let mut output = crate::types::error::builders::ResourceNotFoundExceptionBuilder::default();
25                output = crate::protocol_serde::shape_resource_not_found_exception::de_resource_not_found_exception_json_err(_response_body, output)
26                    .map_err(crate::operation::get_gateway::GetGatewayError::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        "InternalServerException" => crate::operation::get_gateway::GetGatewayError::InternalServerException({
36            #[allow(unused_mut)]
37            let mut tmp = {
38                #[allow(unused_mut)]
39                let mut output = crate::types::error::builders::InternalServerExceptionBuilder::default();
40                output = crate::protocol_serde::shape_internal_server_exception::de_internal_server_exception_json_err(_response_body, output)
41                    .map_err(crate::operation::get_gateway::GetGatewayError::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        "ThrottlingException" => crate::operation::get_gateway::GetGatewayError::ThrottlingException({
51            #[allow(unused_mut)]
52            let mut tmp = {
53                #[allow(unused_mut)]
54                let mut output = crate::types::error::builders::ThrottlingExceptionBuilder::default();
55                output = crate::protocol_serde::shape_throttling_exception::de_throttling_exception_json_err(_response_body, output)
56                    .map_err(crate::operation::get_gateway::GetGatewayError::unhandled)?;
57                let output = output.meta(generic);
58                crate::serde_util::throttling_exception_correct_errors(output)
59                    .build()
60                    .map_err(crate::operation::get_gateway::GetGatewayError::unhandled)?
61            };
62            if tmp.message.is_none() {
63                tmp.message = _error_message;
64            }
65            tmp
66        }),
67        "ValidationException" => crate::operation::get_gateway::GetGatewayError::ValidationException({
68            #[allow(unused_mut)]
69            let mut tmp = {
70                #[allow(unused_mut)]
71                let mut output = crate::types::error::builders::ValidationExceptionBuilder::default();
72                output = crate::protocol_serde::shape_validation_exception::de_validation_exception_json_err(_response_body, output)
73                    .map_err(crate::operation::get_gateway::GetGatewayError::unhandled)?;
74                let output = output.meta(generic);
75                output.build()
76            };
77            if tmp.message.is_none() {
78                tmp.message = _error_message;
79            }
80            tmp
81        }),
82        _ => crate::operation::get_gateway::GetGatewayError::generic(generic),
83    })
84}
85
86#[allow(clippy::unnecessary_wraps)]
87pub fn de_get_gateway_http_response(
88    _response_status: u16,
89    _response_headers: &::aws_smithy_runtime_api::http::Headers,
90    _response_body: &[u8],
91) -> std::result::Result<crate::operation::get_gateway::GetGatewayOutput, crate::operation::get_gateway::GetGatewayError> {
92    Ok({
93        #[allow(unused_mut)]
94        let mut output = crate::operation::get_gateway::builders::GetGatewayOutputBuilder::default();
95        output = crate::protocol_serde::shape_get_gateway::de_get_gateway(_response_body, output)
96            .map_err(crate::operation::get_gateway::GetGatewayError::unhandled)?;
97        output._set_request_id(::aws_types::request_id::RequestId::request_id(_response_headers).map(str::to_string));
98        output.build()
99    })
100}
101
102pub fn ser_get_gateway_input(
103    input: &crate::operation::get_gateway::GetGatewayInput,
104) -> ::std::result::Result<::aws_smithy_types::body::SdkBody, ::aws_smithy_types::error::operation::SerializationError> {
105    let mut out = String::new();
106    let mut object = ::aws_smithy_json::serialize::JsonObjectWriter::new(&mut out);
107    crate::protocol_serde::shape_get_gateway_input::ser_get_gateway_input_input(&mut object, input)?;
108    object.finish();
109    Ok(::aws_smithy_types::body::SdkBody::from(out))
110}
111
112pub(crate) fn de_get_gateway(
113    value: &[u8],
114    mut builder: crate::operation::get_gateway::builders::GetGatewayOutputBuilder,
115) -> ::std::result::Result<crate::operation::get_gateway::builders::GetGatewayOutputBuilder, ::aws_smithy_json::deserialize::error::DeserializeError>
116{
117    let mut tokens_owned = ::aws_smithy_json::deserialize::json_token_iter(crate::protocol_serde::or_empty_doc(value)).peekable();
118    let tokens = &mut tokens_owned;
119    ::aws_smithy_json::deserialize::token::expect_start_object(tokens.next())?;
120    loop {
121        match tokens.next().transpose()? {
122            Some(::aws_smithy_json::deserialize::Token::EndObject { .. }) => break,
123            Some(::aws_smithy_json::deserialize::Token::ObjectKey { key, .. }) => match key.to_unescaped()?.as_ref() {
124                "Gateway" => {
125                    builder = builder.set_gateway(crate::protocol_serde::shape_gateway_details::de_gateway_details(tokens)?);
126                }
127                _ => ::aws_smithy_json::deserialize::token::skip_value(tokens)?,
128            },
129            other => {
130                return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(format!(
131                    "expected object key or end object, found: {other:?}"
132                )))
133            }
134        }
135    }
136    if tokens.next().is_some() {
137        return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
138            "found more JSON tokens after completing parsing",
139        ));
140    }
141    Ok(builder)
142}