aws_sdk_cloudwatchevents/protocol_serde/
shape_create_archive.rs

1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2#[allow(clippy::unnecessary_wraps)]
3pub fn de_create_archive_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_archive::CreateArchiveOutput, crate::operation::create_archive::CreateArchiveError> {
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_archive::CreateArchiveError::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_archive::CreateArchiveError::unhandled(generic)),
16    };
17
18    let _error_message = generic.message().map(|msg| msg.to_owned());
19    Err(match error_code {
20        "ConcurrentModificationException" => crate::operation::create_archive::CreateArchiveError::ConcurrentModificationException({
21            #[allow(unused_mut)]
22            let mut tmp = {
23                #[allow(unused_mut)]
24                let mut output = crate::types::error::builders::ConcurrentModificationExceptionBuilder::default();
25                output = crate::protocol_serde::shape_concurrent_modification_exception::de_concurrent_modification_exception_json_err(
26                    _response_body,
27                    output,
28                )
29                .map_err(crate::operation::create_archive::CreateArchiveError::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        "InternalException" => crate::operation::create_archive::CreateArchiveError::InternalException({
39            #[allow(unused_mut)]
40            let mut tmp = {
41                #[allow(unused_mut)]
42                let mut output = crate::types::error::builders::InternalExceptionBuilder::default();
43                output = crate::protocol_serde::shape_internal_exception::de_internal_exception_json_err(_response_body, output)
44                    .map_err(crate::operation::create_archive::CreateArchiveError::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        "InvalidEventPatternException" => crate::operation::create_archive::CreateArchiveError::InvalidEventPatternException({
54            #[allow(unused_mut)]
55            let mut tmp = {
56                #[allow(unused_mut)]
57                let mut output = crate::types::error::builders::InvalidEventPatternExceptionBuilder::default();
58                output =
59                    crate::protocol_serde::shape_invalid_event_pattern_exception::de_invalid_event_pattern_exception_json_err(_response_body, output)
60                        .map_err(crate::operation::create_archive::CreateArchiveError::unhandled)?;
61                let output = output.meta(generic);
62                output.build()
63            };
64            if tmp.message.is_none() {
65                tmp.message = _error_message;
66            }
67            tmp
68        }),
69        "LimitExceededException" => crate::operation::create_archive::CreateArchiveError::LimitExceededException({
70            #[allow(unused_mut)]
71            let mut tmp = {
72                #[allow(unused_mut)]
73                let mut output = crate::types::error::builders::LimitExceededExceptionBuilder::default();
74                output = crate::protocol_serde::shape_limit_exceeded_exception::de_limit_exceeded_exception_json_err(_response_body, output)
75                    .map_err(crate::operation::create_archive::CreateArchiveError::unhandled)?;
76                let output = output.meta(generic);
77                output.build()
78            };
79            if tmp.message.is_none() {
80                tmp.message = _error_message;
81            }
82            tmp
83        }),
84        "ResourceAlreadyExistsException" => crate::operation::create_archive::CreateArchiveError::ResourceAlreadyExistsException({
85            #[allow(unused_mut)]
86            let mut tmp = {
87                #[allow(unused_mut)]
88                let mut output = crate::types::error::builders::ResourceAlreadyExistsExceptionBuilder::default();
89                output = crate::protocol_serde::shape_resource_already_exists_exception::de_resource_already_exists_exception_json_err(
90                    _response_body,
91                    output,
92                )
93                .map_err(crate::operation::create_archive::CreateArchiveError::unhandled)?;
94                let output = output.meta(generic);
95                output.build()
96            };
97            if tmp.message.is_none() {
98                tmp.message = _error_message;
99            }
100            tmp
101        }),
102        "ResourceNotFoundException" => crate::operation::create_archive::CreateArchiveError::ResourceNotFoundException({
103            #[allow(unused_mut)]
104            let mut tmp = {
105                #[allow(unused_mut)]
106                let mut output = crate::types::error::builders::ResourceNotFoundExceptionBuilder::default();
107                output = crate::protocol_serde::shape_resource_not_found_exception::de_resource_not_found_exception_json_err(_response_body, output)
108                    .map_err(crate::operation::create_archive::CreateArchiveError::unhandled)?;
109                let output = output.meta(generic);
110                output.build()
111            };
112            if tmp.message.is_none() {
113                tmp.message = _error_message;
114            }
115            tmp
116        }),
117        _ => crate::operation::create_archive::CreateArchiveError::generic(generic),
118    })
119}
120
121#[allow(clippy::unnecessary_wraps)]
122pub fn de_create_archive_http_response(
123    _response_status: u16,
124    _response_headers: &::aws_smithy_runtime_api::http::Headers,
125    _response_body: &[u8],
126) -> std::result::Result<crate::operation::create_archive::CreateArchiveOutput, crate::operation::create_archive::CreateArchiveError> {
127    Ok({
128        #[allow(unused_mut)]
129        let mut output = crate::operation::create_archive::builders::CreateArchiveOutputBuilder::default();
130        output = crate::protocol_serde::shape_create_archive::de_create_archive(_response_body, output)
131            .map_err(crate::operation::create_archive::CreateArchiveError::unhandled)?;
132        output._set_request_id(::aws_types::request_id::RequestId::request_id(_response_headers).map(str::to_string));
133        output.build()
134    })
135}
136
137pub fn ser_create_archive_input(
138    input: &crate::operation::create_archive::CreateArchiveInput,
139) -> ::std::result::Result<::aws_smithy_types::body::SdkBody, ::aws_smithy_types::error::operation::SerializationError> {
140    let mut out = String::new();
141    let mut object = ::aws_smithy_json::serialize::JsonObjectWriter::new(&mut out);
142    crate::protocol_serde::shape_create_archive_input::ser_create_archive_input_input(&mut object, input)?;
143    object.finish();
144    Ok(::aws_smithy_types::body::SdkBody::from(out))
145}
146
147pub(crate) fn de_create_archive(
148    value: &[u8],
149    mut builder: crate::operation::create_archive::builders::CreateArchiveOutputBuilder,
150) -> ::std::result::Result<
151    crate::operation::create_archive::builders::CreateArchiveOutputBuilder,
152    ::aws_smithy_json::deserialize::error::DeserializeError,
153> {
154    let mut tokens_owned = ::aws_smithy_json::deserialize::json_token_iter(crate::protocol_serde::or_empty_doc(value)).peekable();
155    let tokens = &mut tokens_owned;
156    ::aws_smithy_json::deserialize::token::expect_start_object(tokens.next())?;
157    loop {
158        match tokens.next().transpose()? {
159            Some(::aws_smithy_json::deserialize::Token::EndObject { .. }) => break,
160            Some(::aws_smithy_json::deserialize::Token::ObjectKey { key, .. }) => match key.to_unescaped()?.as_ref() {
161                "ArchiveArn" => {
162                    builder = builder.set_archive_arn(
163                        ::aws_smithy_json::deserialize::token::expect_string_or_null(tokens.next())?
164                            .map(|s| s.to_unescaped().map(|u| u.into_owned()))
165                            .transpose()?,
166                    );
167                }
168                "State" => {
169                    builder = builder.set_state(
170                        ::aws_smithy_json::deserialize::token::expect_string_or_null(tokens.next())?
171                            .map(|s| s.to_unescaped().map(|u| crate::types::ArchiveState::from(u.as_ref())))
172                            .transpose()?,
173                    );
174                }
175                "StateReason" => {
176                    builder = builder.set_state_reason(
177                        ::aws_smithy_json::deserialize::token::expect_string_or_null(tokens.next())?
178                            .map(|s| s.to_unescaped().map(|u| u.into_owned()))
179                            .transpose()?,
180                    );
181                }
182                "CreationTime" => {
183                    builder = builder.set_creation_time(::aws_smithy_json::deserialize::token::expect_timestamp_or_null(
184                        tokens.next(),
185                        ::aws_smithy_types::date_time::Format::EpochSeconds,
186                    )?);
187                }
188                _ => ::aws_smithy_json::deserialize::token::skip_value(tokens)?,
189            },
190            other => {
191                return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(format!(
192                    "expected object key or end object, found: {other:?}"
193                )))
194            }
195        }
196    }
197    if tokens.next().is_some() {
198        return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
199            "found more JSON tokens after completing parsing",
200        ));
201    }
202    Ok(builder)
203}