All Projects → pouya-eghbali → sia

pouya-eghbali / sia

Licence: Apache-2.0 License
Sia - Binary serialisation and deserialisation

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to sia

Bincode
A binary encoder / decoder implementation in Rust.
Stars: ✭ 1,100 (+2015.38%)
Mutual labels:  encoding, serialization, binary
Pbf
A low-level, lightweight protocol buffers implementation in JavaScript.
Stars: ✭ 618 (+1088.46%)
Mutual labels:  encoding, serialization, binary
Binary
Generic and fast binary serializer for Go
Stars: ✭ 86 (+65.38%)
Mutual labels:  encoding, serialization, binary
sirdez
Glorious Binary Serialization and Deserialization for TypeScript.
Stars: ✭ 20 (-61.54%)
Mutual labels:  encoding, serialization, binary
Qs
Quick serialization of R objects
Stars: ✭ 225 (+332.69%)
Mutual labels:  encoding, serialization
Jsonlab
JSONLab: a native JSON/UBJSON/MassagePack encoder/decoder for MATLAB/Octave
Stars: ✭ 202 (+288.46%)
Mutual labels:  encoding, serialization
protodata
A textual language for binary data.
Stars: ✭ 35 (-32.69%)
Mutual labels:  serialization, binary
ronin-support
A support library for Ronin. Like activesupport, but for hacking!
Stars: ✭ 23 (-55.77%)
Mutual labels:  encoding, binary
Bitmatch
A Rust crate that allows you to match, bind, and pack the individual bits of integers.
Stars: ✭ 82 (+57.69%)
Mutual labels:  encoding, binary
GenericProtocol
⚡️ A fast TCP event based buffered server/client protocol for transferring data over the (inter)net in .NET 🌐
Stars: ✭ 38 (-26.92%)
Mutual labels:  serialization, binary
nason
🗜 Ultra tiny serializer / encoder with plugin-support. Useful to build binary files containing images, strings, numbers and more!
Stars: ✭ 30 (-42.31%)
Mutual labels:  serialization, binary
Phpasn1
A PHP library to encode and decode arbitrary ASN.1 structures using ITU-T X.690 encoding rules.
Stars: ✭ 136 (+161.54%)
Mutual labels:  encoding, binary
Msgpack
msgpack.org[Go] MessagePack encoding for Golang
Stars: ✭ 1,353 (+2501.92%)
Mutual labels:  encoding, serialization
surge
Simple, specialised, and efficient binary marshaling
Stars: ✭ 36 (-30.77%)
Mutual labels:  serialization, binary
Bois
Salar.Bois is a compact, fast and powerful binary serializer for .NET Framework. With Bois you can serialize your existing objects with almost no change.
Stars: ✭ 53 (+1.92%)
Mutual labels:  serialization, binary
parco
🏇🏻 generalist, fast and tiny binary parser and compiler generator, powered by Go 1.18+ Generics
Stars: ✭ 57 (+9.62%)
Mutual labels:  serialization, binary
GroBuf
Fast binary serializer
Stars: ✭ 56 (+7.69%)
Mutual labels:  serialization, binary
content inspector
Fast inspection of binary buffers to guess/determine the type of content
Stars: ✭ 28 (-46.15%)
Mutual labels:  encoding, binary
Scodec
Scala combinator library for working with binary data
Stars: ✭ 709 (+1263.46%)
Mutual labels:  encoding, binary
Apex.Serialization
High performance contract-less binary serializer for .NET
Stars: ✭ 82 (+57.69%)
Mutual labels:  serialization, binary

Codacy Badge codecov

Sia

Sia - Binary serialisation and deserialisation with built-in compression. You can consider Sia a strongly typed, statically typed domain specific binary language for constructing data. Sia preserves data types and supports custom ones.

Please note the Sia specification and implementation isn't final yet. As a core part of Clio programming language, Sia evolves with Clio. It is made to make fast RPC calls possible.

Why

I needed a fast schema-less serialization library that preserves type info and is able to code/decode custom types. I couldn't find one. At first I wanted to go with a JSON with types solution but it didn't work out, so I created my own.

Performance

This repository contains a pure JS implementation of Sia, on our test data Sia is 66% to 1250% faster than JSON and serialized data (including type information for all entries) is 10% to 30% smaller than JSON. Sia is faster and smaller than MessagePack and CBOR/CBOR-X. It is possible to use lz4 to compress Sia generated data even more and still be faster than JSON, MessagePack and CBOR-X.

Sia

Tests are run on a 2.4 GHz 8-Core Intel Core i9-9980HK CPU (5 GHz while running the benchmarks) with 64 GB 2667 MHz DDR4 RAM. Node version 16.4.2, Mac OS 11.5.1. 100 loops each serialization library. To run the benchmark suite you can run npm run benchmark and to run the tests you can run npm run test.

Specification

Read specs.md.

Install

To install the Node library and save it as a dependency, do:

npm i -S sializer

Documentation

WIP

The Node Sia library exports 5 items:

const { sia, desia, Sia, DeSia, constructors } = require("sializer");
  • sia(data) function serializes the given data using the default parameters.
  • desia(buf) function deserializes the given buffer using the default parameters.
  • Sia(options) class makes an instance of Sia serializer using the given options.
  • DeSia(options) class makes an instance of Sia deserializer using the given options.
  • constructors is an array of default constructors used both by Sia and DeSia.

The Sia and DeSia objects are the core components of the Sia library.

Basic usage

const { sia, desia } = require("sializer");

const buf = sia(data);
const result = desia(buf);

Sia class

const sia = new Sia({
  size = 33554432, // Buffer size to use
  constructors = builtinConstructors // An array of extra classes and types
});

const buf = sia.serialize(data);

Where size is the maximum size of buffer to use, use a big size if you're expecting to serialize huge objects. The constructors option is an array of extra types and classes, it includes instructions for serializing the custom types and classes.

DeSia class

const desia = new DeSia({
  mapSize = 256 * 1000, // String map size
  constructors = builtinConstructors, // An array of extra classes and types
});

const data = desia.deserialize(buf);

Where mapSize is the minimum size of string map array to use, use a big size if you're expecting to serialize huge objects. The constructors option is an array of extra types and classes, it includes instructions for deserializing the custom types and classes.

sia function

const buf = sia(data);

The sia function is the Sia.serialize method on an instance initialized with the default options.

desia function

const data = desia(buf);

The desia function is the DeSia.deserialize method on an instance initialized with the default options.

constructors

The constructors option is an array of extra types and classes that Sia should support. Here's an example of how to use it:

const { Sia, DeSia } = require("sializer");
const { constructors: builtins } = require("sializer");

const constructors = [
  ...builtins,
  {
    constructor: RegExp, // The custom class you want to support
    code: 7, // A unique positive code point for this class, the smaller the better
    args: (item) => [item.source, item.flags], // A function to serialize the instances of the class
    build(source, flags) { // A function for restoring instances of the class
      return new RegExp(source, flags);
    },
  },
];

const sia = new Sia({ constructors });
const desia = new DeSia({ constructors });

const regex = /[0-9]+/;
const buf = sia.serialize(regex); // serialize the data
const result = desia.deserialize(buf); // deserialize
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].