aws_sdk_dynamodb/protocol_serde/
shape_global_secondary_index.rs

1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2pub fn ser_global_secondary_index(
3    object: &mut ::aws_smithy_json::serialize::JsonObjectWriter,
4    input: &crate::types::GlobalSecondaryIndex,
5) -> ::std::result::Result<(), ::aws_smithy_types::error::operation::SerializationError> {
6    {
7        object.key("IndexName").string(input.index_name.as_str());
8    }
9    {
10        let mut array_1 = object.key("KeySchema").start_array();
11        for item_2 in &input.key_schema {
12            {
13                #[allow(unused_mut)]
14                let mut object_3 = array_1.value().start_object();
15                crate::protocol_serde::shape_key_schema_element::ser_key_schema_element(&mut object_3, item_2)?;
16                object_3.finish();
17            }
18        }
19        array_1.finish();
20    }
21    if let Some(var_4) = &input.projection {
22        #[allow(unused_mut)]
23        let mut object_5 = object.key("Projection").start_object();
24        crate::protocol_serde::shape_projection::ser_projection(&mut object_5, var_4)?;
25        object_5.finish();
26    }
27    if let Some(var_6) = &input.provisioned_throughput {
28        #[allow(unused_mut)]
29        let mut object_7 = object.key("ProvisionedThroughput").start_object();
30        crate::protocol_serde::shape_provisioned_throughput::ser_provisioned_throughput(&mut object_7, var_6)?;
31        object_7.finish();
32    }
33    if let Some(var_8) = &input.on_demand_throughput {
34        #[allow(unused_mut)]
35        let mut object_9 = object.key("OnDemandThroughput").start_object();
36        crate::protocol_serde::shape_on_demand_throughput::ser_on_demand_throughput(&mut object_9, var_8)?;
37        object_9.finish();
38    }
39    if let Some(var_10) = &input.warm_throughput {
40        #[allow(unused_mut)]
41        let mut object_11 = object.key("WarmThroughput").start_object();
42        crate::protocol_serde::shape_warm_throughput::ser_warm_throughput(&mut object_11, var_10)?;
43        object_11.finish();
44    }
45    Ok(())
46}
47
48pub(crate) fn de_global_secondary_index<'a, I>(
49    tokens: &mut ::std::iter::Peekable<I>,
50) -> ::std::result::Result<Option<crate::types::GlobalSecondaryIndex>, ::aws_smithy_json::deserialize::error::DeserializeError>
51where
52    I: Iterator<Item = Result<::aws_smithy_json::deserialize::Token<'a>, ::aws_smithy_json::deserialize::error::DeserializeError>>,
53{
54    match tokens.next().transpose()? {
55        Some(::aws_smithy_json::deserialize::Token::ValueNull { .. }) => Ok(None),
56        Some(::aws_smithy_json::deserialize::Token::StartObject { .. }) => {
57            #[allow(unused_mut)]
58            let mut builder = crate::types::builders::GlobalSecondaryIndexBuilder::default();
59            loop {
60                match tokens.next().transpose()? {
61                    Some(::aws_smithy_json::deserialize::Token::EndObject { .. }) => break,
62                    Some(::aws_smithy_json::deserialize::Token::ObjectKey { key, .. }) => match key.to_unescaped()?.as_ref() {
63                        "IndexName" => {
64                            builder = builder.set_index_name(
65                                ::aws_smithy_json::deserialize::token::expect_string_or_null(tokens.next())?
66                                    .map(|s| s.to_unescaped().map(|u| u.into_owned()))
67                                    .transpose()?,
68                            );
69                        }
70                        "KeySchema" => {
71                            builder = builder.set_key_schema(crate::protocol_serde::shape_key_schema::de_key_schema(tokens)?);
72                        }
73                        "Projection" => {
74                            builder = builder.set_projection(crate::protocol_serde::shape_projection::de_projection(tokens)?);
75                        }
76                        "ProvisionedThroughput" => {
77                            builder = builder
78                                .set_provisioned_throughput(crate::protocol_serde::shape_provisioned_throughput::de_provisioned_throughput(tokens)?);
79                        }
80                        "OnDemandThroughput" => {
81                            builder =
82                                builder.set_on_demand_throughput(crate::protocol_serde::shape_on_demand_throughput::de_on_demand_throughput(tokens)?);
83                        }
84                        "WarmThroughput" => {
85                            builder = builder.set_warm_throughput(crate::protocol_serde::shape_warm_throughput::de_warm_throughput(tokens)?);
86                        }
87                        _ => ::aws_smithy_json::deserialize::token::skip_value(tokens)?,
88                    },
89                    other => {
90                        return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(format!(
91                            "expected object key or end object, found: {:?}",
92                            other
93                        )))
94                    }
95                }
96            }
97            Ok(Some(crate::serde_util::global_secondary_index_correct_errors(builder).build().map_err(
98                |err| ::aws_smithy_json::deserialize::error::DeserializeError::custom_source("Response was invalid", err),
99            )?))
100        }
101        _ => Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
102            "expected start object or null",
103        )),
104    }
105}