This is an automated email from the ASF dual-hosted git repository.

chaokunyang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/fory.git


The following commit(s) were added to refs/heads/main by this push:
     new 1574d44ee chore(Rust): Remove new_from_fory from context.rs (#2831)
1574d44ee is described below

commit 1574d44ee1f14c65b3b7ca4eaf6bfe27480a5537
Author: urlyy <[email protected]>
AuthorDate: Fri Oct 24 15:16:52 2025 +0800

    chore(Rust): Remove new_from_fory from context.rs (#2831)
    
    ## What does this PR do?
    1. Remove new_from_fory from context.rs
    2. add `allow(clippy::needless_lifetimes)]` to keep lifetime but avoid
    lint error.
    3. refactor some unit tests.
    
    ## Related issues
    close #2827
---
 .../test/java/org/apache/fory/RustXlangTest.java   |   9 +-
 rust/fory-core/src/buffer.rs                       |   4 +
 rust/fory-core/src/fory.rs                         |   5 -
 rust/fory-core/src/resolver/context.rs             |  50 +--
 rust/fory-core/src/row/row.rs                      |   3 +
 rust/fory-core/src/util.rs                         |   6 +-
 rust/tests/tests/compatible/test_basic_type.rs     | 349 +++++++++------------
 rust/tests/tests/test_cross_language.rs            | 154 ++++-----
 8 files changed, 253 insertions(+), 327 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 09c5dd512..4e0332b7a 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
@@ -316,14 +316,14 @@ public class RustXlangTest extends ForyTestBase {
           "Hello, 世界",
         };
     for (String s : testStrings) {
-      serializer.writeJavaString(buffer, s);
+      fory.serialize(buffer, s);
     }
     Pair<Map<String, String>, File> env_workdir =
         setFilePath(language, command, dataFile, buffer.getBytes(0, 
buffer.writerIndex()));
     Assert.assertTrue(executeCommand(command, 30, env_workdir.getLeft(), 
env_workdir.getRight()));
     buffer = MemoryUtils.wrap(Files.readAllBytes(dataFile));
     for (String expected : testStrings) {
-      String actual = serializer.readJavaString(buffer);
+      String actual = (String) fory.deserialize(buffer);
       Assert.assertEquals(actual, expected);
     }
   }
@@ -810,8 +810,9 @@ public class RustXlangTest extends ForyTestBase {
     for (int i = 0; i < 3; i++) {
       fory.serialize(buffer, Color.White);
     }
-    // todo: checkVersion
-    //        fory.serialize(buffer, myStruct);
+    for (int i = 0; i < 3; i++) {
+      fory.serialize(buffer, myStruct);
+    }
     for (int i = 0; i < 3; i++) {
       fory.serialize(buffer, myExt);
     }
diff --git a/rust/fory-core/src/buffer.rs b/rust/fory-core/src/buffer.rs
index d09959210..84a7739bc 100644
--- a/rust/fory-core/src/buffer.rs
+++ b/rust/fory-core/src/buffer.rs
@@ -333,11 +333,13 @@ impl<'a> Writer<'a> {
 }
 
 #[derive(Default)]
+#[allow(clippy::needless_lifetimes)]
 pub struct Reader<'a> {
     pub(crate) bf: &'a [u8],
     pub(crate) cursor: usize,
 }
 
+#[allow(clippy::needless_lifetimes)]
 impl<'a> Reader<'a> {
     #[inline(always)]
     pub fn new(bf: &[u8]) -> Reader<'_> {
@@ -743,5 +745,7 @@ impl<'a> Reader<'a> {
     }
 }
 
+#[allow(clippy::needless_lifetimes)]
 unsafe impl<'a> Send for Reader<'a> {}
+#[allow(clippy::needless_lifetimes)]
 unsafe impl<'a> Sync for Reader<'a> {}
diff --git a/rust/fory-core/src/fory.rs b/rust/fory-core/src/fory.rs
index 9c34195dd..5d02f699f 100644
--- a/rust/fory-core/src/fory.rs
+++ b/rust/fory-core/src/fory.rs
@@ -335,11 +335,6 @@ impl Fory {
         self.check_struct_version
     }
 
-    /// Returns a type resolver for type lookups.
-    pub(crate) fn get_type_resolver(&self) -> &TypeResolver {
-        &self.type_resolver
-    }
-
     /// Serializes a value of type `T` into a byte vector.
     ///
     /// # Type Parameters
diff --git a/rust/fory-core/src/resolver/context.rs 
b/rust/fory-core/src/resolver/context.rs
index b69a05616..737013cd1 100644
--- a/rust/fory-core/src/resolver/context.rs
+++ b/rust/fory-core/src/resolver/context.rs
@@ -19,7 +19,6 @@ use crate::buffer::{Reader, Writer};
 use std::mem;
 
 use crate::error::Error;
-use crate::fory::Fory;
 use crate::meta::MetaString;
 use crate::resolver::meta_resolver::{MetaReaderResolver, MetaWriterResolver};
 use crate::resolver::meta_string_resolver::{MetaStringReaderResolver, 
MetaStringWriterResolver};
@@ -31,6 +30,7 @@ use std::rc::Rc;
 
 /// Serialization state container used on a single thread at a time.
 /// Sharing the same instance across threads simultaneously causes undefined 
behavior.
+#[allow(clippy::needless_lifetimes)]
 pub struct WriteContext<'a> {
     // Replicated environment fields (direct access, no Arc indirection for 
flags)
     type_resolver: TypeResolver,
@@ -48,6 +48,7 @@ pub struct WriteContext<'a> {
     pub ref_writer: RefWriter,
 }
 
+#[allow(clippy::needless_lifetimes)]
 impl<'a> WriteContext<'a> {
     pub fn new(
         type_resolver: TypeResolver,
@@ -89,27 +90,6 @@ impl<'a> WriteContext<'a> {
         self.writer = default.unwrap();
     }
 
-    /// Test method to create WriteContext from Fory instance
-    /// Will be removed in future releases, do not use it in production code
-    pub fn new_from_fory(fory: &Fory) -> WriteContext<'a> {
-        WriteContext {
-            default_writer: None,
-            writer: Writer::from_buffer(Self::get_leak_buffer()),
-            type_resolver: fory
-                .get_type_resolver()
-                .build_final_type_resolver()
-                .unwrap(),
-            compatible: fory.is_compatible(),
-            share_meta: fory.is_share_meta(),
-            compress_string: fory.is_compress_string(),
-            xlang: fory.is_xlang(),
-            check_struct_version: fory.is_check_struct_version(),
-            meta_resolver: MetaWriterResolver::default(),
-            meta_string_resolver: MetaStringWriterResolver::default(),
-            ref_writer: RefWriter::new(),
-        }
-    }
-
     /// Get type resolver
     #[inline(always)]
     pub fn get_type_resolver(&self) -> &TypeResolver {
@@ -227,6 +207,7 @@ impl<'a> WriteContext<'a> {
     }
 }
 
+#[allow(clippy::needless_lifetimes)]
 impl<'a> Drop for WriteContext<'a> {
     fn drop(&mut self) {
         unsafe {
@@ -239,7 +220,9 @@ impl<'a> Drop for WriteContext<'a> {
 // ensures single-threaded access while the context is in use. Users must 
never hold the same
 // instance on multiple threads simultaneously; that would violate the 
invariants and result in
 // undefined behavior. Under that assumption, marking it Send/Sync is sound.
+#[allow(clippy::needless_lifetimes)]
 unsafe impl<'a> Send for WriteContext<'a> {}
+#[allow(clippy::needless_lifetimes)]
 unsafe impl<'a> Sync for WriteContext<'a> {}
 
 /// Deserialization state container used on a single thread at a time.
@@ -265,7 +248,9 @@ pub struct ReadContext<'a> {
 // single-threaded use. Concurrent access to the same instance across threads 
is forbidden and
 // would result in undefined behavior. With exclusive use guaranteed, the 
Send/Sync markers are safe
 // even though Rc is used internally.
+#[allow(clippy::needless_lifetimes)]
 unsafe impl<'a> Send for ReadContext<'a> {}
+#[allow(clippy::needless_lifetimes)]
 unsafe impl<'a> Sync for ReadContext<'a> {}
 
 impl<'a> ReadContext<'a> {
@@ -292,27 +277,6 @@ impl<'a> ReadContext<'a> {
         }
     }
 
-    /// Test method to create ReadContext from Fory instance
-    /// Will be removed in future releases, do not use it in production code
-    pub fn new_from_fory(fory: &Fory) -> ReadContext<'a> {
-        ReadContext {
-            type_resolver: fory
-                .get_type_resolver()
-                .build_final_type_resolver()
-                .unwrap(),
-            compatible: fory.is_compatible(),
-            share_meta: fory.is_share_meta(),
-            xlang: fory.is_xlang(),
-            max_dyn_depth: fory.get_max_dyn_depth(),
-            check_struct_version: fory.is_check_struct_version(),
-            reader: Reader::default(),
-            meta_resolver: MetaReaderResolver::default(),
-            meta_string_resolver: MetaStringReaderResolver::default(),
-            ref_reader: RefReader::new(),
-            current_depth: 0,
-        }
-    }
-
     /// Get type resolver
     #[inline(always)]
     pub fn get_type_resolver(&self) -> &TypeResolver {
diff --git a/rust/fory-core/src/row/row.rs b/rust/fory-core/src/row/row.rs
index eec67418c..6ef9ab222 100644
--- a/rust/fory-core/src/row/row.rs
+++ b/rust/fory-core/src/row/row.rs
@@ -143,6 +143,7 @@ pub struct ArrayGetter<'a, T> {
     _marker: PhantomData<T>,
 }
 
+#[allow(clippy::needless_lifetimes)]
 impl<'a, T: Row<'a>> ArrayGetter<'a, T> {
     pub fn size(&self) -> usize {
         self.array_data.num_elements()
@@ -157,6 +158,7 @@ impl<'a, T: Row<'a>> ArrayGetter<'a, T> {
     }
 }
 
+#[allow(clippy::needless_lifetimes)]
 impl<'a, T: Row<'a>> Row<'a> for Vec<T> {
     type ReadResult = ArrayGetter<'a, T>;
 
@@ -218,6 +220,7 @@ impl<'a, T1: Row<'a> + Ord, T2: Row<'a> + Ord> 
MapGetter<'a, T1, T2> {
     }
 }
 
+#[allow(clippy::needless_lifetimes)]
 impl<'a, T1: Row<'a> + Ord, T2: Row<'a> + Ord> Row<'a> for BTreeMap<T1, T2> {
     type ReadResult = MapGetter<'a, T1, T2>;
 
diff --git a/rust/fory-core/src/util.rs b/rust/fory-core/src/util.rs
index cca6c4772..589a2f77d 100644
--- a/rust/fory-core/src/util.rs
+++ b/rust/fory-core/src/util.rs
@@ -174,16 +174,17 @@ impl<T> Spinlock<T> {
     }
 }
 
+#[allow(clippy::needless_lifetimes)]
 pub struct SpinlockGuard<'a, T> {
     lock: &'a Spinlock<T>,
 }
-
+#[allow(clippy::needless_lifetimes)]
 impl<'a, T> Drop for SpinlockGuard<'a, T> {
     fn drop(&mut self) {
         self.lock.unlock();
     }
 }
-
+#[allow(clippy::needless_lifetimes)]
 impl<'a, T> Deref for SpinlockGuard<'a, T> {
     type Target = T;
     fn deref(&self) -> &Self::Target {
@@ -191,6 +192,7 @@ impl<'a, T> Deref for SpinlockGuard<'a, T> {
     }
 }
 
+#[allow(clippy::needless_lifetimes)]
 impl<'a, T> DerefMut for SpinlockGuard<'a, T> {
     fn deref_mut(&mut self) -> &mut Self::Target {
         unsafe { &mut *self.lock.data.get() }
diff --git a/rust/tests/tests/compatible/test_basic_type.rs 
b/rust/tests/tests/compatible/test_basic_type.rs
index 0582b3df4..02f8abbf2 100644
--- a/rust/tests/tests/compatible/test_basic_type.rs
+++ b/rust/tests/tests/compatible/test_basic_type.rs
@@ -16,7 +16,7 @@
 // under the License.
 
 use chrono::{NaiveDate, NaiveDateTime};
-use fory_core::fory::Fory;
+use fory_core::{fory::Fory, Reader};
 
 // primitive_val
 const BOOL_VAL: bool = true;
@@ -42,418 +42,371 @@ const INT64_ARRAY: [i64; 1] = [51];
 const FLOAT32_ARRAY: [f32; 1] = [52.0];
 const FLOAT64_ARRAY: [f64; 1] = [53.0];
 
-fn serialize_non_null(fory: &Fory) -> Vec<Vec<u8>> {
-    vec![
-        fory.serialize(&BOOL_VAL).unwrap(),
-        fory.serialize(&I8_VAL).unwrap(),
-        fory.serialize(&I16_VAL).unwrap(),
-        fory.serialize(&I32_VAL).unwrap(),
-        fory.serialize(&I64_VAL).unwrap(),
-        fory.serialize(&F32_VAL).unwrap(),
-        fory.serialize(&F64_VAL).unwrap(),
-        fory.serialize(&STR_LATIN1_VAL.to_string()).unwrap(),
-        fory.serialize(&LOCAL_DATE_VAL).unwrap(),
-        fory.serialize(&TIMESTAMP_VAL).unwrap(),
-        fory.serialize(&BOOL_ARRAY.to_vec()).unwrap(),
-        fory.serialize(&INT8_ARRAY.to_vec()).unwrap(),
-        fory.serialize(&INT16_ARRAY.to_vec()).unwrap(),
-        fory.serialize(&INT32_ARRAY.to_vec()).unwrap(),
-        fory.serialize(&INT64_ARRAY.to_vec()).unwrap(),
-        fory.serialize(&FLOAT32_ARRAY.to_vec()).unwrap(),
-        fory.serialize(&FLOAT64_ARRAY.to_vec()).unwrap(),
-    ]
+fn serialize_non_null(fory: &Fory) -> Vec<u8> {
+    let mut buf = Vec::new();
+    fory.serialize_to(&BOOL_VAL, &mut buf).unwrap();
+    fory.serialize_to(&I8_VAL, &mut buf).unwrap();
+    fory.serialize_to(&I16_VAL, &mut buf).unwrap();
+    fory.serialize_to(&I32_VAL, &mut buf).unwrap();
+    fory.serialize_to(&I64_VAL, &mut buf).unwrap();
+    fory.serialize_to(&F32_VAL, &mut buf).unwrap();
+    fory.serialize_to(&F64_VAL, &mut buf).unwrap();
+    fory.serialize_to(&STR_LATIN1_VAL.to_string(), &mut buf)
+        .unwrap();
+    fory.serialize_to(&LOCAL_DATE_VAL, &mut buf).unwrap();
+    fory.serialize_to(&TIMESTAMP_VAL, &mut buf).unwrap();
+    fory.serialize_to(&BOOL_ARRAY.to_vec(), &mut buf).unwrap();
+    fory.serialize_to(&INT8_ARRAY.to_vec(), &mut buf).unwrap();
+    fory.serialize_to(&INT16_ARRAY.to_vec(), &mut buf).unwrap();
+    fory.serialize_to(&INT32_ARRAY.to_vec(), &mut buf).unwrap();
+    fory.serialize_to(&INT64_ARRAY.to_vec(), &mut buf).unwrap();
+    fory.serialize_to(&FLOAT32_ARRAY.to_vec(), &mut buf)
+        .unwrap();
+    fory.serialize_to(&FLOAT64_ARRAY.to_vec(), &mut buf)
+        .unwrap();
+    buf
 }
 
-fn serialize_nullable(fory: &Fory) -> Vec<Vec<u8>> {
-    vec![
-        fory.serialize(&Some(BOOL_VAL)).unwrap(),
-        fory.serialize(&Some(I8_VAL)).unwrap(),
-        fory.serialize(&Some(I16_VAL)).unwrap(),
-        fory.serialize(&Some(I32_VAL)).unwrap(),
-        fory.serialize(&Some(I64_VAL)).unwrap(),
-        fory.serialize(&Some(F32_VAL)).unwrap(),
-        fory.serialize(&Some(F64_VAL)).unwrap(),
-        fory.serialize(&Some(STR_LATIN1_VAL.to_string())).unwrap(),
-        fory.serialize(&Some(LOCAL_DATE_VAL)).unwrap(),
-        fory.serialize(&Some(TIMESTAMP_VAL)).unwrap(),
-        fory.serialize(&Some(BOOL_ARRAY.to_vec())).unwrap(),
-        fory.serialize(&Some(INT8_ARRAY.to_vec())).unwrap(),
-        fory.serialize(&Some(INT16_ARRAY.to_vec())).unwrap(),
-        fory.serialize(&Some(INT32_ARRAY.to_vec())).unwrap(),
-        fory.serialize(&Some(INT64_ARRAY.to_vec())).unwrap(),
-        fory.serialize(&Some(FLOAT32_ARRAY.to_vec())).unwrap(),
-        fory.serialize(&Some(FLOAT64_ARRAY.to_vec())).unwrap(),
-        fory.serialize(&Option::<bool>::None).unwrap(),
-        fory.serialize(&Option::<i8>::None).unwrap(),
-        fory.serialize(&Option::<i16>::None).unwrap(),
-        fory.serialize(&Option::<i32>::None).unwrap(),
-        fory.serialize(&Option::<i64>::None).unwrap(),
-        fory.serialize(&Option::<f32>::None).unwrap(),
-        fory.serialize(&Option::<f64>::None).unwrap(),
-        fory.serialize(&Option::<String>::None).unwrap(),
-        fory.serialize(&Option::<NaiveDate>::None).unwrap(),
-        fory.serialize(&Option::<NaiveDateTime>::None).unwrap(),
-        fory.serialize(&Option::<Vec<bool>>::None).unwrap(),
-        fory.serialize(&Option::<Vec<i8>>::None).unwrap(),
-        fory.serialize(&Option::<Vec<i16>>::None).unwrap(),
-        fory.serialize(&Option::<Vec<i32>>::None).unwrap(),
-        fory.serialize(&Option::<Vec<i64>>::None).unwrap(),
-        fory.serialize(&Option::<Vec<f32>>::None).unwrap(),
-        fory.serialize(&Option::<Vec<f64>>::None).unwrap(),
-    ]
+fn serialize_nullable(fory: &Fory) -> Vec<u8> {
+    let mut buf = Vec::new();
+    fory.serialize_to(&Some(BOOL_VAL), &mut buf).unwrap();
+    fory.serialize_to(&Some(I8_VAL), &mut buf).unwrap();
+    fory.serialize_to(&Some(I16_VAL), &mut buf).unwrap();
+    fory.serialize_to(&Some(I32_VAL), &mut buf).unwrap();
+    fory.serialize_to(&Some(I64_VAL), &mut buf).unwrap();
+    fory.serialize_to(&Some(F32_VAL), &mut buf).unwrap();
+    fory.serialize_to(&Some(F64_VAL), &mut buf).unwrap();
+    fory.serialize_to(&Some(STR_LATIN1_VAL.to_string()), &mut buf)
+        .unwrap();
+    fory.serialize_to(&Some(LOCAL_DATE_VAL), &mut buf).unwrap();
+    fory.serialize_to(&Some(TIMESTAMP_VAL), &mut buf).unwrap();
+    fory.serialize_to(&Some(BOOL_ARRAY.to_vec()), &mut buf)
+        .unwrap();
+    fory.serialize_to(&Some(INT8_ARRAY.to_vec()), &mut buf)
+        .unwrap();
+    fory.serialize_to(&Some(INT16_ARRAY.to_vec()), &mut buf)
+        .unwrap();
+    fory.serialize_to(&Some(INT32_ARRAY.to_vec()), &mut buf)
+        .unwrap();
+    fory.serialize_to(&Some(INT64_ARRAY.to_vec()), &mut buf)
+        .unwrap();
+    fory.serialize_to(&Some(FLOAT32_ARRAY.to_vec()), &mut buf)
+        .unwrap();
+    fory.serialize_to(&Some(FLOAT64_ARRAY.to_vec()), &mut buf)
+        .unwrap();
+    fory.serialize_to(&Option::<bool>::None, &mut buf).unwrap();
+    fory.serialize_to(&Option::<i8>::None, &mut buf).unwrap();
+    fory.serialize_to(&Option::<i16>::None, &mut buf).unwrap();
+    fory.serialize_to(&Option::<i32>::None, &mut buf).unwrap();
+    fory.serialize_to(&Option::<i64>::None, &mut buf).unwrap();
+    fory.serialize_to(&Option::<f32>::None, &mut buf).unwrap();
+    fory.serialize_to(&Option::<f64>::None, &mut buf).unwrap();
+    fory.serialize_to(&Option::<String>::None, &mut buf)
+        .unwrap();
+    fory.serialize_to(&Option::<NaiveDate>::None, &mut buf)
+        .unwrap();
+    fory.serialize_to(&Option::<NaiveDateTime>::None, &mut buf)
+        .unwrap();
+    fory.serialize_to(&Option::<Vec<bool>>::None, &mut buf)
+        .unwrap();
+    fory.serialize_to(&Option::<Vec<i8>>::None, &mut buf)
+        .unwrap();
+    fory.serialize_to(&Option::<Vec<i16>>::None, &mut buf)
+        .unwrap();
+    fory.serialize_to(&Option::<Vec<i32>>::None, &mut buf)
+        .unwrap();
+    fory.serialize_to(&Option::<Vec<i64>>::None, &mut buf)
+        .unwrap();
+    fory.serialize_to(&Option::<Vec<f32>>::None, &mut buf)
+        .unwrap();
+    fory.serialize_to(&Option::<Vec<f64>>::None, &mut buf)
+        .unwrap();
+    buf
 }
 
-fn deserialize_non_null(fory: &Fory, mut bins: Vec<Vec<u8>>, auto_conv: bool) {
-    bins.reverse();
+fn deserialize_non_null(fory: &Fory, bins: Vec<u8>, auto_conv: bool) {
+    let mut reader = Reader::new(bins.as_slice());
     assert_eq!(
         BOOL_VAL,
-        fory.deserialize::<bool>(bins.pop().unwrap().as_slice())
-            .unwrap()
-    );
-    assert_eq!(
-        I8_VAL,
-        fory.deserialize::<i8>(bins.pop().unwrap().as_slice())
-            .unwrap()
-    );
-    assert_eq!(
-        I16_VAL,
-        fory.deserialize::<i16>(bins.pop().unwrap().as_slice())
-            .unwrap()
-    );
-    assert_eq!(
-        I32_VAL,
-        fory.deserialize::<i32>(bins.pop().unwrap().as_slice())
-            .unwrap()
-    );
-    assert_eq!(
-        I64_VAL,
-        fory.deserialize::<i64>(bins.pop().unwrap().as_slice())
-            .unwrap()
-    );
-    assert_eq!(
-        F32_VAL,
-        fory.deserialize::<f32>(bins.pop().unwrap().as_slice())
-            .unwrap()
-    );
-    assert_eq!(
-        F64_VAL,
-        fory.deserialize::<f64>(bins.pop().unwrap().as_slice())
-            .unwrap()
+        fory.deserialize_from::<bool>(&mut reader).unwrap()
     );
+    assert_eq!(I8_VAL, fory.deserialize_from::<i8>(&mut reader).unwrap());
+    assert_eq!(I16_VAL, fory.deserialize_from::<i16>(&mut reader).unwrap());
+    assert_eq!(I32_VAL, fory.deserialize_from::<i32>(&mut reader).unwrap());
+    assert_eq!(I64_VAL, fory.deserialize_from::<i64>(&mut reader).unwrap());
+    assert_eq!(F32_VAL, fory.deserialize_from::<f32>(&mut reader).unwrap());
+    assert_eq!(F64_VAL, fory.deserialize_from::<f64>(&mut reader).unwrap());
     assert_eq!(
         STR_LATIN1_VAL.to_string(),
-        fory.deserialize::<String>(bins.pop().unwrap().as_slice())
-            .unwrap()
+        fory.deserialize_from::<String>(&mut reader).unwrap()
     );
     assert_eq!(
         LOCAL_DATE_VAL,
-        fory.deserialize::<NaiveDate>(bins.pop().unwrap().as_slice())
-            .unwrap()
+        fory.deserialize_from::<NaiveDate>(&mut reader).unwrap()
     );
     assert_eq!(
         TIMESTAMP_VAL,
-        fory.deserialize::<NaiveDateTime>(bins.pop().unwrap().as_slice())
-            .unwrap()
+        fory.deserialize_from::<NaiveDateTime>(&mut reader).unwrap()
     );
 
     assert_eq!(
         BOOL_ARRAY.to_vec(),
-        fory.deserialize::<Vec<bool>>(bins.pop().unwrap().as_slice())
-            .unwrap()
+        fory.deserialize_from::<Vec<bool>>(&mut reader).unwrap()
     );
     assert_eq!(
         INT8_ARRAY.to_vec(),
-        fory.deserialize::<Vec<i8>>(bins.pop().unwrap().as_slice())
-            .unwrap()
+        fory.deserialize_from::<Vec<i8>>(&mut reader).unwrap()
     );
     assert_eq!(
         INT16_ARRAY.to_vec(),
-        fory.deserialize::<Vec<i16>>(bins.pop().unwrap().as_slice())
-            .unwrap()
+        fory.deserialize_from::<Vec<i16>>(&mut reader).unwrap()
     );
     assert_eq!(
         INT32_ARRAY.to_vec(),
-        fory.deserialize::<Vec<i32>>(bins.pop().unwrap().as_slice())
-            .unwrap()
+        fory.deserialize_from::<Vec<i32>>(&mut reader).unwrap()
     );
     assert_eq!(
         INT64_ARRAY.to_vec(),
-        fory.deserialize::<Vec<i64>>(bins.pop().unwrap().as_slice())
-            .unwrap()
+        fory.deserialize_from::<Vec<i64>>(&mut reader).unwrap()
     );
     assert_eq!(
         FLOAT32_ARRAY.to_vec(),
-        fory.deserialize::<Vec<f32>>(bins.pop().unwrap().as_slice())
-            .unwrap()
+        fory.deserialize_from::<Vec<f32>>(&mut reader).unwrap()
     );
     assert_eq!(
         FLOAT64_ARRAY.to_vec(),
-        fory.deserialize::<Vec<f64>>(bins.pop().unwrap().as_slice())
-            .unwrap()
+        fory.deserialize_from::<Vec<f64>>(&mut reader).unwrap()
     );
     if auto_conv {
         assert_eq!(
             bool::default(),
-            fory.deserialize::<bool>(bins.pop().unwrap().as_slice())
-                .unwrap()
+            fory.deserialize_from::<bool>(&mut reader).unwrap()
         );
         assert_eq!(
             i8::default(),
-            fory.deserialize::<i8>(bins.pop().unwrap().as_slice())
-                .unwrap()
+            fory.deserialize_from::<i8>(&mut reader).unwrap()
         );
         assert_eq!(
             i16::default(),
-            fory.deserialize::<i16>(bins.pop().unwrap().as_slice())
-                .unwrap()
+            fory.deserialize_from::<i16>(&mut reader).unwrap()
         );
         assert_eq!(
             i32::default(),
-            fory.deserialize::<i32>(bins.pop().unwrap().as_slice())
-                .unwrap()
+            fory.deserialize_from::<i32>(&mut reader).unwrap()
         );
         assert_eq!(
             i64::default(),
-            fory.deserialize::<i64>(bins.pop().unwrap().as_slice())
-                .unwrap()
+            fory.deserialize_from::<i64>(&mut reader).unwrap()
         );
         assert_eq!(
             f32::default(),
-            fory.deserialize::<f32>(bins.pop().unwrap().as_slice())
-                .unwrap()
+            fory.deserialize_from::<f32>(&mut reader).unwrap()
         );
         assert_eq!(
             f64::default(),
-            fory.deserialize::<f64>(bins.pop().unwrap().as_slice())
-                .unwrap()
+            fory.deserialize_from::<f64>(&mut reader).unwrap()
         );
         assert_eq!(
             String::default(),
-            fory.deserialize::<String>(bins.pop().unwrap().as_slice())
-                .unwrap()
+            fory.deserialize_from::<String>(&mut reader).unwrap()
         );
         assert_eq!(
             NaiveDate::default(),
-            fory.deserialize::<NaiveDate>(bins.pop().unwrap().as_slice())
-                .unwrap()
+            fory.deserialize_from::<NaiveDate>(&mut reader).unwrap()
         );
         assert_eq!(
             NaiveDateTime::default(),
-            fory.deserialize::<NaiveDateTime>(bins.pop().unwrap().as_slice())
-                .unwrap()
+            fory.deserialize_from::<NaiveDateTime>(&mut reader).unwrap()
         );
 
         assert_eq!(
             Vec::<bool>::default(),
-            fory.deserialize::<Vec<bool>>(bins.pop().unwrap().as_slice())
-                .unwrap()
+            fory.deserialize_from::<Vec<bool>>(&mut reader).unwrap()
         );
         assert_eq!(
             Vec::<i8>::default(),
-            fory.deserialize::<Vec<i8>>(bins.pop().unwrap().as_slice())
-                .unwrap()
+            fory.deserialize_from::<Vec<i8>>(&mut reader).unwrap()
         );
         assert_eq!(
             Vec::<i16>::default(),
-            fory.deserialize::<Vec<i16>>(bins.pop().unwrap().as_slice())
-                .unwrap()
+            fory.deserialize_from::<Vec<i16>>(&mut reader).unwrap()
         );
         assert_eq!(
             Vec::<i32>::default(),
-            fory.deserialize::<Vec<i32>>(bins.pop().unwrap().as_slice())
-                .unwrap()
+            fory.deserialize_from::<Vec<i32>>(&mut reader).unwrap()
         );
         assert_eq!(
             Vec::<i64>::default(),
-            fory.deserialize::<Vec<i64>>(bins.pop().unwrap().as_slice())
-                .unwrap()
+            fory.deserialize_from::<Vec<i64>>(&mut reader).unwrap()
         );
         assert_eq!(
             Vec::<f32>::default(),
-            fory.deserialize::<Vec<f32>>(bins.pop().unwrap().as_slice())
-                .unwrap()
+            fory.deserialize_from::<Vec<f32>>(&mut reader).unwrap()
         );
         assert_eq!(
             Vec::<f64>::default(),
-            fory.deserialize::<Vec<f64>>(bins.pop().unwrap().as_slice())
-                .unwrap()
+            fory.deserialize_from::<Vec<f64>>(&mut reader).unwrap()
         );
     }
 }
 
-fn deserialize_nullable(fory: &Fory, mut bins: Vec<Vec<u8>>, auto_conv: bool) {
-    bins.reverse();
+fn deserialize_nullable(fory: &Fory, bins: Vec<u8>, auto_conv: bool) {
+    let mut reader = Reader::new(bins.as_slice());
     assert_eq!(
         Some(BOOL_VAL),
-        fory.deserialize::<Option<bool>>(bins.pop().unwrap().as_slice())
-            .unwrap()
+        fory.deserialize_from::<Option<bool>>(&mut reader).unwrap()
     );
     assert_eq!(
         Some(I8_VAL),
-        fory.deserialize::<Option<i8>>(bins.pop().unwrap().as_slice())
-            .unwrap()
+        fory.deserialize_from::<Option<i8>>(&mut reader).unwrap()
     );
     assert_eq!(
         Some(I16_VAL),
-        fory.deserialize::<Option<i16>>(bins.pop().unwrap().as_slice())
-            .unwrap()
+        fory.deserialize_from::<Option<i16>>(&mut reader).unwrap()
     );
     assert_eq!(
         Some(I32_VAL),
-        fory.deserialize::<Option<i32>>(bins.pop().unwrap().as_slice())
-            .unwrap()
+        fory.deserialize_from::<Option<i32>>(&mut reader).unwrap()
     );
     assert_eq!(
         Some(I64_VAL),
-        fory.deserialize::<Option<i64>>(bins.pop().unwrap().as_slice())
-            .unwrap()
+        fory.deserialize_from::<Option<i64>>(&mut reader).unwrap()
     );
     assert_eq!(
         Some(F32_VAL),
-        fory.deserialize::<Option<f32>>(bins.pop().unwrap().as_slice())
-            .unwrap()
+        fory.deserialize_from::<Option<f32>>(&mut reader).unwrap()
     );
     assert_eq!(
         Some(F64_VAL),
-        fory.deserialize::<Option<f64>>(bins.pop().unwrap().as_slice())
-            .unwrap()
+        fory.deserialize_from::<Option<f64>>(&mut reader).unwrap()
     );
     assert_eq!(
         Some(STR_LATIN1_VAL.to_string()),
-        fory.deserialize::<Option<String>>(bins.pop().unwrap().as_slice())
+        fory.deserialize_from::<Option<String>>(&mut reader)
             .unwrap()
     );
     assert_eq!(
         Some(LOCAL_DATE_VAL),
-        fory.deserialize::<Option<NaiveDate>>(bins.pop().unwrap().as_slice())
+        fory.deserialize_from::<Option<NaiveDate>>(&mut reader)
             .unwrap()
     );
     assert_eq!(
         Some(TIMESTAMP_VAL),
-        
fory.deserialize::<Option<NaiveDateTime>>(bins.pop().unwrap().as_slice())
+        fory.deserialize_from::<Option<NaiveDateTime>>(&mut reader)
             .unwrap()
     );
-
     assert_eq!(
         Some(BOOL_ARRAY.to_vec()),
-        fory.deserialize::<Option<Vec<bool>>>(bins.pop().unwrap().as_slice())
+        fory.deserialize_from::<Option<Vec<bool>>>(&mut reader)
             .unwrap()
     );
     assert_eq!(
         Some(INT8_ARRAY.to_vec()),
-        fory.deserialize::<Option<Vec<i8>>>(bins.pop().unwrap().as_slice())
+        fory.deserialize_from::<Option<Vec<i8>>>(&mut reader)
             .unwrap()
     );
     assert_eq!(
         Some(INT16_ARRAY.to_vec()),
-        fory.deserialize::<Option<Vec<i16>>>(bins.pop().unwrap().as_slice())
+        fory.deserialize_from::<Option<Vec<i16>>>(&mut reader)
             .unwrap()
     );
     assert_eq!(
         Some(INT32_ARRAY.to_vec()),
-        fory.deserialize::<Option<Vec<i32>>>(bins.pop().unwrap().as_slice())
+        fory.deserialize_from::<Option<Vec<i32>>>(&mut reader)
             .unwrap()
     );
     assert_eq!(
         Some(INT64_ARRAY.to_vec()),
-        fory.deserialize::<Option<Vec<i64>>>(bins.pop().unwrap().as_slice())
+        fory.deserialize_from::<Option<Vec<i64>>>(&mut reader)
             .unwrap()
     );
     assert_eq!(
         Some(FLOAT32_ARRAY.to_vec()),
-        fory.deserialize::<Option<Vec<f32>>>(bins.pop().unwrap().as_slice())
+        fory.deserialize_from::<Option<Vec<f32>>>(&mut reader)
             .unwrap()
     );
     assert_eq!(
         Some(FLOAT64_ARRAY.to_vec()),
-        fory.deserialize::<Option<Vec<f64>>>(bins.pop().unwrap().as_slice())
+        fory.deserialize_from::<Option<Vec<f64>>>(&mut reader)
             .unwrap()
     );
     if !auto_conv {
         assert_eq!(
             None,
-            fory.deserialize::<Option<bool>>(bins.pop().unwrap().as_slice())
-                .unwrap()
+            fory.deserialize_from::<Option<bool>>(&mut reader).unwrap()
         );
         assert_eq!(
             None,
-            fory.deserialize::<Option<i8>>(bins.pop().unwrap().as_slice())
-                .unwrap()
+            fory.deserialize_from::<Option<i8>>(&mut reader).unwrap()
         );
         assert_eq!(
             None,
-            fory.deserialize::<Option<i16>>(bins.pop().unwrap().as_slice())
-                .unwrap()
+            fory.deserialize_from::<Option<i16>>(&mut reader).unwrap()
         );
         assert_eq!(
             None,
-            fory.deserialize::<Option<i32>>(bins.pop().unwrap().as_slice())
-                .unwrap()
+            fory.deserialize_from::<Option<i32>>(&mut reader).unwrap()
         );
         assert_eq!(
             None,
-            fory.deserialize::<Option<i64>>(bins.pop().unwrap().as_slice())
-                .unwrap()
+            fory.deserialize_from::<Option<i64>>(&mut reader).unwrap()
         );
         assert_eq!(
             None,
-            fory.deserialize::<Option<f32>>(bins.pop().unwrap().as_slice())
-                .unwrap()
+            fory.deserialize_from::<Option<f32>>(&mut reader).unwrap()
         );
         assert_eq!(
             None,
-            fory.deserialize::<Option<f64>>(bins.pop().unwrap().as_slice())
-                .unwrap()
+            fory.deserialize_from::<Option<f64>>(&mut reader).unwrap()
         );
         assert_eq!(
             None,
-            fory.deserialize::<Option<String>>(bins.pop().unwrap().as_slice())
+            fory.deserialize_from::<Option<String>>(&mut reader)
                 .unwrap()
         );
         assert_eq!(
             None,
-            
fory.deserialize::<Option<NaiveDate>>(bins.pop().unwrap().as_slice())
+            fory.deserialize_from::<Option<NaiveDate>>(&mut reader)
                 .unwrap()
         );
         assert_eq!(
             None,
-            
fory.deserialize::<Option<NaiveDateTime>>(bins.pop().unwrap().as_slice())
+            fory.deserialize_from::<Option<NaiveDateTime>>(&mut reader)
                 .unwrap()
         );
-
         assert_eq!(
             None,
-            
fory.deserialize::<Option<Vec<bool>>>(bins.pop().unwrap().as_slice())
+            fory.deserialize_from::<Option<Vec<bool>>>(&mut reader)
                 .unwrap()
         );
         assert_eq!(
             None,
-            fory.deserialize::<Option<Vec<i8>>>(bins.pop().unwrap().as_slice())
+            fory.deserialize_from::<Option<Vec<i8>>>(&mut reader)
                 .unwrap()
         );
         assert_eq!(
             None,
-            
fory.deserialize::<Option<Vec<i16>>>(bins.pop().unwrap().as_slice())
+            fory.deserialize_from::<Option<Vec<i16>>>(&mut reader)
                 .unwrap()
         );
         assert_eq!(
             None,
-            
fory.deserialize::<Option<Vec<i32>>>(bins.pop().unwrap().as_slice())
+            fory.deserialize_from::<Option<Vec<i32>>>(&mut reader)
                 .unwrap()
         );
         assert_eq!(
             None,
-            
fory.deserialize::<Option<Vec<i64>>>(bins.pop().unwrap().as_slice())
+            fory.deserialize_from::<Option<Vec<i64>>>(&mut reader)
                 .unwrap()
         );
         assert_eq!(
             None,
-            
fory.deserialize::<Option<Vec<f32>>>(bins.pop().unwrap().as_slice())
+            fory.deserialize_from::<Option<Vec<f32>>>(&mut reader)
                 .unwrap()
         );
         assert_eq!(
             None,
-            
fory.deserialize::<Option<Vec<f64>>>(bins.pop().unwrap().as_slice())
+            fory.deserialize_from::<Option<Vec<f64>>>(&mut reader)
                 .unwrap()
         );
     }
diff --git a/rust/tests/tests/test_cross_language.rs 
b/rust/tests/tests/test_cross_language.rs
index f19961ab5..d3957f844 100644
--- a/rust/tests/tests/test_cross_language.rs
+++ b/rust/tests/tests/test_cross_language.rs
@@ -226,20 +226,16 @@ fn test_murmurhash3() {
 fn test_string_serializer() {
     let data_file_path = get_data_file();
     let bytes = fs::read(&data_file_path).unwrap();
-    let reader = Reader::new(bytes.as_slice());
+    let mut reader = Reader::new(bytes.as_slice());
     let fory = Fory::default()
         .compatible(true)
         .xlang(true)
         .compress_string(false);
-    let mut context = ReadContext::new_from_fory(&fory);
-    context.attach_reader(reader);
-    let reader_compress = Reader::new(bytes.as_slice());
+    let mut reader_compress = Reader::new(bytes.as_slice());
     let fory_compress = Fory::default()
         .compatible(true)
         .xlang(true)
         .compress_string(true);
-    let mut context_compress = ReadContext::new_from_fory(&fory_compress);
-    context_compress.attach_reader(reader_compress);
     let test_strings: Vec<String> = vec![
         // Latin1
         "ab".to_string(),
@@ -253,21 +249,25 @@ fn test_string_serializer() {
         "Hello, 世界".to_string(),
     ];
     for s in &test_strings {
-        // make is_field=true to skip read/write type_id
-        assert_eq!(*s, String::fory_read_data(&mut context).unwrap());
-        assert_eq!(*s, String::fory_read_data(&mut context_compress).unwrap());
+        assert_eq!(*s, fory.deserialize_from::<String>(&mut reader).unwrap());
+        assert_eq!(
+            *s,
+            fory_compress
+                .deserialize_from::<String>(&mut reader_compress)
+                .unwrap()
+        );
     }
     let fory = Fory::default().compatible(true).xlang(true);
-    let mut context = WriteContext::new_from_fory(&fory);
+    let mut buf = Vec::new();
     for s in &test_strings {
-        s.fory_write_data(&mut context).unwrap();
+        fory.serialize_to(s, &mut buf).unwrap();
     }
-    fs::write(&data_file_path, context.writer.dump()).unwrap();
+    fs::write(&data_file_path, buf).unwrap();
 }
 
 macro_rules! assert_de {
     ($fory:expr, $reader:expr, $ty:ty, $expected:expr) => {{
-        let v: $ty = ($fory.deserialize_from(&mut $reader).unwrap());
+        let v: $ty = $fory.deserialize_from(&mut $reader).unwrap();
         assert_eq!(v, $expected);
     }};
 }
@@ -318,34 +318,34 @@ fn test_cross_language_serializer() {
     assert_de!(fory, reader, HashMap::<String, String>, str_map);
     assert_de!(fory, reader, Color, color);
 
-    let context = WriteContext::new_from_fory(&fory);
-    fory.serialize(&true).unwrap();
-    fory.serialize(&false).unwrap();
-    fory.serialize(&-1).unwrap();
-    fory.serialize(&i8::MAX).unwrap();
-    fory.serialize(&i8::MIN).unwrap();
-    fory.serialize(&i16::MAX).unwrap();
-    fory.serialize(&i16::MIN).unwrap();
-    fory.serialize(&i32::MAX).unwrap();
-    fory.serialize(&i32::MIN).unwrap();
-    fory.serialize(&i64::MAX).unwrap();
-    fory.serialize(&i64::MIN).unwrap();
-    fory.serialize(&-1f32).unwrap();
-    fory.serialize(&-1f64).unwrap();
-    fory.serialize(&"str".to_string()).unwrap();
-    fory.serialize(&day).unwrap();
-    fory.serialize(&instant).unwrap();
-    fory.serialize(&vec![true, false]).unwrap();
-    fory.serialize(&vec![1, i16::MAX]).unwrap();
-    fory.serialize(&vec![1, i32::MAX]).unwrap();
-    fory.serialize(&vec![1, i64::MAX]).unwrap();
-    fory.serialize(&vec![1f32, 2f32]).unwrap();
-    fory.serialize(&vec![1f64, 2f64]).unwrap();
-    fory.serialize(&str_list).unwrap();
-    fory.serialize(&str_set).unwrap();
-    fory.serialize(&str_map).unwrap();
-    fory.serialize(&color).unwrap();
-    fs::write(&data_file_path, context.writer.dump()).unwrap();
+    let mut buf = Vec::new();
+    fory.serialize_to(&true, &mut buf).unwrap();
+    fory.serialize_to(&false, &mut buf).unwrap();
+    fory.serialize_to(&-1, &mut buf).unwrap();
+    fory.serialize_to(&i8::MAX, &mut buf).unwrap();
+    fory.serialize_to(&i8::MIN, &mut buf).unwrap();
+    fory.serialize_to(&i16::MAX, &mut buf).unwrap();
+    fory.serialize_to(&i16::MIN, &mut buf).unwrap();
+    fory.serialize_to(&i32::MAX, &mut buf).unwrap();
+    fory.serialize_to(&i32::MIN, &mut buf).unwrap();
+    fory.serialize_to(&i64::MAX, &mut buf).unwrap();
+    fory.serialize_to(&i64::MIN, &mut buf).unwrap();
+    fory.serialize_to(&-1f32, &mut buf).unwrap();
+    fory.serialize_to(&-1f64, &mut buf).unwrap();
+    fory.serialize_to(&"str".to_string(), &mut buf).unwrap();
+    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, 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();
+    fory.serialize_to(&vec![1f32, 2f32], &mut buf).unwrap();
+    fory.serialize_to(&vec![1f64, 2f64], &mut buf).unwrap();
+    fory.serialize_to(&str_list, &mut buf).unwrap();
+    fory.serialize_to(&str_set, &mut buf).unwrap();
+    fory.serialize_to(&str_map, &mut buf).unwrap();
+    fory.serialize_to(&color, &mut buf).unwrap();
+    fs::write(&data_file_path, buf).unwrap();
 }
 
 #[test]
@@ -418,9 +418,10 @@ fn test_list() {
     let data_file_path = get_data_file();
     let bytes = fs::read(&data_file_path).unwrap();
 
-    let mut fory = Fory::default().compatible(true);
+    let mut fory = Fory::default().compatible(true).xlang(true);
     fory.register::<Item>(102).unwrap();
     let mut reader = Reader::new(bytes.as_slice());
+
     let str_list = vec![Some("a".to_string()), Some("b".to_string())];
     let str_list2 = vec![None, Some("b".to_string())];
     let item = Item {
@@ -444,13 +445,13 @@ fn test_list() {
     let remote_item_list2: Vec<Option<Item>> = fory.deserialize_from(&mut 
reader).unwrap();
     assert_eq!(remote_item_list2, item_list2);
 
-    let context = WriteContext::new_from_fory(&fory);
-    fory.serialize(&remote_str_list).unwrap();
-    fory.serialize(&remote_str_list2).unwrap();
-    fory.serialize(&remote_item_list).unwrap();
-    fory.serialize(&remote_item_list2).unwrap();
+    let mut buf = Vec::new();
+    fory.serialize_to(&remote_str_list, &mut buf).unwrap();
+    fory.serialize_to(&remote_str_list2, &mut buf).unwrap();
+    fory.serialize_to(&remote_item_list, &mut buf).unwrap();
+    fory.serialize_to(&remote_item_list2, &mut buf).unwrap();
 
-    fs::write(&data_file_path, context.writer.dump()).unwrap();
+    fs::write(&data_file_path, buf).unwrap();
 }
 
 #[test]
@@ -459,7 +460,7 @@ fn test_map() {
     let data_file_path = get_data_file();
     let bytes = fs::read(&data_file_path).unwrap();
 
-    let mut fory = Fory::default().compatible(true);
+    let mut fory = Fory::default().compatible(true).xlang(true);
     fory.register::<Item>(102).unwrap();
     let mut reader = Reader::new(bytes.as_slice());
 
@@ -527,7 +528,7 @@ fn test_integer() {
     let data_file_path = get_data_file();
     let bytes = fs::read(&data_file_path).unwrap();
 
-    let mut fory = Fory::default().compatible(true);
+    let mut fory = Fory::default().compatible(true).xlang(true);
     fory.register::<Item2>(101).unwrap();
     let mut reader = Reader::new(bytes.as_slice());
     let f1 = 1;
@@ -560,15 +561,15 @@ fn test_integer() {
     let remote_f6: Option<i32> = fory.deserialize_from(&mut reader).unwrap();
     assert_eq!(remote_f6, f6);
 
-    let context = WriteContext::new_from_fory(&fory);
-    fory.serialize(&remote_item2).unwrap();
-    fory.serialize(&remote_f1).unwrap();
-    fory.serialize(&remote_f2).unwrap();
-    fory.serialize(&remote_f3).unwrap();
-    fory.serialize(&remote_f4).unwrap();
-    fory.serialize(&remote_f5).unwrap();
-    fory.serialize(&remote_f6).unwrap();
-    fs::write(&data_file_path, context.writer.dump()).unwrap();
+    let mut buf = Vec::new();
+    fory.serialize_to(&remote_item2, &mut buf).unwrap();
+    fory.serialize_to(&remote_f1, &mut buf).unwrap();
+    fory.serialize_to(&remote_f2, &mut buf).unwrap();
+    fory.serialize_to(&remote_f3, &mut buf).unwrap();
+    fory.serialize_to(&remote_f4, &mut buf).unwrap();
+    fory.serialize_to(&remote_f5, &mut buf).unwrap();
+    fory.serialize_to(&remote_f6, &mut buf).unwrap();
+    fs::write(&data_file_path, buf).unwrap();
 }
 
 #[derive(ForyObject, Debug, PartialEq)]
@@ -581,13 +582,11 @@ struct MyExt {
 }
 impl Serializer for MyExt {
     fn fory_write_data(&self, context: &mut WriteContext) -> Result<(), 
fory_core::error::Error> {
-        // set is_field=false to write type_id like in java
         write_data(&self.id, context)
     }
 
     fn fory_read_data(context: &mut ReadContext) -> Result<Self, Error> {
         Ok(Self {
-            // set is_field=false to write type_id like in java
             id: read_data(context)?,
         })
     }
@@ -634,10 +633,10 @@ fn _test_skip_custom(fory1: &Fory, fory2: &Fory) {
 #[test]
 #[ignore]
 fn test_skip_id_custom() {
-    let mut fory1 = Fory::default().compatible(true);
+    let mut fory1 = Fory::default().compatible(true).xlang(true);
     fory1.register_serializer::<MyExt>(103).unwrap();
     fory1.register::<Empty>(104).unwrap();
-    let mut fory2 = Fory::default().compatible(true);
+    let mut fory2 = Fory::default().compatible(true).xlang(true);
     fory2.register::<Color>(101).unwrap();
     fory2.register::<MyStruct>(102).unwrap();
     fory2.register_serializer::<MyExt>(103).unwrap();
@@ -648,12 +647,12 @@ fn test_skip_id_custom() {
 #[test]
 #[ignore]
 fn test_skip_name_custom() {
-    let mut fory1 = Fory::default().compatible(true);
+    let mut fory1 = Fory::default().compatible(true).xlang(true);
     fory1
         .register_serializer_by_name::<MyExt>("my_ext")
         .unwrap();
     fory1.register_by_name::<Empty>("my_wrapper").unwrap();
-    let mut fory2 = Fory::default().compatible(true);
+    let mut fory2 = Fory::default().compatible(true).xlang(true);
     fory2.register_by_name::<Color>("color").unwrap();
     fory2.register_by_name::<MyStruct>("my_struct").unwrap();
     fory2
@@ -666,13 +665,13 @@ fn test_skip_name_custom() {
 #[test]
 #[ignore]
 fn test_consistent_named() {
-    let mut fory = Fory::default().compatible(false);
+    let mut fory = Fory::default().compatible(false).xlang(true);
     fory.register_by_name::<Color>("color").unwrap();
     fory.register_by_name::<MyStruct>("my_struct").unwrap();
     fory.register_serializer_by_name::<MyExt>("my_ext").unwrap();
 
     let color = Color::White;
-    let _my_struct = MyStruct { id: 42 };
+    let my_struct = MyStruct { id: 42 };
     let my_ext = MyExt { id: 43 };
 
     let data_file_path = get_data_file();
@@ -682,21 +681,26 @@ fn test_consistent_named() {
     for _ in 0..3 {
         assert_eq!(fory.deserialize_from::<Color>(&mut reader).unwrap(), 
color);
     }
+    for _ in 0..3 {
+        assert_eq!(
+            fory.deserialize_from::<MyStruct>(&mut reader).unwrap(),
+            my_struct
+        );
+    }
     for _ in 0..3 {
         assert_eq!(fory.deserialize_from::<MyExt>(&mut reader).unwrap(), 
my_ext);
     }
-    // assert_eq!(fory.deserialize::<MyStruct>(&mut context).unwrap(), 
my_struct);
-
-    let context = WriteContext::new_from_fory(&fory);
+    let mut buf = Vec::new();
+    for _ in 0..3 {
+        fory.serialize_to(&color, &mut buf).unwrap();
+    }
     for _ in 0..3 {
-        fory.serialize(&color).unwrap();
+        fory.serialize_to(&my_struct, &mut buf).unwrap();
     }
     for _ in 0..3 {
-        fory.serialize(&my_ext).unwrap();
+        fory.serialize_to(&my_ext, &mut buf).unwrap();
     }
-    // // todo: checkVersion
-    // // fory.serialize(&my_struct, &mut context);
-    fs::write(&data_file_path, context.writer.dump()).unwrap();
+    fs::write(&data_file_path, buf).unwrap();
 }
 
 #[derive(ForyObject, Debug, PartialEq)]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]


Reply via email to