pub(crate) fn de_batch_job_identifier<'a, I>(
tokens: &mut ::std::iter::Peekable<I>,
_value: &'a [u8],
) -> ::std::result::Result<Option<crate::types::BatchJobIdentifier>, ::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() {
"fileBatchJobIdentifier" => Some(crate::types::BatchJobIdentifier::FileBatchJobIdentifier(
crate::protocol_serde::shape_file_batch_job_identifier::de_file_batch_job_identifier(tokens, _value)?.ok_or_else(
|| {
::aws_smithy_json::deserialize::error::DeserializeError::custom(
"value for 'fileBatchJobIdentifier' cannot be null",
)
},
)?,
)),
"scriptBatchJobIdentifier" => Some(crate::types::BatchJobIdentifier::ScriptBatchJobIdentifier(
crate::protocol_serde::shape_script_batch_job_identifier::de_script_batch_job_identifier(tokens, _value)?.ok_or_else(
|| {
::aws_smithy_json::deserialize::error::DeserializeError::custom(
"value for 'scriptBatchJobIdentifier' cannot be null",
)
},
)?,
)),
"s3BatchJobIdentifier" => Some(crate::types::BatchJobIdentifier::S3BatchJobIdentifier(
crate::protocol_serde::shape_s3_batch_job_identifier::de_s3_batch_job_identifier(tokens, _value)?.ok_or_else(|| {
::aws_smithy_json::deserialize::error::DeserializeError::custom("value for 's3BatchJobIdentifier' cannot be null")
})?,
)),
"restartBatchJobIdentifier" => Some(crate::types::BatchJobIdentifier::RestartBatchJobIdentifier(
crate::protocol_serde::shape_restart_batch_job_identifier::de_restart_batch_job_identifier(tokens, _value)?.ok_or_else(
|| {
::aws_smithy_json::deserialize::error::DeserializeError::custom(
"value for 'restartBatchJobIdentifier' cannot be null",
)
},
)?,
)),
_ => {
::aws_smithy_json::deserialize::token::skip_value(tokens)?;
Some(crate::types::BatchJobIdentifier::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_batch_job_identifier(
object_3: &mut ::aws_smithy_json::serialize::JsonObjectWriter,
input: &crate::types::BatchJobIdentifier,
) -> ::std::result::Result<(), ::aws_smithy_types::error::operation::SerializationError> {
match input {
crate::types::BatchJobIdentifier::FileBatchJobIdentifier(inner) => {
#[allow(unused_mut)]
let mut object_1 = object_3.key("fileBatchJobIdentifier").start_object();
crate::protocol_serde::shape_file_batch_job_identifier::ser_file_batch_job_identifier(&mut object_1, inner)?;
object_1.finish();
}
crate::types::BatchJobIdentifier::ScriptBatchJobIdentifier(inner) => {
#[allow(unused_mut)]
let mut object_2 = object_3.key("scriptBatchJobIdentifier").start_object();
crate::protocol_serde::shape_script_batch_job_identifier::ser_script_batch_job_identifier(&mut object_2, inner)?;
object_2.finish();
}
crate::types::BatchJobIdentifier::S3BatchJobIdentifier(inner) => {
#[allow(unused_mut)]
let mut object_3 = object_3.key("s3BatchJobIdentifier").start_object();
crate::protocol_serde::shape_s3_batch_job_identifier::ser_s3_batch_job_identifier(&mut object_3, inner)?;
object_3.finish();
}
crate::types::BatchJobIdentifier::RestartBatchJobIdentifier(inner) => {
#[allow(unused_mut)]
let mut object_4 = object_3.key("restartBatchJobIdentifier").start_object();
crate::protocol_serde::shape_restart_batch_job_identifier::ser_restart_batch_job_identifier(&mut object_4, inner)?;
object_4.finish();
}
crate::types::BatchJobIdentifier::Unknown => {
return Err(::aws_smithy_types::error::operation::SerializationError::unknown_variant(
"BatchJobIdentifier",
))
}
}
Ok(())
}