Caution
Userdata support has been moved from the internal API into the external API. The internal portion has changed, so breakage will occur for relevant cases.
Caution
Pairs has been removed. No data migration concerns.
BufferSerializer is a binary format for complex data structures whose goal trudges the line of speed and effective output size. Unlike most serializers, BufferSerializer acts as a first-pass compressor by storing duplicate data in fewer bytes. The benefit of this approach is that datasets could be processed much faster than otherwise, however datasets with little duplicate content are less performant. While the format itself is not highly compressible like JSON, there are various approaches to further reduce the output size, see tips.
BufferSerializer supports most of the built-in Luau types, excluding function
and thread. Implementations of the binary format in other programming
languages must follow the specification.
- Custom Userdata
- Look in examples to see common practice for supporting userdata (de)serialization.
- Cyclic tables
- See limitations for more information.
A user needs to prepare data for storing in a database, they will use BufferSerializer to convert the data into a buffer, then store the value.
A user with an extension of Luau may wish to have their userdata objects specially handled, using BufferSerializer, they create two functions to handle the serialization and deserialization of userdata objects.
More in-depth examples can be found in examples, and more information about the API is located in the API documentation.
local BufferSerializer = require("./path/to/BufferSerializer")
-- Serialize
local data = "Hello World!"
local output = BufferSerializer.serialize(data)
-- Deserialize
local input = BufferSerializer.deserialize(output)
print(`Initial Data: {data}, Final Data: {input}`)Under construction...