pub(crate) fn de_value<'a, I>(
tokens: &mut ::std::iter::Peekable<I>,
_value: &'a [u8],
) -> ::std::result::Result<Option<crate::types::Value>, ::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() {
"isNull" => Some(crate::types::Value::IsNull(
::aws_smithy_json::deserialize::token::expect_bool_or_null(tokens.next())?.ok_or_else(|| {
::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'isNull' cannot be null")
})?,
)),
"bitValue" => Some(crate::types::Value::BitValue(
::aws_smithy_json::deserialize::token::expect_bool_or_null(tokens.next())?.ok_or_else(|| {
::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'bitValue' cannot be null")
})?,
)),
"bigIntValue" => Some(crate::types::Value::BigIntValue(
::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 'bigIntValue' cannot be null")
})?,
)),
"intValue" => Some(crate::types::Value::IntValue(
::aws_smithy_json::deserialize::token::expect_number_or_null(tokens.next())?
.map(i32::try_from)
.transpose()?
.ok_or_else(|| {
::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'intValue' cannot be null")
})?,
)),
"doubleValue" => Some(crate::types::Value::DoubleValue(
::aws_smithy_json::deserialize::token::expect_number_or_null(tokens.next())?
.map(|v| v.to_f64_lossy())
.ok_or_else(|| {
::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'doubleValue' cannot be null")
})?,
)),
"realValue" => Some(crate::types::Value::RealValue(
::aws_smithy_json::deserialize::token::expect_number_or_null(tokens.next())?
.map(|v| v.to_f32_lossy())
.ok_or_else(|| {
::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'realValue' cannot be null")
})?,
)),
"stringValue" => Some(crate::types::Value::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")
})?,
)),
"blobValue" => Some(crate::types::Value::BlobValue(
::aws_smithy_json::deserialize::token::expect_blob_or_null(tokens.next())?.ok_or_else(|| {
::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'blobValue' cannot be null")
})?,
)),
"arrayValues" => Some(crate::types::Value::ArrayValues(
crate::protocol_serde::shape_array_value_list::de_array_value_list(tokens, _value)?.ok_or_else(|| {
::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'arrayValues' cannot be null")
})?,
)),
"structValue" => Some(crate::types::Value::StructValue(
crate::protocol_serde::shape_struct_value::de_struct_value(tokens, _value)?.ok_or_else(|| {
::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'structValue' cannot be null")
})?,
)),
_ => {
::aws_smithy_json::deserialize::token::skip_value(tokens)?;
Some(crate::types::Value::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)
}