aws_sdk_rdsdata/protocol_serde/
shape_value.rs

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