/parser

A simple parser for easily creating both encoding and decoding for a given data type

Primary LanguageTypeScriptMozilla Public License 2.0MPL-2.0

Note

This repository has been archived and is no longer maintained.

Binary parser

Deno Coverage deno land deno doc license

A simple parser for easily creating both encoding and decoding for a given data type

This project has no dependencies and should work in any typescript environment although it was developed mainly for deno

Running tests

deno test

🎉 Getting started

Import what you need from mod.ts

📝 Docs

Can be found at https://github.com/glooca/parser/wiki

There's also deno's auto generated docs

✏️ Example

import {
  coderFactory,
  nullTermStr,
  pad,
  u32,
} from "https://deno.land/x/binary_parser/mod.ts";

interface MyInterface {
  someProp: number;
  anotherProp: string;
}
const myCoder = coderFactory<MyInterface>((r) => {
  r(u32(), "someProp");
  r(pad(2));
  r(nullTermStr, "anotherProp");
});

const myData: MyInterface = { someProp: 420, anotherProp: "Hello, World!" };
const encoded: Uint8Array = await myCoder.encode(myData);
const decoded: MyInterface = await myCoder.decode(encoded);

// assertEqual(myData, decoded);