This is a Low-level schematized serialization library for Roblox for handling limited size dictionaries with primitive types. This library aims to do as few operations (table lookups, comparisons, etc.) as possible to achieve it's result while staying a good-enough serialization library.
Sera's intended purpose is to help with serialization schemas when handling high-efficiency game entity replication to clients. Note that this is not a module for beginners and you should at least know the basics of using the buffer class.
- Fast.
- Efficient-enough representation of a dictionary inside a
buffer. Sera.Serialize,Sera.Push,Sera.DeltaSerializeandSera.DeltaPushoutputs can be combined inside a large buffer -Sera.DeserializeandSera.DeltaDeserializeunderstand when an entry ends given a buffer and offset and returns a new offset for the developer to continue reading the buffer.Sera.DeltaSerializeandSera.DeltaPushtreats a schema as an enumerator and serializes an incomplete dictionary with added (n + 1) bytes in the output where "n" is the number of fields present.
- Schemas can only hold up to 255 fields in Sera and it's going to stay that way - you may fork the project and easily change this for yourself.
Sera.SerializeandSera.DeltaSerializewill fail if resulting buffer size is larger than the constantBIG_BUFFER_SIZEinside theSeramodule - This value should be moderate, but within reason since that's the memorySerawill take and never release during runtime.
Source Code (Single ModuleScript)
Join the discussion in the Roblox Developer Forum (click here)
This is an experimental project - there will be no guarantees for backwards-compatibility on further updates
local Sera = require(game.ReplicatedStorage.Sera)
local Schema = Sera.Schema({
Health = Sera.Int16,
Position = Sera.Vector3,
Name = Sera.String8,
})
local serialized, error_message = Sera.Serialize(Schema, {
Health = 150,
Position = Vector3.new(1001, 69, 0.1),
Name = "loleris",
})
if error_message ~= nil then
error(error_message)
end
local deserialized = Sera.Deserialize(Schema, serialized :: buffer)
print(`Serialized buffer size: {buffer.len(serialized :: buffer)} bytes`)
print(`Deserialized:`, deserialized)