diff --git a/rbx_xml/src/tests/snapshots/rbx_xml__tests__formatting__serialized.snap b/rbx_xml/src/tests/snapshots/rbx_xml__tests__formatting__serialized.snap index 6d7e8caf8..9364cd307 100644 --- a/rbx_xml/src/tests/snapshots/rbx_xml__tests__formatting__serialized.snap +++ b/rbx_xml/src/tests/snapshots/rbx_xml__tests__formatting__serialized.snap @@ -1,5 +1,6 @@ --- source: rbx_xml/src/tests/formatting.rs +assertion_line: 174 expression: ser_str --- @@ -31,13 +32,13 @@ expression: ser_str 125600 0 0 0.5 1 0 1 1 0.5 0 0 - + Wow! - - + + - + diff --git a/rbx_xml/src/types/content.rs b/rbx_xml/src/types/content.rs index e9f07da2e..a96d3fc82 100644 --- a/rbx_xml/src/types/content.rs +++ b/rbx_xml/src/types/content.rs @@ -9,11 +9,11 @@ use crate::{ serializer_core::{XmlEventWriter, XmlWriteEvent}, }; -// A Content type is serialized as either: +// A ContentId type is serialized as either: // , which indicates an empty content value // something, where 'something' is a URL to use for content. impl XmlType for Content { - const XML_TAG_NAME: &'static str = "Content"; + const XML_TAG_NAME: &'static str = "ContentId"; fn write_xml(&self, writer: &mut XmlEventWriter) -> Result<(), EncodeError> { // FIXME: Content should have a method for this @@ -66,6 +66,28 @@ impl XmlType for Content { } } +/// In release 645, Roblox changed `Content` to serialize as `ContentId`. +/// However, we still need to deserialize older models, so we have to support +/// `Content`. +/// +/// This may need to be replaced in the future if Roblox implements a new +/// `Content` type, but right now they haven't. +#[derive(Debug, PartialEq, Eq)] +pub struct ContentDummy(pub Content); + +impl XmlType for ContentDummy { + const XML_TAG_NAME: &'static str = "Content"; + + fn write_xml(&self, _writer: &mut XmlEventWriter) -> Result<(), EncodeError> { + panic!("Content values are only read, never written."); + } + + fn read_xml(reader: &mut XmlEventReader) -> Result { + // We just want to use the same deserializer as ContentId + Content::read_xml(reader).map(ContentDummy) + } +} + #[cfg(test)] mod test { use super::*; @@ -86,9 +108,9 @@ mod test { fn deserialize_content_url() { test_util::test_xml_deserialize( r#" - + Some URL - + "#, &Content::from("Some URL"), ); @@ -98,9 +120,9 @@ mod test { fn deserialize_content_null() { test_util::test_xml_deserialize( r#" - + - + "#, &Content::new(), ); @@ -110,9 +132,9 @@ mod test { fn serialize_content_url() { test_util::test_xml_serialize( r#" - + Some URL - + "#, &Content::from("Some URL"), ); @@ -122,9 +144,9 @@ mod test { fn serialize_content_null() { test_util::test_xml_serialize( r#" - + - + "#, &Content::new(), ); diff --git a/rbx_xml/src/types/mod.rs b/rbx_xml/src/types/mod.rs index a05823732..a712d2ae8 100644 --- a/rbx_xml/src/types/mod.rs +++ b/rbx_xml/src/types/mod.rs @@ -83,6 +83,10 @@ macro_rules! declare_rbx_types { let value = self::strings::ProtectedStringDummy::read_outer_xml(reader)?; Ok(Some(Variant::String(value.0))) }, + self::content::ContentDummy::XML_TAG_NAME => { + let value = self::content::ContentDummy::read_outer_xml(reader)?; + Ok(Some(Variant::Content(value.0))) + } self::referent::XML_TAG_NAME => Ok(Some(Variant::Ref(read_ref(reader, instance_id, property_name, state)?))), self::shared_string::XML_TAG_NAME => read_shared_string(reader, instance_id, property_name, state).map(Some),