madson
madson is a binary serialization library for javascript.
Supports recursive self references.
Installation
npm install --save madson
Usage
var madson = ; var obj1 = n: 1 s: 'string' a: 3 z: 4 r: /av[sx]*/gi d: o: p: 1 q: 2 z: false b: true ; JSON // -> string (111 bytes) obj1self = obj1; // JSON.stringify(obj1) -> TypeError: Converting circular structure to JSON var buf = madson; // -> Buffer [75 bytes] var obj2 = madson; // obj1 != obj2 // obj2.self == obj2 // obj2.r instanceof RegExp // obj2.d instanceof Date
Custom Class Types
var madson = ; var preset = madsoncodecpreset;preset;preset; { thisx = x; thisy = y;} { var array = cx cy; // return serialized Buffer return madson;} { var array = madson; // return deserialized Object return array0 array1;} var data = 1 2;var encoded = madson;console; var decoded = madson;console;