aws_sdk_wafv2/protocol_serde/
shape_byte_match_statement.rs

1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2pub fn ser_byte_match_statement(
3    object: &mut ::aws_smithy_json::serialize::JsonObjectWriter,
4    input: &crate::types::ByteMatchStatement,
5) -> ::std::result::Result<(), ::aws_smithy_types::error::operation::SerializationError> {
6    {
7        object
8            .key("SearchString")
9            .string_unchecked(&::aws_smithy_types::base64::encode(&input.search_string));
10    }
11    if let Some(var_1) = &input.field_to_match {
12        #[allow(unused_mut)]
13        let mut object_2 = object.key("FieldToMatch").start_object();
14        crate::protocol_serde::shape_field_to_match::ser_field_to_match(&mut object_2, var_1)?;
15        object_2.finish();
16    }
17    {
18        let mut array_3 = object.key("TextTransformations").start_array();
19        for item_4 in &input.text_transformations {
20            {
21                #[allow(unused_mut)]
22                let mut object_5 = array_3.value().start_object();
23                crate::protocol_serde::shape_text_transformation::ser_text_transformation(&mut object_5, item_4)?;
24                object_5.finish();
25            }
26        }
27        array_3.finish();
28    }
29    {
30        object.key("PositionalConstraint").string(input.positional_constraint.as_str());
31    }
32    Ok(())
33}
34
35pub(crate) fn de_byte_match_statement<'a, I>(
36    tokens: &mut ::std::iter::Peekable<I>,
37) -> ::std::result::Result<Option<crate::types::ByteMatchStatement>, ::aws_smithy_json::deserialize::error::DeserializeError>
38where
39    I: Iterator<Item = Result<::aws_smithy_json::deserialize::Token<'a>, ::aws_smithy_json::deserialize::error::DeserializeError>>,
40{
41    match tokens.next().transpose()? {
42        Some(::aws_smithy_json::deserialize::Token::ValueNull { .. }) => Ok(None),
43        Some(::aws_smithy_json::deserialize::Token::StartObject { .. }) => {
44            #[allow(unused_mut)]
45            let mut builder = crate::types::builders::ByteMatchStatementBuilder::default();
46            loop {
47                match tokens.next().transpose()? {
48                    Some(::aws_smithy_json::deserialize::Token::EndObject { .. }) => break,
49                    Some(::aws_smithy_json::deserialize::Token::ObjectKey { key, .. }) => match key.to_unescaped()?.as_ref() {
50                        "SearchString" => {
51                            builder = builder.set_search_string(::aws_smithy_json::deserialize::token::expect_blob_or_null(tokens.next())?);
52                        }
53                        "FieldToMatch" => {
54                            builder = builder.set_field_to_match(crate::protocol_serde::shape_field_to_match::de_field_to_match(tokens)?);
55                        }
56                        "TextTransformations" => {
57                            builder =
58                                builder.set_text_transformations(crate::protocol_serde::shape_text_transformations::de_text_transformations(tokens)?);
59                        }
60                        "PositionalConstraint" => {
61                            builder = builder.set_positional_constraint(
62                                ::aws_smithy_json::deserialize::token::expect_string_or_null(tokens.next())?
63                                    .map(|s| s.to_unescaped().map(|u| crate::types::PositionalConstraint::from(u.as_ref())))
64                                    .transpose()?,
65                            );
66                        }
67                        _ => ::aws_smithy_json::deserialize::token::skip_value(tokens)?,
68                    },
69                    other => {
70                        return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(format!(
71                            "expected object key or end object, found: {:?}",
72                            other
73                        )))
74                    }
75                }
76            }
77            Ok(Some(crate::serde_util::byte_match_statement_correct_errors(builder).build().map_err(
78                |err| ::aws_smithy_json::deserialize::error::DeserializeError::custom_source("Response was invalid", err),
79            )?))
80        }
81        _ => Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
82            "expected start object or null",
83        )),
84    }
85}