1 - | // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
|
2 - | pub(crate) fn de_my_union<'a, I>(
|
3 - | tokens: &mut ::std::iter::Peekable<I>,
|
4 - | _value: &'a [u8],
|
5 - | depth: u32,
|
6 - | ) -> ::std::result::Result<Option<crate::types::MyUnion>, ::aws_smithy_json::deserialize::error::DeserializeError>
|
7 - | where
|
8 - | I: Iterator<Item = Result<::aws_smithy_json::deserialize::Token<'a>, ::aws_smithy_json::deserialize::error::DeserializeError>>,
|
9 - | {
|
10 - | if depth >= 128u32 {
|
11 - | return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
|
12 - | "maximum nesting depth exceeded",
|
13 - | ));
|
14 - | }
|
15 - | let mut variant = None;
|
16 - | match tokens.next().transpose()? {
|
17 - | Some(::aws_smithy_json::deserialize::Token::ValueNull { .. }) => return Ok(None),
|
18 - | Some(::aws_smithy_json::deserialize::Token::StartObject { .. }) => loop {
|
19 - | match tokens.next().transpose()? {
|
20 - | Some(::aws_smithy_json::deserialize::Token::EndObject { .. }) => break,
|
21 - | Some(::aws_smithy_json::deserialize::Token::ObjectKey { key, .. }) => {
|
22 - | if let ::std::option::Option::Some(::std::result::Result::Ok(::aws_smithy_json::deserialize::Token::ValueNull { .. })) =
|
23 - | tokens.peek()
|
24 - | {
|
25 - | let _ = tokens.next().expect("peek returned a token")?;
|
26 - | continue;
|
27 - | }
|
28 - | let key = key.to_unescaped()?;
|
29 - | if key == "__type" {
|
30 - | ::aws_smithy_json::deserialize::token::skip_value(tokens)?;
|
31 - | continue;
|
32 - | }
|
33 - | if variant.is_some() {
|
34 - | return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
|
35 - | "encountered mixed variants in union",
|
36 - | ));
|
37 - | }
|
38 - | variant = match key.as_ref() {
|
39 - | "stringValue" => Some(crate::types::MyUnion::StringValue(
|
40 - | ::aws_smithy_json::deserialize::token::expect_string_or_null(tokens.next())?
|
41 - | .map(|s| s.to_unescaped().map(|u| u.into_owned()))
|
42 - | .transpose()?
|
43 - | .ok_or_else(|| {
|
44 - | ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'stringValue' cannot be null")
|
45 - | })?,
|
46 - | )),
|
47 - | "booleanValue" => Some(crate::types::MyUnion::BooleanValue(
|
48 - | ::aws_smithy_json::deserialize::token::expect_bool_or_null(tokens.next())?.ok_or_else(|| {
|
49 - | ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'booleanValue' cannot be null")
|
50 - | })?,
|
51 - | )),
|
52 - | "numberValue" => Some(crate::types::MyUnion::NumberValue(
|
53 - | ::aws_smithy_json::deserialize::token::expect_number_or_null(tokens.next())?
|
54 - | .map(i32::try_from)
|
55 - | .transpose()?
|
56 - | .ok_or_else(|| {
|
57 - | ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'numberValue' cannot be null")
|
58 - | })?,
|
59 - | )),
|
60 - | "blobValue" => Some(crate::types::MyUnion::BlobValue(
|
61 - | ::aws_smithy_json::deserialize::token::expect_blob_or_null(tokens.next())?.ok_or_else(|| {
|
62 - | ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'blobValue' cannot be null")
|
63 - | })?,
|
64 - | )),
|
65 - | "timestampValue" => Some(crate::types::MyUnion::TimestampValue(
|
66 - | ::aws_smithy_json::deserialize::token::expect_timestamp_or_null(
|
67 - | tokens.next(),
|
68 - | ::aws_smithy_types::date_time::Format::EpochSeconds,
|
69 - | )?
|
70 - | .ok_or_else(|| {
|
71 - | ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'timestampValue' cannot be null")
|
72 - | })?,
|
73 - | )),
|
74 - | "enumValue" => Some(crate::types::MyUnion::EnumValue(
|
75 - | ::aws_smithy_json::deserialize::token::expect_string_or_null(tokens.next())?
|
76 - | .map(|s| s.to_unescaped().map(|u| crate::types::FooEnum::from(u.as_ref())))
|
77 - | .transpose()?
|
78 - | .ok_or_else(|| {
|
79 - | ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'enumValue' cannot be null")
|
80 - | })?,
|
81 - | )),
|
82 - | "intEnumValue" => Some(crate::types::MyUnion::IntEnumValue(
|
83 - | ::aws_smithy_json::deserialize::token::expect_number_or_null(tokens.next())?
|
84 - | .map(i32::try_from)
|
85 - | .transpose()?
|
86 - | .ok_or_else(|| {
|
87 - | ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'intEnumValue' cannot be null")
|
88 - | })?,
|
89 - | )),
|
90 - | "listValue" => Some(crate::types::MyUnion::ListValue(
|
91 - | crate::protocol_serde::shape_string_list::de_string_list(tokens, _value, depth + 1)?.ok_or_else(|| {
|
92 - | ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'listValue' cannot be null")
|
93 - | })?,
|
94 - | )),
|
95 - | "mapValue" => Some(crate::types::MyUnion::MapValue(
|
96 - | crate::protocol_serde::shape_string_map::de_string_map(tokens, _value, depth + 1)?.ok_or_else(|| {
|
97 - | ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'mapValue' cannot be null")
|
98 - | })?,
|
99 - | )),
|
100 - | "structureValue" => Some(crate::types::MyUnion::StructureValue(
|
101 - | crate::protocol_serde::shape_greeting_struct::de_greeting_struct(tokens, _value, depth + 1)?.ok_or_else(|| {
|
102 - | ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'structureValue' cannot be null")
|
103 - | })?,
|
104 - | )),
|
105 - | _ => {
|
106 - | ::aws_smithy_json::deserialize::token::skip_value(tokens)?;
|
107 - | Some(crate::types::MyUnion::Unknown)
|
108 - | }
|
109 - | };
|
110 - | }
|
111 - | other => {
|
112 - | return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(format!(
|
113 - | "expected object key or end object, found: {other:?}"
|
114 - | )))
|
115 - | }
|
116 - | }
|
117 - | },
|
118 - | _ => {
|
119 - | return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
|
120 - | "expected start object or null",
|
121 - | ))
|
122 - | }
|
123 - | }
|
124 - | if variant.is_none() {
|
125 - | return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
|
126 - | "Union did not contain a valid variant.",
|
127 - | ));
|
128 - | }
|
129 - | Ok(variant)
|
130 - | }
|
131 - |
|
132 - | pub fn ser_my_union(
|
133 - | object_2: &mut ::aws_smithy_json::serialize::JsonObjectWriter,
|
134 - | input: &crate::types::MyUnion,
|
135 - | ) -> ::std::result::Result<(), ::aws_smithy_types::error::operation::SerializationError> {
|
136 - | match input {
|
137 - | crate::types::MyUnion::StringValue(inner) => {
|
138 - | object_2.key("stringValue").string(inner.as_str());
|
139 - | }
|
140 - | crate::types::MyUnion::BooleanValue(inner) => {
|
141 - | object_2.key("booleanValue").boolean(*inner);
|
142 - | }
|
143 - | crate::types::MyUnion::NumberValue(inner) => {
|
144 - | object_2.key("numberValue").number(
|
145 - | #[allow(clippy::useless_conversion)]
|
146 - | ::aws_smithy_types::Number::NegInt((*inner).into()),
|
147 - | );
|
148 - | }
|
149 - | crate::types::MyUnion::BlobValue(inner) => {
|
150 - | object_2.key("blobValue").string_unchecked(&::aws_smithy_types::base64::encode(inner));
|
151 - | }
|
152 - | crate::types::MyUnion::TimestampValue(inner) => {
|
153 - | object_2
|
154 - | .key("timestampValue")
|
155 - | .date_time(inner, ::aws_smithy_types::date_time::Format::EpochSeconds)?;
|
156 - | }
|
157 - | crate::types::MyUnion::EnumValue(inner) => {
|
158 - | object_2.key("enumValue").string(inner.as_str());
|
159 - | }
|
160 - | crate::types::MyUnion::IntEnumValue(inner) => {
|
161 - | object_2.key("intEnumValue").number(
|
162 - | #[allow(clippy::useless_conversion)]
|
163 - | ::aws_smithy_types::Number::NegInt((*inner).into()),
|
164 - | );
|
165 - | }
|
166 - | crate::types::MyUnion::ListValue(inner) => {
|
167 - | let mut array_1 = object_2.key("listValue").start_array();
|
168 - | for item_2 in inner {
|
169 - | {
|
170 - | array_1.value().string(item_2.as_str());
|
171 - | }
|
172 - | }
|
173 - | array_1.finish();
|
174 - | }
|
175 - | crate::types::MyUnion::MapValue(inner) => {
|
176 - | #[allow(unused_mut)]
|
177 - | let mut object_3 = object_2.key("mapValue").start_object();
|
178 - | for (key_4, value_5) in inner {
|
179 - | {
|
180 - | object_3.key(key_4.as_str()).string(value_5.as_str());
|
181 - | }
|
182 - | }
|
183 - | object_3.finish();
|
184 - | }
|
185 - | crate::types::MyUnion::StructureValue(inner) => {
|
186 - | #[allow(unused_mut)]
|
187 - | let mut object_6 = object_2.key("structureValue").start_object();
|
188 - | crate::protocol_serde::shape_greeting_struct::ser_greeting_struct(&mut object_6, inner)?;
|
189 - | object_6.finish();
|
190 - | }
|
191 - | crate::types::MyUnion::Unknown => return Err(::aws_smithy_types::error::operation::SerializationError::unknown_variant("MyUnion")),
|
192 - | }
|
193 - | Ok(())
|
194 - | }
|