Skip to content

Commit

Permalink
Docs: Added explicit hint on Uint8Array to initial example, see #670
Browse files Browse the repository at this point in the history
  • Loading branch information
dcodeIO committed Feb 2, 2017
1 parent 5909f84 commit 33d14c9
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

**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](https://developers.google.com/protocol-buffers/)).

**protobuf.js** is a pure JavaScript implementation with TypeScript support for node and the browser. It's super easy to use, blazingly fast and works out of the box on .proto files!
**protobuf.js** is a pure JavaScript implementation with [TypeScript](https://www.typescriptlang.org) support for [node.js](https://nodejs.org) and the browser. It's super easy to use, blazingly fast and works out of the box with [.proto](https://developers.google.com/protocol-buffers/docs/proto) files!

Contents
--------
Expand Down Expand Up @@ -111,15 +111,15 @@ protobuf.load("awesome.proto", function(err, root) {
// Create a new message
var message = AwesomeMessage.create({ awesomeField: "AwesomeString" });

// Encode a message
// Encode a message to an Uint8Array (browser) or Buffer (node)
var buffer = AwesomeMessage.encode(message).finish();
// ... do something with buffer

// Or, encode a plain object
var buffer = AwesomeMessage.encode({ awesomeField: "AwesomeString" }).finish();
// ... do something with buffer

// Decode a buffer
// Decode an Uint8Array (browser) or Buffer (node) to a message
var message = AwesomeMessage.decode(buffer);
// ... do something with message

Expand Down Expand Up @@ -220,6 +220,8 @@ AwesomeMessage.prototype.customInstanceMethod = function() { ... };
// Continue at "Create a message" above (you can also use the constructor directly)
```

Afterwards, decoded messages of this type are `instanceof AwesomeMessage`.

(*) Besides referencing its reflected type through `AwesomeMessage.$type` and `AwesomeMesage#$type`, the respective custom class is automatically populated with:

* `AwesomeMessage.create`
Expand Down Expand Up @@ -390,7 +392,7 @@ Consolidates imports and converts between file formats.
usage: pbjs [options] file1.proto file2.json ... (or) other | pbjs [options] -
```

For production environments it is recommended to bundle all your .proto files to a single .json file, which reduces the number of network requests and parser invocations required:
For production environments it is recommended to bundle all your .proto files to a single .json file, which minimizes the number of network requests and avoids any parser overhead (hint: works with just the [light library](#distributions)):

```
$> pbjs -t json file1.proto file2.proto > bundle.json
Expand All @@ -410,7 +412,7 @@ protobuf.load("bundle.json", function(err, root) {
});
```

As you might have noticed, `pbjs` is also capable of generating static code. For example
The `pbjs` utility is also capable of generating static code (hint: works with just the [minimal library](#distributions)). For example

```
$> pbjs -t static-module -w commonjs -o compiled.js file1.proto file2.proto
Expand Down

0 comments on commit 33d14c9

Please sign in to comment.