0.1.10 • Published 9 days ago

jserial v0.1.10

Weekly downloads
11
License
-
Repository
github
Last release
9 days ago

jserial

GitHub npm

Compressed and Fast JSON Serializer

Using Libraries

msgpackr, @evan/wasm/lz4

Quick Start

Installation

npm install jserial --save

Basic Usage

const JSONSerializer = require("jserial");
const serializer = new JSONSerializer();

const json = {
  hello: "world",
};
const serialized = serializer.serialize(json);
const deserialized = serializer.deserialize(serialized);
if (deserialized instanceof Error) {
  // Deserialize Error
}

Msgpack Custom Extension

const JSONSerializer = require("jserial");
class CustomClass {};
JSONSerializer.addExtension({
    class: CustomClass,
    type: 1, // 1 ~ 100
    read(instance) {
        return instance.customData;
    },
    write(data) {
        const customClass = new CustomClass();
        customClass.customData = data;
        return customClass;
    }
});

Using Msgpackr Dictionary

const JSONSerializer = require("jserial");
const serializer = new JSONSerializer("namespace");
// or
const serializer = new JSONSerializer({ namespace: "namespace" });

const json = {
  hello: "world",
};
const serialized = serializer.serialize(json);
const deserialized = serializer.deserialize(serialized);

Using simple En-Decoding (simple internal logic, sometimes fast than serialize)

const JSONSerializer = require("jserial");
const serializer = new JSONSerializer();

const json = {
  hello: "world",
};
const serialized = serializer.serializeSimple(json);
const deserialized = serializer.deserializeSimple(serialized);

Benchmark

Node Version: v20.9.0
Repeated 50 times
-----------------------Benchmark JSON Size: 488,002 bytes-----------------------
JSON.stringify                / CompressedSize:  488,002bytes (100.00%), Serialize:   1.14 ms, Deserialize:  1.08 ms
@msgpack/msgpack              / CompressedSize:  424,096bytes  (86.90%), Serialize:   2.02 ms, Deserialize:  2.76 ms
msgpack5                      / CompressedSize:  424,096bytes  (86.90%), Serialize:  23.64 ms, Deserialize:   9.2 ms
Msgpackr                      / CompressedSize:  426,578bytes  (87.41%), Serialize:   1.26 ms, Deserialize:  1.84 ms
JSON.stringify with Snappy    / CompressedSize:  155,540bytes  (31.87%), Serialize:    2.5 ms, Deserialize:   1.9 ms
Msgpackr with Snappy          / CompressedSize:  150,903bytes  (30.92%), Serialize:   1.52 ms, Deserialize:  1.88 ms
JSON.stringify with Brotli    / CompressedSize:   15,537bytes   (3.18%), Serialize:  90.16 ms, Deserialize:  2.64 ms
JSON.stringify with Inflate   / CompressedSize:   98,075bytes  (20.10%), Serialize:   8.64 ms, Deserialize:  2.72 ms
JSON.stringify with Gzip      / CompressedSize:   98,087bytes  (20.10%), Serialize:   8.74 ms, Deserialize:   2.6 ms
CBOR                          / CompressedSize:  423,927bytes  (86.87%), Serialize:  16.44 ms, Deserialize: 16.68 ms
Encodr MSGPACK                / CompressedSize:  424,096bytes  (86.90%), Serialize:   2.92 ms, Deserialize:  6.42 ms
Encodr JSON                   / CompressedSize:  488,002bytes (100.00%), Serialize:   1.24 ms, Deserialize:   1.1 ms
jserial                       / CompressedSize:   49,235bytes  (10.09%), Serialize:   1.14 ms, Deserialize:  0.58 ms
jserial simple                / CompressedSize:  122,747bytes  (25.15%), Serialize:   1.22 ms, Deserialize:  0.56 ms
--------------------------------------------------------------------------------
0.1.10

9 days ago

0.1.9

6 months ago

0.1.8

8 months ago

0.1.7

8 months ago

0.1.6

1 year ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago