pub fn ser_attribute_value(
object_6: &mut ::aws_smithy_json::serialize::JsonObjectWriter,
input: &crate::types::AttributeValue,
) -> ::std::result::Result<(), ::aws_smithy_types::error::operation::SerializationError> {
match input {
crate::types::AttributeValue::S(inner) => {
object_6.key("S").string(inner.as_str());
}
crate::types::AttributeValue::N(inner) => {
object_6.key("N").string(inner.as_str());
}
crate::types::AttributeValue::B(inner) => {
object_6.key("B").string_unchecked(&::aws_smithy_types::base64::encode(inner));
}
crate::types::AttributeValue::Ss(inner) => {
let mut array_1 = object_6.key("SS").start_array();
for item_2 in inner {
{
array_1.value().string(item_2.as_str());
}
}
array_1.finish();
}
crate::types::AttributeValue::Ns(inner) => {
let mut array_3 = object_6.key("NS").start_array();
for item_4 in inner {
{
array_3.value().string(item_4.as_str());
}
}
array_3.finish();
}
crate::types::AttributeValue::Bs(inner) => {
let mut array_5 = object_6.key("BS").start_array();
for item_6 in inner {
{
array_5.value().string_unchecked(&::aws_smithy_types::base64::encode(item_6));
}
}
array_5.finish();
}
crate::types::AttributeValue::M(inner) => {
#[allow(unused_mut)]
let mut object_7 = object_6.key("M").start_object();
for (key_8, value_9) in inner {
{
#[allow(unused_mut)]
let mut object_10 = object_7.key(key_8.as_str()).start_object();
crate::protocol_serde::shape_attribute_value::ser_attribute_value(&mut object_10, value_9)?;
object_10.finish();
}
}
object_7.finish();
}
crate::types::AttributeValue::L(inner) => {
let mut array_11 = object_6.key("L").start_array();
for item_12 in inner {
{
#[allow(unused_mut)]
let mut object_13 = array_11.value().start_object();
crate::protocol_serde::shape_attribute_value::ser_attribute_value(&mut object_13, item_12)?;
object_13.finish();
}
}
array_11.finish();
}
crate::types::AttributeValue::Null(inner) => {
object_6.key("NULL").boolean(*inner);
}
crate::types::AttributeValue::Bool(inner) => {
object_6.key("BOOL").boolean(*inner);
}
crate::types::AttributeValue::Unknown => {
return Err(::aws_smithy_types::error::operation::SerializationError::unknown_variant(
"AttributeValue",
))
}
}
Ok(())
}
pub(crate) fn de_attribute_value<'a, I>(
tokens: &mut ::std::iter::Peekable<I>,
_value: &'a [u8],
) -> ::std::result::Result<Option<crate::types::AttributeValue>, ::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() {
"S" => Some(crate::types::AttributeValue::S(
::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 'S' cannot be null"))?,
)),
"N" => Some(crate::types::AttributeValue::N(
::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 'N' cannot be null"))?,
)),
"B" => Some(crate::types::AttributeValue::B(
::aws_smithy_json::deserialize::token::expect_blob_or_null(tokens.next())?
.ok_or_else(|| ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'B' cannot be null"))?,
)),
"SS" => Some(crate::types::AttributeValue::Ss(
crate::protocol_serde::shape_string_set_attribute_value::de_string_set_attribute_value(tokens, _value)?
.ok_or_else(|| ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'SS' cannot be null"))?,
)),
"NS" => Some(crate::types::AttributeValue::Ns(
crate::protocol_serde::shape_number_set_attribute_value::de_number_set_attribute_value(tokens, _value)?
.ok_or_else(|| ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'NS' cannot be null"))?,
)),
"BS" => Some(crate::types::AttributeValue::Bs(
crate::protocol_serde::shape_binary_set_attribute_value::de_binary_set_attribute_value(tokens, _value)?
.ok_or_else(|| ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'BS' cannot be null"))?,
)),
"M" => Some(crate::types::AttributeValue::M(
crate::protocol_serde::shape_map_attribute_value::de_map_attribute_value(tokens, _value)?
.ok_or_else(|| ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'M' cannot be null"))?,
)),
"L" => Some(crate::types::AttributeValue::L(
crate::protocol_serde::shape_list_attribute_value::de_list_attribute_value(tokens, _value)?
.ok_or_else(|| ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'L' cannot be null"))?,
)),
"NULL" => Some(crate::types::AttributeValue::Null(
::aws_smithy_json::deserialize::token::expect_bool_or_null(tokens.next())?
.ok_or_else(|| ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'NULL' cannot be null"))?,
)),
"BOOL" => Some(crate::types::AttributeValue::Bool(
::aws_smithy_json::deserialize::token::expect_bool_or_null(tokens.next())?
.ok_or_else(|| ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'BOOL' cannot be null"))?,
)),
_ => {
::aws_smithy_json::deserialize::token::skip_value(tokens)?;
Some(crate::types::AttributeValue::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)
}