Deserializes data from a byte slice into a value of type `T`. # Type Parameters `T` - The target type to deserialize into. Must implement `Serializer` and `ForyDefault`. # Arguments `bf` - The byte slice containing the serialized data. # Returns `Ok(T)` - The deserialized value on success. `Err(Error)` - An error if deserialization fails (e.g., invalid format, type mismatch). # Panics Pani
(&self, bf: &[u8])
| 985 | /// let deserialized: Point = fory.deserialize(&bytes).unwrap(); |
| 986 | /// ``` |
| 987 | pub fn deserialize<T: Serializer + ForyDefault>(&self, bf: &[u8]) -> Result<T, Error> { |
| 988 | self.with_read_context(|context| { |
| 989 | let outlive_buffer = unsafe { mem::transmute::<&[u8], &[u8]>(bf) }; |
| 990 | context.attach_reader(Reader::new(outlive_buffer)); |
| 991 | let result = self.deserialize_with_context(context); |
| 992 | context.detach_reader(); |
| 993 | result |
| 994 | }) |
| 995 | } |
| 996 | |
| 997 | /// Deserializes data from a `Reader` into a value of type `T`. |
| 998 | /// |