aws_sdk_sagemaker/protocol_serde/
shape_model_latency_threshold.rs

1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2pub fn ser_model_latency_threshold(
3    object: &mut ::aws_smithy_json::serialize::JsonObjectWriter,
4    input: &crate::types::ModelLatencyThreshold,
5) -> ::std::result::Result<(), ::aws_smithy_types::error::operation::SerializationError> {
6    if let Some(var_1) = &input.percentile {
7        object.key("Percentile").string(var_1.as_str());
8    }
9    if let Some(var_2) = &input.value_in_milliseconds {
10        object.key("ValueInMilliseconds").number(
11            #[allow(clippy::useless_conversion)]
12            ::aws_smithy_types::Number::NegInt((*var_2).into()),
13        );
14    }
15    Ok(())
16}
17
18pub(crate) fn de_model_latency_threshold<'a, I>(
19    tokens: &mut ::std::iter::Peekable<I>,
20) -> ::std::result::Result<Option<crate::types::ModelLatencyThreshold>, ::aws_smithy_json::deserialize::error::DeserializeError>
21where
22    I: Iterator<Item = Result<::aws_smithy_json::deserialize::Token<'a>, ::aws_smithy_json::deserialize::error::DeserializeError>>,
23{
24    match tokens.next().transpose()? {
25        Some(::aws_smithy_json::deserialize::Token::ValueNull { .. }) => Ok(None),
26        Some(::aws_smithy_json::deserialize::Token::StartObject { .. }) => {
27            #[allow(unused_mut)]
28            let mut builder = crate::types::builders::ModelLatencyThresholdBuilder::default();
29            loop {
30                match tokens.next().transpose()? {
31                    Some(::aws_smithy_json::deserialize::Token::EndObject { .. }) => break,
32                    Some(::aws_smithy_json::deserialize::Token::ObjectKey { key, .. }) => match key.to_unescaped()?.as_ref() {
33                        "Percentile" => {
34                            builder = builder.set_percentile(
35                                ::aws_smithy_json::deserialize::token::expect_string_or_null(tokens.next())?
36                                    .map(|s| s.to_unescaped().map(|u| u.into_owned()))
37                                    .transpose()?,
38                            );
39                        }
40                        "ValueInMilliseconds" => {
41                            builder = builder.set_value_in_milliseconds(
42                                ::aws_smithy_json::deserialize::token::expect_number_or_null(tokens.next())?
43                                    .map(i32::try_from)
44                                    .transpose()?,
45                            );
46                        }
47                        _ => ::aws_smithy_json::deserialize::token::skip_value(tokens)?,
48                    },
49                    other => {
50                        return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(format!(
51                            "expected object key or end object, found: {:?}",
52                            other
53                        )))
54                    }
55                }
56            }
57            Ok(Some(builder.build()))
58        }
59        _ => Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
60            "expected start object or null",
61        )),
62    }
63}