Skip to main content

aws_sdk_connect/protocol_serde/
shape_channel_to_count_map.rs

1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2pub(crate) fn de_channel_to_count_map<'a, I>(
3    tokens: &mut ::std::iter::Peekable<I>,
4    _value: &'a [u8],
5) -> ::std::result::Result<Option<::std::collections::HashMap<crate::types::Channel, i32>>, ::aws_smithy_json::deserialize::error::DeserializeError>
6where
7    I: Iterator<Item = Result<::aws_smithy_json::deserialize::Token<'a>, ::aws_smithy_json::deserialize::error::DeserializeError>>,
8{
9    match tokens.next().transpose()? {
10        Some(::aws_smithy_json::deserialize::Token::ValueNull { .. }) => Ok(None),
11        Some(::aws_smithy_json::deserialize::Token::StartObject { .. }) => {
12            let mut map = ::std::collections::HashMap::new();
13            loop {
14                match tokens.next().transpose()? {
15                    Some(::aws_smithy_json::deserialize::Token::EndObject { .. }) => break,
16                    Some(::aws_smithy_json::deserialize::Token::ObjectKey { key, .. }) => {
17                        let key = key.to_unescaped().map(|u| crate::types::Channel::from(u.as_ref()))?;
18                        let value = ::aws_smithy_json::deserialize::token::expect_number_or_null(tokens.next())?
19                            .map(i32::try_from)
20                            .transpose()?;
21                        match value {
22                            Some(value) => {
23                                map.insert(key, value);
24                            }
25                            None => {
26                                return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
27                                    "dense map cannot contain null values",
28                                ))
29                            }
30                        }
31                    }
32                    other => {
33                        return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(format!(
34                            "expected object key or end object, found: {other:?}"
35                        )))
36                    }
37                }
38            }
39            Ok(Some(map))
40        }
41        _ => Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
42            "expected start object or null",
43        )),
44    }
45}