aws-sdk-qapps 1.62.0

AWS SDK for QApps
Documentation
// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
pub fn ser_document_attribute_value(
    object_2: &mut ::aws_smithy_json::serialize::JsonObjectWriter,
    input: &crate::types::DocumentAttributeValue,
) -> ::std::result::Result<(), ::aws_smithy_types::error::operation::SerializationError> {
    match input {
        crate::types::DocumentAttributeValue::StringValue(inner) => {
            object_2.key("stringValue").string(inner.as_str());
        }
        crate::types::DocumentAttributeValue::StringListValue(inner) => {
            let mut array_1 = object_2.key("stringListValue").start_array();
            for item_2 in inner {
                {
                    array_1.value().string(item_2.as_str());
                }
            }
            array_1.finish();
        }
        crate::types::DocumentAttributeValue::LongValue(inner) => {
            object_2.key("longValue").number(
                #[allow(clippy::useless_conversion)]
                ::aws_smithy_types::Number::NegInt((*inner).into()),
            );
        }
        crate::types::DocumentAttributeValue::DateValue(inner) => {
            object_2
                .key("dateValue")
                .date_time(inner, ::aws_smithy_types::date_time::Format::EpochSeconds)?;
        }
        crate::types::DocumentAttributeValue::Unknown => {
            return Err(::aws_smithy_types::error::operation::SerializationError::unknown_variant(
                "DocumentAttributeValue",
            ))
        }
    }
    Ok(())
}

pub(crate) fn de_document_attribute_value<'a, I>(
    tokens: &mut ::std::iter::Peekable<I>,
    _value: &'a [u8],
) -> ::std::result::Result<Option<crate::types::DocumentAttributeValue>, ::aws_smithy_json::deserialize::error::DeserializeError>
where
    I: Iterator<Item = Result<::aws_smithy_json::deserialize::Token<'a>, ::aws_smithy_json::deserialize::error::DeserializeError>>,
{
    let mut variant = None;
    match tokens.next().transpose()? {
        Some(::aws_smithy_json::deserialize::Token::ValueNull { .. }) => return Ok(None),
        Some(::aws_smithy_json::deserialize::Token::StartObject { .. }) => loop {
            match tokens.next().transpose()? {
                Some(::aws_smithy_json::deserialize::Token::EndObject { .. }) => break,
                Some(::aws_smithy_json::deserialize::Token::ObjectKey { key, .. }) => {
                    if let ::std::option::Option::Some(::std::result::Result::Ok(::aws_smithy_json::deserialize::Token::ValueNull { .. })) =
                        tokens.peek()
                    {
                        let _ = tokens.next().expect("peek returned a token")?;
                        continue;
                    }
                    let key = key.to_unescaped()?;
                    if key == "__type" {
                        ::aws_smithy_json::deserialize::token::skip_value(tokens)?;
                        continue;
                    }
                    if variant.is_some() {
                        return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
                            "encountered mixed variants in union",
                        ));
                    }
                    variant = match key.as_ref() {
                        "stringValue" => Some(crate::types::DocumentAttributeValue::StringValue(
                            ::aws_smithy_json::deserialize::token::expect_string_or_null(tokens.next())?
                                .map(|s| s.to_unescaped().map(|u| u.into_owned()))
                                .transpose()?
                                .ok_or_else(|| {
                                    ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'stringValue' cannot be null")
                                })?,
                        )),
                        "stringListValue" => Some(crate::types::DocumentAttributeValue::StringListValue(
                            crate::protocol_serde::shape_document_attribute_string_list_value::de_document_attribute_string_list_value(
                                tokens, _value,
                            )?
                            .ok_or_else(|| {
                                ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'stringListValue' cannot be null")
                            })?,
                        )),
                        "longValue" => Some(crate::types::DocumentAttributeValue::LongValue(
                            ::aws_smithy_json::deserialize::token::expect_number_or_null(tokens.next())?
                                .map(i64::try_from)
                                .transpose()?
                                .ok_or_else(|| {
                                    ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'longValue' cannot be null")
                                })?,
                        )),
                        "dateValue" => Some(crate::types::DocumentAttributeValue::DateValue(
                            ::aws_smithy_json::deserialize::token::expect_timestamp_or_null(
                                tokens.next(),
                                ::aws_smithy_types::date_time::Format::EpochSeconds,
                            )?
                            .ok_or_else(|| ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'dateValue' cannot be null"))?,
                        )),
                        _ => {
                            ::aws_smithy_json::deserialize::token::skip_value(tokens)?;
                            Some(crate::types::DocumentAttributeValue::Unknown)
                        }
                    };
                }
                other => {
                    return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(format!(
                        "expected object key or end object, found: {other:?}"
                    )))
                }
            }
        },
        _ => {
            return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
                "expected start object or null",
            ))
        }
    }
    if variant.is_none() {
        return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
            "Union did not contain a valid variant.",
        ));
    }
    Ok(variant)
}