serialization/deserialization library for JavaScript and TypeScript on Browser or Server (not yet) with built in compression.
Its intended to be educational resource (with a goal to become more than that)
Install the library with your package manager of choice, e.g.:
yarn add <TODO solidbuff>
The easiest way to use SolidBuff is with its built in instance (<TODO>/instance
) and serialize
, deserialize
methods.
Easily serialize all of your data:
import sb from 'solidbuff/node'; // or
// import sb from 'solidbuff/browser';
const object = { date: new Date(0)};
const payload = sb.serialize(object);
// payload => Uint8Array([84,40,4,0,100,0,97,0,116,0,101,60,0,0,0,0,0,0,0,0,85]) // 21B
And deserialize it:
const object = sb.deserialize<{ date: Date }>(payload);
// object => { date: new Date(0) }
(TS) Make sure to have
"moduleResolution": "NodeNext"
setup in tsconfig for it to work correctly
{
"compilerOptions": {
"moduleResolution": "NodeNext"
}
}
For quite some time now i was thinking about how it would be really nice to have faster and more performant way to send data between two sources.
I already had contact with similar things (protobuf's, msgpack, etc...) and got idea to build my own in TypeScript, for fun ofc.
It should be:
- Simple codebase
- Lightweight clients
- Extensible serialization/deserialization
- Performance (needs more work/testing 😅)
- Small data transferred over the wire
- Schema-less
- Language agnostic (It should be possible, but JavaScript is first citizen, unless)
Its done by using Buffers in Nodejs, in browsers they are more known as ArrayBuffer.
Its an array of bytes, to manipulate with them we need to use view objects.
To have schema-less but still strongly typed protocol, idea began from msgpack with mix of protobuf.
Its block based serialization. Each block is prefixed with single byte that defines whole block. some special types (e.g. objects) needs to have start and end "signals".
This document was inspired by the Sia spec file.
- Resizable buffer
- Add ability to add non-default data types
- Make it as fast as possible
Make server version- Make package to distribute easier (probably make separate packages)
- Add more examples (currently in
index.spec.ts
files) Use esbuild for bundling(used different tool)Use enums instead of raw numbers for types- Add eslint, prettier and similar tools
- Add docs
- Place at the end for inspiration and all the credits
- Add Rust and Go version (both server and client are same)
Thanks for checking