aws_sdk_drs/protocol_serde/
shape_reverse_replication.rs

1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2#[allow(clippy::unnecessary_wraps)]
3pub fn de_reverse_replication_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::reverse_replication::ReverseReplicationOutput,
9    crate::operation::reverse_replication::ReverseReplicationError,
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::reverse_replication::ReverseReplicationError::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::reverse_replication::ReverseReplicationError::unhandled(generic)),
19    };
20
21    let _error_message = generic.message().map(|msg| msg.to_owned());
22    Err(match error_code {
23        "AccessDeniedException" => crate::operation::reverse_replication::ReverseReplicationError::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::reverse_replication::ReverseReplicationError::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::reverse_replication::ReverseReplicationError::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::reverse_replication::ReverseReplicationError::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::reverse_replication::ReverseReplicationError::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::reverse_replication::ReverseReplicationError::unhandled)?;
60                output = output.set_retry_after_seconds(
61                    crate::protocol_serde::shape_internal_server_exception::de_retry_after_seconds_header(_response_headers).map_err(|_| {
62                        crate::operation::reverse_replication::ReverseReplicationError::unhandled(
63                            "Failed to parse retryAfterSeconds from header `Retry-After",
64                        )
65                    })?,
66                );
67                let output = output.meta(generic);
68                crate::serde_util::internal_server_exception_correct_errors(output)
69                    .build()
70                    .map_err(crate::operation::reverse_replication::ReverseReplicationError::unhandled)?
71            };
72            tmp
73        }),
74        "ResourceNotFoundException" => crate::operation::reverse_replication::ReverseReplicationError::ResourceNotFoundException({
75            #[allow(unused_mut)]
76            let mut tmp = {
77                #[allow(unused_mut)]
78                let mut output = crate::types::error::builders::ResourceNotFoundExceptionBuilder::default();
79                output = crate::protocol_serde::shape_resource_not_found_exception::de_resource_not_found_exception_json_err(_response_body, output)
80                    .map_err(crate::operation::reverse_replication::ReverseReplicationError::unhandled)?;
81                let output = output.meta(generic);
82                output.build()
83            };
84            if tmp.message.is_none() {
85                tmp.message = _error_message;
86            }
87            tmp
88        }),
89        "ThrottlingException" => crate::operation::reverse_replication::ReverseReplicationError::ThrottlingException({
90            #[allow(unused_mut)]
91            let mut tmp = {
92                #[allow(unused_mut)]
93                let mut output = crate::types::error::builders::ThrottlingExceptionBuilder::default();
94                output = crate::protocol_serde::shape_throttling_exception::de_throttling_exception_json_err(_response_body, output)
95                    .map_err(crate::operation::reverse_replication::ReverseReplicationError::unhandled)?;
96                output = output.set_retry_after_seconds(
97                    crate::protocol_serde::shape_throttling_exception::de_retry_after_seconds_header(_response_headers).map_err(|_| {
98                        crate::operation::reverse_replication::ReverseReplicationError::unhandled(
99                            "Failed to parse retryAfterSeconds from header `Retry-After",
100                        )
101                    })?,
102                );
103                let output = output.meta(generic);
104                crate::serde_util::throttling_exception_correct_errors(output)
105                    .build()
106                    .map_err(crate::operation::reverse_replication::ReverseReplicationError::unhandled)?
107            };
108            tmp
109        }),
110        "UninitializedAccountException" => crate::operation::reverse_replication::ReverseReplicationError::UninitializedAccountException({
111            #[allow(unused_mut)]
112            let mut tmp = {
113                #[allow(unused_mut)]
114                let mut output = crate::types::error::builders::UninitializedAccountExceptionBuilder::default();
115                output =
116                    crate::protocol_serde::shape_uninitialized_account_exception::de_uninitialized_account_exception_json_err(_response_body, output)
117                        .map_err(crate::operation::reverse_replication::ReverseReplicationError::unhandled)?;
118                let output = output.meta(generic);
119                output.build()
120            };
121            if tmp.message.is_none() {
122                tmp.message = _error_message;
123            }
124            tmp
125        }),
126        "ValidationException" => crate::operation::reverse_replication::ReverseReplicationError::ValidationException({
127            #[allow(unused_mut)]
128            let mut tmp = {
129                #[allow(unused_mut)]
130                let mut output = crate::types::error::builders::ValidationExceptionBuilder::default();
131                output = crate::protocol_serde::shape_validation_exception::de_validation_exception_json_err(_response_body, output)
132                    .map_err(crate::operation::reverse_replication::ReverseReplicationError::unhandled)?;
133                let output = output.meta(generic);
134                output.build()
135            };
136            if tmp.message.is_none() {
137                tmp.message = _error_message;
138            }
139            tmp
140        }),
141        _ => crate::operation::reverse_replication::ReverseReplicationError::generic(generic),
142    })
143}
144
145#[allow(clippy::unnecessary_wraps)]
146pub fn de_reverse_replication_http_response(
147    _response_status: u16,
148    _response_headers: &::aws_smithy_runtime_api::http::Headers,
149    _response_body: &[u8],
150) -> std::result::Result<
151    crate::operation::reverse_replication::ReverseReplicationOutput,
152    crate::operation::reverse_replication::ReverseReplicationError,
153> {
154    Ok({
155        #[allow(unused_mut)]
156        let mut output = crate::operation::reverse_replication::builders::ReverseReplicationOutputBuilder::default();
157        output = crate::protocol_serde::shape_reverse_replication::de_reverse_replication(_response_body, output)
158            .map_err(crate::operation::reverse_replication::ReverseReplicationError::unhandled)?;
159        output._set_request_id(::aws_types::request_id::RequestId::request_id(_response_headers).map(str::to_string));
160        output.build()
161    })
162}
163
164pub fn ser_reverse_replication_input(
165    input: &crate::operation::reverse_replication::ReverseReplicationInput,
166) -> ::std::result::Result<::aws_smithy_types::body::SdkBody, ::aws_smithy_types::error::operation::SerializationError> {
167    let mut out = String::new();
168    let mut object = ::aws_smithy_json::serialize::JsonObjectWriter::new(&mut out);
169    crate::protocol_serde::shape_reverse_replication_input::ser_reverse_replication_input_input(&mut object, input)?;
170    object.finish();
171    Ok(::aws_smithy_types::body::SdkBody::from(out))
172}
173
174pub(crate) fn de_reverse_replication(
175    value: &[u8],
176    mut builder: crate::operation::reverse_replication::builders::ReverseReplicationOutputBuilder,
177) -> ::std::result::Result<
178    crate::operation::reverse_replication::builders::ReverseReplicationOutputBuilder,
179    ::aws_smithy_json::deserialize::error::DeserializeError,
180> {
181    let mut tokens_owned = ::aws_smithy_json::deserialize::json_token_iter(crate::protocol_serde::or_empty_doc(value)).peekable();
182    let tokens = &mut tokens_owned;
183    ::aws_smithy_json::deserialize::token::expect_start_object(tokens.next())?;
184    loop {
185        match tokens.next().transpose()? {
186            Some(::aws_smithy_json::deserialize::Token::EndObject { .. }) => break,
187            Some(::aws_smithy_json::deserialize::Token::ObjectKey { key, .. }) => match key.to_unescaped()?.as_ref() {
188                "reversedDirectionSourceServerArn" => {
189                    builder = builder.set_reversed_direction_source_server_arn(
190                        ::aws_smithy_json::deserialize::token::expect_string_or_null(tokens.next())?
191                            .map(|s| s.to_unescaped().map(|u| u.into_owned()))
192                            .transpose()?,
193                    );
194                }
195                _ => ::aws_smithy_json::deserialize::token::skip_value(tokens)?,
196            },
197            other => {
198                return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(format!(
199                    "expected object key or end object, found: {:?}",
200                    other
201                )))
202            }
203        }
204    }
205    if tokens.next().is_some() {
206        return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
207            "found more JSON tokens after completing parsing",
208        ));
209    }
210    Ok(builder)
211}