aws-sdk-cloudwatchomni 1.2.0

AWS SDK for CloudWatch Omni
Documentation
// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
pub fn ser_alert_condition(
    encoder: &mut ::aws_smithy_cbor::Encoder,
    #[allow(unused)] input: &crate::types::AlertCondition,
) -> ::std::result::Result<(), ::aws_smithy_types::error::operation::SerializationError> {
    encoder.begin_map();
    if let Some(var_1) = &input.threshold_mode {
        encoder.str("thresholdMode").str(var_1.as_str());
    }
    if let Some(var_2) = &input.threshold_field {
        encoder.str("thresholdField").str(var_2.as_str());
    }
    if let Some(var_3) = &input.comparator {
        encoder.str("comparator").str(var_3.as_str());
    }
    if let Some(var_4) = &input.warning_threshold {
        encoder.str("warningThreshold").double(*var_4);
    }
    if let Some(var_5) = &input.critical_threshold {
        encoder.str("criticalThreshold").double(*var_5);
    }
    encoder.end();
    Ok(())
}

pub(crate) fn de_alert_condition(
    decoder: &mut ::aws_smithy_cbor::Decoder,
    depth: u32,
) -> ::std::result::Result<crate::types::AlertCondition, ::aws_smithy_cbor::decode::DeserializeError> {
    if depth >= 128u32 {
        return Err(::aws_smithy_cbor::decode::DeserializeError::custom(
            "maximum nesting depth exceeded",
            decoder.position(),
        ));
    }
    #[allow(clippy::match_single_binding, unused_variables)]
    fn pair(
        mut builder: crate::types::builders::AlertConditionBuilder,
        decoder: &mut ::aws_smithy_cbor::Decoder,
        depth: u32,
    ) -> ::std::result::Result<crate::types::builders::AlertConditionBuilder, ::aws_smithy_cbor::decode::DeserializeError> {
        builder = match decoder.str()?.as_ref() {
            "thresholdMode" => ::aws_smithy_cbor::decode::set_optional(builder, decoder, |builder, decoder| {
                Ok(builder.set_threshold_mode(Some(decoder.string().map(|s| crate::types::ThresholdMode::from(s.as_str()))?)))
            })?,
            "thresholdField" => ::aws_smithy_cbor::decode::set_optional(builder, decoder, |builder, decoder| {
                Ok(builder.set_threshold_field(Some(decoder.string()?)))
            })?,
            "comparator" => ::aws_smithy_cbor::decode::set_optional(builder, decoder, |builder, decoder| {
                Ok(builder.set_comparator(Some(decoder.string().map(|s| crate::types::Comparator::from(s.as_str()))?)))
            })?,
            "warningThreshold" => ::aws_smithy_cbor::decode::set_optional(builder, decoder, |builder, decoder| {
                Ok(builder.set_warning_threshold(Some(decoder.double()?)))
            })?,
            "criticalThreshold" => ::aws_smithy_cbor::decode::set_optional(builder, decoder, |builder, decoder| {
                Ok(builder.set_critical_threshold(Some(decoder.double()?)))
            })?,
            _ => {
                decoder.skip()?;
                builder
            }
        };
        Ok(builder)
    }

    let mut builder = crate::types::builders::AlertConditionBuilder::default();

    match decoder.map()? {
        None => loop {
            match decoder.datatype()? {
                ::aws_smithy_cbor::data::Type::Break => {
                    decoder.skip()?;
                    break;
                }
                _ => {
                    builder = pair(builder, decoder, depth)?;
                }
            };
        },
        Some(n) => {
            for _ in 0..n {
                builder = pair(builder, decoder, depth)?;
            }
        }
    };
    #[allow(clippy::needless_question_mark)]
    {
        return Ok(builder.build());
    }
}