js-ubf
Universal Binary Format (UBF)
import {parse, Parser} from "ubf";
function hexBuf(buf) {
return new Buffer(buf.replace(/[^0-9a-f]/gi, ""), "hex");
}
// ----------
let buf = hexBuf("20 0b 48 65 6c 6c 6f 20 57 6f 72 6c 64");
parse(buf).then((value) => {
// value = "Hello World"
});
// ----------
let p = new Parser();
p.context.on("value", (e) => {
// e.value = ...
});
p.parse(hexBuf("20 03 61 62 63"));
// e.value = "abc"
p.parse(hexBuf("30 07 41"));
// e.value = 7; e.value = true
p.parse(hexBuf("14 06 30 01 30 02 30 03"));
// e.value = [ 1, 2, 3 ]
Updated less than a minute ago