diff --git a/lang/rust/avro/src/de.rs b/lang/rust/avro/src/de.rs index 33cd5af9c1f..b354d042b77 100644 --- a/lang/rust/avro/src/de.rs +++ b/lang/rust/avro/src/de.rs @@ -668,6 +668,8 @@ mod tests { use serde::{Deserialize, Serialize}; use serial_test::serial; use std::sync::atomic::Ordering; + use serde::Serialize; + use serde_bytes::ByteArray; use uuid::Uuid; use apache_avro_test_helper::TestResult; @@ -1554,7 +1556,7 @@ mod tests { fn test_avro_3631_struct_fixed_field() { #[derive(Debug, Serialize, Deserialize)] struct TestStructFixedField { - field: [u8; 6], + field: ByteArray<6>, } let value = Value::Record(vec![( @@ -1562,6 +1564,5 @@ mod tests { Value::Fixed(6, vec![0, 0, 0, 0, 0, 0]), )]); let _deserialized: TestStructFixedField = from_value(&value).unwrap(); - } } diff --git a/lang/rust/avro/src/ser.rs b/lang/rust/avro/src/ser.rs index aa033f7b6ee..714a43c45ab 100644 --- a/lang/rust/avro/src/ser.rs +++ b/lang/rust/avro/src/ser.rs @@ -174,7 +174,7 @@ impl<'b> ser::Serializer for &'b mut Serializer { } fn serialize_bytes(self, v: &[u8]) -> Result { - Ok(Value::Bytes(v.to_owned())) + Ok(Value::Fixed(v.len(), v.to_owned())) } fn serialize_none(self) -> Result { @@ -486,6 +486,7 @@ mod tests { use serde::{Deserialize, Serialize}; use serial_test::serial; use std::sync::atomic::Ordering; + use serde_bytes::ByteArray; #[derive(Debug, Deserialize, Serialize, Clone)] struct Test { @@ -678,7 +679,7 @@ mod tests { #[derive(Debug, Serialize, Deserialize)] struct TestStructFixedField { - field: [u8; 6], + field: ByteArray<6>, } #[test] @@ -1038,15 +1039,17 @@ mod tests { } #[test] - fn test_to_value_fixed_field_avro_3631() { - let test = TestStructFixedField { field: [1; 6] }; + fn avro_3631_test_to_value_fixed_field() { + let test = TestStructFixedField { + field: ByteArray::new([1; 6]), + }; let expected = Value::Record(vec![( "field".to_owned(), - Value::Fixed(6, Vec::from(test.field.clone())), + Value::Fixed(6, Vec::from(test.field.clone().into_array())), )]); assert_eq!( - to_value(test).unwrap(), expected, + to_value(test).unwrap(), "error serializing fixed array" ); } diff --git a/lang/rust/avro/src/types.rs b/lang/rust/avro/src/types.rs index 4744cf55c42..2af12e30a29 100644 --- a/lang/rust/avro/src/types.rs +++ b/lang/rust/avro/src/types.rs @@ -1167,6 +1167,7 @@ mod tests { use pretty_assertions::assert_eq; use serde::{Deserialize, Serialize}; use serde_json::json; + use serde_bytes::ByteArray; use uuid::Uuid; #[test] @@ -3123,14 +3124,16 @@ Field with name '"b"' is not a member of the map items"#, ); } - #[derive(Debug, Serialize, Deserialize)] - struct TestStructFixedField { - field: [u8; 6], - } - #[test] - fn test_avro_3631_serialize_fixed_fields() { - let test = TestStructFixedField { field: [1; 6] }; + fn avro_3631_test_serialize_fixed_fields() { + #[derive(Debug, Serialize, Deserialize)] + struct TestStructFixedField { + field: ByteArray<6>, + } + + let test = TestStructFixedField { + field: ByteArray::new([1; 6]), + }; let value: Value = to_value(test).unwrap(); let schema = Schema::parse_str( r#"