1 - | // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
|
2 - | pub fn ser_content_block(
|
3 - | object_3: &mut ::aws_smithy_json::serialize::JsonObjectWriter,
|
4 - | input: &crate::types::ContentBlock,
|
5 - | ) -> ::std::result::Result<(), ::aws_smithy_types::error::operation::SerializationError> {
|
6 - | match input {
|
7 - | crate::types::ContentBlock::Text(inner) => {
|
8 - | object_3.key("text").string(inner.as_str());
|
9 - | }
|
10 - | crate::types::ContentBlock::Image(inner) => {
|
11 - | #[allow(unused_mut)]
|
12 - | let mut object_1 = object_3.key("image").start_object();
|
13 - | crate::protocol_serde::shape_image_block::ser_image_block(&mut object_1, inner)?;
|
14 - | object_1.finish();
|
15 - | }
|
16 - | crate::types::ContentBlock::Document(inner) => {
|
17 - | #[allow(unused_mut)]
|
18 - | let mut object_2 = object_3.key("document").start_object();
|
19 - | crate::protocol_serde::shape_document_block::ser_document_block(&mut object_2, inner)?;
|
20 - | object_2.finish();
|
21 - | }
|
22 - | crate::types::ContentBlock::Video(inner) => {
|
23 - | #[allow(unused_mut)]
|
24 - | let mut object_3 = object_3.key("video").start_object();
|
25 - | crate::protocol_serde::shape_video_block::ser_video_block(&mut object_3, inner)?;
|
26 - | object_3.finish();
|
27 - | }
|
28 - | crate::types::ContentBlock::ToolUse(inner) => {
|
29 - | #[allow(unused_mut)]
|
30 - | let mut object_4 = object_3.key("toolUse").start_object();
|
31 - | crate::protocol_serde::shape_tool_use_block::ser_tool_use_block(&mut object_4, inner)?;
|
32 - | object_4.finish();
|
33 - | }
|
34 - | crate::types::ContentBlock::ToolResult(inner) => {
|
35 - | #[allow(unused_mut)]
|
36 - | let mut object_5 = object_3.key("toolResult").start_object();
|
37 - | crate::protocol_serde::shape_tool_result_block::ser_tool_result_block(&mut object_5, inner)?;
|
38 - | object_5.finish();
|
39 - | }
|
40 - | crate::types::ContentBlock::GuardContent(inner) => {
|
41 - | #[allow(unused_mut)]
|
42 - | let mut object_6 = object_3.key("guardContent").start_object();
|
43 - | crate::protocol_serde::shape_guardrail_converse_content_block::ser_guardrail_converse_content_block(&mut object_6, inner)?;
|
44 - | object_6.finish();
|
45 - | }
|
46 - | crate::types::ContentBlock::CachePoint(inner) => {
|
47 - | #[allow(unused_mut)]
|
48 - | let mut object_7 = object_3.key("cachePoint").start_object();
|
49 - | crate::protocol_serde::shape_cache_point_block::ser_cache_point_block(&mut object_7, inner)?;
|
50 - | object_7.finish();
|
51 - | }
|
52 - | crate::types::ContentBlock::ReasoningContent(inner) => {
|
53 - | #[allow(unused_mut)]
|
54 - | let mut object_8 = object_3.key("reasoningContent").start_object();
|
55 - | crate::protocol_serde::shape_reasoning_content_block::ser_reasoning_content_block(&mut object_8, inner)?;
|
56 - | object_8.finish();
|
57 - | }
|
58 - | crate::types::ContentBlock::CitationsContent(inner) => {
|
59 - | #[allow(unused_mut)]
|
60 - | let mut object_9 = object_3.key("citationsContent").start_object();
|
61 - | crate::protocol_serde::shape_citations_content_block::ser_citations_content_block(&mut object_9, inner)?;
|
62 - | object_9.finish();
|
63 - | }
|
64 - | crate::types::ContentBlock::Unknown => return Err(::aws_smithy_types::error::operation::SerializationError::unknown_variant("ContentBlock")),
|
65 - | }
|
66 - | Ok(())
|
67 - | }
|
68 - |
|
69 - | pub(crate) fn de_content_block<'a, I>(
|
70 - | tokens: &mut ::std::iter::Peekable<I>,
|
71 - | _value: &'a [u8],
|
72 - | ) -> ::std::result::Result<Option<crate::types::ContentBlock>, ::aws_smithy_json::deserialize::error::DeserializeError>
|
73 - | where
|
74 - | I: Iterator<Item = Result<::aws_smithy_json::deserialize::Token<'a>, ::aws_smithy_json::deserialize::error::DeserializeError>>,
|
75 - | {
|
76 - | let mut variant = None;
|
77 - | match tokens.next().transpose()? {
|
78 - | Some(::aws_smithy_json::deserialize::Token::ValueNull { .. }) => return Ok(None),
|
79 - | Some(::aws_smithy_json::deserialize::Token::StartObject { .. }) => loop {
|
80 - | match tokens.next().transpose()? {
|
81 - | Some(::aws_smithy_json::deserialize::Token::EndObject { .. }) => break,
|
82 - | Some(::aws_smithy_json::deserialize::Token::ObjectKey { key, .. }) => {
|
83 - | if let ::std::option::Option::Some(::std::result::Result::Ok(::aws_smithy_json::deserialize::Token::ValueNull { .. })) =
|
84 - | tokens.peek()
|
85 - | {
|
86 - | let _ = tokens.next().expect("peek returned a token")?;
|
87 - | continue;
|
88 - | }
|
89 - | let key = key.to_unescaped()?;
|
90 - | if key == "__type" {
|
91 - | ::aws_smithy_json::deserialize::token::skip_value(tokens)?;
|
92 - | continue;
|
93 - | }
|
94 - | if variant.is_some() {
|
95 - | return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
|
96 - | "encountered mixed variants in union",
|
97 - | ));
|
98 - | }
|
99 - | variant = match key.as_ref() {
|
100 - | "text" => Some(crate::types::ContentBlock::Text(
|
101 - | ::aws_smithy_json::deserialize::token::expect_string_or_null(tokens.next())?
|
102 - | .map(|s| s.to_unescaped().map(|u| u.into_owned()))
|
103 - | .transpose()?
|
104 - | .ok_or_else(|| ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'text' cannot be null"))?,
|
105 - | )),
|
106 - | "image" => Some(crate::types::ContentBlock::Image(
|
107 - | crate::protocol_serde::shape_image_block::de_image_block(tokens, _value)?
|
108 - | .ok_or_else(|| ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'image' cannot be null"))?,
|
109 - | )),
|
110 - | "document" => Some(crate::types::ContentBlock::Document(
|
111 - | crate::protocol_serde::shape_document_block::de_document_block(tokens, _value)?.ok_or_else(|| {
|
112 - | ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'document' cannot be null")
|
113 - | })?,
|
114 - | )),
|
115 - | "video" => Some(crate::types::ContentBlock::Video(
|
116 - | crate::protocol_serde::shape_video_block::de_video_block(tokens, _value)?
|
117 - | .ok_or_else(|| ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'video' cannot be null"))?,
|
118 - | )),
|
119 - | "toolUse" => Some(crate::types::ContentBlock::ToolUse(
|
120 - | crate::protocol_serde::shape_tool_use_block::de_tool_use_block(tokens, _value)?.ok_or_else(|| {
|
121 - | ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'toolUse' cannot be null")
|
122 - | })?,
|
123 - | )),
|
124 - | "toolResult" => Some(crate::types::ContentBlock::ToolResult(
|
125 - | crate::protocol_serde::shape_tool_result_block::de_tool_result_block(tokens, _value)?.ok_or_else(|| {
|
126 - | ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'toolResult' cannot be null")
|
127 - | })?,
|
128 - | )),
|
129 - | "guardContent" => Some(crate::types::ContentBlock::GuardContent(
|
130 - | crate::protocol_serde::shape_guardrail_converse_content_block::de_guardrail_converse_content_block(tokens, _value)?
|
131 - | .ok_or_else(|| {
|
132 - | ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'guardContent' cannot be null")
|
133 - | })?,
|
134 - | )),
|
135 - | "cachePoint" => Some(crate::types::ContentBlock::CachePoint(
|
136 - | crate::protocol_serde::shape_cache_point_block::de_cache_point_block(tokens, _value)?.ok_or_else(|| {
|
137 - | ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'cachePoint' cannot be null")
|
138 - | })?,
|
139 - | )),
|
140 - | "reasoningContent" => Some(crate::types::ContentBlock::ReasoningContent(
|
141 - | crate::protocol_serde::shape_reasoning_content_block::de_reasoning_content_block(tokens, _value)?.ok_or_else(|| {
|
142 - | ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'reasoningContent' cannot be null")
|
143 - | })?,
|
144 - | )),
|
145 - | "citationsContent" => Some(crate::types::ContentBlock::CitationsContent(
|
146 - | crate::protocol_serde::shape_citations_content_block::de_citations_content_block(tokens, _value)?.ok_or_else(|| {
|
147 - | ::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 'citationsContent' cannot be null")
|
148 - | })?,
|
149 - | )),
|
150 - | _ => {
|
151 - | ::aws_smithy_json::deserialize::token::skip_value(tokens)?;
|
152 - | Some(crate::types::ContentBlock::Unknown)
|
153 - | }
|
154 - | };
|
155 - | }
|
156 - | other => {
|
157 - | return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(format!(
|
158 - | "expected object key or end object, found: {other:?}"
|
159 - | )))
|
160 - | }
|
161 - | }
|
162 - | },
|
163 - | _ => {
|
164 - | return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
|
165 - | "expected start object or null",
|
166 - | ))
|
167 - | }
|
168 - | }
|
169 - | if variant.is_none() {
|
170 - | return Err(::aws_smithy_json::deserialize::error::DeserializeError::custom(
|
171 - | "Union did not contain a valid variant.",
|
172 - | ));
|
173 - | }
|
174 - | Ok(variant)
|
175 - | }
|