This is an automated email from the ASF dual-hosted git repository. chaokunyang pushed a commit to tag v0.13.2-rc1 in repository https://gitbox.apache.org/repos/asf/fory.git
commit d3acdc8ac7edd5dd337b59054a33b9114b71628d Author: urlyy <[email protected]> AuthorDate: Thu Nov 6 14:24:15 2025 +0800 fix(Rust): fix Binary implementation (#2902) ## What does this PR do? fix Binary implementation ## Related issues close #2900 --- .../src/test/java/org/apache/fory/RustXlangTest.java | 2 ++ rust/fory-core/src/serializer/list.rs | 1 + rust/fory-core/src/serializer/primitive_list.rs | 2 +- rust/tests/tests/test_cross_language.rs | 3 +++ rust/tests/tests/test_unsigned.rs | 18 +++++++++++++++++- 5 files changed, 24 insertions(+), 2 deletions(-) diff --git a/java/fory-core/src/test/java/org/apache/fory/RustXlangTest.java b/java/fory-core/src/test/java/org/apache/fory/RustXlangTest.java index f272f0115..3b6c289fb 100644 --- a/java/fory-core/src/test/java/org/apache/fory/RustXlangTest.java +++ b/java/fory-core/src/test/java/org/apache/fory/RustXlangTest.java @@ -373,6 +373,7 @@ public class RustXlangTest extends ForyTestBase { Instant instant = Instant.ofEpochSecond(100); fory.serialize(buffer, instant); fory.serialize(buffer, new boolean[] {true, false}); + fory.serialize(buffer, new byte[] {1, Byte.MAX_VALUE}); fory.serialize(buffer, new short[] {1, Short.MAX_VALUE}); fory.serialize(buffer, new int[] {1, Integer.MAX_VALUE}); fory.serialize(buffer, new long[] {1, Long.MAX_VALUE}); @@ -402,6 +403,7 @@ public class RustXlangTest extends ForyTestBase { assertStringEquals(fory.deserialize(buf), day, useToString); assertStringEquals(fory.deserialize(buf), instant, useToString); assertStringEquals(fory.deserialize(buf), new boolean[] {true, false}, false); + assertStringEquals(fory.deserialize(buf), new byte[] {1, Byte.MAX_VALUE}, false); assertStringEquals(fory.deserialize(buf), new short[] {1, Short.MAX_VALUE}, false); assertStringEquals(fory.deserialize(buf), new int[] {1, Integer.MAX_VALUE}, false); assertStringEquals(fory.deserialize(buf), new long[] {1, Long.MAX_VALUE}, false); diff --git a/rust/fory-core/src/serializer/list.rs b/rust/fory-core/src/serializer/list.rs index 58711242c..054923a02 100644 --- a/rust/fory-core/src/serializer/list.rs +++ b/rust/fory-core/src/serializer/list.rs @@ -43,6 +43,7 @@ pub(super) fn get_primitive_type_id<T: Serializer>() -> TypeId { TypeId::INT64 => TypeId::INT64_ARRAY, TypeId::FLOAT32 => TypeId::FLOAT32_ARRAY, TypeId::FLOAT64 => TypeId::FLOAT64_ARRAY, + TypeId::U8 => TypeId::BINARY, TypeId::U16 => TypeId::U16_ARRAY, TypeId::U32 => TypeId::U32_ARRAY, TypeId::U64 => TypeId::U64_ARRAY, diff --git a/rust/fory-core/src/serializer/primitive_list.rs b/rust/fory-core/src/serializer/primitive_list.rs index d0a32e717..e1e3a4eb1 100644 --- a/rust/fory-core/src/serializer/primitive_list.rs +++ b/rust/fory-core/src/serializer/primitive_list.rs @@ -26,7 +26,7 @@ pub fn fory_write_data<T: Serializer>(this: &[T], context: &mut WriteContext) -> if context.is_xlang() && matches!( T::fory_static_type_id(), - TypeId::U8 | TypeId::U16 | TypeId::U32 | TypeId::U64 | TypeId::USIZE | TypeId::U128 + TypeId::U16 | TypeId::U32 | TypeId::U64 | TypeId::USIZE | TypeId::U128 ) { return Err(Error::not_allowed( diff --git a/rust/tests/tests/test_cross_language.rs b/rust/tests/tests/test_cross_language.rs index 1bc64434e..fa55ac01d 100644 --- a/rust/tests/tests/test_cross_language.rs +++ b/rust/tests/tests/test_cross_language.rs @@ -308,6 +308,7 @@ fn test_cross_language_serializer() { assert_de!(fory, reader, NaiveDate, day); assert_de!(fory, reader, NaiveDateTime, instant); assert_de!(fory, reader, Vec<bool>, [true, false]); + assert_de!(fory, reader, Vec<u8>, [1, i8::MAX as u8]); assert_de!(fory, reader, Vec<i16>, [1, i16::MAX]); assert_de!(fory, reader, Vec<i32>, [1, i32::MAX]); assert_de!(fory, reader, Vec<i64>, [1, i64::MAX]); @@ -336,6 +337,8 @@ fn test_cross_language_serializer() { fory.serialize_to(&day, &mut buf).unwrap(); fory.serialize_to(&instant, &mut buf).unwrap(); fory.serialize_to(&vec![true, false], &mut buf).unwrap(); + fory.serialize_to(&vec![1, i8::MAX as u8], &mut buf) + .unwrap(); fory.serialize_to(&vec![1, i16::MAX], &mut buf).unwrap(); fory.serialize_to(&vec![1, i32::MAX], &mut buf).unwrap(); fory.serialize_to(&vec![1, i64::MAX], &mut buf).unwrap(); diff --git a/rust/tests/tests/test_unsigned.rs b/rust/tests/tests/test_unsigned.rs index f6c790e3d..f0a4a3486 100644 --- a/rust/tests/tests/test_unsigned.rs +++ b/rust/tests/tests/test_unsigned.rs @@ -46,7 +46,7 @@ fn test_unsigned_arrays() { #[test] fn test_unsigned_arrays_when_xlang() { let fory = Fory::default().xlang(true); - assert!(fory.serialize(&vec![u8::MAX]).is_err()); + assert!(fory.serialize(&vec![u8::MAX]).is_ok()); assert!(fory.serialize(&vec![u16::MAX]).is_err()); assert!(fory.serialize(&vec![u32::MAX]).is_err()); assert!(fory.serialize(&vec![u64::MAX]).is_err()); @@ -54,6 +54,22 @@ fn test_unsigned_arrays_when_xlang() { assert!(fory.serialize(&vec![u128::MAX]).is_err()); } +#[test] +fn test_binary_when_xlang() { + let mut fory = Fory::default().xlang(true); + #[derive(ForyObject, Debug, PartialEq)] + struct UnsignedData { + binary: Vec<u8>, + } + fory.register::<UnsignedData>(100).unwrap(); + let binary = vec![0u8, 1, 2, u8::MAX]; + test_roundtrip(&fory, binary.clone()); + let data = UnsignedData { binary }; + let bytes = fory.serialize(&data).unwrap(); + let result: UnsignedData = fory.deserialize(&bytes).unwrap(); + assert_eq!(data, result); +} + #[test] fn test_unsigned_struct_non_compatible() { #[derive(ForyObject, Debug, PartialEq)] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
