aws_sdk_rdsdata/protocol_serde/
shape_value.rs1pub(crate) fn de_value<'a, I>(
3 tokens: &mut ::std::iter::Peekable<I>,
4 _value: &'a [u8],
5) -> ::std::result::Result<Option<crate::types::Value>, ::aws_smithy_json::deserialize::error::DeserializeError>
6where
7 I: Iterator<Item = Result<::aws_smithy_json::deserialize::Token<'a>, ::aws_smithy_json::deserialize::error::DeserializeError>>,
8{
9 let mut variant = None;
10 match tokens.next().transpose()? {
11 Some(::aws_smithy_json::deserialize::Token::ValueNull { .. }) => return Ok(None),
12 Some(::aws_smithy_json::deserialize::Token::StartObject { .. }) => loop {
13 match tokens.next().transpose()? {
14 Some(::aws_smithy_json::deserialize::Token::EndObject { .. }) => break,
15 Some(::aws_smithy_json::deserialize::Token::ObjectKey { key, .. }) => {
16 if let ::std::option::Option::Some(::std::result::Result::Ok(::aws_smithy_json::deserialize::Token::ValueNull { .. })) =
17 tokens.peek()
18 {
19 let _ = tokens.next().expect("peek returned a token")?;
20 continue;
21 }
22 let key = key.to_unescaped()?;
23 if key == "__type" {
24 ::aws_smithy_json::deserialize::token::skip_value(tokens)?;
25 continue;
26 }
27 if variant.is_some() {
28 return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
29 "encountered mixed variants in union",
30 ));
31 }
32 variant = match key.as_ref() {
33 "isNull" => Some(crate::types::Value::IsNull(
34 ::aws_smithy_json::deserialize::token::expect_bool_or_null(tokens.next())?.ok_or_else(|| {
35 ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'isNull' cannot be null")
36 })?,
37 )),
38 "bitValue" => Some(crate::types::Value::BitValue(
39 ::aws_smithy_json::deserialize::token::expect_bool_or_null(tokens.next())?.ok_or_else(|| {
40 ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'bitValue' cannot be null")
41 })?,
42 )),
43 "bigIntValue" => Some(crate::types::Value::BigIntValue(
44 ::aws_smithy_json::deserialize::token::expect_number_or_null(tokens.next())?
45 .map(i64::try_from)
46 .transpose()?
47 .ok_or_else(|| {
48 ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'bigIntValue' cannot be null")
49 })?,
50 )),
51 "intValue" => Some(crate::types::Value::IntValue(
52 ::aws_smithy_json::deserialize::token::expect_number_or_null(tokens.next())?
53 .map(i32::try_from)
54 .transpose()?
55 .ok_or_else(|| {
56 ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'intValue' cannot be null")
57 })?,
58 )),
59 "doubleValue" => Some(crate::types::Value::DoubleValue(
60 ::aws_smithy_json::deserialize::token::expect_number_or_null(tokens.next())?
61 .map(|v| v.to_f64_lossy())
62 .ok_or_else(|| {
63 ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'doubleValue' cannot be null")
64 })?,
65 )),
66 "realValue" => Some(crate::types::Value::RealValue(
67 ::aws_smithy_json::deserialize::token::expect_number_or_null(tokens.next())?
68 .map(|v| v.to_f32_lossy())
69 .ok_or_else(|| {
70 ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'realValue' cannot be null")
71 })?,
72 )),
73 "stringValue" => Some(crate::types::Value::StringValue(
74 ::aws_smithy_json::deserialize::token::expect_string_or_null(tokens.next())?
75 .map(|s| s.to_unescaped().map(|u| u.into_owned()))
76 .transpose()?
77 .ok_or_else(|| {
78 ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'stringValue' cannot be null")
79 })?,
80 )),
81 "blobValue" => Some(crate::types::Value::BlobValue(
82 ::aws_smithy_json::deserialize::token::expect_blob_or_null(tokens.next())?.ok_or_else(|| {
83 ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'blobValue' cannot be null")
84 })?,
85 )),
86 "arrayValues" => Some(crate::types::Value::ArrayValues(
87 crate::protocol_serde::shape_array_value_list::de_array_value_list(tokens, _value)?.ok_or_else(|| {
88 ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'arrayValues' cannot be null")
89 })?,
90 )),
91 "structValue" => Some(crate::types::Value::StructValue(
92 crate::protocol_serde::shape_struct_value::de_struct_value(tokens, _value)?.ok_or_else(|| {
93 ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'structValue' cannot be null")
94 })?,
95 )),
96 _ => {
97 ::aws_smithy_json::deserialize::token::skip_value(tokens)?;
98 Some(crate::types::Value::Unknown)
99 }
100 };
101 }
102 other => {
103 return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(format!(
104 "expected object key or end object, found: {other:?}"
105 )))
106 }
107 }
108 },
109 _ => {
110 return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
111 "expected start object or null",
112 ))
113 }
114 }
115 if variant.is_none() {
116 return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
117 "Union did not contain a valid variant.",
118 ));
119 }
120 Ok(variant)
121}