Fireboltofdeath / flamework-binary-serializer

A blazing fast binary serializer, or something
7 stars 0 forks source link

Same type different format compiled #16

Open st-Wook opened 4 months ago

st-Wook commented 4 months ago

I am experiencing an issue with the @rbxts/flamework-binary-serializer@0.6.0 package. Here is my code:

interface TryOnItemInStorePackedObject {
    itemId: DataType.f64;
    itemType: "Asset" | "Bundle";
    storeOwnerId: DataType.f64 | undefined;
}

// test1.ts
private tryOnItemInStoreSerializer = createBinarySerializer<DataType.Packed<TryOnItemInStorePackedObject>>();

// test2.ts
private tryOnItemInStoreSerializer = createBinarySerializer<DataType.Packed<TryOnItemInStorePackedObject>>();

When compiled, the output occasionally differs as shown below:

-- test1.lua
self.tryOnItemInStoreSerializer = createBinarySerializer({ "packed", { "object_raw", { { "itemId", { "f64" } }, { "itemType", { "literal", { "Asset", "Bundle" }, 0 } }, { "storeOwnerId", { "optional", { "f64" } } } } } })

-- test2.lua
self.tryOnItemInStoreSerializer = createBinarySerializer({ "packed", { "object_raw", { { "storeOwnerId", { "optional", { "f64" } } }, { "itemId", { "f64" } }, { "itemType", { "literal", { "Asset", "Bundle" }, 0 } } } } })

When the incorrect case is compiled, I encounter the following error:

ReplicatedStorage.rbxts_include.node_modules.@rbxts.flamework-binary-serializer.out.serialization.createDeserializer:23: buffer access out of bounds

Additionally, the packed object type definitions are shared and used in multiple places. The same type is used across different createBinarySerializer calls. However, during serialization and deserialization, the formats differ, causing the error. Could you modify the compilation process to ensure that the same type always compiles to the same format?

Fireboltofdeath commented 4 months ago

This is a known limitation, and it's mentioned in the createBinarySerializer documentation.

Changing this behavior in Flamework would likely be the easiest solution as it's otherwise non-trivial to sort the various types.

st-Wook commented 4 months ago

Ah, I see... Thank you for the explanation!