Note
This repository has been archived and is no longer maintained.
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
deno test
Import what you need from mod.ts
Can be found at https://github.com/glooca/parser/wiki
There's also deno's auto generated docs
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);