Reimplementation of keichi/binary-parser, supporting both streams and serialization.
The API is mainly the same as
binary-parser's, with a couple of additions and one removed method.
Dropped support for Due to undefined behavior,
.skipis not supported. As a workaround the
.buffermethod can be used.
.streammethod returns a transform stream that reads incoming data and emits parser results. The parser instance is looped until the end of the input is reached.
As a counterpart to
.serializetakes an object and returns a buffer representation of it. Optionally, an already allowcated buffer can be passed as a second argument.
.fixedSizeNestis a variation of
nestthat ensures the nested parser reads a specific amount of bytes. Fixed-size nested parsers are the only source of ambiguity remaining while serializing, as missing bytes are simply skipped. And error is thrown during serialization if the nested parser attempts to write more bytes than the size permits.
Properties with a specified formatting function need to also provide a
formatters require a
deformatterfunction that restores the original value.
As a very simple extension, the
flattenoption allows nested parsers to write to the current object. Its motivation is the aim for a flat output structure after
Bitfields can be (almost) infinitely longA relaxation from the 32 bit limit of
binary-parser. Also, a bug of the original project that leads to the
bit32method always parsing a value of
0is not present.