163 163 | }
|
164 164 | /// Returns true if this is a [`TimestampValue`](crate::types::MyUnion::TimestampValue).
|
165 165 | pub fn is_timestamp_value(&self) -> bool {
|
166 166 | self.as_timestamp_value().is_ok()
|
167 167 | }
|
168 168 | /// Returns true if the enum instance is the `Unknown` variant.
|
169 169 | pub fn is_unknown(&self) -> bool {
|
170 170 | matches!(self, Self::Unknown)
|
171 171 | }
|
172 172 | }
|
173 + | static MYUNION_MEMBER_STRINGVALUE: ::aws_smithy_schema::Schema<'static> = ::aws_smithy_schema::Schema::new_member(
|
174 + | ::aws_smithy_schema::ShapeId::from_parts("aws.protocoltests.json10#MyUnion$stringValue", "aws.protocoltests.json10", "MyUnion"),
|
175 + | ::aws_smithy_schema::ShapeType::String,
|
176 + | "stringValue",
|
177 + | 0,
|
178 + | );
|
179 + | static MYUNION_MEMBER_BOOLEANVALUE: ::aws_smithy_schema::Schema<'static> = ::aws_smithy_schema::Schema::new_member(
|
180 + | ::aws_smithy_schema::ShapeId::from_parts("aws.protocoltests.json10#MyUnion$booleanValue", "aws.protocoltests.json10", "MyUnion"),
|
181 + | ::aws_smithy_schema::ShapeType::Boolean,
|
182 + | "booleanValue",
|
183 + | 1,
|
184 + | );
|
185 + | static MYUNION_MEMBER_NUMBERVALUE: ::aws_smithy_schema::Schema<'static> = ::aws_smithy_schema::Schema::new_member(
|
186 + | ::aws_smithy_schema::ShapeId::from_parts("aws.protocoltests.json10#MyUnion$numberValue", "aws.protocoltests.json10", "MyUnion"),
|
187 + | ::aws_smithy_schema::ShapeType::Integer,
|
188 + | "numberValue",
|
189 + | 2,
|
190 + | );
|
191 + | static MYUNION_MEMBER_BLOBVALUE: ::aws_smithy_schema::Schema<'static> = ::aws_smithy_schema::Schema::new_member(
|
192 + | ::aws_smithy_schema::ShapeId::from_parts("aws.protocoltests.json10#MyUnion$blobValue", "aws.protocoltests.json10", "MyUnion"),
|
193 + | ::aws_smithy_schema::ShapeType::Blob,
|
194 + | "blobValue",
|
195 + | 3,
|
196 + | );
|
197 + | static MYUNION_MEMBER_TIMESTAMPVALUE: ::aws_smithy_schema::Schema<'static> = ::aws_smithy_schema::Schema::new_member(
|
198 + | ::aws_smithy_schema::ShapeId::from_parts("aws.protocoltests.json10#MyUnion$timestampValue", "aws.protocoltests.json10", "MyUnion"),
|
199 + | ::aws_smithy_schema::ShapeType::Timestamp,
|
200 + | "timestampValue",
|
201 + | 4,
|
202 + | );
|
203 + | static MYUNION_MEMBER_ENUMVALUE: ::aws_smithy_schema::Schema<'static> = ::aws_smithy_schema::Schema::new_member(
|
204 + | ::aws_smithy_schema::ShapeId::from_parts("aws.protocoltests.json10#MyUnion$enumValue", "aws.protocoltests.json10", "MyUnion"),
|
205 + | ::aws_smithy_schema::ShapeType::String,
|
206 + | "enumValue",
|
207 + | 5,
|
208 + | );
|
209 + | static MYUNION_MEMBER_INTENUMVALUE: ::aws_smithy_schema::Schema<'static> = ::aws_smithy_schema::Schema::new_member(
|
210 + | ::aws_smithy_schema::ShapeId::from_parts("aws.protocoltests.json10#MyUnion$intEnumValue", "aws.protocoltests.json10", "MyUnion"),
|
211 + | ::aws_smithy_schema::ShapeType::Integer,
|
212 + | "intEnumValue",
|
213 + | 6,
|
214 + | );
|
215 + | static MYUNION_MEMBER_LISTVALUE_MEMBER: ::aws_smithy_schema::Schema<'static> = ::aws_smithy_schema::Schema::new_member(
|
216 + | ::aws_smithy_schema::ShapeId::from_parts("aws.protocoltests.shared#StringList$member", "aws.protocoltests.shared", "StringList"),
|
217 + | ::aws_smithy_schema::ShapeType::String,
|
218 + | "member",
|
219 + | 0,
|
220 + | );
|
221 + | static MYUNION_MEMBER_LISTVALUE: ::aws_smithy_schema::Schema<'static> = ::aws_smithy_schema::Schema::new_member(
|
222 + | ::aws_smithy_schema::ShapeId::from_parts("aws.protocoltests.json10#MyUnion$listValue", "aws.protocoltests.json10", "MyUnion"),
|
223 + | ::aws_smithy_schema::ShapeType::List,
|
224 + | "listValue",
|
225 + | 7,
|
226 + | )
|
227 + | .with_list_member(&MYUNION_MEMBER_LISTVALUE_MEMBER);
|
228 + | static MYUNION_MEMBER_MAPVALUE_KEY: ::aws_smithy_schema::Schema<'static> = ::aws_smithy_schema::Schema::new_member(
|
229 + | ::aws_smithy_schema::ShapeId::from_parts("aws.protocoltests.shared#StringMap$key", "aws.protocoltests.shared", "StringMap"),
|
230 + | ::aws_smithy_schema::ShapeType::String,
|
231 + | "key",
|
232 + | 0,
|
233 + | );
|
234 + | static MYUNION_MEMBER_MAPVALUE_VALUE: ::aws_smithy_schema::Schema<'static> = ::aws_smithy_schema::Schema::new_member(
|
235 + | ::aws_smithy_schema::ShapeId::from_parts("aws.protocoltests.shared#StringMap$value", "aws.protocoltests.shared", "StringMap"),
|
236 + | ::aws_smithy_schema::ShapeType::String,
|
237 + | "value",
|
238 + | 1,
|
239 + | );
|
240 + | static MYUNION_MEMBER_MAPVALUE: ::aws_smithy_schema::Schema<'static> = ::aws_smithy_schema::Schema::new_member(
|
241 + | ::aws_smithy_schema::ShapeId::from_parts("aws.protocoltests.json10#MyUnion$mapValue", "aws.protocoltests.json10", "MyUnion"),
|
242 + | ::aws_smithy_schema::ShapeType::Map,
|
243 + | "mapValue",
|
244 + | 8,
|
245 + | )
|
246 + | .with_map_members(&MYUNION_MEMBER_MAPVALUE_KEY, &MYUNION_MEMBER_MAPVALUE_VALUE);
|
247 + | static MYUNION_MEMBER_STRUCTUREVALUE: ::aws_smithy_schema::Schema<'static> = ::aws_smithy_schema::Schema::new_member(
|
248 + | ::aws_smithy_schema::ShapeId::from_parts("aws.protocoltests.json10#MyUnion$structureValue", "aws.protocoltests.json10", "MyUnion"),
|
249 + | ::aws_smithy_schema::ShapeType::Structure,
|
250 + | "structureValue",
|
251 + | 9,
|
252 + | );
|
253 + | static MYUNION_SCHEMA: ::aws_smithy_schema::Schema<'static> = ::aws_smithy_schema::Schema::new_struct(
|
254 + | ::aws_smithy_schema::ShapeId::from_parts("aws.protocoltests.json10#MyUnion", "aws.protocoltests.json10", "MyUnion"),
|
255 + | ::aws_smithy_schema::ShapeType::Union,
|
256 + | &[
|
257 + | &MYUNION_MEMBER_STRINGVALUE,
|
258 + | &MYUNION_MEMBER_BOOLEANVALUE,
|
259 + | &MYUNION_MEMBER_NUMBERVALUE,
|
260 + | &MYUNION_MEMBER_BLOBVALUE,
|
261 + | &MYUNION_MEMBER_TIMESTAMPVALUE,
|
262 + | &MYUNION_MEMBER_ENUMVALUE,
|
263 + | &MYUNION_MEMBER_INTENUMVALUE,
|
264 + | &MYUNION_MEMBER_LISTVALUE,
|
265 + | &MYUNION_MEMBER_MAPVALUE,
|
266 + | &MYUNION_MEMBER_STRUCTUREVALUE,
|
267 + | ],
|
268 + | );
|
269 + | impl MyUnion {
|
270 + | /// The schema for this shape.
|
271 + | pub const SCHEMA: &'static ::aws_smithy_schema::Schema<'static> = &MYUNION_SCHEMA;
|
272 + | }
|
273 + | impl ::aws_smithy_schema::serde::SerializableStruct for MyUnion {
|
274 + | #[allow(unused_variables, clippy::diverging_sub_expression)]
|
275 + | fn serialize_members(
|
276 + | &self,
|
277 + | ser: &mut dyn ::aws_smithy_schema::serde::ShapeSerializer,
|
278 + | ) -> ::std::result::Result<(), ::aws_smithy_schema::serde::SerdeError> {
|
279 + | match self {
|
280 + | Self::StringValue(val) => {
|
281 + | ser.write_string(&MYUNION_MEMBER_STRINGVALUE, val)?;
|
282 + | }
|
283 + | Self::BooleanValue(val) => {
|
284 + | ser.write_boolean(&MYUNION_MEMBER_BOOLEANVALUE, *val)?;
|
285 + | }
|
286 + | Self::NumberValue(val) => {
|
287 + | ser.write_integer(&MYUNION_MEMBER_NUMBERVALUE, *val)?;
|
288 + | }
|
289 + | Self::BlobValue(val) => {
|
290 + | ser.write_blob(&MYUNION_MEMBER_BLOBVALUE, val.clone())?;
|
291 + | }
|
292 + | Self::TimestampValue(val) => {
|
293 + | ser.write_timestamp(&MYUNION_MEMBER_TIMESTAMPVALUE, val)?;
|
294 + | }
|
295 + | Self::EnumValue(val) => {
|
296 + | ser.write_string(&MYUNION_MEMBER_ENUMVALUE, val.as_str())?;
|
297 + | }
|
298 + | Self::IntEnumValue(val) => {
|
299 + | ser.write_integer(&MYUNION_MEMBER_INTENUMVALUE, *val)?;
|
300 + | }
|
301 + | Self::ListValue(val) => {
|
302 + | ser.write_string_list(&MYUNION_MEMBER_LISTVALUE, val)?;
|
303 + | }
|
304 + | Self::MapValue(val) => {
|
305 + | ser.write_string_string_map(&MYUNION_MEMBER_MAPVALUE, val)?;
|
306 + | }
|
307 + | Self::StructureValue(val) => {
|
308 + | ser.write_struct(&MYUNION_MEMBER_STRUCTUREVALUE, val)?;
|
309 + | }
|
310 + | Self::Unknown => return Err(::aws_smithy_schema::serde::SerdeError::custom("cannot serialize unknown union variant")),
|
311 + | }
|
312 + | Ok(())
|
313 + | }
|
314 + | }
|
315 + | impl MyUnion {
|
316 + | /// Deserializes this union from a [`ShapeDeserializer`].
|
317 + | pub fn deserialize(
|
318 + | deserializer: &mut dyn ::aws_smithy_schema::serde::ShapeDeserializer,
|
319 + | ) -> ::std::result::Result<Self, ::aws_smithy_schema::serde::SerdeError> {
|
320 + | let mut result: ::std::option::Option<Self> = ::std::option::Option::None;
|
321 + | #[allow(unused_variables, unreachable_code, clippy::single_match, clippy::match_single_binding)]
|
322 + | deserializer.read_struct(&MYUNION_SCHEMA, &mut |member, deser| {
|
323 + | // A union holds exactly one member; the deserializer reports every key
|
324 + | // (known or not), so a second one is an error whatever it names.
|
325 + | if result.is_some() {
|
326 + | return Err(::aws_smithy_schema::serde::SerdeError::invalid_input(
|
327 + | "encountered mixed variants in union",
|
328 + | ));
|
329 + | }
|
330 + | result = ::std::option::Option::Some(match member.member_index() {
|
331 + | Some(0) => Self::StringValue(deser.read_string(member)?),
|
332 + | Some(1) => Self::BooleanValue(deser.read_boolean(member)?),
|
333 + | Some(2) => Self::NumberValue(deser.read_integer(member)?),
|
334 + | Some(3) => Self::BlobValue(deser.read_blob(member)?),
|
335 + | Some(4) => Self::TimestampValue(deser.read_timestamp(member)?),
|
336 + | Some(5) => Self::EnumValue(crate::types::FooEnum::from(deser.read_string(member)?.as_str())),
|
337 + | Some(6) => Self::IntEnumValue(deser.read_integer(member)?),
|
338 + | Some(7) => Self::ListValue(deser.read_string_list(member)?),
|
339 + | Some(8) => Self::MapValue(deser.read_string_string_map(member)?),
|
340 + | Some(9) => Self::StructureValue(crate::types::GreetingStruct::deserialize(deser)?),
|
341 + | _ => Self::Unknown,
|
342 + | });
|
343 + | Ok(())
|
344 + | })?;
|
345 + | result.ok_or_else(|| ::aws_smithy_schema::serde::SerdeError::custom("expected a union variant"))
|
346 + | }
|
347 + | }
|