• Stars
    star
    117
  • Rank 301,828 (Top 6 %)
  • Language
    Zig
  • License
    MIT License
  • Created over 2 years ago
  • Updated 10 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A zig binary serialization format.

struct to stream | stream to struct

A Zig binary serialization format and library.

Project logo

Features

  • Convert (nearly) any Zig runtime datatype to binary data and back.
  • Computes a stream signature that prevents deserialization of invalid data.
  • No support for graph like structures. Everything is considered to be tree data.

Unsupported types:

  • All comptime only types
  • Unbound pointers (c pointers, pointer to many)
  • volatile pointers
  • Untagged or external unions
  • Opaque types
  • Function pointers
  • Frames

API

The library itself provides only some APIs, as most of the serialization process is not configurable.

/// Serializes the given `value: T` into the `stream`.
/// - `stream` is a instance of `std.io.Writer`
/// - `T` is the type to serialize
/// - `value` is the instance to serialize.
fn serialize(stream: anytype, comptime T: type, value: T) StreamError!void;

/// Deserializes a value of type `T` from the `stream`.
/// - `stream` is a instance of `std.io.Reader`
/// - `T` is the type to deserialize
fn deserialize(stream: anytype, comptime T: type) (StreamError || error{UnexpectedData,EndOfStream})!T;

/// Deserializes a value of type `T` from the `stream`.
/// - `stream` is a instance of `std.io.Reader`
/// - `T` is the type to deserialize
/// - `allocator` is an allocator require to allocate slices and pointers.
/// Result must be freed by using `free()`.
fn deserializeAlloc(stream: anytype, comptime T: type, allocator: std.mem.Allocator) (StreamError || error{ UnexpectedData, OutOfMemory,EndOfStream })!T;

/// Releases all memory allocated by `deserializeAlloc`.
/// - `allocator` is the allocator passed to `deserializeAlloc`.
/// - `T` is the type that was passed to `deserializeAlloc`.
/// - `value` is the value that was returned by `deserializeAlloc`.
fn free(allocator: std.mem.Allocator, comptime T: type, value: T) void;

Usage and Development

Adding the library

Just add the s2s.zig as a package to your Zig project. It has no external dependencies.

Running the test suite

[user@host s2s]$ zig test s2s.zig
All 3 tests passed.
[user@host s2s]$

Project Status

Most of the serialization/deserialization is implemented for the trivial case.

Pointers/slices with non-standard alignment aren't properly supported yet.

More Repositories

1

zgl

Zig OpenGL Wrapper
Zig
380
star
2

known-folders

Provides access to well-known folders across several operating systems
Zig
218
star
3

zlm

Zig linear mathemathics
Zig
142
star
4

positron

A web renderer frontend for zig applications
C++
107
star
5

repository

A community-maintained repository of zig packages
Zig
101
star
6

ansi-term

Zig library for dealing with ANSI terminals
Zig
64
star
7

zinput

A Zig command-line input library!
Zig
47
star
8

zig-lsp

Microsoft's Language Server Protocol implemented in Zig for use in zls and beyond! <3
Zig
44
star
9

tres

ValueTree-based JSON parser
Zig
39
star
10

treez

tree-sitter bindings for Zig
Zig
38
star
11

antiphony

A zig remote procedure call solution
Zig
32
star
12

fontaine

A library to support text rendering in arbitrary contexts
Zig
32
star
13

funzig

Fun functional functionality for Zig!
Zig
30
star
14

zig-lv2

Zig-intuitive bindings for LV2.
Zig
29
star
15

zorm

Lightweight and efficient object-relational mapping
Zig
26
star
16

eggzon

πŸ₯šZon - A DOM based Zig Object Notation parser
Zig
22
star
17

ini

A teeny tiny ini parser
Zig
21
star
18

diffz

Implementation of go-diff's diffmatchpatch in Zig
Zig
19
star
19

painterz

Low-level implementation of different painting primitives (lines, rectangles, ...) without specialization on a certain draw target
Zig
19
star
20

string-searching

String(not limited to []const u8)-searching algorithms in zig
Zig
18
star
21

tree-sitter-zig

Zig tree-sitter grammar
JavaScript
18
star
22

zigfp

Basic fixed point implementation in Zig.
Zig
18
star
23

zCOM

A composable network protocol stack for embedded and desktop.
Zig
15
star
24

lscolors

A zig library for colorizing paths according to LS_COLORS
Zig
14
star
25

computils

Zig utilities for all your comptime needs.
Zig
9
star
26

zig-windows-console

Zig Windows Console stuff
Zig
6
star
27

comptemplate

Comptime Templates
Zig
5
star
28

zwin

Making windows with Zig! (Only works on Windows at the moment)
Zig
4
star
29

zdb

Allocator-free document oriented database management. WIP
Zig
3
star
30

wavefront-obj

A parser for wavefront object files
Zig
2
star
31

package-collector

Collects packages from all over the ziguanity.
Go
2
star
32

uuencode

Unix-To-Unix-Encoding for Zig
Zig
1
star