MCPcopy Create free account
hub / github.com/apache/fory / deserialize_from

Method deserialize_from

rust/fory-core/src/fory.rs:1045–1059  ·  view source on GitHub ↗

Deserializes data from a `Reader` into a value of type `T`. This method is the paired read operation for [`serialize_to`](Self::serialize_to). It reads serialized data from the current position of the reader and automatically advances the cursor to the end of the read data, making it suitable for reading multiple objects sequentially from the same buffer. # Type Parameters `T` - The target type

(
        &self,
        reader: &mut Reader,
    )

Source from the content-addressed store, hash-verified

1043 /// let deserialized: Point = fory.deserialize_from(&mut reader).unwrap();
1044 /// ```
1045 pub fn deserialize_from<T: Serializer + ForyDefault>(
1046 &self,
1047 reader: &mut Reader,
1048 ) -> Result<T, Error> {
1049 self.with_read_context(|context| {
1050 let outlive_buffer = unsafe { mem::transmute::<&[u8], &[u8]>(reader.bf) };
1051 let mut new_reader = Reader::new(outlive_buffer);
1052 new_reader.set_cursor(reader.cursor);
1053 context.attach_reader(new_reader);
1054 let result = self.deserialize_with_context(context);
1055 let end = context.detach_reader().get_cursor();
1056 reader.set_cursor(end);
1057 result
1058 })
1059 }
1060
1061 /// Executes a closure with mutable access to a ReadContext for this Fory instance.
1062 /// The context is stored in thread-local storage, eliminating all lock contention.

Callers 15

test_listFunction · 0.80
test_mapFunction · 0.80
test_integerFunction · 0.80
test_decimalFunction · 0.80
test_itemFunction · 0.80
test_colorFunction · 0.80
test_struct_with_listFunction · 0.80
test_struct_with_mapFunction · 0.80
test_polymorphic_listFunction · 0.80
test_polymorphic_mapFunction · 0.80
test_union_xlangFunction · 0.80

Calls 6

with_read_contextMethod · 0.80
set_cursorMethod · 0.80
attach_readerMethod · 0.80
get_cursorMethod · 0.80
detach_readerMethod · 0.80

Tested by 15

test_listFunction · 0.64
test_mapFunction · 0.64
test_integerFunction · 0.64
test_decimalFunction · 0.64
test_itemFunction · 0.64
test_colorFunction · 0.64
test_struct_with_listFunction · 0.64
test_struct_with_mapFunction · 0.64
test_polymorphic_listFunction · 0.64
test_polymorphic_mapFunction · 0.64
test_union_xlangFunction · 0.64