PookieBuns commented on code in PR #458:
URL: https://github.com/apache/avro-rs/pull/458#discussion_r2791288075
##########
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);
+ }
Review Comment:
updated in
https://github.com/apache/avro-rs/pull/458/changes/6c58e62db077ad87efb8549e4200a20f5298b465
with test to verify behavior
--
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]