Skip to content

joeedh/STRUCT

Repository files navigation

nSTRUCT.js

nSTRUCT.js is a ProtoBuf-like serialization system for JavaScript. It's designed with JavaScript in mind, and supports direct serialization/deserialization of objects (unlike ProtoBuf or JSON, which build intermediary objects).

Example

import * as nstructjs from "nstructjs";

class Point {
  constructor(x = 0, y = 0) { this.x = x; this.y = y; }
  loadSTRUCT(reader) { reader(this); }

  static STRUCT = nstructjs.inlineRegister(this, `
    Point { x : float; y : float; }
  `);
}

const data = [];                                  // write to a byte array
nstructjs.writeObject(data, new Point(1, 2));

const view = new DataView(new Uint8Array(data).buffer);
const p = nstructjs.readObject(view, Point);      // -> Point { x: 1, y: 2 }

Documentation

The maintained documentation lives in documentation/:

The full API reference is generated with TypeDoc (pnpm docs, output in docs/) and includes the pages above. The old GitHub wiki is deprecated.

Build

pnpm install
pnpm build      # build the library bundles into build/
pnpm test       # run the vitest suite
pnpm docs       # generate API docs into docs/

About

A nice little serialization scheme for ES6

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors