aws-sdk-wafv2 1.130.0

AWS SDK for AWS WAFV2
Documentation
// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
pub fn ser_data_protection(
    object: &mut ::aws_smithy_json::serialize::JsonObjectWriter,
    input: &crate::types::DataProtection,
) -> ::std::result::Result<(), ::aws_smithy_types::error::operation::SerializationError> {
    if let Some(var_1) = &input.field {
        #[allow(unused_mut)]
        let mut object_2 = object.key("Field").start_object();
        crate::protocol_serde::shape_field_to_protect::ser_field_to_protect(&mut object_2, var_1)?;
        object_2.finish();
    }
    {
        object.key("Action").string(input.action.as_str());
    }
    if input.exclude_rule_match_details {
        object.key("ExcludeRuleMatchDetails").boolean(input.exclude_rule_match_details);
    }
    if input.exclude_rate_based_details {
        object.key("ExcludeRateBasedDetails").boolean(input.exclude_rate_based_details);
    }
    Ok(())
}

pub(crate) fn de_data_protection<'a, I>(
    tokens: &mut ::std::iter::Peekable<I>,
    _value: &'a [u8],
    depth: u32,
) -> ::std::result::Result<Option<crate::types::DataProtection>, ::aws_smithy_json::deserialize::error::DeserializeError>
where
    I: Iterator<Item = Result<::aws_smithy_json::deserialize::Token<'a>, ::aws_smithy_json::deserialize::error::DeserializeError>>,
{
    if depth >= 128u32 {
        return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
            "maximum nesting depth exceeded",
        ));
    }
    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::DataProtectionBuilder::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() {
                        "Field" => {
                            builder = builder.set_field(crate::protocol_serde::shape_field_to_protect::de_field_to_protect(
                                tokens,
                                _value,
                                depth + 1,
                            )?);
                        }
                        "Action" => {
                            builder = builder.set_action(
                                ::aws_smithy_json::deserialize::token::expect_string_or_null(tokens.next())?
                                    .map(|s| s.to_unescaped().map(|u| crate::types::DataProtectionAction::from(u.as_ref())))
                                    .transpose()?,
                            );
                        }
                        "ExcludeRuleMatchDetails" => {
                            builder =
                                builder.set_exclude_rule_match_details(::aws_smithy_json::deserialize::token::expect_bool_or_null(tokens.next())?);
                        }
                        "ExcludeRateBasedDetails" => {
                            builder =
                                builder.set_exclude_rate_based_details(::aws_smithy_json::deserialize::token::expect_bool_or_null(tokens.next())?);
                        }
                        _ => ::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(crate::serde_util::data_protection_correct_errors(builder).build().map_err(
                |err| ::aws_smithy_json::deserialize::error::DeserializeError::custom_source("Response was invalid", err),
            )?))
        }
        _ => Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
            "expected start object or null",
        )),
    }
}