Skip to content

Commit 320dea5

Browse files
committed
Docs: Restructured README to Installation, Usage and Examples sections [ci skip]
1 parent 1c9055d commit 320dea5

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

README.md

+19-13
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
Contents
99
--------
1010

11-
* [Usage](#usage)<br />
11+
* [Installation](#installation)<br />
1212
How to include protobuf.js in your project.
1313

14-
* [Distributions](#distributions)<br />
15-
A brief introduction to the available distributions and their use cases.
14+
* [Usage](#usage)<br />
15+
A brief introduction to using the toolset.
1616

1717
* [Examples](#examples)<br />
1818
A few examples to get you started.
@@ -32,7 +32,7 @@ Contents
3232
* [Building](#building)<br />
3333
How to build the library and its components yourself.
3434

35-
Usage
35+
Installation
3636
---------------
3737

3838
### node.js
@@ -61,16 +61,15 @@ Production:
6161

6262
The `protobuf` namespace will always be available globally / also supports AMD loaders.
6363

64-
Distributions
65-
-------------
64+
### Distributions
6665

6766
The library supports both reflection-based and code-based use cases:
6867

6968
1. Parsing protocol buffer definitions (.proto files) to reflection
7069
2. Loading JSON descriptors to reflection
7170
3. Generating static code without any reflection features
7271

73-
There is a suitable distribution for each of these:
72+
Where bundle size is a factor, there is a suitable distribution for each of these:
7473

7574
| | Gzipped | Downloads | How to require | Description
7675
|---------|---------|------------------------------|---------------------------------|-------------
@@ -84,12 +83,10 @@ In case of doubt you can just use the full library.
8483
[dist-light]: https://github.com/dcodeIO/protobuf.js/tree/master/dist/light
8584
[dist-minimal]: https://github.com/dcodeIO/protobuf.js/tree/master/dist/minimal
8685

87-
Examples
88-
--------
89-
90-
### Understanding the toolset
86+
Usage
87+
-----
9188

92-
For optimal performance, protobuf.js tries to avoid redundant assertions. Instead, it provides multiple methods, each doing just one thing.
89+
For [performance](#performance) reasons, protobuf.js provides multiple methods per message type with each of them doing just one thing. This avoids redundant assertions where messages are already known to be valid but also requires explicit verification where necessary. Note that `Message` refers to any message below.
9390

9491
* **Message.verify**(message: *Object*): *?string*<br />
9592
explicitly performs verification prior to encoding / converting a plain object (i.e. where data comes from user input). Instead of throwing, it returns the error message as a string, if any.
@@ -108,6 +105,9 @@ For optimal performance, protobuf.js tries to avoid redundant assertions. Instea
108105
var buffer = AwesomeMessage.encode(message).finish();
109106
```
110107

108+
* **Message.encodeDelimited**(message: *Message|Object*[, writer: *Writer*]): *Writer*<br />
109+
additionally prepends the length of the message as a varint.
110+
111111
* **Message.decode**(reader: *Reader|Uint8Array*): *Message*<br />
112112
is a message specific decoder expecting a valid buffer. If required fields are missing, it throws a `protobuf.util.ProtocolError` with an `instance` property set to the so far decoded message - otherwise an `Error`. The result is a runtime message.
113113

@@ -121,6 +121,9 @@ For optimal performance, protobuf.js tries to avoid redundant assertions. Instea
121121
}
122122
```
123123

124+
* **Message.decodeDelimited**(reader: *Reader|Uint8Array*): *Message*<br />
125+
additionally reads the length of the meessage prepended as a varint.
126+
124127
* **Message.create**(properties: *Object*): *Message*<br />
125128
quickly creates a new runtime message from known to be valid properties without any conversion being performed.
126129

@@ -144,9 +147,12 @@ For optimal performance, protobuf.js tries to avoid redundant assertions. Instea
144147
// converts enums, longs and bytes to their string representation and includes default values
145148
```
146149

150+
Examples
151+
--------
152+
147153
### Using .proto files
148154

149-
It's possible to load existing .proto files using the full library, which parses and compiles the definitions to ready to use (reflection-based) message classes:
155+
It is possible to load existing .proto files using the full library, which parses and compiles the definitions to ready to use (reflection-based) message classes:
150156

151157
```protobuf
152158
// awesome.proto

0 commit comments

Comments
 (0)