aws_sdk_iotevents/protocol_serde/
shape_event.rs1pub fn ser_event(
3 object: &mut ::aws_smithy_json::serialize::JsonObjectWriter,
4 input: &crate::types::Event,
5) -> ::std::result::Result<(), ::aws_smithy_types::error::operation::SerializationError> {
6 {
7 object.key("eventName").string(input.event_name.as_str());
8 }
9 if let Some(var_1) = &input.condition {
10 object.key("condition").string(var_1.as_str());
11 }
12 if let Some(var_2) = &input.actions {
13 let mut array_3 = object.key("actions").start_array();
14 for item_4 in var_2 {
15 {
16 #[allow(unused_mut)]
17 let mut object_5 = array_3.value().start_object();
18 crate::protocol_serde::shape_action::ser_action(&mut object_5, item_4)?;
19 object_5.finish();
20 }
21 }
22 array_3.finish();
23 }
24 Ok(())
25}
26
27pub(crate) fn de_event<'a, I>(
28 tokens: &mut ::std::iter::Peekable<I>,
29) -> ::std::result::Result<Option<crate::types::Event>, ::aws_smithy_json::deserialize::error::DeserializeError>
30where
31 I: Iterator<Item = Result<::aws_smithy_json::deserialize::Token<'a>, ::aws_smithy_json::deserialize::error::DeserializeError>>,
32{
33 match tokens.next().transpose()? {
34 Some(::aws_smithy_json::deserialize::Token::ValueNull { .. }) => Ok(None),
35 Some(::aws_smithy_json::deserialize::Token::StartObject { .. }) => {
36 #[allow(unused_mut)]
37 let mut builder = crate::types::builders::EventBuilder::default();
38 loop {
39 match tokens.next().transpose()? {
40 Some(::aws_smithy_json::deserialize::Token::EndObject { .. }) => break,
41 Some(::aws_smithy_json::deserialize::Token::ObjectKey { key, .. }) => match key.to_unescaped()?.as_ref() {
42 "eventName" => {
43 builder = builder.set_event_name(
44 ::aws_smithy_json::deserialize::token::expect_string_or_null(tokens.next())?
45 .map(|s| s.to_unescaped().map(|u| u.into_owned()))
46 .transpose()?,
47 );
48 }
49 "condition" => {
50 builder = builder.set_condition(
51 ::aws_smithy_json::deserialize::token::expect_string_or_null(tokens.next())?
52 .map(|s| s.to_unescaped().map(|u| u.into_owned()))
53 .transpose()?,
54 );
55 }
56 "actions" => {
57 builder = builder.set_actions(crate::protocol_serde::shape_actions::de_actions(tokens)?);
58 }
59 _ => ::aws_smithy_json::deserialize::token::skip_value(tokens)?,
60 },
61 other => {
62 return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(format!(
63 "expected object key or end object, found: {other:?}"
64 )))
65 }
66 }
67 }
68 Ok(Some(crate::serde_util::event_correct_errors(builder).build().map_err(|err| {
69 ::aws_smithy_json::deserialize::error::DeserializeError::custom_source("Response was invalid", err)
70 })?))
71 }
72 _ => Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
73 "expected start object or null",
74 )),
75 }
76}