aws_sdk_qconnect/protocol_serde/
shape_source_configuration.rs

1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2pub fn ser_source_configuration(
3    object_10: &mut ::aws_smithy_json::serialize::JsonObjectWriter,
4    input: &crate::types::SourceConfiguration,
5) -> ::std::result::Result<(), ::aws_smithy_types::error::operation::SerializationError> {
6    match input {
7        crate::types::SourceConfiguration::AppIntegrations(inner) => {
8            #[allow(unused_mut)]
9            let mut object_1 = object_10.key("appIntegrations").start_object();
10            crate::protocol_serde::shape_app_integrations_configuration::ser_app_integrations_configuration(&mut object_1, inner)?;
11            object_1.finish();
12        }
13        crate::types::SourceConfiguration::ManagedSourceConfiguration(inner) => {
14            #[allow(unused_mut)]
15            let mut object_2 = object_10.key("managedSourceConfiguration").start_object();
16            crate::protocol_serde::shape_managed_source_configuration::ser_managed_source_configuration(&mut object_2, inner)?;
17            object_2.finish();
18        }
19        crate::types::SourceConfiguration::Unknown => {
20            return Err(::aws_smithy_types::error::operation::SerializationError::unknown_variant(
21                "SourceConfiguration",
22            ))
23        }
24    }
25    Ok(())
26}
27
28pub(crate) fn de_source_configuration<'a, I>(
29    tokens: &mut ::std::iter::Peekable<I>,
30) -> ::std::result::Result<Option<crate::types::SourceConfiguration>, ::aws_smithy_json::deserialize::error::DeserializeError>
31where
32    I: Iterator<Item = Result<::aws_smithy_json::deserialize::Token<'a>, ::aws_smithy_json::deserialize::error::DeserializeError>>,
33{
34    let mut variant = None;
35    match tokens.next().transpose()? {
36        Some(::aws_smithy_json::deserialize::Token::ValueNull { .. }) => return Ok(None),
37        Some(::aws_smithy_json::deserialize::Token::StartObject { .. }) => loop {
38            match tokens.next().transpose()? {
39                Some(::aws_smithy_json::deserialize::Token::EndObject { .. }) => break,
40                Some(::aws_smithy_json::deserialize::Token::ObjectKey { key, .. }) => {
41                    if let ::std::option::Option::Some(::std::result::Result::Ok(::aws_smithy_json::deserialize::Token::ValueNull { .. })) =
42                        tokens.peek()
43                    {
44                        let _ = tokens.next().expect("peek returned a token")?;
45                        continue;
46                    }
47                    let key = key.to_unescaped()?;
48                    if key == "__type" {
49                        ::aws_smithy_json::deserialize::token::skip_value(tokens)?;
50                        continue;
51                    }
52                    if variant.is_some() {
53                        return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
54                            "encountered mixed variants in union",
55                        ));
56                    }
57                    variant = match key.as_ref() {
58                        "appIntegrations" => Some(crate::types::SourceConfiguration::AppIntegrations(
59                            crate::protocol_serde::shape_app_integrations_configuration::de_app_integrations_configuration(tokens)?.ok_or_else(
60                                || ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'appIntegrations' cannot be null"),
61                            )?,
62                        )),
63                        "managedSourceConfiguration" => Some(crate::types::SourceConfiguration::ManagedSourceConfiguration(
64                            crate::protocol_serde::shape_managed_source_configuration::de_managed_source_configuration(tokens)?.ok_or_else(|| {
65                                ::aws_smithy_json::deserialize::error::DeserializeError::custom(
66                                    "value for 'managedSourceConfiguration' cannot be null",
67                                )
68                            })?,
69                        )),
70                        _ => {
71                            ::aws_smithy_json::deserialize::token::skip_value(tokens)?;
72                            Some(crate::types::SourceConfiguration::Unknown)
73                        }
74                    };
75                }
76                other => {
77                    return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(format!(
78                        "expected object key or end object, found: {other:?}"
79                    )))
80                }
81            }
82        },
83        _ => {
84            return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
85                "expected start object or null",
86            ))
87        }
88    }
89    if variant.is_none() {
90        return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
91            "Union did not contain a valid variant.",
92        ));
93    }
94    Ok(variant)
95}