gpb

0.8.2 • Public • Published

Node-gpb

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.

Installation

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.

Usage

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": [
    1.1,
    2.2,
    3.3
  ]
};
 
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);
 

Contributing

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

License

MIT license. See license text in file LICENSE.

Bitdeli Badge

Readme

Keywords

none

Package Sidebar

Install

npm i gpb

Weekly Downloads

2

Version

0.8.2

License

none

Last publish

Collaborators

  • sannis