# pbjs

> A minimal implementation of Google Protocol Buffers for JavaScript

Latest version **0.0.14** (published 2019-11-25) · 0 weekly downloads

## Install

```sh
npm install pbjs
pnpm add pbjs
yarn add pbjs
bun add pbjs
```

Provides the command `pbjs`.

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.14 |
| Published | 2019-11-25 |
| First published | 2016-04-14 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 397.7 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Maintainers | evanw |

## Links

- npm: https://www.npmjs.com/package/pbjs
- npm.io page: https://npm.io/package/pbjs

## Dependencies (2)

- [commander](https://npm.io/package/commander.md) 4.0.1
- [protocol-buffers-schema](https://npm.io/package/protocol-buffers-schema.md) 3.1.0

## Recent versions

- 0.0.14 (latest) — 2019-11-25
- 0.0.13 — 2019-11-24
- 0.0.12 — 2019-11-24
- 0.0.11 — 2019-11-24
- 0.0.10 — 2019-11-23
- 0.0.9 — 2019-11-22
- 0.0.8 — 2019-11-22
- 0.0.7 — 2019-11-22
- 0.0.6 — 2019-11-22
- 0.0.5 — 2017-07-13
- 0.0.4 — 2017-07-13
- 0.0.3 — 2016-04-21
- 0.0.2 — 2016-04-14
- 0.0.1 — 2016-04-14

## README

# Protocol Buffers for JavaScript

This is a minimal implementation of [Google Protocol Buffers](https://developers.google.com/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.

## Command-Line Examples

* Generate ES5 JavaScript:

  ```
  pbjs wire-format.proto --es5 wire-format.js
  ```

  See [test.proto.es5.js](https://github.com/evanw/pbjs/blob/master/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](https://github.com/evanw/pbjs/blob/master/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](https://github.com/evanw/pbjs/blob/master/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
  ```

## API Example

```js
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 }
```

---
_Source: https://npm.io/package/pbjs · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
