diff --git a/resources/test/component8.sav b/resources/test/component8.sav old mode 100755 new mode 100644 diff --git a/resources/test/enum_array.sav b/resources/test/enum_array.sav old mode 100755 new mode 100644 diff --git a/src/properties/enum_property.rs b/src/properties/enum_property.rs index 6ca73d7..771e2db 100644 --- a/src/properties/enum_property.rs +++ b/src/properties/enum_property.rs @@ -1,6 +1,7 @@ use std::io::{Cursor, Read, Seek, Write}; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; +use unreal_helpers::UnrealWriteExt; use crate::{ cursor_ext::{ReadExt, WriteExt}, @@ -13,16 +14,16 @@ use super::{impl_read_header, impl_write, impl_write_header_part, PropertyOption #[derive(Debug, Clone, PartialEq, Eq, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct EnumProperty { - enum_type: String, + enum_type: Option, value: String, } -impl_write!(EnumProperty, (write_string, enum_type)); +impl_write!(EnumProperty, (write_fstring, enum_type)); impl EnumProperty { /// Creates a new `EnumProperty` instance. #[inline] - pub fn new(enum_type: String, value: String) -> Self { + pub fn new(enum_type: Option, value: String) -> Self { EnumProperty { enum_type, value } } @@ -34,14 +35,14 @@ impl EnumProperty { if include_header { Self::read_header(cursor) } else { - Self::read_body(cursor, String::from("")) + Self::read_body(cursor, None) } } impl_read_header!(enum_type); #[inline] - fn read_body(cursor: &mut R, enum_type: String) -> Result { + fn read_body(cursor: &mut R, enum_type: Option) -> Result { let value = cursor.read_string()?; Ok(EnumProperty { enum_type, value }) diff --git a/src/properties/mod.rs b/src/properties/mod.rs index f2c302c..fec7efe 100644 --- a/src/properties/mod.rs +++ b/src/properties/mod.rs @@ -186,7 +186,7 @@ macro_rules! impl_read_header { assert_eq!(separator, 0); let start = reader.stream_position()?; - let result = Self::read_body(reader $(, $var)*)?; + let result = Self::read_body(reader $(, Some($var))*)?; let end = reader.stream_position()?; assert_eq!(end - start, length); @@ -298,6 +298,10 @@ macro_rules! impl_write { /// /// This macro is used inside the `impl_write!` macro to write individual parts of a property header. macro_rules! impl_write_header_part { + ($self:ident, $writer:ident, (write_fstring, $member:ident)) => { + $writer.write_fstring($self.$member.as_deref())?; + }; + ($self:ident, $writer:ident, ($write_fn:ident, $member:ident)) => { $writer.$write_fn(&$self.$member)?; }; diff --git a/tests/test_property.rs b/tests/test_property.rs index f65357d..fe7693d 100644 --- a/tests/test_property.rs +++ b/tests/test_property.rs @@ -90,7 +90,7 @@ test_property!(test_str, StrProperty, StrProperty::from("test string")); test_property!( test_enum, EnumProperty, - EnumProperty::new(String::from("type"), String::from("value")) + EnumProperty::new(Some(String::from("type")), String::from("value")) ); // StructProperty