
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
This is a minimal implementation of Google Protocol Buffers for JavaScript and TypeScript. It generates completely self-contained code without any dependencies. Install it using npm:
npm install pbjs
Unlike other JavaScript implementations, this library doesn't write out default values. This makes it possible to tell if a field has been written at all or not, which allows for efficient encoding of maps. For example, it's possible to distinguish between a missing list and a list that is present but empty.
Generate ES5 JavaScript:
pbjs wire-format.proto --es5 wire-format.js
See test.proto.es5.js for an example of the generated code.
Generate ES6 JavaScript:
pbjs wire-format.proto --es6 wire-format.js
See test.proto.es6.js for an example of the generated code.
Generate TypeScript:
pbjs wire-format.proto --ts wire-format.ts
See test.proto.ts for an example of the generated code.
Convert to JSON:
pbjs wire-format.proto --decode MessageType < wire-format.bin > wire-format.json
Convert to Binary:
pbjs wire-format.proto --encode MessageType < wire-format.json > wire-format.bin
const pbjs = require('pbjs');
const schema = pbjs.parseSchema(`
message Demo {
optional int32 x = 1;
optional float y = 2;
}
`).compile();
const buffer = schema.encodeDemo({x: 1, y: 2});
console.log(buffer);
const message = schema.decodeDemo(buffer);
console.log(message);
Running the above code should output this:
<Buffer 08 01 15 00 00 00 40>
{ x: 1, y: 2 }
FAQs
A minimal implementation of Google Protocol Buffers for JavaScript
The npm package pbjs receives a total of 2,768 weekly downloads. As such, pbjs popularity was classified as popular.
We found that pbjs demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.