0.0.6 • Published 8 months ago

@coconut-xr/xserialization v0.0.6

Weekly downloads
-
License
SEE LICENSE IN LI...
Repository
github
Last release
8 months ago

@coconut-xr/xserialization

Version License Twitter Discord

fast and efficient js data serialization

Features

  • preserves referential integrity
  • can serialize recursive data structures
  • 0 dependencies
  • true to js (supports null, undefined, NaN, ...)
  • custom data types

API

type SerializationOptions = {
  custom?: {
    isCustom(data: any): boolean;
    /**
     * custom serilization function
     * @param serialize allows to serialize any value inside the custom serialization function
     * @returns the data type of the serialized value
     */
    serialize(writer: Writer, data: any, serialize: (data: any) => void): number;
    /**
     * custom deserialization function
     */
    deserialize(reader: Reader, dataType: number, deserialize: () => any): any;
  };
};
function serializeInto(writer: Writer, data: any, options: SerializationOptions = {}): void;
function deserializeFrom(reader: Reader, options: SerializationOptions = {}): any;

Usage

const value = "test";
const writer = new Writer();
serializeInto(writer, value);
const buffer = writer.finishReference();
const reader = new Reader();
reader.start(buffer);
const result = deserializeInto(reader);
reader.finish();
console.log(result);

Why so complex, you might ask?

Using this design reader and writer can be reused and serializeInto can be called multiple times to write into the same buffer.

Data Types

Namerange
Custom data type0 - 31
FixUint (values 0 to 31)32-63
FixNUint (values -1 to -32)64-95
FixStr (string length 0 to 31)96-127
FixPtr (pointer 0 to 31)128-159
FixArr (array length 0 to 31)160-191
FixObj8 (object length 0 to 31 with a key length of 0 to 256)192-223
NaN224
PosInf225
NegInf226
Null227
Undefined228
False229
True230
Float64231
Uint8232
Uint16233
Uint32234
NUint8235
NUint16236
NUint32237
Str8238
Str16239
Str32240
Pointer8241
Pointer16242
Pointer32243
Arr8244
Arr16245
Arr32246
Obj8247
Obj16248
Obj32249
Reserved for future use250-255

Achknowledgement

xserialization builds on the structure and idea of msgpack but focusses solely on js data.

0.0.6

8 months ago

0.0.5

8 months ago

0.0.4

9 months ago

0.0.3

9 months ago

0.0.2

9 months ago

0.0.1

9 months ago

0.0.0

9 months ago