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,
)
| 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. |