PookieBuns commented on code in PR #458:
URL: https://github.com/apache/avro-rs/pull/458#discussion_r2789331424
##########
avro/src/serde/ser_schema.rs:
##########
@@ -1460,19 +1477,37 @@ impl<'s, W: Write> SchemaAwareWriteSerializer<'s, W> {
encode_int(variant_index as i32, &mut self.writer)
}
Schema::Union(union_schema) => {
- if variant_index as usize >= union_schema.schemas.len() {
+ // If we came here from a some, we need to check if we are
serializing a
+ // non-newtype enum
+ if self.serializing_some {
+ for (i, variant_schema) in
union_schema.schemas.iter().enumerate() {
+ match variant_schema {
+ Schema::Enum(enum_schema) if enum_schema.name.name
== name => {
+ if variant_index as usize >=
enum_schema.symbols.len() {
+ return Err(create_error(format!(
+ "Variant index out of bounds: {}. The
Enum schema has '{}' symbols",
+ variant_index,
+ enum_schema.symbols.len()
+ )));
+ }
+ encode_int(i as i32, &mut self.writer)?;
+ return encode_int(variant_index as i32, &mut
self.writer);
+ }
+ _ => { /* skip */ }
+ }
+ }
+ }
+ let branch_index = variant_index as usize +
usize::from(self.serializing_some);
Review Comment:
Updated to throw error if null isn't first branch, reasoning stated in
https://github.com/apache/avro-rs/pull/458#discussion_r2789323892
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]