API Reference
protobuf.js
JavaScript Protocol Buffers implementation with runtime message classes, reflection, and JSON mapping.
Official Documentation ↗CompatibilityThis documentation covers version
v8.8.1. Check the official docs for the latest API surface.Installation
npm
npm install protobufjsMethods
No methods match this filter.
protobufjs loads .proto schemas at runtime or uses generated static code to encode and decode messages.
Key Features
- Dynamic reflection or static generated code
- toObject and fromObject JSON mapping
- verify for schema validation
Usage Notes
Pin a version and check the official docs for the API surface you depend on before upgrading.
Errors
The following points are quoted verbatim from the official documentation (https://github.com/protobufjs/protobuf.js). Any error type, throw condition or recovery step not stated there is left unspecified; this page does not infer exception classes or return values.
- Instead of throwing, it returns the error message as a string, if any. (https://github.com/protobufjs/protobuf.js)
- If required fields are missing, it throws a util.ProtocolError with an instance property set to the so far decoded message. (https://github.com/protobufjs/protobuf.js)
FAQ
- What is the difference between static and dynamic code?
- pbjs generates static modules with typed classes for build-time speed, while protobuf.load parses schemas at runtime, which is flexible but slower.
- How do I map enums and bytes in JSON?
- Pass options such as enums: String and bytes: String to toObject, or define your own conversion functions.
- Does protobufjs validate messages?
- Yes. Type.verify reports schema violations before encode, though Type.fromObject also coerces common mismatches.
Report a problem with this API docOpens a pre-filled issue on GitHub.