Skip to content

nwinn-student/luau-buffer-serialize

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

475 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BufferSerializer

Luau Version License: GPL-3.0

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.

Purpose

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.

Additional Features

  • Custom Userdata
    • Look in examples to see common practice for supporting userdata (de)serialization.
  • Cyclic tables

Usage Cases

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.

Example

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}`)

Performance

Under construction...

About

First pass compression for booleans, numbers, vectors, and more.

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors