Getting Started
Gives tools to describe binary structures with full TypeScript support. Encodes and decodes into pure JavaScript objects, while giving type context for the parsed data.
Install
Section titled “Install”npm install --save typed-binarypnpm add typed-binaryyarn add typed-binaryUse in the browser
Section titled “Use in the browser”import bin from 'typed-binary';
// Define a schemaconst Vec2f = bin.tupleOf([bin.f32, bin.f32]);const Vec2fSize = Vec2f.measure(bin.MaxValue).size;
const buffer = new ArrayBuffer(Vec2fSize);Vec2f.write(new bin.BufferWriter(buffer), [0.5, 3.14]);Use in Node.js
Section titled “Use in Node.js”import bin from 'typed-binary';
// Define a schemaconst Vec2f = bin.tupleOf([bin.f32, bin.f32]);const Vec2fSize = Vec2f.measure(bin.MaxValue).size;
const buffer = Buffer.alloc(Vec2fSize);Vec2f.write(new bin.BufferWriter(buffer), [0.5, 3.14]);