Skip to content

Commit 9df6a3d

Browse files
committed
Added variations for Root#load, see #527
1 parent 7c3bf8d commit 9df6a3d

12 files changed

Lines changed: 91 additions & 59 deletions

File tree

dist/protobuf.js

Lines changed: 32 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/protobuf.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/protobuf.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/protobuf.min.js.gz

6 Bytes
Binary file not shown.

dist/protobuf.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/codegen/decode.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ var Enum = require("../enum"),
1515

1616
/**
1717
* Decodes a message of `this` message's type.
18-
* @param {Reader} reader Reader to decode from
18+
* @param {Reader|Uint8Array} readerOrBuffer Reader or buffer to decode from
1919
* @param {number} [length] Length of the message, if known beforehand
2020
* @returns {Prototype} Populated runtime message
2121
* @this Type
2222
*/
23-
decode.fallback = function decode_fallback(reader, length) {
23+
decode.fallback = function decode_fallback(readerOrBuffer, length) {
2424
/* eslint-disable no-invalid-this, block-scoped-var, no-redeclare */
2525
var fields = this.getFieldsById(),
26-
reader = reader instanceof Reader ? reader : Reader.create(reader),
26+
reader = readerOrBuffer instanceof Reader ? readerOrBuffer : Reader.create(readerOrBuffer),
2727
limit = length === undefined ? reader.len : reader.pos + length,
2828
message = new (this.getCtor())();
2929
while (reader.pos < limit) {
@@ -87,7 +87,7 @@ decode.fallback = function decode_fallback(reader, length) {
8787
/**
8888
* Generates a decoder specific to the specified message type, with an identical signature to {@link codegen.decode.fallback}.
8989
* @param {Type} mtype Message type
90-
* @returns {function(string, ...*):string} {@link codegen} instance
90+
* @returns {CodegenInstance} {@link codegen|Codegen} instance
9191
*/
9292
decode.generate = function decode_generate(mtype) {
9393
/* eslint-disable no-unexpected-multiline */

src/codegen/encode.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ encode.fallback = function encode_fallback(message, writer) {
9595
/**
9696
* Generates an encoder specific to the specified message type, with an identical signature to {@link codegen.encode.fallback}.
9797
* @param {Type} mtype Message type
98-
* @returns {function(string, ...*):string} {@link codegen} instance
98+
* @returns {CodegenInstance} {@link codegen|Codegen} instance
9999
*/
100100
encode.generate = function encode_generate(mtype) {
101101
/* eslint-disable no-unexpected-multiline */

src/codegen/verify.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ verify.fallback = function verify_fallback(message) {
4646
/**
4747
* Generates a verifier specific to the specified message type, with an identical signature to {@link codegen.verify.fallback}.
4848
* @param {Type} mtype Message type
49-
* @returns {function(string, ...*):string} {@link codegen} instance
49+
* @returns {CodegenInstance} {@link codegen|Codegen} instance
5050
*/
5151
verify.generate = function verify_generate(mtype) {
5252
/* eslint-disable no-unexpected-multiline */

src/field.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ var _TypeError = util._TypeError;
2121
* @param {string} name Unique name within its namespace
2222
* @param {number} id Unique id within its namespace
2323
* @param {string} type Value type
24-
* @param {string} [rule=optional] Field rule
25-
* @param {string} [extend] Extended type if different from parent
24+
* @param {string|Object} [rule="optional"] Field rule
25+
* @param {string|Object} [extend] Extended type if different from parent
2626
* @param {Object} [options] Declared options
2727
*/
2828
function Field(name, id, type, rule, extend, options) {

src/index.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
var protobuf = global.protobuf = exports;
33

44
/**
5-
* Loads one or multiple .proto or preprocessed .json files into a common root namespace.
5+
* Loads one or multiple .proto or preprocessed .json files into a common root namespace and calls the callback.
66
* @param {string|string[]} filename One or multiple files to load
77
* @param {Root} root Root namespace, defaults to create a new one if omitted.
88
* @param {function(?Error, Root=)} callback Callback function
@@ -17,9 +17,10 @@ function load(filename, root, callback) {
1717
root = new protobuf.Root();
1818
return root.load(filename, callback);
1919
}
20+
// function load(filename:string, root:Root, callback:function):undefined
2021

2122
/**
22-
* Loads one or multiple .proto or preprocessed .json files into a common root namespace.
23+
* Loads one or multiple .proto or preprocessed .json files into a common root namespace and calls the callback.
2324
* @name load
2425
* @function
2526
* @param {string|string[]} filename One or multiple files to load
@@ -28,19 +29,19 @@ function load(filename, root, callback) {
2829
* @throws {TypeError} If arguments are invalid
2930
* @variation 2
3031
*/
31-
// function load(filename, callback)
32+
// function load(filename:string, callback:function):undefined
3233

3334
/**
34-
* Loads one or multiple .proto or preprocessed .json files into a common root namespace.
35+
* Loads one or multiple .proto or preprocessed .json files into a common root namespace and returns a promise.
3536
* @name load
3637
* @function
3738
* @param {string|string[]} filename One or multiple files to load
3839
* @param {Root} [root] Root namespace, defaults to create a new one if omitted.
39-
* @returns {Promise<Root>} A promise
40+
* @returns {Promise<Root>} Promise
4041
* @throws {TypeError} If arguments are invalid
4142
* @variation 3
4243
*/
43-
// function load(filename, [root]):Promise
44+
// function load(filename:string, [root:Root]):Promise<Root>
4445

4546
protobuf.load = load;
4647

0 commit comments

Comments
 (0)