Introduction
What is Sia?
Sia is a binary serialization and deserialization library. It provides a chainable API for reading and writing typed binary data into byte buffers. No schemas required, no code generation needed, no boilerplate.
Sia has native implementations in TypeScript, Go, Python, and C++, all sharing the same wire format. Data serialized in one language can be deserialized in another.
Sia is the serialization format used by the Timeleap network. It is designed for high throughput and minimal allocations, making it well-suited for network protocols, WebSocket communication, file formats, and any scenario where JSON is too slow or too large.
Key Features
- Fast: In our benchmarks, 2-4x faster than JSON, MessagePack, CBOR, and Protobuf for serialization.
- Multi-language: Native implementations in TypeScript, Go, Python, and C++ with the same wire format.
- Compact: No field tags, no type markers, no key names. 14-77% smaller than equivalent JSON.
- Chainable: All
add*methods return the instance, enabling fluent one-liner serialization. - Zero-copy capable: Optional reference-based reads avoid unnecessary memory copies (TypeScript).
- Schema compiler: Optional schema language with code generation for all four languages.
How It Works
Sia works by writing typed values sequentially into a byte buffer. You serialize data with add* methods and deserialize it with the corresponding read* methods, in the same order.
import { Sia } from "@timeleap/sia";
// Serialize
const sia = new Sia();
sia.addString8("Alice").addUInt8(30).addBool(true);
const bytes = sia.toUint8Array();
// Deserialize
const reader = new Sia(bytes);
const name = reader.readString8(); // "Alice"
const age = reader.readUInt8(); // 30
const active = reader.readBool(); // true
The add* and read* methods are symmetric: every write method has a matching read method. The number suffix (8, 16, 32, 64) indicates the bit width used to store the value or its length prefix:
- For integers, the suffix is the storage size:
addUInt8stores 1 byte,addUInt32stores 4 bytes. - For strings and byte arrays, the suffix indicates the length prefix size:
addString8prefixes the string data with a 1-byte length (max 255 bytes), whileaddString32uses a 4-byte length prefix (max ~4 GB). - For arrays, the suffix indicates the length prefix for the array count:
addArray8supports up to 255 elements,addArray32up to ~4 billion.
Quick Start
Install
npm install @timeleap/sia
Serialize and deserialize
import { Sia } from "@timeleap/sia";
const sia = new Sia();
sia.addString8("Hello, Sia!").addUInt32(2025).addBool(true);
const bytes = sia.toUint8Array();
const reader = new Sia(bytes);
console.log(reader.readString8()); // "Hello, Sia!"
console.log(reader.readUInt32()); // 2025
console.log(reader.readBool()); // true
Explore by Topic
Language Support
Sia has native implementations in four languages. The core API is the same across all of them: add* methods to serialize, read* methods to deserialize, chainable calls, and the same wire format.
| Feature | TypeScript | Go | Python | C++ |
|---|---|---|---|---|
| Integers (8-64 bit) | ||||
| Strings (N/8/16/32/64) | ||||
| Byte arrays | ||||
| Booleans | ||||
| BigInt | ||||
| Typed arrays | ||||
| ASCII encoding | ||||
| UTFZ compression | ||||
| Functional API | ||||
| Shared buffer pool |
Use the language selector in the sidebar to switch all code examples across the docs.