martin-g commented on code in PR #2583:
URL: https://github.com/apache/avro/pull/2583#discussion_r1391060320


##########
lang/rust/avro/src/encode.rs:
##########
@@ -242,11 +252,26 @@ pub(crate) fn encode_internal<S: Borrow<Schema>>(
                         ));
                     }
                 }
+            } else if let Schema::Union(UnionSchema{ schemas, .. }) = schema {
+                let original_size = buffer.len();
+                for (index,s) in schemas.iter().enumerate() {
+                    encode_long(index as i64, buffer);
+                    match encode_internal(value, s, names, 
enclosing_namespace, buffer) {
+                        Ok(_) => return Ok(()),
+                        Err(_) => {
+                            buffer.truncate(original_size); //undo any partial 
encoding

Review Comment:
   Should we exit/break the loop in this case ?



-- 
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]

Reply via email to