aws_sdk_wafv2/protocol_serde/
shape_size_constraint_statement.rs1pub fn ser_size_constraint_statement(
3 object: &mut ::aws_smithy_json::serialize::JsonObjectWriter,
4 input: &crate::types::SizeConstraintStatement,
5) -> ::std::result::Result<(), ::aws_smithy_types::error::operation::SerializationError> {
6 if let Some(var_1) = &input.field_to_match {
7 #[allow(unused_mut)]
8 let mut object_2 = object.key("FieldToMatch").start_object();
9 crate::protocol_serde::shape_field_to_match::ser_field_to_match(&mut object_2, var_1)?;
10 object_2.finish();
11 }
12 {
13 object.key("ComparisonOperator").string(input.comparison_operator.as_str());
14 }
15 {
16 object.key("Size").number(
17 #[allow(clippy::useless_conversion)]
18 ::aws_smithy_types::Number::NegInt((input.size).into()),
19 );
20 }
21 {
22 let mut array_3 = object.key("TextTransformations").start_array();
23 for item_4 in &input.text_transformations {
24 {
25 #[allow(unused_mut)]
26 let mut object_5 = array_3.value().start_object();
27 crate::protocol_serde::shape_text_transformation::ser_text_transformation(&mut object_5, item_4)?;
28 object_5.finish();
29 }
30 }
31 array_3.finish();
32 }
33 Ok(())
34}
35
36pub(crate) fn de_size_constraint_statement<'a, I>(
37 tokens: &mut ::std::iter::Peekable<I>,
38) -> ::std::result::Result<Option<crate::types::SizeConstraintStatement>, ::aws_smithy_json::deserialize::error::DeserializeError>
39where
40 I: Iterator<Item = Result<::aws_smithy_json::deserialize::Token<'a>, ::aws_smithy_json::deserialize::error::DeserializeError>>,
41{
42 match tokens.next().transpose()? {
43 Some(::aws_smithy_json::deserialize::Token::ValueNull { .. }) => Ok(None),
44 Some(::aws_smithy_json::deserialize::Token::StartObject { .. }) => {
45 #[allow(unused_mut)]
46 let mut builder = crate::types::builders::SizeConstraintStatementBuilder::default();
47 loop {
48 match tokens.next().transpose()? {
49 Some(::aws_smithy_json::deserialize::Token::EndObject { .. }) => break,
50 Some(::aws_smithy_json::deserialize::Token::ObjectKey { key, .. }) => match key.to_unescaped()?.as_ref() {
51 "FieldToMatch" => {
52 builder = builder.set_field_to_match(crate::protocol_serde::shape_field_to_match::de_field_to_match(tokens)?);
53 }
54 "ComparisonOperator" => {
55 builder = builder.set_comparison_operator(
56 ::aws_smithy_json::deserialize::token::expect_string_or_null(tokens.next())?
57 .map(|s| s.to_unescaped().map(|u| crate::types::ComparisonOperator::from(u.as_ref())))
58 .transpose()?,
59 );
60 }
61 "Size" => {
62 builder = builder.set_size(
63 ::aws_smithy_json::deserialize::token::expect_number_or_null(tokens.next())?
64 .map(i64::try_from)
65 .transpose()?,
66 );
67 }
68 "TextTransformations" => {
69 builder =
70 builder.set_text_transformations(crate::protocol_serde::shape_text_transformations::de_text_transformations(tokens)?);
71 }
72 _ => ::aws_smithy_json::deserialize::token::skip_value(tokens)?,
73 },
74 other => {
75 return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(format!(
76 "expected object key or end object, found: {:?}",
77 other
78 )))
79 }
80 }
81 }
82 Ok(Some(
83 crate::serde_util::size_constraint_statement_correct_errors(builder)
84 .build()
85 .map_err(|err| ::aws_smithy_json::deserialize::error::DeserializeError::custom_source("Response was invalid", err))?,
86 ))
87 }
88 _ => Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
89 "expected start object or null",
90 )),
91 }
92}