Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RobloxString to rbx_types, use it for instance names #478

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft
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
15 changes: 1 addition & 14 deletions rbx_binary/src/deserializer/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,20 +385,7 @@ impl<'db, R: Read> DeserializerState<'db, R> {
for referent in &type_info.referents {
let instance = self.instances_by_ref.get_mut(referent).unwrap();
let binary_string = chunk.read_binary_string()?;
let value = match std::str::from_utf8(&binary_string) {
Ok(value) => Cow::Borrowed(value),
Err(_) => {
log::warn!(
"Performing lossy string conversion on property {}.{} because it did not contain UTF-8.
This may cause unexpected or broken behavior in your final results if you rely on this property being non UTF-8.",
type_info.type_name,
prop_name
);

String::from_utf8_lossy(binary_string.as_ref())
}
};
instance.builder.set_name(value);
instance.builder.set_name(binary_string);
}

return Ok(());
Expand Down
22 changes: 18 additions & 4 deletions rbx_binary/src/serializer/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use rbx_dom_weak::{
Attributes, Axes, BinaryString, BrickColor, CFrame, Color3, Color3uint8, ColorSequence,
ColorSequenceKeypoint, Content, Enum, EnumItem, Faces, Font, MaterialColors, Matrix3,
NumberRange, NumberSequence, NumberSequenceKeypoint, PhysicalProperties, Ray, Rect, Ref,
SecurityCapabilities, SharedString, Tags, UDim, UDim2, UniqueId, Variant, VariantType,
Vector2, Vector3, Vector3int16,
RobloxString, SecurityCapabilities, SharedString, Tags, UDim, UDim2, UniqueId, Variant,
VariantType, Vector2, Vector3, Vector3int16,
},
Instance, Ustr, UstrSet, WeakDom,
};
Expand Down Expand Up @@ -629,7 +629,14 @@ impl<'dom, 'db, W: Write> SerializerState<'dom, 'db, W> {
// convenience, but when serializing to the binary model
// format we need to handle it just like other properties.
if *prop_name == "Name" {
return Cow::Owned(Variant::String(instance.name.clone()));
let name_as_string = match &instance.name {
RobloxString::Binary(buffer) => {
String::from_utf8_lossy(buffer.as_slice()).to_string()
}
RobloxString::Utf8(string) => string.to_string(),
};

return Cow::Owned(Variant::String(name_as_string));
}

// Most properties will be stored on instances using the
Expand Down Expand Up @@ -1313,7 +1320,14 @@ impl<'dom, 'db, W: Write> SerializerState<'dom, 'db, W> {

while current_id.is_some() {
let instance = self.dom.get_by_ref(current_id).unwrap();
components.push(instance.name.as_str());
let name_as_string = match &instance.name {
RobloxString::Binary(buffer) => {
String::from_utf8_lossy(buffer.as_slice()).to_string()
}
RobloxString::Utf8(string) => string.to_string(),
};

components.push(name_as_string);
current_id = instance.parent();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ source: rbx_binary/src/tests/util.rs
expression: decoded_viewed
---
- referent: referent-0
name: Folder
name:
Utf8:
- Folder
class: Folder
properties:
Attributes:
Expand Down Expand Up @@ -89,4 +91,3 @@ expression: decoded_viewed
Tags:
Tags: []
children: []

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ source: rbx_binary/src/tests/util.rs
expression: decoded_viewed
---
- referent: referent-0
name: ""
name:
Utf8:
- ""
class: ArcHandles
properties:
Adornee: "null"
Expand All @@ -24,7 +26,9 @@ expression: decoded_viewed
Bool: true
children: []
- referent: referent-1
name: X
name:
Utf8:
- X
class: ArcHandles
properties:
Adornee: "null"
Expand All @@ -46,7 +50,9 @@ expression: decoded_viewed
Bool: true
children: []
- referent: referent-2
name: "X, Y"
name:
Utf8:
- "X, Y"
class: ArcHandles
properties:
Adornee: "null"
Expand All @@ -69,7 +75,9 @@ expression: decoded_viewed
Bool: true
children: []
- referent: referent-3
name: "X, Y, Z"
name:
Utf8:
- "X, Y, Z"
class: ArcHandles
properties:
Adornee: "null"
Expand All @@ -93,7 +101,9 @@ expression: decoded_viewed
Bool: true
children: []
- referent: referent-4
name: "X, Z"
name:
Utf8:
- "X, Z"
class: ArcHandles
properties:
Adornee: "null"
Expand All @@ -116,7 +126,9 @@ expression: decoded_viewed
Bool: true
children: []
- referent: referent-5
name: Y
name:
Utf8:
- Y
class: ArcHandles
properties:
Adornee: "null"
Expand All @@ -138,7 +150,9 @@ expression: decoded_viewed
Bool: true
children: []
- referent: referent-6
name: "Y, Z"
name:
Utf8:
- "Y, Z"
class: ArcHandles
properties:
Adornee: "null"
Expand All @@ -161,7 +175,9 @@ expression: decoded_viewed
Bool: true
children: []
- referent: referent-7
name: Z
name:
Utf8:
- Z
class: ArcHandles
properties:
Adornee: "null"
Expand All @@ -182,4 +198,3 @@ expression: decoded_viewed
Visible:
Bool: true
children: []

Loading