aws_sdk_mediapackagev2/protocol_serde/
shape_get_channel_policy.rs

1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2#[allow(clippy::unnecessary_wraps)]
3pub fn de_get_channel_policy_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_channel_policy::GetChannelPolicyOutput, crate::operation::get_channel_policy::GetChannelPolicyError> {
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_channel_policy::GetChannelPolicyError::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_channel_policy::GetChannelPolicyError::unhandled(generic)),
16    };
17
18    let _error_message = generic.message().map(|msg| msg.to_owned());
19    Err(match error_code {
20        "AccessDeniedException" => crate::operation::get_channel_policy::GetChannelPolicyError::AccessDeniedException({
21            #[allow(unused_mut)]
22            let mut tmp = {
23                #[allow(unused_mut)]
24                let mut output = crate::types::error::builders::AccessDeniedExceptionBuilder::default();
25                output = crate::protocol_serde::shape_access_denied_exception::de_access_denied_exception_json_err(_response_body, output)
26                    .map_err(crate::operation::get_channel_policy::GetChannelPolicyError::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_channel_policy::GetChannelPolicyError::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_channel_policy::GetChannelPolicyError::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        "ResourceNotFoundException" => crate::operation::get_channel_policy::GetChannelPolicyError::ResourceNotFoundException({
51            #[allow(unused_mut)]
52            let mut tmp = {
53                #[allow(unused_mut)]
54                let mut output = crate::types::error::builders::ResourceNotFoundExceptionBuilder::default();
55                output = crate::protocol_serde::shape_resource_not_found_exception::de_resource_not_found_exception_json_err(_response_body, output)
56                    .map_err(crate::operation::get_channel_policy::GetChannelPolicyError::unhandled)?;
57                let output = output.meta(generic);
58                output.build()
59            };
60            if tmp.message.is_none() {
61                tmp.message = _error_message;
62            }
63            tmp
64        }),
65        "ThrottlingException" => crate::operation::get_channel_policy::GetChannelPolicyError::ThrottlingException({
66            #[allow(unused_mut)]
67            let mut tmp = {
68                #[allow(unused_mut)]
69                let mut output = crate::types::error::builders::ThrottlingExceptionBuilder::default();
70                output = crate::protocol_serde::shape_throttling_exception::de_throttling_exception_json_err(_response_body, output)
71                    .map_err(crate::operation::get_channel_policy::GetChannelPolicyError::unhandled)?;
72                let output = output.meta(generic);
73                output.build()
74            };
75            if tmp.message.is_none() {
76                tmp.message = _error_message;
77            }
78            tmp
79        }),
80        "ValidationException" => crate::operation::get_channel_policy::GetChannelPolicyError::ValidationException({
81            #[allow(unused_mut)]
82            let mut tmp = {
83                #[allow(unused_mut)]
84                let mut output = crate::types::error::builders::ValidationExceptionBuilder::default();
85                output = crate::protocol_serde::shape_validation_exception::de_validation_exception_json_err(_response_body, output)
86                    .map_err(crate::operation::get_channel_policy::GetChannelPolicyError::unhandled)?;
87                let output = output.meta(generic);
88                output.build()
89            };
90            if tmp.message.is_none() {
91                tmp.message = _error_message;
92            }
93            tmp
94        }),
95        _ => crate::operation::get_channel_policy::GetChannelPolicyError::generic(generic),
96    })
97}
98
99#[allow(clippy::unnecessary_wraps)]
100pub fn de_get_channel_policy_http_response(
101    _response_status: u16,
102    _response_headers: &::aws_smithy_runtime_api::http::Headers,
103    _response_body: &[u8],
104) -> std::result::Result<crate::operation::get_channel_policy::GetChannelPolicyOutput, crate::operation::get_channel_policy::GetChannelPolicyError> {
105    Ok({
106        #[allow(unused_mut)]
107        let mut output = crate::operation::get_channel_policy::builders::GetChannelPolicyOutputBuilder::default();
108        output = crate::protocol_serde::shape_get_channel_policy::de_get_channel_policy(_response_body, output)
109            .map_err(crate::operation::get_channel_policy::GetChannelPolicyError::unhandled)?;
110        output._set_request_id(::aws_types::request_id::RequestId::request_id(_response_headers).map(str::to_string));
111        crate::serde_util::get_channel_policy_output_output_correct_errors(output)
112            .build()
113            .map_err(crate::operation::get_channel_policy::GetChannelPolicyError::unhandled)?
114    })
115}
116
117pub(crate) fn de_get_channel_policy(
118    value: &[u8],
119    mut builder: crate::operation::get_channel_policy::builders::GetChannelPolicyOutputBuilder,
120) -> ::std::result::Result<
121    crate::operation::get_channel_policy::builders::GetChannelPolicyOutputBuilder,
122    ::aws_smithy_json::deserialize::error::DeserializeError,
123> {
124    let mut tokens_owned = ::aws_smithy_json::deserialize::json_token_iter(crate::protocol_serde::or_empty_doc(value)).peekable();
125    let tokens = &mut tokens_owned;
126    ::aws_smithy_json::deserialize::token::expect_start_object(tokens.next())?;
127    loop {
128        match tokens.next().transpose()? {
129            Some(::aws_smithy_json::deserialize::Token::EndObject { .. }) => break,
130            Some(::aws_smithy_json::deserialize::Token::ObjectKey { key, .. }) => match key.to_unescaped()?.as_ref() {
131                "ChannelGroupName" => {
132                    builder = builder.set_channel_group_name(
133                        ::aws_smithy_json::deserialize::token::expect_string_or_null(tokens.next())?
134                            .map(|s| s.to_unescaped().map(|u| u.into_owned()))
135                            .transpose()?,
136                    );
137                }
138                "ChannelName" => {
139                    builder = builder.set_channel_name(
140                        ::aws_smithy_json::deserialize::token::expect_string_or_null(tokens.next())?
141                            .map(|s| s.to_unescaped().map(|u| u.into_owned()))
142                            .transpose()?,
143                    );
144                }
145                "Policy" => {
146                    builder = builder.set_policy(
147                        ::aws_smithy_json::deserialize::token::expect_string_or_null(tokens.next())?
148                            .map(|s| s.to_unescaped().map(|u| u.into_owned()))
149                            .transpose()?,
150                    );
151                }
152                _ => ::aws_smithy_json::deserialize::token::skip_value(tokens)?,
153            },
154            other => {
155                return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(format!(
156                    "expected object key or end object, found: {:?}",
157                    other
158                )))
159            }
160        }
161    }
162    if tokens.next().is_some() {
163        return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
164            "found more JSON tokens after completing parsing",
165        ));
166    }
167    Ok(builder)
168}