Skip to content

TimeleapLabs/sia

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sia

Binary serialization that gets out of your way.

Sia is a fast, compact binary serialization library with native implementations in TypeScript, Go, Python, and C++. No field tags, no type markers: just values and length prefixes. All four implementations produce the same bytes on the wire, so you can serialize in one language and deserialize in another.

Repositories

Language Repo Package Install
TypeScript ts-sia @timeleap/sia npm install @timeleap/sia
Go go-sia github.com/TimeleapLabs/go-sia/v2 go get github.com/TimeleapLabs/go-sia/v2
Python py-sia timeleap-sia pip install timeleap-sia
C++ cpp-sia CMake FetchContent or add_subdirectory
Schema sia-schema @timeleap/sia-schema npm install -g @timeleap/sia-schema

Quick Example

Define a User, serialize it, read it back:

TypeScript

import { Sia } from "@timeleap/sia";

const sia = new Sia();
sia.addString8("Alice").addUInt8(30).addBool(true);

sia.seek(0);
console.log(sia.readString8()); // "Alice"
console.log(sia.readUInt8()); // 30
console.log(sia.readBool()); // true

Go

import sia "github.com/TimeleapLabs/go-sia/v2/pkg"

s := sia.New()
s.AddString8("Alice").AddUInt8(30).AddBool(true)

s.Seek(0)
fmt.Println(s.ReadString8())  // "Alice"
fmt.Println(s.ReadUInt8())    // 30
fmt.Println(s.ReadBool())     // true

Python

from sia import Sia

s = Sia()
s.add_string8("Alice").add_uint8(30).add_bool(True)

s.seek(0)
print(s.read_string8())   # "Alice"
print(s.read_uint8())     # 30
print(s.read_bool())      # True

C++

#include <sia/sia.hpp>

auto s = sia::New();
s->AddString8("Alice");
s->AddUInt8(30);
s->AddBool(true);

s->Seek(0);
std::cout << s->ReadString8() << std::endl;  // "Alice"
std::cout << s->ReadUInt8() << std::endl;    // 30
std::cout << s->ReadBool() << std::endl;     // true

Why Sia

  • 2-4x faster than JSON, MessagePack, and Protobuf in TypeScript benchmarks
  • 14-77% smaller wire format: no field names, no type markers, just values and length prefixes
  • Zero dependencies in every language: pure standard-library code, no native modules, no WASM
  • Schema compiler: define types in .sia files, generate serializers for all four languages

Schema Compiler

Instead of writing addString8 / readString8 calls by hand, define your types once:

schema User {
  name    string8
  age     uint8
  email   string16
  active  bool
}

Then generate code for any target language:

sia compile user.sia -o user.ts
sia compile user.sia -o user.go
sia compile user.sia -o user.py
sia compile user.sia -o user.cpp

The schema compiler is a Node.js CLI tool (@timeleap/sia-schema). The generated code is native to each target language with no Node.js dependency. See the sia-schema repo for details.

Documentation

This repository contains the unified documentation site for all Sia implementations, built with Docus.

Running locally

npm install
npm run dev

The site starts at http://localhost:3000.

Structure

content/
  index.md               Landing page
  docs/
    0.index.md           Introduction
    1.installation.md    Installation for all languages
    2.quickstart.md      Quick start guide
    3.core/              Buffer management, serialization, deserialization
    4.api/               API reference (integers, strings, byte arrays, arrays, booleans, bigint)
    6.schema/            Schema compiler docs (syntax, code generation, plugins, VS Code)
    7.guides/            Data types, memory management, performance
    8.advanced/          Unsafe buffers, custom serialization, benchmarks

License

ISC

About

Sia binary serialization library: documentation and cross-language reference

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors