0.3.2 • Published 6 months ago

ebinary v0.3.2

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

ebinary

Description

Statically typed data binary encoding library. Dependency free. Good types supporting.

Installation

npm i ebinary

Usage

import { Encoder, Type } from 'ebinary';

const encoder = new Encoder(Type.Array(Type.Struct({
    id: Type.UInt32(),
    count: Type.UInt16(),
    enabled: Type.Nullable(Type.Bool()),
})));

const buffer = encoder.encode([
    { id: 1, count: 123, enabled: null },
    { id: 2, count: 756, enabled: true },
    { id: 3, count: 435, enabled: false },
]);

const value = encoder.decode(buffer);

Supported types

NameByte lengthJS typeDescription
Struct<T>...{...T}-
OneOf<T>1,2+...{$key:T[$key]}Only one of properties provided
Array<T,L>sizeof(L)+...T[]L - typeof length
String<L>sizeof(L)+...stringutf8 / ascii. L - typeof length
Buffer<L>sizeof(L)+...Uint8ArrayL - typeof length
Enum<T>1,2T-
Const<T>0TNot encodes into buffer
Nullable<T>1+...T\|nullundefined encodes as null
Aligned<T,A>0,7+...TAdd trailing empty bytes for desired bytes align (A) (eg. for C struct compatibility)
UVarInt321, 5numbervariable length unsigned int
VarInt321, 5numbervariable length signed int
Bool1boolean-
Float648numberlittle / big endian
Float324numberlittle / big endian
UInt648bigintlittle / big endian
Int648bigintlittle / big endian
UInt324numberlittle / big endian
Int324numberlittle / big endian
UInt162numberlittle / big endian
Int162numberlittle / big endian
UInt81number-
Int81number-
0.3.0

6 months ago

0.3.2

6 months ago

0.3.1

6 months ago

0.2.2

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago