Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pbjs

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pbjs

A minimal implementation of Google Protocol Buffers for JavaScript

  • 0.0.5
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Protocol Buffers for JavaScript

This is a minimal implementation of Google Protocol Buffers for JavaScript. 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.

Command-Line Examples

  • Generate JavaScript:

    pbjs wire-format.proto --js wire-format.js
    

    The generated code depends only on bytebuffer.js. See test.proto.js 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
    

The generated JavaScript code

API Example

var pbjs = require('pbjs');
var fs = require('fs');

var schema = pbjs.parseSchema([
  'message Demo {',
  '  optional int32 x = 1;',
  '  optional float y = 2;',
  '}',
].join('\n')).compile();

var buffer = schema.encodeDemo({x: 1, y: 2});
console.log(buffer);

var 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

Package last updated on 13 Jul 2017

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc