Low-Level API

Sia provides a low-level API for serializing and deserializing data. This API is ideal for developers who require fine-grained control over the serialization process.

ℹ️
Sia Schema
The low-level API is intended for developers who require fine-grained control over the serialization process. If you prefer a more high-level approach, consider using the Sia schema and the high-level API documented here.

Basics

Sia is a flat binary serialization format that stores data in a compact and efficient way. Sia strips away all unnecessary metadata and focuses on the essentials. The Sia format is designed to be fast, small, and easy to use.

The low-level API defines a set of methods for adding and reading data. Libraries for each language follow the naming conventions of the language. For example, in JavaScript, the method to add a is , while in Go, the method is , and in Python, the method is .

At the end of each function name, the number represents the number of bytes used to store the data, or the number of bytes required to store the length of an or . For example, stores an value in one byte, while stores an with a length that fits in eight bytes (up to).

JavaScript/TypeScript

Install the Sia package from npm:

Then, use the following code to serialize and deserialize a JavaScript object:

⚠️
Shared Buffers
For performance reasons, the JS Sia class uses a shared buffer for all instances. If you need a dedicated buffer for each instance, you can create a new buffer and pass it to the Sia constructor. You can also use the function to allocate a new buffer. To use a slice of the shared buffer, you can use the function. The function is faster than the function, and keeps track of the slice length. It guarantees no overlap with other slices, until the combined length of all slices exceeds the shared buffer length.
ℹ️
Special ASCII Type
The method is a spcial method only available in the JavaScript/TypeScript Sia implementation. It is added for performance reasons, and is not available in other Sia implementations. In other languages, an ASCII string value can be read and written using the and methods.

Arrays

You can serialize and deserialize arrays of objects using the Sia low-level API like this:

Golang

Install the Sia package from GitHub:

Then, use the following code to serialize a Go struct:

Arrays

You can serialize and deserialize arrays of objects using the Sia low-level API like this:

Python

Install the Sia package from PyPI:

Then, use the following code to serialize and deserialize a Python object:

Arrays

You can serialize and deserialize arrays of objects using the Sia low-level API like this:

How was this page?

Timeleap SA.

Pl. de l'Industrie 2, 1180 Rolle, Switzerland

Logo

Social Media

Tokenomics

Info