Skip to content

Commit 7983ee0

Browse files
committed
Refactored Prototype and inherits away, is now Class and Message for more intuitive documentation and type refs
1 parent 954577c commit 7983ee0

35 files changed

+963
-970
lines changed

README.md

+22-37
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,11 @@ var root = new Root().define("awesomepackage").add(AwesomeMessage);
151151

152152
```js
153153
...
154-
var Prototype = protobuf.Prototype;
155154

156155
function AwesomeMessage(properties) {
157-
Prototype.call(this, properties);
156+
protobuf.Message.call(this, properties);
158157
}
159-
protobuf.inherits(AwesomeMessage, root.lookup("awesomepackage.AwesomeMessage") /* or use reflection */);
158+
protobuf.Class.create(root.lookup("awesomepackage.AwesomeMessage") /* or use reflection */, AwesomeMessage);
160159

161160
var message = new AwesomeMessage({ awesomeField: "AwesomeString" });
162161

@@ -203,6 +202,8 @@ function rpcImpl(method, requestData, callback) {
203202
}
204203
```
205204

205+
There is also an [example for streaming RPC](https://github.com/dcodeIO/protobuf.js/blob/master/examples/streaming-rpc.js).
206+
206207
### Usage with TypeScript
207208

208209
```ts
@@ -218,8 +219,11 @@ The library exports a flat `protobuf` namespace with the following members, orde
218219

219220
### Parser
220221

221-
* **load(filename: `string|Array`, [root: `Root`], [callback: `function(err: Error, [root: Root])`]): `Promise`** [[source](https://github.com/dcodeIO/protobuf.js/blob/master/src/index.js)]<br />
222-
Loads one or multiple .proto files into the specified root or creates a new one when omitted.
222+
* **load(filename: `string|Array`, [root: `Root`], [callback: `function(err: Error, [root: Root])`]): `Promise|undefined`** [[source](https://github.com/dcodeIO/protobuf.js/blob/master/src/index.js)]<br />
223+
Loads one or multiple .proto or preprocessed .json files into a common root namespace.
224+
225+
* **loadSync(filename: `string|string[]`, [root: `Root`]): `Root`** [[source](https://github.com/dcodeIO/protobuf.js/blob/master/src/index.js)]<br />
226+
Synchronously loads one or multiple .proto or preprocessed .json files into a common root namespace (node only).
223227

224228
* **tokenize(source: `string`): `Object`** [[source](https://github.com/dcodeIO/protobuf.js/blob/master/src/tokenize.js)]<br />
225229
Tokenizes the given .proto source and returns an object with useful utility functions.
@@ -256,14 +260,8 @@ The library exports a flat `protobuf` namespace with the following members, orde
256260
* **BufferReader** _extends **Reader**_ [[source](https://github.com/dcodeIO/protobuf.js/blob/master/src/reader.js)]<br />
257261
Wire format reader using node buffers.
258262

259-
* **Encoder** [[source](https://github.com/dcodeIO/protobuf.js/blob/master/src/encoder.js)]<br />
260-
Wire format encoder using code generation on top of reflection.
261-
262-
* **Decoder** [[source](https://github.com/dcodeIO/protobuf.js/blob/master/src/decoder.js)]<br />
263-
Wire format decoder using code generation on top of reflection.
264-
265-
* **Verifier** [[source](https://github.com/dcodeIO/protobuf.js/blob/master/src/verifier.js)]<br />
266-
Runtime message verifier using code generation on top of reflection.
263+
* **codegen** [[source](https://github.com/dcodeIO/protobuf.js/blob/master/src/codegen.js)]<br />
264+
A closure for generating functions programmatically.
267265

268266
### Reflection
269267

@@ -296,22 +294,25 @@ The library exports a flat `protobuf` namespace with the following members, orde
296294

297295
### Runtime
298296

299-
* **inherits(clazz: `Function`, type: `Type`, [options: `Object.<string,*>`]): `Prototype`** [[source](https://github.com/dcodeIO/protobuf.js/blob/master/src/inherits.js)]<br />
300-
Inherits a custom class from the message prototype of the specified message type.
297+
* **Class** [[source](https://github.com/dcodeIO/protobuf.js/blob/master/src/class.js)]<br />
298+
Runtime class providing the tools to create your own custom classes.
301299

302-
* **Prototype** [[source](https://github.com/dcodeIO/protobuf.js/blob/master/src/prototype.js)]<br />
303-
Runtime message prototype ready to be extended by custom classes or generated code.
300+
* **Message** [[source](https://github.com/dcodeIO/protobuf.js/blob/master/src/message.js)]<br />
301+
Abstract runtime message.
304302

305303
### Utility
306304

307-
* **util: `Object`** [[source](https://github.com/dcodeIO/protobuf.js/blob/master/src/util.js)]<br />
308-
Utility functions.
305+
* **types: `Object`** [[source](https://github.com/dcodeIO/protobuf.js/blob/master/src/types.js)]<br />
306+
Common type constants.
309307

310308
* **common(name: `string`, json: `Object`)** [[source](https://github.com/dcodeIO/protobuf.js/blob/master/src/common.js)]<br />
311309
Provides common type definitions.
312310

313-
* **types: `Object`** [[source](https://github.com/dcodeIO/protobuf.js/blob/master/src/types.js)]<br />
314-
Common type constants.
311+
* **rpc: `Object`** [[source](https://github.com/dcodeIO/protobuf.js/blob/master/src/rpc.js)]<br />
312+
Streaming RPC helpers.
313+
314+
* **util: `Object`** [[source](https://github.com/dcodeIO/protobuf.js/blob/master/src/util.js)]<br />
315+
Various utility functions.
315316

316317
Documentation
317318
-------------
@@ -320,22 +321,6 @@ Documentation
320321

321322
* [protobuf.js API Documentation](http://dcode.io/protobuf.js/)
322323

323-
### Data type recommendations
324-
325-
| Value type | protobuf Type | Size / Notes
326-
|---------------------|---------------|-----------------------------------------------------------------------------------
327-
| Unsigned 32 bit int | uint32 | 1 to 5 bytes.
328-
| Signed 32 bit int | sint32 | 1 to 5 bytes. Do not use int32 (always encodes negative values as 10 bytes).
329-
| Unsigned 52 bit int | uint64 | 1 to 10 bytes.
330-
| Signed 52 bit int | sint64 | 1 to 10 bytes. Do not use int64 (always encodes negative values as 10 bytes).
331-
| Unsigned 64 bit int | uint64 | Use with long.js. 1 to 10 bytes.
332-
| Signed 64 bit int | sint64 | Use with long.js. 1 to 10 bytes. Do not use int64 (always encodes negative values as 10 bytes).
333-
| 32 bit float | float | 4 bytes.
334-
| 64 bit float | double | 8 bytes. Use float if 32 bits of precision are enough.
335-
| Boolean values | bool | 1 byte.
336-
| Strings | string | 1 to 5 bytes + utf8 byte length.
337-
| Buffers | bytes | 1 to 5 bytes + byte length.
338-
339324
Command line
340325
------------
341326

0 commit comments

Comments
 (0)