Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 18 additions & 19 deletions src/deserializer/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,26 +142,25 @@ impl<'a, 'b: 'a> Iterator for PropertyIterator<'a, 'b> {
class: cls,
data: _,
}) = self.object_table.get(*idx)
&& let Some(Archived::Class(cls)) = self.object_table.get(*cls)
{
if let Some(Archived::Class(cls)) = self.object_table.get(*cls) {
let class_name = self
.type_table
.get(cls.name_index)
.and_then(|types| types.first())
.and_then(|t| match t {
Type::String(name) => Some(*name),
_ => None,
})
.unwrap_or("Unknown Class");
// recurse into that object’s own data
let sub_iter =
PropertyIterator::new(self.object_table, self.type_table, *idx)?;
resolved.push(Property::Object {
class: cls,
name: class_name,
data: sub_iter,
});
}
let class_name = self
.type_table
.get(cls.name_index)
.and_then(|types| types.first())
.and_then(|t| match t {
Type::String(name) => Some(*name),
_ => None,
})
.unwrap_or("Unknown Class");
// recurse into that object’s own data
let sub_iter =
PropertyIterator::new(self.object_table, self.type_table, *idx)?;
resolved.push(Property::Object {
class: cls,
name: class_name,
data: sub_iter,
});
}
}
prim => resolved.push(Property::Primitive(prim)),
Expand Down
27 changes: 13 additions & 14 deletions src/deserializer/typedstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,10 @@ impl<'a> TypedStreamDeserializer<'a> {

// The class we just appended (*idx*) is the **parent** of the
// class we appended in the previous iteration (*prev_new*)
if let Some(child_idx) = prev_new {
if let Archived::Class(ref mut child_cls) = self.object_table[child_idx] {
child_cls.parent_index = Some(idx);
}
if let Some(child_idx) = prev_new
&& let Archived::Class(ref mut child_cls) = self.object_table[child_idx]
{
child_cls.parent_index = Some(idx);
}

// remember the first class we ever pushed
Expand Down Expand Up @@ -264,10 +264,10 @@ impl<'a> TypedStreamDeserializer<'a> {

// Patch the outer-most newly created class so that it points to the
// already-existing parent (or to `None` if EMPTY terminated the list).
if let Some(outer_idx) = prev_new {
if let Archived::Class(ref mut outer_cls) = self.object_table[outer_idx] {
outer_cls.parent_index = final_parent;
}
if let Some(outer_idx) = prev_new
&& let Archived::Class(ref mut outer_cls) = self.object_table[outer_idx]
{
outer_cls.parent_index = final_parent;
}

// Return the index of the bottom-most child we created first.
Expand All @@ -294,15 +294,14 @@ impl<'a> TypedStreamDeserializer<'a> {
// Read the next type, which should be an object
if let Some(next_index) = self.read_type(false)? {
// Recursively read the types for this object
if let Some(data) = self.read_types(next_index)? {
if let Some(Archived::Object {
if let Some(data) = self.read_types(next_index)?
&& let Some(Archived::Object {
class: _,
data: data_vec,
}) = self.object_table.get_mut(placeholder_index)
{
// Add the data to the object
data_vec.push(data);
}
{
// Add the data to the object
data_vec.push(data);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/models/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl<'a> Type<'a> {
Self::String(str)
}

pub(crate) fn get_array_length(types: &[u8]) -> Option<Vec<Type>> {
pub(crate) fn get_array_length(types: &'_ [u8]) -> Option<Vec<Type<'_>>> {
if types.first() == Some(&0x5b) {
let len =
types[1..]
Expand All @@ -109,7 +109,7 @@ impl<'a> Type<'a> {
None
}

pub(crate) fn read_new_type(data: &[u8]) -> Result<Consumed<Vec<Type>>> {
pub(crate) fn read_new_type(data: &'_ [u8]) -> Result<Consumed<Vec<Type<'_>>>> {
// Get the type of the object
let type_length = read_unsigned_int(data)?;

Expand Down