protobufjs
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
@protobufjs/aspromise | 1.1.2 | 2.53 kB | BSD-3-Clause | prod | |
@protobufjs/base64 | 1.1.2 | 3.17 kB | BSD-3-Clause | prod | |
@protobufjs/codegen | 2.0.4 | 3.33 kB | BSD-3-Clause | prod | |
@protobufjs/eventemitter | 1.1.0 | 2.7 kB | BSD-3-Clause | prod | |
@protobufjs/fetch | 1.1.0 | 3.25 kB | BSD-3-Clause | prod | |
@protobufjs/float | 1.0.2 | 5.89 kB | BSD-3-Clause | prod | |
@protobufjs/inquire | 1.1.0 | 2.21 kB | BSD-3-Clause | prod | |
@protobufjs/path | 1.1.2 | 2.64 kB | BSD-3-Clause | prod | |
@protobufjs/pool | 1.1.0 | 2.5 kB | BSD-3-Clause | prod | |
@protobufjs/utf8 | 1.1.0 | 9.4 kB | BSD-3-Clause | prod | |
@types/node | 20.12.7 | 1.94 MB | MIT | prod | |
long | 5.2.3 | 24.15 kB | Apache-2.0 | prod |
Protobufjs is a pure JavaScript and TypeScript library that provides a language-neutral, platform-neutral, extensible way of serializing structured data. It's designed for use in communications protocols, data storage, and more. It is a Protocol Buffers (Protobuf) implementation targeting Node.js and browsers. It can parse and compile .proto definition files into ready-to-use message classes, convert between JSON and typed arrays, and dynamically generate message types or bundle an optimized version of all schema types. The generated message types are reflection-based by default, thus being comparable to dynamic messages in other languages.
To use protobufjs in your Node.js or JavaScript applications, first, you need to install protobufjs via npm with the following command:
npm install protobufjs
Next, you can require protobufjs in your project as shown below:
var protobuf = require("protobufjs");
The protobufjs library provides several utility functions for working with Protocol Buffers, including load, encode, decode, and verify as well as numerous others. Here is a sample usage:
protobuf.load("awesome.proto", function(err, root) {
if (err) throw err;
var AwesomeMessage = root.lookupType("awesomepackage.AwesomeMessage");
var payload = { awesomeField: "AwesomeString" };
var errMsg = AwesomeMessage.verify(payload);
if (errMsg) throw Error(errMsg);
var message = AwesomeMessage.create(payload);
var buffer = AwesomeMessage.encode(message).finish();
var decodedMessage = AwesomeMessage.decode(buffer);
});
In the provided example, protobufjs loads a .proto file, looks up a message type and verifies its payload. Then, it creates a valid message, encodes it to a buffer, and finally decodes the buffer back to a message.
The documentation for protobufjs is located right within the project's Github repository README file, the link is: Protobuf.js README. Further detailed API documentation for more advanced uses and concepts can be accessed at API Documentation. Also, users can access the CHANGELOG for updates, fixes, and enhancements. Community support can be found on StackOverflow with the protobuf.js tag.