Skip to content

Commit 33d14c9

Browse files
committed
Docs: Added explicit hint on Uint8Array to initial example, see #670
1 parent 5909f84 commit 33d14c9

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

README.md

+7-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
**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/)).
55

6-
**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!
6+
**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!
77

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

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

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

122-
// Decode a buffer
122+
// Decode an Uint8Array (browser) or Buffer (node) to a message
123123
var message = AwesomeMessage.decode(buffer);
124124
// ... do something with message
125125

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

223+
Afterwards, decoded messages of this type are `instanceof AwesomeMessage`.
224+
223225
(*) Besides referencing its reflected type through `AwesomeMessage.$type` and `AwesomeMesage#$type`, the respective custom class is automatically populated with:
224226

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

393-
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:
395+
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)):
394396

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

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

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

0 commit comments

Comments
 (0)