aws_sdk_elastictranscoder/protocol_serde/
shape_captions.rs

1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2pub fn ser_captions(
3    object: &mut ::aws_smithy_json::serialize::JsonObjectWriter,
4    input: &crate::types::Captions,
5) -> ::std::result::Result<(), ::aws_smithy_types::error::operation::SerializationError> {
6    if let Some(var_1) = &input.merge_policy {
7        object.key("MergePolicy").string(var_1.as_str());
8    }
9    if let Some(var_2) = &input.caption_sources {
10        let mut array_3 = object.key("CaptionSources").start_array();
11        for item_4 in var_2 {
12            {
13                #[allow(unused_mut)]
14                let mut object_5 = array_3.value().start_object();
15                crate::protocol_serde::shape_caption_source::ser_caption_source(&mut object_5, item_4)?;
16                object_5.finish();
17            }
18        }
19        array_3.finish();
20    }
21    if let Some(var_6) = &input.caption_formats {
22        let mut array_7 = object.key("CaptionFormats").start_array();
23        for item_8 in var_6 {
24            {
25                #[allow(unused_mut)]
26                let mut object_9 = array_7.value().start_object();
27                crate::protocol_serde::shape_caption_format::ser_caption_format(&mut object_9, item_8)?;
28                object_9.finish();
29            }
30        }
31        array_7.finish();
32    }
33    Ok(())
34}
35
36pub(crate) fn de_captions<'a, I>(
37    tokens: &mut ::std::iter::Peekable<I>,
38) -> ::std::result::Result<Option<crate::types::Captions>, ::aws_smithy_json::deserialize::error::DeserializeError>
39where
40    I: Iterator<Item = Result<::aws_smithy_json::deserialize::Token<'a>, ::aws_smithy_json::deserialize::error::DeserializeError>>,
41{
42    match tokens.next().transpose()? {
43        Some(::aws_smithy_json::deserialize::Token::ValueNull { .. }) => Ok(None),
44        Some(::aws_smithy_json::deserialize::Token::StartObject { .. }) => {
45            #[allow(unused_mut)]
46            let mut builder = crate::types::builders::CaptionsBuilder::default();
47            loop {
48                match tokens.next().transpose()? {
49                    Some(::aws_smithy_json::deserialize::Token::EndObject { .. }) => break,
50                    Some(::aws_smithy_json::deserialize::Token::ObjectKey { key, .. }) => match key.to_unescaped()?.as_ref() {
51                        "MergePolicy" => {
52                            builder = builder.set_merge_policy(
53                                ::aws_smithy_json::deserialize::token::expect_string_or_null(tokens.next())?
54                                    .map(|s| s.to_unescaped().map(|u| u.into_owned()))
55                                    .transpose()?,
56                            );
57                        }
58                        "CaptionSources" => {
59                            builder = builder.set_caption_sources(crate::protocol_serde::shape_caption_sources::de_caption_sources(tokens)?);
60                        }
61                        "CaptionFormats" => {
62                            builder = builder.set_caption_formats(crate::protocol_serde::shape_caption_formats::de_caption_formats(tokens)?);
63                        }
64                        _ => ::aws_smithy_json::deserialize::token::skip_value(tokens)?,
65                    },
66                    other => {
67                        return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(format!(
68                            "expected object key or end object, found: {:?}",
69                            other
70                        )))
71                    }
72                }
73            }
74            Ok(Some(builder.build()))
75        }
76        _ => Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
77            "expected start object or null",
78        )),
79    }
80}