Skip to content

Commit

Permalink
proto compiler docs
Browse files Browse the repository at this point in the history
  • Loading branch information
mourner committed Feb 5, 2015
1 parent 3b2d172 commit 024dce0
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,23 @@ function writeLayer(layer, pbf) {
}
```

#### Using Compiled Code

Install `pbf` and compile reading/writing JavaScript module from a `.proto` file:

```bash
$ npm install -g pbf
$ pbf test.proto > test.js
```

Then read and write objects using the module like this:

```js
var obj = Test.read(new Pbf(buffer)); // read
var buffer = Test.write(obj, new Pbf()); // write
```


## Install

Node and Browserify:
Expand Down Expand Up @@ -219,6 +236,26 @@ Misc methods:

For an example of a real-world usage of the library, see [vector-tile-js](https://github.com/mapbox/vector-tile-js).


## Proto Schema to JavaScript

If installed globally, `pbf` provides a binary that compiles `proto` files into JavaScript modules. Usage:

```bash
$ pbf <proto_path> [--no-write] [--no-read] [--browser]
```

The `--no-write` and `--no-read` switches remove corresponding code in the output.
The `--browser` switch makes the module work in browsers instead of Node.

The resulting module exports each message by name with the following methods:

* `read(pbf)` - decodes an object from the given `Pbf` instance
* `write(obj, pbf)` - encodes an object into the given `Pbf` instance (usually empty)

The resulting code is pretty short and easy to understand, so you can customize it easily.


## Changelog

#### 1.2.0 (Jan 5, 2015)
Expand Down

0 comments on commit 024dce0

Please sign in to comment.