You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@avro.apache.org by mg...@apache.org on 2022/10/19 13:21:19 UTC
[avro] branch master updated: AVRO-3645: [RUST] Fix deserialization of enum with unit type (#1916)
This is an automated email from the ASF dual-hosted git repository.
mgrigorov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/avro.git
The following commit(s) were added to refs/heads/master by this push:
new 3e3be73bd AVRO-3645: [RUST] Fix deserialization of enum with unit type (#1916)
3e3be73bd is described below
commit 3e3be73bdb7f42bb05babc9c89f38c0e08734e62
Author: LucasJavaudin <32...@users.noreply.github.com>
AuthorDate: Wed Oct 19 15:21:14 2022 +0200
AVRO-3645: [RUST] Fix deserialization of enum with unit type (#1916)
- deserialize_unit properly reads union with a Unit value as a Unit.
- Add a unit test to check that an enum with a unit value is properly
deserialized.
Co-authored-by: Lucas Javaudin <lu...@cyu.fr>
---
lang/rust/avro/src/de.rs | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/lang/rust/avro/src/de.rs b/lang/rust/avro/src/de.rs
index 83a09ebdc..1d3b50360 100644
--- a/lang/rust/avro/src/de.rs
+++ b/lang/rust/avro/src/de.rs
@@ -366,6 +366,10 @@ impl<'a, 'de> de::Deserializer<'de> for &'a Deserializer<'de> {
{
match *self.input {
Value::Null => visitor.visit_unit(),
+ Value::Union(_i, ref x) => match **x {
+ Value::Null => visitor.visit_unit(),
+ _ => Err(de::Error::custom("not a null")),
+ },
_ => Err(de::Error::custom("not a null")),
}
}
@@ -658,6 +662,17 @@ mod tests {
Val2,
}
+ #[derive(Debug, Deserialize, Serialize, PartialEq, Eq)]
+ struct TestNullExternalEnum {
+ a: NullExternalEnum,
+ }
+
+ #[derive(Debug, Deserialize, Serialize, PartialEq, Eq)]
+ enum NullExternalEnum {
+ Val1(()),
+ Val2(u64),
+ }
+
#[derive(Debug, Serialize, Deserialize, PartialEq)]
struct TestSingleValueExternalEnum {
a: SingleValueExternalEnum,
@@ -770,6 +785,26 @@ mod tests {
);
}
+ #[test]
+ fn test_from_value_null_enum() {
+ let expected = TestNullExternalEnum {
+ a: NullExternalEnum::Val1(()),
+ };
+
+ let test = Value::Record(vec![(
+ "a".to_owned(),
+ Value::Record(vec![
+ ("type".to_owned(), Value::String("Val1".to_owned())),
+ ("value".to_owned(), Value::Union(0, Box::new(Value::Null))),
+ ]),
+ )]);
+ let final_value: TestNullExternalEnum = from_value(&test).unwrap();
+ assert_eq!(
+ final_value, expected,
+ "Error deserializing null external enum"
+ );
+ }
+
#[test]
fn test_from_value_single_value_enum() {
let expected = TestSingleValueExternalEnum {