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

rbx_types Variant::String should be backed by Vec<u8> instead of String #475

Open
kennethloeffler opened this issue Nov 5, 2024 · 1 comment

Comments

@kennethloeffler
Copy link
Member

kennethloeffler commented Nov 5, 2024

Right now, rbx_types uses the Rust String type to represent Roblox string values. This works most of the time, but is actually incorrect because Roblox strings are not required to be UTF-8. So, rbx-dom is currently unable to losslessly decode files that have non UTF-8 string properties.

The idea of using the bstr crate has been thrown around before, but after a bit of investigation, this won't work very well because BString's human-readable serde representation is always a list of numbers, which makes rbx-dom's various snapshot tests unreadable, and which will seriously bloat the JSON representation. We also cannot provide our own Serialize/Deserialize implementations for BString because of the orphan rule. We could just newtype it... but this somewhat nullifies the benefits of pulling in a crate!

So, to put the nail in the coffin on this, I'm thinking we'll have change rbx-dom's String variant so it is backed by a type that contains either a Vec<u8> or a String, perhaps called RobloxString or something.

Lastly, we've just had breaking changes to rbx_dom_weak. Breaking 2 different crates in rbx-dom at once might be a bit much to take on right now since we'll already have to make some fairly sweeping changes to Rojo, so this should probably wait until after rbx-dom's next batch of releases.

@kennethloeffler kennethloeffler changed the title Represent strings in rbx_types using Vec<u8> instead of String rbx_types String variant should be backed by Vec<u8> instead of String Nov 5, 2024
@kennethloeffler kennethloeffler changed the title rbx_types String variant should be backed by Vec<u8> instead of String rbx_types Variant::String should be backed by Vec<u8> instead of String Nov 5, 2024
@kennethloeffler
Copy link
Member Author

kennethloeffler commented Nov 5, 2024

Lastly, we've just had breaking changes to rbx_dom_weak. Breaking 2 different crates in rbx-dom at once might be a bit much to take on right now since we'll already have to make some fairly sweeping changes to Rojo, so this should probably wait until after rbx-dom's next batch of releases.

Or, we might leave Variant::String alone, and just add RobloxString and change the types of Instance.name and InstanceBuilder.name to it for now, since we're breaking rbx_dom_weak anyway?

Scratch that, we'll need to do it all at once because of how serialization works in rbx_binary and rbx_xml

Scratch that (again) - we would be able to change the types of Instance.name and InstanceBuilder.name to RobloxString, and could deserialize instance names just fine without touching Variant::String, but would have to perform a lossy conversion for instance names during serialization, and also perform a lossy conversion for other string properties during both serialization and deserialization.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant