binary-parser-encoder is a JavaScript/TypeScript library designed for declaratively building binary data parsers and encoders. It stands as a feature-rich fork of the popular `binary-parser` project, notably extending its capabilities by adding an `encode` method to convert JavaScript objects back into binary buffers—a key differentiator absent in the original library. The current stable version, 1.5.3, has recently incorporated updates from the upstream `binary-parser` v1.7.0, ensuring continued compatibility while expanding functionality. The library dynamically generates and compiles parser/encoder code on-the-fly, achieving performance comparable to hand-written implementations. It supports a comprehensive set of data types including 8-bit to 64-bit integers, floating-point numbers, bit fields, strings, arrays, choices, and user-defined structures. Its release cadence is primarily influenced by updates to the upstream `binary-parser` and the ongoing development of its unique encoding features, with an explicit long-term goal of merging these enhancements back into the main project.
npm install binary-parser-encoderVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to define a binary parser and encoder for an IP packet header, then parse a hex buffer and encode a JavaScript object back to binary.
Always install `binary-parser-encoder` when encoding capabilities are required. Be mindful that API methods and options related to encoding are unique to this fork.
Review your TypeScript configuration and ensure compatibility. If type errors occur, consider updating your `@types/node` package or adjusting type assertions. Pure JavaScript users should perform thorough regression testing.
Ensure that `binary-parser-encoder` is correctly installed and that your import statements are referencing `Parser` from `binary-parser-encoder` to access the encoding functionality.
Understand that `smartBufferSize` is an optimization for encoding performance and memory usage. Adjust its value based on your specific encoding workload and system memory constraints.
For CommonJS, use `const { Parser } = require('binary-parser-encoder');`. For ESM, use `import { Parser } from 'binary-parser-encoder';`.Verify your `package.json` to ensure `binary-parser-encoder` is installed. Double-check your import statements to confirm that you are importing `Parser` specifically from `binary-parser-encoder`.
Ensure that `@types/binary-parser` is not installed if you are exclusively using `binary-parser-encoder`. This package ships its own type definitions, which correctly include the `encode` method. Restart your TypeScript language server or IDE after making dependency changes.
No dependency data recorded yet.