Forest Logo
search
package_2

ttb

By @karl1229idk

Roblox

Mirrored

transform_table_buffer (TTB)

High performance Roblox serializer to seamlessly transform array/hashmap <-> buffer
[image: REUSE status]

Why TTB & TTBW?

  • Minimal Buffer: size = (1 + element bytes)
  • Zero-Dependency: download it, and plug-and-play
  • Dynamic Typed: no need to wait for IDL compile, which slow down the development process
  • Type Infer: you don't need to pass in type name, feel free to skip it
  • Explicit Typing: you can force TTB to use a type you want, for example, u8 instead of f64(default)
  • HashMap Support: support HashMap for lazy-devs, don't need to transform to array first
  • Safety with TTBW: TTBW guarantee the TTB to not crash

Supported Types

TypesSize (bytes)Notes
number / f648Standard Luau number type
string2 + NLength-prefixed (max 64KB)
CFrame48Complete lossless CFrame
f32432 bit float
u81Unsigned 8 bit integer
u162Unsigned 16 bit integer
i324Signed 32 bit integer
Vector312Raw float packing
Vector28Raw float packing
Color33Compressed
Color3F12Uncompressed
boolean17-bit aligned

Disclaimer

Safety is guaranteed by YOU, not the library!

  • No Nesting: TTB is designed for flat data streams, it is unsupported and will never be supported
  • Strict Type: Passing unsupported type or wrong argument will be resulted in undefined behavior/crash
  • Hashmap Rule: Key must be string (max 255 bytes), Max 65535 pairs per map

TTBW: The offical TTB wrapper

If you are processing data from untrusted source, TTBW will be your best friend!

  • Crash Preventation: Prevent hard errors/terminations from malformed buffers
  • Validation: Perform boundary checks/type checkings before TTB execute
  • Usage: Always check if return value is nil. nil indicates corrupted or malformed data

Usage

TTB Serialization

local ttb = require("path/to/TTB")
local data = { Vector3.new(1, 2, 3), Vector3.new(1, 2, 3) }
local buf = ttb.getBufferFromArray(
    data --,
    --"Vector3" -- Feel free to not pass in type
                -- TTB will infer it for you!
)

local decoded = ttb.decode(buf)
assert(data[1] == decoded[1] and decoded[2] == data[2])

local map = { player1 = 10, player2 = 20 }
local buf = ttb.getBufferFromHashmap(
    map,
    "u8" -- u8, u16, i32, f32, f64 are supported
         -- Without telling, TTB assume f64 for numbers
)
local decoded = ttb.decode(buf)
assert(map.player1 == decoded.player1 and decoded.player2 == map.player2)

TTBW Serialization

local ttbw = require("path/to/TTB/TTBW")
local decoded = ttbw.safeDecode(receivedBuffer)

if decoded then
    print("Processing")
else
    warn("Corrupted/Malformed buffer detected")
end

License

Licensed under MPL-2.0
REUSE 3.3 compliant

Zen of TTB

  • Do one thing and do it well
  • Explicit > Implicit
  • Performance > DRY
  • Safety belongs to users

Package Details

Install command (Click to copy)


Version

1.1.1

License

MPL-2.0

warning

Usable with conditions

infoFile-level copyleft: if you modify this package's own source files, those modified files must be made available under MPL-2.0. Using it unmodified in a closed-source game is fine.

infoThe package archive does not include its license text; the license is declared in its manifest metadata.

Automated license review — not legal advice.