aws_sdk_ecs/protocol_serde/
shape_port_mapping.rs

1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2pub fn ser_port_mapping(
3    object: &mut ::aws_smithy_json::serialize::JsonObjectWriter,
4    input: &crate::types::PortMapping,
5) -> ::std::result::Result<(), ::aws_smithy_types::error::operation::SerializationError> {
6    if let Some(var_1) = &input.container_port {
7        object.key("containerPort").number(
8            #[allow(clippy::useless_conversion)]
9            ::aws_smithy_types::Number::NegInt((*var_1).into()),
10        );
11    }
12    if let Some(var_2) = &input.host_port {
13        object.key("hostPort").number(
14            #[allow(clippy::useless_conversion)]
15            ::aws_smithy_types::Number::NegInt((*var_2).into()),
16        );
17    }
18    if let Some(var_3) = &input.protocol {
19        object.key("protocol").string(var_3.as_str());
20    }
21    if let Some(var_4) = &input.name {
22        object.key("name").string(var_4.as_str());
23    }
24    if let Some(var_5) = &input.app_protocol {
25        object.key("appProtocol").string(var_5.as_str());
26    }
27    if let Some(var_6) = &input.container_port_range {
28        object.key("containerPortRange").string(var_6.as_str());
29    }
30    Ok(())
31}
32
33pub(crate) fn de_port_mapping<'a, I>(
34    tokens: &mut ::std::iter::Peekable<I>,
35) -> ::std::result::Result<Option<crate::types::PortMapping>, ::aws_smithy_json::deserialize::error::DeserializeError>
36where
37    I: Iterator<Item = Result<::aws_smithy_json::deserialize::Token<'a>, ::aws_smithy_json::deserialize::error::DeserializeError>>,
38{
39    match tokens.next().transpose()? {
40        Some(::aws_smithy_json::deserialize::Token::ValueNull { .. }) => Ok(None),
41        Some(::aws_smithy_json::deserialize::Token::StartObject { .. }) => {
42            #[allow(unused_mut)]
43            let mut builder = crate::types::builders::PortMappingBuilder::default();
44            loop {
45                match tokens.next().transpose()? {
46                    Some(::aws_smithy_json::deserialize::Token::EndObject { .. }) => break,
47                    Some(::aws_smithy_json::deserialize::Token::ObjectKey { key, .. }) => match key.to_unescaped()?.as_ref() {
48                        "containerPort" => {
49                            builder = builder.set_container_port(
50                                ::aws_smithy_json::deserialize::token::expect_number_or_null(tokens.next())?
51                                    .map(i32::try_from)
52                                    .transpose()?,
53                            );
54                        }
55                        "hostPort" => {
56                            builder = builder.set_host_port(
57                                ::aws_smithy_json::deserialize::token::expect_number_or_null(tokens.next())?
58                                    .map(i32::try_from)
59                                    .transpose()?,
60                            );
61                        }
62                        "protocol" => {
63                            builder = builder.set_protocol(
64                                ::aws_smithy_json::deserialize::token::expect_string_or_null(tokens.next())?
65                                    .map(|s| s.to_unescaped().map(|u| crate::types::TransportProtocol::from(u.as_ref())))
66                                    .transpose()?,
67                            );
68                        }
69                        "name" => {
70                            builder = builder.set_name(
71                                ::aws_smithy_json::deserialize::token::expect_string_or_null(tokens.next())?
72                                    .map(|s| s.to_unescaped().map(|u| u.into_owned()))
73                                    .transpose()?,
74                            );
75                        }
76                        "appProtocol" => {
77                            builder = builder.set_app_protocol(
78                                ::aws_smithy_json::deserialize::token::expect_string_or_null(tokens.next())?
79                                    .map(|s| s.to_unescaped().map(|u| crate::types::ApplicationProtocol::from(u.as_ref())))
80                                    .transpose()?,
81                            );
82                        }
83                        "containerPortRange" => {
84                            builder = builder.set_container_port_range(
85                                ::aws_smithy_json::deserialize::token::expect_string_or_null(tokens.next())?
86                                    .map(|s| s.to_unescaped().map(|u| u.into_owned()))
87                                    .transpose()?,
88                            );
89                        }
90                        _ => ::aws_smithy_json::deserialize::token::skip_value(tokens)?,
91                    },
92                    other => {
93                        return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(format!(
94                            "expected object key or end object, found: {:?}",
95                            other
96                        )))
97                    }
98                }
99            }
100            Ok(Some(builder.build()))
101        }
102        _ => Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
103            "expected start object or null",
104        )),
105    }
106}