Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Pure node.js Google Protocol Buffers implementation

branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time



NPM version Build status

Google Protocol Buffers pure JavaScript implementation for node.js.

Protocol buffers are Google's language-neutral, platform-neutral, extensible mechanism for serializing structured data – think XML, but smaller, faster, and simpler. You define how you want your data to be structured once, then you can use special generated source code to easily write and read your structured data to and from a variety of data streams and using a variety of languages – Java, C++, or Python.

And now Google Protocol Buffers are available in node.js without compiling binary addons!

This module has been tested with node.js versions 0.8.26, 0.10.22 and 0.11.9.

Based on prtbfr.php by Gaetano Giunta.

Check out the Github repo for the source code.


You can install this module via npm:

$> npm install gpb

No specific libraries are needed because this is pure node.js module, not a binary addon.


var GPB = require('gpb');

var proto = {
  1: ["field_string", GPB.STRING, GPB.REQUIRED],
  2: ["field_double", GPB.DOUBLE, GPB.OPTIONAL],
  3: ["field_floats", GPB.FLOAT, GPB.REPEATED],

var data = {
  "field_string": "Some string",
  "field_double": 2e30,
  "field_floats": [

var expected_encoded_data_length = GPB.encoded_length(data, proto);

var encoded_data = new Buffer(expected_encoded_data_length);

var actual_encoded_data_length = GPB.encode(encoded_data, 0/*offset*/, data, proto);


To contribute any patches, simply fork this repository using GitHub and send a pull request to me. Thanks!


MIT license. See license text in file LICENSE.

Bitdeli Badge

Something went wrong with that request. Please try again.