Skip to content

Commit 1917a22

Browse files
committed
Fix JSON round trip of properties with nested structs with native serialization
1 parent 2b27f84 commit 1917a22

2 files changed

Lines changed: 36 additions & 12 deletions

File tree

uesave/src/lib.rs

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -687,21 +687,23 @@ impl PropertyTagDataPartial {
687687
Self::Other(t) => PropertyTagDataFull::Other(t),
688688
}
689689
}
690-
}
691-
692-
impl PropertyTagDataFull {
693-
fn basic_type(&self) -> PropertyType {
690+
pub(crate) fn has_raw_struct(&self) -> bool {
694691
match self {
695-
Self::Array(_) => PropertyType::ArrayProperty,
696-
Self::Struct { .. } => PropertyType::StructProperty,
697-
Self::Set { .. } => PropertyType::SetProperty,
698-
Self::Map { .. } => PropertyType::MapProperty,
699-
Self::Byte(_) => PropertyType::ByteProperty,
700-
Self::Enum(_, _) => PropertyType::EnumProperty,
701-
Self::Bool(_) => PropertyType::BoolProperty,
702-
Self::Other(property_type) => *property_type,
692+
Self::Array(inner) => inner.has_raw_struct(),
693+
Self::Struct { struct_type, .. } => struct_type.raw(),
694+
Self::Set { key_type } => key_type.has_raw_struct(),
695+
Self::Map {
696+
key_type,
697+
value_type,
698+
} => key_type.has_raw_struct() || value_type.has_raw_struct(),
699+
Self::Byte(_) => false,
700+
Self::Enum(_, _) => false,
701+
Self::Other(_) => false,
703702
}
704703
}
704+
}
705+
706+
impl PropertyTagDataFull {
705707
fn has_raw_struct(&self) -> bool {
706708
match self {
707709
Self::Array(inner) => inner.has_raw_struct(),
@@ -717,6 +719,18 @@ impl PropertyTagDataFull {
717719
Self::Other(_) => false,
718720
}
719721
}
722+
fn basic_type(&self) -> PropertyType {
723+
match self {
724+
Self::Array(_) => PropertyType::ArrayProperty,
725+
Self::Struct { .. } => PropertyType::StructProperty,
726+
Self::Set { .. } => PropertyType::SetProperty,
727+
Self::Map { .. } => PropertyType::MapProperty,
728+
Self::Byte(_) => PropertyType::ByteProperty,
729+
Self::Enum(_, _) => PropertyType::EnumProperty,
730+
Self::Bool(_) => PropertyType::BoolProperty,
731+
Self::Other(property_type) => *property_type,
732+
}
733+
}
720734
fn from_type(inner_type: PropertyType, struct_type: Option<StructType>) -> Self {
721735
match inner_type {
722736
PropertyType::BoolProperty => Self::Bool(false),
@@ -4467,6 +4481,13 @@ impl<T: ArchiveType> Property<T> {
44674481
tag: PropertyTagFull,
44684482
) -> Result<(Property<T>, Option<PropertyTagDataFull>)> {
44694483
if tag.data.has_raw_struct() {
4484+
if ar.log() {
4485+
eprintln!(
4486+
"Warning: Storing property '{}' as raw bytes; tag contains native-serialized struct with no parser: {:?}",
4487+
ar.path(),
4488+
tag.data,
4489+
);
4490+
}
44704491
let mut raw = vec![0; tag.size as usize];
44714492
ar.read_exact(&mut raw)?;
44724493
return Ok((Property::Raw(raw), None));

uesave/src/serialization.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ impl<'de, 'a> DeserializeSeed<'de> for PropertySeed<'a> {
146146
D: Deserializer<'de>,
147147
{
148148
use crate::PropertyType;
149+
if self.tag.has_raw_struct() {
150+
return Ok(Property::Raw(Vec::<u8>::deserialize(deserializer)?));
151+
}
149152
match &self.tag {
150153
PropertyTagDataPartial::Other(pt) => match pt {
151154
PropertyType::BoolProperty => Ok(Property::Bool(bool::deserialize(deserializer)?)),

0 commit comments

Comments
 (0)