Caution
Userdata support will be moved from the internal API into the external API.
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
- Users can add support for (de)serializing userdata using the internal API.
- Cyclic tables
- See limitations for more information.
- Pairs
- Pays an upfront cost for future duplicates of the paired value to be cheaper.
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...