1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
pub fn ser_network(
    object: &mut aws_smithy_json::serialize::JsonObjectWriter,
    input: &crate::types::Network,
) -> Result<(), aws_smithy_http::operation::error::SerializationError> {
    if let Some(var_1) = &input.direction {
        object.key("Direction").string(var_1.as_str());
    }
    if let Some(var_2) = &input.protocol {
        object.key("Protocol").string(var_2.as_str());
    }
    if let Some(var_3) = &input.open_port_range {
        #[allow(unused_mut)]
        let mut object_4 = object.key("OpenPortRange").start_object();
        crate::protocol_serde::shape_port_range::ser_port_range(&mut object_4, var_3)?;
        object_4.finish();
    }
    if let Some(var_5) = &input.source_ip_v4 {
        object.key("SourceIpV4").string(var_5.as_str());
    }
    if let Some(var_6) = &input.source_ip_v6 {
        object.key("SourceIpV6").string(var_6.as_str());
    }
    if input.source_port != 0 {
        object.key("SourcePort").number(
            #[allow(clippy::useless_conversion)]
            aws_smithy_types::Number::NegInt((input.source_port).into()),
        );
    }
    if let Some(var_7) = &input.source_domain {
        object.key("SourceDomain").string(var_7.as_str());
    }
    if let Some(var_8) = &input.source_mac {
        object.key("SourceMac").string(var_8.as_str());
    }
    if let Some(var_9) = &input.destination_ip_v4 {
        object.key("DestinationIpV4").string(var_9.as_str());
    }
    if let Some(var_10) = &input.destination_ip_v6 {
        object.key("DestinationIpV6").string(var_10.as_str());
    }
    if input.destination_port != 0 {
        object.key("DestinationPort").number(
            #[allow(clippy::useless_conversion)]
            aws_smithy_types::Number::NegInt((input.destination_port).into()),
        );
    }
    if let Some(var_11) = &input.destination_domain {
        object.key("DestinationDomain").string(var_11.as_str());
    }
    Ok(())
}

pub(crate) fn de_network<'a, I>(
    tokens: &mut std::iter::Peekable<I>,
) -> Result<Option<crate::types::Network>, aws_smithy_json::deserialize::error::DeserializeError>
where
    I: Iterator<
        Item = Result<
            aws_smithy_json::deserialize::Token<'a>,
            aws_smithy_json::deserialize::error::DeserializeError,
        >,
    >,
{
    match tokens.next().transpose()? {
        Some(aws_smithy_json::deserialize::Token::ValueNull { .. }) => Ok(None),
        Some(aws_smithy_json::deserialize::Token::StartObject { .. }) => {
            #[allow(unused_mut)]
            let mut builder = crate::types::builders::NetworkBuilder::default();
            loop {
                match tokens.next().transpose()? {
                    Some(aws_smithy_json::deserialize::Token::EndObject { .. }) => break,
                    Some(aws_smithy_json::deserialize::Token::ObjectKey { key, .. }) => {
                        match key.to_unescaped()?.as_ref() {
                            "Direction" => {
                                builder = builder.set_direction(
                                    aws_smithy_json::deserialize::token::expect_string_or_null(
                                        tokens.next(),
                                    )?
                                    .map(|s| {
                                        s.to_unescaped().map(|u| {
                                            crate::types::NetworkDirection::from(u.as_ref())
                                        })
                                    })
                                    .transpose()?,
                                );
                            }
                            "Protocol" => {
                                builder = builder.set_protocol(
                                    aws_smithy_json::deserialize::token::expect_string_or_null(
                                        tokens.next(),
                                    )?
                                    .map(|s| s.to_unescaped().map(|u| u.into_owned()))
                                    .transpose()?,
                                );
                            }
                            "OpenPortRange" => {
                                builder = builder.set_open_port_range(
                                    crate::protocol_serde::shape_port_range::de_port_range(tokens)?,
                                );
                            }
                            "SourceIpV4" => {
                                builder = builder.set_source_ip_v4(
                                    aws_smithy_json::deserialize::token::expect_string_or_null(
                                        tokens.next(),
                                    )?
                                    .map(|s| s.to_unescaped().map(|u| u.into_owned()))
                                    .transpose()?,
                                );
                            }
                            "SourceIpV6" => {
                                builder = builder.set_source_ip_v6(
                                    aws_smithy_json::deserialize::token::expect_string_or_null(
                                        tokens.next(),
                                    )?
                                    .map(|s| s.to_unescaped().map(|u| u.into_owned()))
                                    .transpose()?,
                                );
                            }
                            "SourcePort" => {
                                builder = builder.set_source_port(
                                    aws_smithy_json::deserialize::token::expect_number_or_null(
                                        tokens.next(),
                                    )?
                                    .map(i32::try_from)
                                    .transpose()?,
                                );
                            }
                            "SourceDomain" => {
                                builder = builder.set_source_domain(
                                    aws_smithy_json::deserialize::token::expect_string_or_null(
                                        tokens.next(),
                                    )?
                                    .map(|s| s.to_unescaped().map(|u| u.into_owned()))
                                    .transpose()?,
                                );
                            }
                            "SourceMac" => {
                                builder = builder.set_source_mac(
                                    aws_smithy_json::deserialize::token::expect_string_or_null(
                                        tokens.next(),
                                    )?
                                    .map(|s| s.to_unescaped().map(|u| u.into_owned()))
                                    .transpose()?,
                                );
                            }
                            "DestinationIpV4" => {
                                builder = builder.set_destination_ip_v4(
                                    aws_smithy_json::deserialize::token::expect_string_or_null(
                                        tokens.next(),
                                    )?
                                    .map(|s| s.to_unescaped().map(|u| u.into_owned()))
                                    .transpose()?,
                                );
                            }
                            "DestinationIpV6" => {
                                builder = builder.set_destination_ip_v6(
                                    aws_smithy_json::deserialize::token::expect_string_or_null(
                                        tokens.next(),
                                    )?
                                    .map(|s| s.to_unescaped().map(|u| u.into_owned()))
                                    .transpose()?,
                                );
                            }
                            "DestinationPort" => {
                                builder = builder.set_destination_port(
                                    aws_smithy_json::deserialize::token::expect_number_or_null(
                                        tokens.next(),
                                    )?
                                    .map(i32::try_from)
                                    .transpose()?,
                                );
                            }
                            "DestinationDomain" => {
                                builder = builder.set_destination_domain(
                                    aws_smithy_json::deserialize::token::expect_string_or_null(
                                        tokens.next(),
                                    )?
                                    .map(|s| s.to_unescaped().map(|u| u.into_owned()))
                                    .transpose()?,
                                );
                            }
                            _ => aws_smithy_json::deserialize::token::skip_value(tokens)?,
                        }
                    }
                    other => {
                        return Err(
                            aws_smithy_json::deserialize::error::DeserializeError::custom(format!(
                                "expected object key or end object, found: {:?}",
                                other
                            )),
                        )
                    }
                }
            }
            Ok(Some(builder.build()))
        }
        _ => Err(
            aws_smithy_json::deserialize::error::DeserializeError::custom(
                "expected start object or null",
            ),
        ),
    }
}