/
index.js
131 lines (116 loc) · 4.16 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
"use strict";
var protobuf = global.protobuf = exports;
/**
* A node-style callback as used by {@link load} and {@link Root#load}.
* @typedef LoadCallback
* @type {function}
* @param {?Error} error Error, if any, otherwise `null`
* @param {Root} [root] Root, if there hasn't been an error
* @returns {undefined}
*/
/**
* Loads one or multiple .proto or preprocessed .json files into a common root namespace and calls the callback.
* @param {string|string[]} filename One or multiple files to load
* @param {Root} root Root namespace, defaults to create a new one if omitted.
* @param {LoadCallback} callback Callback function
* @returns {undefined}
*/
function load(filename, root, callback) {
if (typeof root === 'function') {
callback = root;
root = new protobuf.Root();
} else if (!root)
root = new protobuf.Root();
return root.load(filename, callback);
}
// function load(filename:string, root:Root, callback:LoadCallback):undefined
/**
* Loads one or multiple .proto or preprocessed .json files into a common root namespace and calls the callback.
* @name load
* @function
* @param {string|string[]} filename One or multiple files to load
* @param {LoadCallback} callback Callback function
* @returns {undefined}
* @variation 2
*/
// function load(filename:string, callback:LoadCallback):undefined
/**
* Loads one or multiple .proto or preprocessed .json files into a common root namespace and returns a promise.
* @name load
* @function
* @param {string|string[]} filename One or multiple files to load
* @param {Root} [root] Root namespace, defaults to create a new one if omitted.
* @returns {Promise<Root>} Promise
* @variation 3
*/
// function load(filename:string, [root:Root]):Promise<Root>
protobuf.load = load;
/**
* Synchronously loads one or multiple .proto or preprocessed .json files into a common root namespace (node only).
* @param {string|string[]} filename One or multiple files to load
* @param {Root} [root] Root namespace, defaults to create a new one if omitted.
* @returns {Root} Root namespace
* @throws {Error} If synchronous fetching is not supported (i.e. in browsers) or if a file's syntax is invalid
*/
function loadSync(filename, root) {
if (!root)
root = new protobuf.Root();
return root.loadSync(filename);
}
protobuf.loadSync = loadSync;
/**
* Named roots.
* @name roots
* @type {Object.<string,Root>}
*/
protobuf.roots = {};
// Parser
protobuf.tokenize = require("./tokenize");
protobuf.parse = require("./parse");
// Serialization
protobuf.Writer = require("./writer");
protobuf.BufferWriter = protobuf.Writer.BufferWriter;
var Reader =
protobuf.Reader = require("./reader");
protobuf.BufferReader = protobuf.Reader.BufferReader;
protobuf.encode = require("./encode");
protobuf.decode = require("./decode");
protobuf.verify = require("./verify");
// Reflection
protobuf.ReflectionObject = require("./object");
protobuf.Namespace = require("./namespace");
protobuf.Root = require("./root");
protobuf.Enum = require("./enum");
protobuf.Type = require("./type");
protobuf.Field = require("./field");
protobuf.OneOf = require("./oneof");
protobuf.MapField = require("./mapfield");
protobuf.Service = require("./service");
protobuf.Method = require("./method");
// Runtime
protobuf.Class = require("./class");
protobuf.Message = require("./message");
// Utility
protobuf.types = require("./types");
protobuf.common = require("./common");
protobuf.rpc = require("./rpc");
var util =
protobuf.util = require("./util");
protobuf.configure = configure;
/**
* Reconfigures the library according to the environment.
* @returns {undefined}
*/
function configure() {
util._configure();
Reader._configure();
}
// Be nice to AMD
if (typeof define === 'function' && define.amd)
define(["long"], function(Long) {
if (Long) {
protobuf.util.Long = Long;
configure();
}
return protobuf;
});