Skip to content

Commit

Permalink
Refactor StructPropertyValue
Browse files Browse the repository at this point in the history
  • Loading branch information
scottanderson committed Oct 21, 2024
1 parent 207c296 commit 032a38c
Show file tree
Hide file tree
Showing 11 changed files with 1,421 additions and 1,290 deletions.
11 changes: 5 additions & 6 deletions src/properties/array_property.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use super::{
int_property::{BoolProperty, ByteProperty, BytePropertyValue, FloatProperty, IntProperty},
name_property::NameProperty,
str_property::StrProperty,
struct_property::StructProperty,
struct_property::{StructProperty, StructPropertyValue},
Property, PropertyOptions, PropertyTrait,
};

Expand Down Expand Up @@ -78,7 +78,7 @@ pub enum ArrayProperty {
#[cfg_attr(feature = "serde", serde(default))]
guid: Guid,
/// An array of values.
structs: Vec<StructProperty>,
structs: Vec<StructPropertyValue>,
},
/// Any other Property value
Properties {
Expand Down Expand Up @@ -226,7 +226,7 @@ impl ArrayProperty {
("StructProperty", Some((field_name, type_name, guid))) => match properties
.iter()
.map(|p| match p {
Property::StructProperty(struct_property) => Ok(struct_property.clone()),
Property::StructPropertyValue(value) => Ok(value.clone()),
_ => Err(p),
})
.collect::<Result<_, _>>()
Expand Down Expand Up @@ -324,9 +324,8 @@ impl ArrayProperty {

let properties_start = cursor.stream_position()?;
for _ in 0..property_count {
properties.push(
StructProperty::read_with_type_name(cursor, &struct_name, options)?.into(),
);
let value = StructProperty::read_body(cursor, &struct_name, options)?;
properties.push(Property::from(value));
}
let properties_end = cursor.stream_position()?;
let actual_size = properties_end - properties_start;
Expand Down
19 changes: 17 additions & 2 deletions src/properties/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use self::{
object_property::ObjectProperty,
set_property::SetProperty,
str_property::StrProperty,
struct_property::StructProperty,
struct_property::{StructProperty, StructPropertyValue},
text_property::TextProperty,
unknown_property::UnknownProperty,
};
Expand Down Expand Up @@ -536,6 +536,8 @@ pub enum Property {
StrProperty,
/// A `StructProperty`.
StructProperty,
/// A raw `StructPropertyValue`.
StructPropertyValue,
/// A `TextProperty`.
TextProperty,
/// A `UInt16Property`.
Expand Down Expand Up @@ -585,7 +587,20 @@ impl Property {
Ok(MulticastSparseDelegateProperty::read(cursor, include_header)?.into())
}
"FieldPathProperty" => Ok(FieldPathProperty::read(cursor, include_header)?.into()),
"StructProperty" => Ok(StructProperty::read(cursor, include_header, options)?.into()),
"StructProperty" => match include_header {
true => Ok(StructProperty::read(cursor, include_header, options)?.into()),
false => {
let struct_path = options.properties_stack.join(".");
let Some(hint) = options.hints.get(&struct_path) else {
Err(DeserializeError::MissingHint(
"StructProperty".into(),
struct_path.into_boxed_str(),
cursor.stream_position()?,
))?
};
Ok(StructProperty::read_body(cursor, hint, options)?.into())
}
},
"ArrayProperty" => Ok(ArrayProperty::read(cursor, include_header, options)?.into()),
"SetProperty" => Ok(SetProperty::read(cursor, include_header, options)?.into()),
"MapProperty" => Ok(MapProperty::read(cursor, include_header, options)?.into()),
Expand Down
Loading

0 comments on commit 032a38c

Please sign in to comment.