Serialization
Getting Started
To serialize a BufferComponent, you simply need to assign a Schema and the table containing the values.
Note
Each index must exactly match the name in the Schema. e.g: Schema = {Hello = "String8"}, Values = {Hello = "World"} Otherwise the value will be skipped and may cause errors.
Warning
You can serialize/deserialize an Instance, but it will use a table not a buffer.
Methods
Serialize
Serializes the given Values according to the Schema into a BufferComponentClass
Deserialize
local Buffer = require(somewhere.Buffer)
local Schema : Buffer.BufferSchema = {
Hello = "String16"
}
local Value = {
Hello = "Hello World !"
}
local serialized = Buffer.Serialize(Schema,Value)
--Deserializing the buffer
--the schema need to be same as the one used to serialize
local deserialized = Buffer.Deserialize(Schema,serialized)
print(deserialized) -- will print { Hello = "Hello World !" }
Deserializes a BufferComponentClass into a table of values according to Schema
SerializeAll
Same as Serialize but accepts a table of values and a table of schemas.
Each schema will be serialized with its corresponding value.
Note
This return a numeric table with BufferComponentClass as values in order.
DeserializeAll
Same as Serialize but accepts a table of values and a table of schemas.
Each schema will be serialized with its corresponding value.
Note
This return a numeric table with BufferComponentClass as values in order.
SerializeCompress
Serializes a set of values according to the provided schema and then compresses the resulting buffer.
Parameters:
- Schema
BufferSchema - Values
table<string, T>
Returns: buffer
- A compressed buffer produced by first serializing the input
- values and then applying Zstd compression.
Warning
- The returned buffer is not directly readable. Use
DeserializeCompressed(...) - Do not use this for buffers smaller than 30 bytes or in the 30–50 bytes range.
DeserializeCompress
Decompresses a previously compressed buffer and then deserializes its content according to the provided schema.
Parameters:
- Schema
BufferSchema
The schema describing how data was originally structured and stored.
- compressedBuffer
buffer
A buffer that was produced using SerializeCompressed(...) and compressed using Zstd.
Returns: table<string, T>
A table of deserialized values mapped by field name.
Warning
- The buffer must have been created with the same schema used here.
- If the schema does not match the original one, deserialization will fail or produce invalid data.
- You must use a compressed buffer using
:Compresswith the same Compression Algorithm.
SerializeAllCompressed
Serializes and compresses multiple value sets using corresponding schemas.
Parameters:
- Schemas
{BufferSchema}
An array of schemas. Each schema describes how its corresponding value set should be serialized.
- Values
{ table<string, T> }
An array where each entry is a table of named values to be serialized. The index of each value set must match the index of its schema.
Returns: { buffer }
An array of compressed buffers, one for each (Schema, Values) pair.
Info
- For each index i:
- Serialize(Schemas[i], Values[i]) →
Buffer - Compress(Buffer) →
CompressedBuffer
- Serialize(Schemas[i], Values[i]) →
- The resulting compressed buffer is appended to the output array.
Note
- Schemas and Values must have the same length and aligned ordering.
- If any schema or value set is invalid, the function throws an error.
- This is the bulk equivalent of
SerializeCompressed(...).
DeserializeAllCompressed
Decompresses and deserializes multiple compressed buffers using their corresponding schemas.
Parameters:
- Schemas
({BufferSchema})
An array of schemas. Each schema defines how its corresponding decompressed buffer should be interpreted and reconstructed.
- Buffers
({buffer})
An array of compressed buffers produced by SerializeAllCompressed(...) or SerializeCompressed(...). The index of each buffer must match the index of its schema.
Returns: { { [string] : T } }
An array of deserialized value tables. Each entry corresponds to the decompressed and deserialized result of the matching schema and buffer pair.
Serializable Types
| Type | Bytes |
|---|---|
| I1 | 1 |
| I8 | 1 |
| I16 | 2 |
| I24 | 3 |
| I32 | 4 |
| I40 | 5 |
| I48 | 6 |
| I54 | 7 |
| U1 | 1 |
| U8 | 1 |
| U16 | 2 |
| U24 | 3 |
| U32 | 4 |
| U40 | 5 |
| U48 | 6 |
| U54 | 7 |
| F16 | 2 |
| F32 | 4 |
| F64 | 8 |
| Bool1 | 1 |
| Bool8 | 1 |
| String8 | 8 (8-character max) |
| String16 | 16 (16-character max) |
| String32 | 32 (32-character max) |
| String64 | 64 (64-character max) |
| String | desired len (must use {Type = "String",Length = number}) |
| String16 | 16 (16-character max) |
| Color3 | 12 |
| Vector2 | 16 |
| Vector2int16 | 4 |
| Vector3 | 24 |
| Vector3int16 | 6 |
| CFrame | 96 |
| LossyCFrame | 48 |
| Rect | 32 |
| Region3 | 120 |
| Region3int16 | 12 |
| UDim | 8 |
| UDim2 | 16 |
| vector | 24 |
| Enum | 4 |
| NumberRange | 8 |
| FloatCurveKey | 16 or 24 (if you use KeyInterpolationMode.Cubic) |
| RotationCurveKey | 104 or 112 (if you use KeyInterpoliationMode.Cubic) |
| ColorSequence | 1 + 16 * number of ColorSequenceKeypoint |
| NumberSequence | 1 + 12 * number of NumberSequenceKeypoint |
| Array | Depends on Array size |