Skip to main content

aws_sdk_proton/protocol_serde/
shape_tag.rs

1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2pub fn ser_tag(
3    object: &mut ::aws_smithy_json::serialize::JsonObjectWriter,
4    input: &crate::types::Tag,
5) -> ::std::result::Result<(), ::aws_smithy_types::error::operation::SerializationError> {
6    {
7        object.key("key").string(input.key.as_str());
8    }
9    {
10        object.key("value").string(input.value.as_str());
11    }
12    Ok(())
13}
14
15pub(crate) fn de_tag<'a, I>(
16    tokens: &mut ::std::iter::Peekable<I>,
17    _value: &'a [u8],
18) -> ::std::result::Result<Option<crate::types::Tag>, ::aws_smithy_json::deserialize::error::DeserializeError>
19where
20    I: Iterator<Item = Result<::aws_smithy_json::deserialize::Token<'a>, ::aws_smithy_json::deserialize::error::DeserializeError>>,
21{
22    match tokens.next().transpose()? {
23        Some(::aws_smithy_json::deserialize::Token::ValueNull { .. }) => Ok(None),
24        Some(::aws_smithy_json::deserialize::Token::StartObject { .. }) => {
25            #[allow(unused_mut)]
26            let mut builder = crate::types::builders::TagBuilder::default();
27            loop {
28                match tokens.next().transpose()? {
29                    Some(::aws_smithy_json::deserialize::Token::EndObject { .. }) => break,
30                    Some(::aws_smithy_json::deserialize::Token::ObjectKey { key, .. }) => match key.to_unescaped()?.as_ref() {
31                        "key" => {
32                            builder = builder.set_key(
33                                ::aws_smithy_json::deserialize::token::expect_string_or_null(tokens.next())?
34                                    .map(|s| s.to_unescaped().map(|u| u.into_owned()))
35                                    .transpose()?,
36                            );
37                        }
38                        "value" => {
39                            builder = builder.set_value(
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                            );
44                        }
45                        _ => ::aws_smithy_json::deserialize::token::skip_value(tokens)?,
46                    },
47                    other => {
48                        return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(format!(
49                            "expected object key or end object, found: {other:?}"
50                        )))
51                    }
52                }
53            }
54            Ok(Some(crate::serde_util::tag_correct_errors(builder).build().map_err(|err| {
55                ::aws_smithy_json::deserialize::error::DeserializeError::custom_source("Response was invalid", err)
56            })?))
57        }
58        _ => Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
59            "expected start object or null",
60        )),
61    }
62}