aws-sdk-bedrockagentcore 1.45.0

AWS SDK for Amazon Bedrock AgentCore
Documentation
// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
pub(crate) fn de_agent_traces_config<'a, I>(
    tokens: &mut ::std::iter::Peekable<I>,
    _value: &'a [u8],
) -> ::std::result::Result<Option<crate::types::AgentTracesConfig>, ::aws_smithy_json::deserialize::error::DeserializeError>
where
    I: Iterator<Item = Result<::aws_smithy_json::deserialize::Token<'a>, ::aws_smithy_json::deserialize::error::DeserializeError>>,
{
    let mut variant = None;
    match tokens.next().transpose()? {
        Some(::aws_smithy_json::deserialize::Token::ValueNull { .. }) => return Ok(None),
        Some(::aws_smithy_json::deserialize::Token::StartObject { .. }) => loop {
            match tokens.next().transpose()? {
                Some(::aws_smithy_json::deserialize::Token::EndObject { .. }) => break,
                Some(::aws_smithy_json::deserialize::Token::ObjectKey { key, .. }) => {
                    if let ::std::option::Option::Some(::std::result::Result::Ok(::aws_smithy_json::deserialize::Token::ValueNull { .. })) =
                        tokens.peek()
                    {
                        let _ = tokens.next().expect("peek returned a token")?;
                        continue;
                    }
                    let key = key.to_unescaped()?;
                    if key == "__type" {
                        ::aws_smithy_json::deserialize::token::skip_value(tokens)?;
                        continue;
                    }
                    if variant.is_some() {
                        return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
                            "encountered mixed variants in union",
                        ));
                    }
                    variant = match key.as_ref() {
                        "sessionSpans" => Some(crate::types::AgentTracesConfig::SessionSpans(
                            crate::protocol_serde::shape_spans::de_spans(tokens, _value)?.ok_or_else(|| {
                                ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'sessionSpans' cannot be null")
                            })?,
                        )),
                        "cloudwatchLogs" => Some(crate::types::AgentTracesConfig::CloudwatchLogs(
                            crate::protocol_serde::shape_cloud_watch_logs_trace_config::de_cloud_watch_logs_trace_config(tokens, _value)?
                                .ok_or_else(|| {
                                    ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'cloudwatchLogs' cannot be null")
                                })?,
                        )),
                        _ => {
                            ::aws_smithy_json::deserialize::token::skip_value(tokens)?;
                            Some(crate::types::AgentTracesConfig::Unknown)
                        }
                    };
                }
                other => {
                    return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(format!(
                        "expected object key or end object, found: {other:?}"
                    )))
                }
            }
        },
        _ => {
            return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
                "expected start object or null",
            ))
        }
    }
    if variant.is_none() {
        return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
            "Union did not contain a valid variant.",
        ));
    }
    Ok(variant)
}

pub fn ser_agent_traces_config(
    object_4: &mut ::aws_smithy_json::serialize::JsonObjectWriter,
    input: &crate::types::AgentTracesConfig,
) -> ::std::result::Result<(), ::aws_smithy_types::error::operation::SerializationError> {
    match input {
        crate::types::AgentTracesConfig::SessionSpans(inner) => {
            let mut array_1 = object_4.key("sessionSpans").start_array();
            for item_2 in inner {
                {
                    array_1.value().document(item_2);
                }
            }
            array_1.finish();
        }
        crate::types::AgentTracesConfig::CloudwatchLogs(inner) => {
            #[allow(unused_mut)]
            let mut object_3 = object_4.key("cloudwatchLogs").start_object();
            crate::protocol_serde::shape_cloud_watch_logs_trace_config::ser_cloud_watch_logs_trace_config(&mut object_3, inner)?;
            object_3.finish();
        }
        crate::types::AgentTracesConfig::Unknown => {
            return Err(::aws_smithy_types::error::operation::SerializationError::unknown_variant(
                "AgentTracesConfig",
            ))
        }
    }
    Ok(())
}