Protocol Buffers are a language-neutral, platform-neutral, extensible way of serializing structured data for use in communications protocols, data storage, and more, originally designed at Google (see).
protobuf.js is a pure JavaScript implementation with TypeScript support for node.js and the browser. It's easy to use, blazingly fast and works out of the box with .proto files!
-
Installation
How to include protobuf.js in your project. -
Usage
A brief introduction to using the toolset. -
Examples
A few examples to get you started. -
Command line
How to use the command line utility. -
Additional documentation
A list of available documentation resources. -
Performance
A few internals and a benchmark on performance. -
Compatibility
Notes on compatibility regarding browsers and optional libraries. -
Building
How to build the library and its components yourself.
$> npm install protobufjs [--save --save-prefix=~]
var protobuf = require("protobufjs");
Note that this library's versioning scheme is not semver-compatible for historical reasons. For guaranteed backward compatibility, always depend on ~6.A.B
instead of ^6.A.B
(hence the --save-prefix
above).
Development:
<script src="//cdn.rawgit.com/dcodeIO/protobuf.js/6.X.X/dist/protobuf.js"></script>
Production:
<script src="//cdn.rawgit.com/dcodeIO/protobuf.js/6.X.X/dist/protobuf.min.js"></script>
Remember to replace the version tag with the exact release your project depends upon.
The library supports CommonJS and AMD loaders and also exports globally as protobuf
.
Where bundle size is a factor, there are additional stripped-down versions of the full library (~19kb gzipped) available that exclude certain functionality:
-
When working with JSON descriptors (i.e. generated by pbjs) and/or reflection only, see the light library (~16kb gzipped) that excludes the parser. CommonJS entry point is:
var protobuf = require("protobufjs/light");
-
When working with statically generated code only, see the minimal library (~6.5kb gzipped) that also excludes reflection. CommonJS entry point is:
var protobuf = require("protobufjs/minimal");
Because JavaScript is a dynamically typed language, protobuf.js introduces the concept of a valid message in order to provide the best possible performance (and, as a side product, proper typings):