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 - | ) -> ::std::result::Result<Option<crate::types::MyUnion>, ::aws_smithy_json::deserialize::error::DeserializeError>
|
6 - | where
|
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 - | "stringValue" => Some(crate::types::MyUnion::StringValue(
|
34 - | ::aws_smithy_json::deserialize::token::expect_string_or_null(tokens.next())?
|
35 - | .map(|s| s.to_unescaped().map(|u| u.into_owned()))
|
36 - | .transpose()?
|
37 - | .ok_or_else(|| {
|
38 - | ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'stringValue' cannot be null")
|
39 - | })?,
|
40 - | )),
|
41 - | "booleanValue" => Some(crate::types::MyUnion::BooleanValue(
|
42 - | ::aws_smithy_json::deserialize::token::expect_bool_or_null(tokens.next())?.ok_or_else(|| {
|
43 - | ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'booleanValue' cannot be null")
|
44 - | })?,
|
45 - | )),
|
46 - | "numberValue" => Some(crate::types::MyUnion::NumberValue(
|
47 - | ::aws_smithy_json::deserialize::token::expect_number_or_null(tokens.next())?
|
48 - | .map(i32::try_from)
|
49 - | .transpose()?
|
50 - | .ok_or_else(|| {
|
51 - | ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'numberValue' cannot be null")
|
52 - | })?,
|
53 - | )),
|
54 - | "blobValue" => Some(crate::types::MyUnion::BlobValue(
|
55 - | ::aws_smithy_json::deserialize::token::expect_blob_or_null(tokens.next())?.ok_or_else(|| {
|
56 - | ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'blobValue' cannot be null")
|
57 - | })?,
|
58 - | )),
|
59 - | "timestampValue" => Some(crate::types::MyUnion::TimestampValue(
|
60 - | ::aws_smithy_json::deserialize::token::expect_timestamp_or_null(
|
61 - | tokens.next(),
|
62 - | ::aws_smithy_types::date_time::Format::EpochSeconds,
|
63 - | )?
|
64 - | .ok_or_else(|| {
|
65 - | ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'timestampValue' cannot be null")
|
66 - | })?,
|
67 - | )),
|
68 - | "enumValue" => Some(crate::types::MyUnion::EnumValue(
|
69 - | ::aws_smithy_json::deserialize::token::expect_string_or_null(tokens.next())?
|
70 - | .map(|s| s.to_unescaped().map(|u| crate::types::FooEnum::from(u.as_ref())))
|
71 - | .transpose()?
|
72 - | .ok_or_else(|| {
|
73 - | ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'enumValue' cannot be null")
|
74 - | })?,
|
75 - | )),
|
76 - | "listValue" => Some(crate::types::MyUnion::ListValue(
|
77 - | crate::protocol_serde::shape_string_list::de_string_list(tokens, _value)?.ok_or_else(|| {
|
78 - | ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'listValue' cannot be null")
|
79 - | })?,
|
80 - | )),
|
81 - | "mapValue" => Some(crate::types::MyUnion::MapValue(
|
82 - | crate::protocol_serde::shape_string_map::de_string_map(tokens, _value)?.ok_or_else(|| {
|
83 - | ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'mapValue' cannot be null")
|
84 - | })?,
|
85 - | )),
|
86 - | "structureValue" => Some(crate::types::MyUnion::StructureValue(
|
87 - | crate::protocol_serde::shape_greeting_struct::de_greeting_struct(tokens, _value)?.ok_or_else(|| {
|
88 - | ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'structureValue' cannot be null")
|
89 - | })?,
|
90 - | )),
|
91 - | "renamedStructureValue" => Some(crate::types::MyUnion::RenamedStructureValue(
|
92 - | crate::protocol_serde::shape_renamed_greeting::de_renamed_greeting(tokens, _value)?.ok_or_else(|| {
|
93 - | ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'renamedStructureValue' cannot be null")
|
94 - | })?,
|
95 - | )),
|
96 - | _ => {
|
97 - | ::aws_smithy_json::deserialize::token::skip_value(tokens)?;
|
98 - | Some(crate::types::MyUnion::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 - | }
|
122 - |
|
123 - | pub fn ser_my_union(
|
124 - | object_2: &mut ::aws_smithy_json::serialize::JsonObjectWriter,
|
125 - | input: &crate::types::MyUnion,
|
126 - | ) -> ::std::result::Result<(), ::aws_smithy_types::error::operation::SerializationError> {
|
127 - | match input {
|
128 - | crate::types::MyUnion::StringValue(inner) => {
|
129 - | object_2.key("stringValue").string(inner.as_str());
|
130 - | }
|
131 - | crate::types::MyUnion::BooleanValue(inner) => {
|
132 - | object_2.key("booleanValue").boolean(*inner);
|
133 - | }
|
134 - | crate::types::MyUnion::NumberValue(inner) => {
|
135 - | object_2.key("numberValue").number(
|
136 - | #[allow(clippy::useless_conversion)]
|
137 - | ::aws_smithy_types::Number::NegInt((*inner).into()),
|
138 - | );
|
139 - | }
|
140 - | crate::types::MyUnion::BlobValue(inner) => {
|
141 - | object_2.key("blobValue").string_unchecked(&::aws_smithy_types::base64::encode(inner));
|
142 - | }
|
143 - | crate::types::MyUnion::TimestampValue(inner) => {
|
144 - | object_2
|
145 - | .key("timestampValue")
|
146 - | .date_time(inner, ::aws_smithy_types::date_time::Format::EpochSeconds)?;
|
147 - | }
|
148 - | crate::types::MyUnion::EnumValue(inner) => {
|
149 - | object_2.key("enumValue").string(inner.as_str());
|
150 - | }
|
151 - | crate::types::MyUnion::ListValue(inner) => {
|
152 - | let mut array_1 = object_2.key("listValue").start_array();
|
153 - | for item_2 in inner {
|
154 - | {
|
155 - | array_1.value().string(item_2.as_str());
|
156 - | }
|
157 - | }
|
158 - | array_1.finish();
|
159 - | }
|
160 - | crate::types::MyUnion::MapValue(inner) => {
|
161 - | #[allow(unused_mut)]
|
162 - | let mut object_3 = object_2.key("mapValue").start_object();
|
163 - | for (key_4, value_5) in inner {
|
164 - | {
|
165 - | object_3.key(key_4.as_str()).string(value_5.as_str());
|
166 - | }
|
167 - | }
|
168 - | object_3.finish();
|
169 - | }
|
170 - | crate::types::MyUnion::StructureValue(inner) => {
|
171 - | #[allow(unused_mut)]
|
172 - | let mut object_6 = object_2.key("structureValue").start_object();
|
173 - | crate::protocol_serde::shape_greeting_struct::ser_greeting_struct(&mut object_6, inner)?;
|
174 - | object_6.finish();
|
175 - | }
|
176 - | crate::types::MyUnion::RenamedStructureValue(inner) => {
|
177 - | #[allow(unused_mut)]
|
178 - | let mut object_7 = object_2.key("renamedStructureValue").start_object();
|
179 - | crate::protocol_serde::shape_renamed_greeting::ser_renamed_greeting(&mut object_7, inner)?;
|
180 - | object_7.finish();
|
181 - | }
|
182 - | crate::types::MyUnion::Unknown => return Err(::aws_smithy_types::error::operation::SerializationError::unknown_variant("MyUnion")),
|
183 - | }
|
184 - | Ok(())
|
185 - | }
|