pub struct TypedStreamDeserializer<'a> {
pub data: &'a [u8],
pub type_table: Vec<Vec<Type<'a>>>,
pub object_table: Vec<Archived<'a>>,
/* private fields */
}
Expand description
Contains logic and data used to deserialize data from a typedstream
.
typedstream
is a binary serialization format developed by NeXTSTEP
and later adopted by Apple.
It’s designed to serialize and deserialize complex object graphs and data structures in C and Objective-C.
A typedstream
begins with a header that includes format version and architecture information,
followed by a stream of typed data elements. Each element is prefixed with type information,
allowing the TypedStreamDeserializer
to understand the original data structures.
Fields§
§data: &'a [u8]
The typedstream
we want to parse
type_table: Vec<Vec<Type<'a>>>
As we parse the typedstream
, build a table of seen Type
s to reference in the future
The first time a Type
is seen, it is present in the stream literally,
but afterwards are only referenced by index in order of appearance.
object_table: Vec<Archived<'a>>
As we parse the typedstream
, build a table of seen Archived
data to reference in the future
Implementations§
Source§impl<'a> TypedStreamDeserializer<'a>
impl<'a> TypedStreamDeserializer<'a>
Sourcepub fn new(data: &'a [u8]) -> Self
pub fn new(data: &'a [u8]) -> Self
Create a new TypedStreamDeserializer
for the provided byte slice.
§Examples
use crabstep::deserializer::typedstream::TypedStreamDeserializer;
let data: &[u8] = &[];
let deserializer = TypedStreamDeserializer::new(data);
Sourcepub fn iter_root(&mut self) -> Result<PropertyIterator<'a, '_>>
pub fn iter_root(&mut self) -> Result<PropertyIterator<'a, '_>>
Creates an iterator that resolves the properties of the root object in the typedstream
.
§Examples
use crabstep::deserializer::typedstream::TypedStreamDeserializer;
let data: &[u8] = &[];
let mut deserializer = TypedStreamDeserializer::new(data);
// Walk the object root, printing each primitive value
deserializer.iter_root().into_iter().for_each(|prop| {
prop.primitives().into_iter().for_each(|data| println!("{data}"));
});
Sourcepub fn oxidize(&mut self) -> Result<usize>
pub fn oxidize(&mut self) -> Result<usize>
Parse the typedstream
, consuming header and objects, returning the index of the top-level archived object.
§Errors
Returns a TypedStreamError
if parsing fails or the stream ends unexpectedly.
§Examples
use crabstep::TypedStreamDeserializer;
let mut deserializer = TypedStreamDeserializer::new(&[]);
let result = deserializer.oxidize();
Sourcepub fn resolve_properties(
&self,
root_object_index: usize,
) -> Result<PropertyIterator<'a, '_>>
pub fn resolve_properties( &self, root_object_index: usize, ) -> Result<PropertyIterator<'a, '_>>
Creates an iterator that resolves the properties of an object
at the specified index in the object_table
, preserving nested structure.
This should be called after oxidize()
.
§Arguments
root_object_index
- Index of the object in the deserializer’sobject_table
to iterate.
§Errors
Returns TypedStreamError::InvalidPointer
if the index is not a valid object reference.
§Examples
use crabstep::TypedStreamDeserializer;
let mut ts = TypedStreamDeserializer::new(&[]);
let root = ts.oxidize().unwrap();
let iter = ts.resolve_properties(root).unwrap();