protobufjs 6.8.8 → 6.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/CHANGELOG.md +941 -921
  2. package/LICENSE +39 -39
  3. package/README.md +901 -879
  4. package/cli/LICENSE +33 -33
  5. package/cli/README.md +11 -11
  6. package/cli/index.d.ts +3 -3
  7. package/cli/index.js +3 -3
  8. package/cli/lib/tsd-jsdoc/LICENSE +20 -20
  9. package/cli/lib/tsd-jsdoc/README.md +23 -23
  10. package/cli/lib/tsd-jsdoc/plugin.js +21 -21
  11. package/cli/lib/tsd-jsdoc/publish.js +705 -693
  12. package/cli/lib/tsd-jsdoc.json +18 -18
  13. package/cli/package.json +1 -1
  14. package/cli/package.standalone.json +32 -32
  15. package/cli/pbjs.d.ts +9 -9
  16. package/cli/pbjs.js +329 -329
  17. package/cli/pbts.d.ts +9 -9
  18. package/cli/pbts.js +197 -197
  19. package/cli/targets/json-module.js +38 -38
  20. package/cli/targets/json.js +8 -8
  21. package/cli/targets/proto.js +326 -326
  22. package/cli/targets/proto2.js +10 -10
  23. package/cli/targets/proto3.js +10 -10
  24. package/cli/targets/static-module.js +29 -29
  25. package/cli/targets/static.js +702 -702
  26. package/cli/util.js +183 -183
  27. package/cli/wrappers/amd.js +7 -7
  28. package/cli/wrappers/closure.js +7 -7
  29. package/cli/wrappers/commonjs.js +7 -7
  30. package/cli/wrappers/default.js +15 -15
  31. package/cli/wrappers/es6.js +5 -5
  32. package/dist/README.md +31 -31
  33. package/dist/light/README.md +31 -31
  34. package/dist/light/protobuf.js +6058 -6032
  35. package/dist/light/protobuf.js.map +1 -1
  36. package/dist/light/protobuf.min.js +3 -3
  37. package/dist/light/protobuf.min.js.map +1 -1
  38. package/dist/minimal/README.md +31 -31
  39. package/dist/minimal/protobuf.js +1900 -1877
  40. package/dist/minimal/protobuf.js.map +1 -1
  41. package/dist/minimal/protobuf.min.js +3 -3
  42. package/dist/minimal/protobuf.min.js.map +1 -1
  43. package/dist/protobuf.js +7625 -7596
  44. package/dist/protobuf.js.map +1 -1
  45. package/dist/protobuf.min.js +3 -3
  46. package/dist/protobuf.min.js.map +1 -1
  47. package/ext/debug/README.md +4 -4
  48. package/ext/debug/index.js +71 -71
  49. package/ext/descriptor/README.md +72 -72
  50. package/ext/descriptor/index.js +1052 -1052
  51. package/ext/descriptor/test.js +54 -54
  52. package/google/LICENSE +27 -27
  53. package/google/README.md +1 -1
  54. package/google/api/annotations.proto +10 -10
  55. package/google/protobuf/descriptor.proto +286 -286
  56. package/google/protobuf/source_context.proto +7 -7
  57. package/index.d.ts +6 -6
  58. package/index.js +4 -4
  59. package/light.d.ts +2 -2
  60. package/light.js +3 -3
  61. package/minimal.d.ts +2 -2
  62. package/minimal.js +4 -4
  63. package/package-lock.json +4223 -3171
  64. package/package.json +122 -122
  65. package/scripts/changelog.js +150 -150
  66. package/scripts/postinstall.js +35 -35
  67. package/src/common.js +399 -399
  68. package/src/converter.js +293 -293
  69. package/src/decoder.js +106 -106
  70. package/src/encoder.js +100 -100
  71. package/src/enum.js +181 -181
  72. package/src/field.js +371 -371
  73. package/src/index-light.js +104 -104
  74. package/src/index-minimal.js +36 -36
  75. package/src/index.js +12 -12
  76. package/src/mapfield.js +126 -126
  77. package/src/message.js +138 -138
  78. package/src/method.js +151 -151
  79. package/src/namespace.js +433 -433
  80. package/src/object.js +200 -200
  81. package/src/oneof.js +203 -203
  82. package/src/parse.js +761 -758
  83. package/src/reader.js +411 -405
  84. package/src/reader_buffer.js +51 -44
  85. package/src/root.js +353 -351
  86. package/src/roots.js +18 -18
  87. package/src/rpc/service.js +142 -142
  88. package/src/rpc.js +36 -36
  89. package/src/service.js +167 -167
  90. package/src/tokenize.js +397 -397
  91. package/src/type.js +589 -589
  92. package/src/types.js +196 -196
  93. package/src/typescript.jsdoc +15 -15
  94. package/src/util/longbits.js +200 -200
  95. package/src/util/minimal.js +414 -414
  96. package/src/util.js +178 -178
  97. package/src/verifier.js +176 -176
  98. package/src/wrappers.js +83 -83
  99. package/src/writer.js +465 -459
  100. package/src/writer_buffer.js +85 -81
  101. package/tsconfig.json +6 -6
  102. package/cli/node_modules/os-tmpdir/index.js +0 -25
  103. package/cli/node_modules/os-tmpdir/license +0 -21
  104. package/cli/node_modules/os-tmpdir/readme.md +0 -32
  105. package/cli/node_modules/tmp/LICENSE +0 -21
  106. package/cli/node_modules/tmp/README.md +0 -314
  107. package/cli/node_modules/tmp/lib/tmp.js +0 -611
  108. package/cli/package-lock.json +0 -20
@@ -1,414 +1,414 @@
1
- "use strict";
2
- var util = exports;
3
-
4
- // used to return a Promise where callback is omitted
5
- util.asPromise = require("@protobufjs/aspromise");
6
-
7
- // converts to / from base64 encoded strings
8
- util.base64 = require("@protobufjs/base64");
9
-
10
- // base class of rpc.Service
11
- util.EventEmitter = require("@protobufjs/eventemitter");
12
-
13
- // float handling accross browsers
14
- util.float = require("@protobufjs/float");
15
-
16
- // requires modules optionally and hides the call from bundlers
17
- util.inquire = require("@protobufjs/inquire");
18
-
19
- // converts to / from utf8 encoded strings
20
- util.utf8 = require("@protobufjs/utf8");
21
-
22
- // provides a node-like buffer pool in the browser
23
- util.pool = require("@protobufjs/pool");
24
-
25
- // utility to work with the low and high bits of a 64 bit value
26
- util.LongBits = require("./longbits");
27
-
28
- // global object reference
29
- util.global = typeof window !== "undefined" && window
30
- || typeof global !== "undefined" && global
31
- || typeof self !== "undefined" && self
32
- || this; // eslint-disable-line no-invalid-this
33
-
34
- /**
35
- * An immuable empty array.
36
- * @memberof util
37
- * @type {Array.<*>}
38
- * @const
39
- */
40
- util.emptyArray = Object.freeze ? Object.freeze([]) : /* istanbul ignore next */ []; // used on prototypes
41
-
42
- /**
43
- * An immutable empty object.
44
- * @type {Object}
45
- * @const
46
- */
47
- util.emptyObject = Object.freeze ? Object.freeze({}) : /* istanbul ignore next */ {}; // used on prototypes
48
-
49
- /**
50
- * Whether running within node or not.
51
- * @memberof util
52
- * @type {boolean}
53
- * @const
54
- */
55
- util.isNode = Boolean(util.global.process && util.global.process.versions && util.global.process.versions.node);
56
-
57
- /**
58
- * Tests if the specified value is an integer.
59
- * @function
60
- * @param {*} value Value to test
61
- * @returns {boolean} `true` if the value is an integer
62
- */
63
- util.isInteger = Number.isInteger || /* istanbul ignore next */ function isInteger(value) {
64
- return typeof value === "number" && isFinite(value) && Math.floor(value) === value;
65
- };
66
-
67
- /**
68
- * Tests if the specified value is a string.
69
- * @param {*} value Value to test
70
- * @returns {boolean} `true` if the value is a string
71
- */
72
- util.isString = function isString(value) {
73
- return typeof value === "string" || value instanceof String;
74
- };
75
-
76
- /**
77
- * Tests if the specified value is a non-null object.
78
- * @param {*} value Value to test
79
- * @returns {boolean} `true` if the value is a non-null object
80
- */
81
- util.isObject = function isObject(value) {
82
- return value && typeof value === "object";
83
- };
84
-
85
- /**
86
- * Checks if a property on a message is considered to be present.
87
- * This is an alias of {@link util.isSet}.
88
- * @function
89
- * @param {Object} obj Plain object or message instance
90
- * @param {string} prop Property name
91
- * @returns {boolean} `true` if considered to be present, otherwise `false`
92
- */
93
- util.isset =
94
-
95
- /**
96
- * Checks if a property on a message is considered to be present.
97
- * @param {Object} obj Plain object or message instance
98
- * @param {string} prop Property name
99
- * @returns {boolean} `true` if considered to be present, otherwise `false`
100
- */
101
- util.isSet = function isSet(obj, prop) {
102
- var value = obj[prop];
103
- if (value != null && obj.hasOwnProperty(prop)) // eslint-disable-line eqeqeq, no-prototype-builtins
104
- return typeof value !== "object" || (Array.isArray(value) ? value.length : Object.keys(value).length) > 0;
105
- return false;
106
- };
107
-
108
- /**
109
- * Any compatible Buffer instance.
110
- * This is a minimal stand-alone definition of a Buffer instance. The actual type is that exported by node's typings.
111
- * @interface Buffer
112
- * @extends Uint8Array
113
- */
114
-
115
- /**
116
- * Node's Buffer class if available.
117
- * @type {Constructor<Buffer>}
118
- */
119
- util.Buffer = (function() {
120
- try {
121
- var Buffer = util.inquire("buffer").Buffer;
122
- // refuse to use non-node buffers if not explicitly assigned (perf reasons):
123
- return Buffer.prototype.utf8Write ? Buffer : /* istanbul ignore next */ null;
124
- } catch (e) {
125
- /* istanbul ignore next */
126
- return null;
127
- }
128
- })();
129
-
130
- // Internal alias of or polyfull for Buffer.from.
131
- util._Buffer_from = null;
132
-
133
- // Internal alias of or polyfill for Buffer.allocUnsafe.
134
- util._Buffer_allocUnsafe = null;
135
-
136
- /**
137
- * Creates a new buffer of whatever type supported by the environment.
138
- * @param {number|number[]} [sizeOrArray=0] Buffer size or number array
139
- * @returns {Uint8Array|Buffer} Buffer
140
- */
141
- util.newBuffer = function newBuffer(sizeOrArray) {
142
- /* istanbul ignore next */
143
- return typeof sizeOrArray === "number"
144
- ? util.Buffer
145
- ? util._Buffer_allocUnsafe(sizeOrArray)
146
- : new util.Array(sizeOrArray)
147
- : util.Buffer
148
- ? util._Buffer_from(sizeOrArray)
149
- : typeof Uint8Array === "undefined"
150
- ? sizeOrArray
151
- : new Uint8Array(sizeOrArray);
152
- };
153
-
154
- /**
155
- * Array implementation used in the browser. `Uint8Array` if supported, otherwise `Array`.
156
- * @type {Constructor<Uint8Array>}
157
- */
158
- util.Array = typeof Uint8Array !== "undefined" ? Uint8Array /* istanbul ignore next */ : Array;
159
-
160
- /**
161
- * Any compatible Long instance.
162
- * This is a minimal stand-alone definition of a Long instance. The actual type is that exported by long.js.
163
- * @interface Long
164
- * @property {number} low Low bits
165
- * @property {number} high High bits
166
- * @property {boolean} unsigned Whether unsigned or not
167
- */
168
-
169
- /**
170
- * Long.js's Long class if available.
171
- * @type {Constructor<Long>}
172
- */
173
- util.Long = /* istanbul ignore next */ util.global.dcodeIO && /* istanbul ignore next */ util.global.dcodeIO.Long
174
- || /* istanbul ignore next */ util.global.Long
175
- || util.inquire("long");
176
-
177
- /**
178
- * Regular expression used to verify 2 bit (`bool`) map keys.
179
- * @type {RegExp}
180
- * @const
181
- */
182
- util.key2Re = /^true|false|0|1$/;
183
-
184
- /**
185
- * Regular expression used to verify 32 bit (`int32` etc.) map keys.
186
- * @type {RegExp}
187
- * @const
188
- */
189
- util.key32Re = /^-?(?:0|[1-9][0-9]*)$/;
190
-
191
- /**
192
- * Regular expression used to verify 64 bit (`int64` etc.) map keys.
193
- * @type {RegExp}
194
- * @const
195
- */
196
- util.key64Re = /^(?:[\\x00-\\xff]{8}|-?(?:0|[1-9][0-9]*))$/;
197
-
198
- /**
199
- * Converts a number or long to an 8 characters long hash string.
200
- * @param {Long|number} value Value to convert
201
- * @returns {string} Hash
202
- */
203
- util.longToHash = function longToHash(value) {
204
- return value
205
- ? util.LongBits.from(value).toHash()
206
- : util.LongBits.zeroHash;
207
- };
208
-
209
- /**
210
- * Converts an 8 characters long hash string to a long or number.
211
- * @param {string} hash Hash
212
- * @param {boolean} [unsigned=false] Whether unsigned or not
213
- * @returns {Long|number} Original value
214
- */
215
- util.longFromHash = function longFromHash(hash, unsigned) {
216
- var bits = util.LongBits.fromHash(hash);
217
- if (util.Long)
218
- return util.Long.fromBits(bits.lo, bits.hi, unsigned);
219
- return bits.toNumber(Boolean(unsigned));
220
- };
221
-
222
- /**
223
- * Merges the properties of the source object into the destination object.
224
- * @memberof util
225
- * @param {Object.<string,*>} dst Destination object
226
- * @param {Object.<string,*>} src Source object
227
- * @param {boolean} [ifNotSet=false] Merges only if the key is not already set
228
- * @returns {Object.<string,*>} Destination object
229
- */
230
- function merge(dst, src, ifNotSet) { // used by converters
231
- for (var keys = Object.keys(src), i = 0; i < keys.length; ++i)
232
- if (dst[keys[i]] === undefined || !ifNotSet)
233
- dst[keys[i]] = src[keys[i]];
234
- return dst;
235
- }
236
-
237
- util.merge = merge;
238
-
239
- /**
240
- * Converts the first character of a string to lower case.
241
- * @param {string} str String to convert
242
- * @returns {string} Converted string
243
- */
244
- util.lcFirst = function lcFirst(str) {
245
- return str.charAt(0).toLowerCase() + str.substring(1);
246
- };
247
-
248
- /**
249
- * Creates a custom error constructor.
250
- * @memberof util
251
- * @param {string} name Error name
252
- * @returns {Constructor<Error>} Custom error constructor
253
- */
254
- function newError(name) {
255
-
256
- function CustomError(message, properties) {
257
-
258
- if (!(this instanceof CustomError))
259
- return new CustomError(message, properties);
260
-
261
- // Error.call(this, message);
262
- // ^ just returns a new error instance because the ctor can be called as a function
263
-
264
- Object.defineProperty(this, "message", { get: function() { return message; } });
265
-
266
- /* istanbul ignore next */
267
- if (Error.captureStackTrace) // node
268
- Error.captureStackTrace(this, CustomError);
269
- else
270
- Object.defineProperty(this, "stack", { value: (new Error()).stack || "" });
271
-
272
- if (properties)
273
- merge(this, properties);
274
- }
275
-
276
- (CustomError.prototype = Object.create(Error.prototype)).constructor = CustomError;
277
-
278
- Object.defineProperty(CustomError.prototype, "name", { get: function() { return name; } });
279
-
280
- CustomError.prototype.toString = function toString() {
281
- return this.name + ": " + this.message;
282
- };
283
-
284
- return CustomError;
285
- }
286
-
287
- util.newError = newError;
288
-
289
- /**
290
- * Constructs a new protocol error.
291
- * @classdesc Error subclass indicating a protocol specifc error.
292
- * @memberof util
293
- * @extends Error
294
- * @template T extends Message<T>
295
- * @constructor
296
- * @param {string} message Error message
297
- * @param {Object.<string,*>} [properties] Additional properties
298
- * @example
299
- * try {
300
- * MyMessage.decode(someBuffer); // throws if required fields are missing
301
- * } catch (e) {
302
- * if (e instanceof ProtocolError && e.instance)
303
- * console.log("decoded so far: " + JSON.stringify(e.instance));
304
- * }
305
- */
306
- util.ProtocolError = newError("ProtocolError");
307
-
308
- /**
309
- * So far decoded message instance.
310
- * @name util.ProtocolError#instance
311
- * @type {Message<T>}
312
- */
313
-
314
- /**
315
- * A OneOf getter as returned by {@link util.oneOfGetter}.
316
- * @typedef OneOfGetter
317
- * @type {function}
318
- * @returns {string|undefined} Set field name, if any
319
- */
320
-
321
- /**
322
- * Builds a getter for a oneof's present field name.
323
- * @param {string[]} fieldNames Field names
324
- * @returns {OneOfGetter} Unbound getter
325
- */
326
- util.oneOfGetter = function getOneOf(fieldNames) {
327
- var fieldMap = {};
328
- for (var i = 0; i < fieldNames.length; ++i)
329
- fieldMap[fieldNames[i]] = 1;
330
-
331
- /**
332
- * @returns {string|undefined} Set field name, if any
333
- * @this Object
334
- * @ignore
335
- */
336
- return function() { // eslint-disable-line consistent-return
337
- for (var keys = Object.keys(this), i = keys.length - 1; i > -1; --i)
338
- if (fieldMap[keys[i]] === 1 && this[keys[i]] !== undefined && this[keys[i]] !== null)
339
- return keys[i];
340
- };
341
- };
342
-
343
- /**
344
- * A OneOf setter as returned by {@link util.oneOfSetter}.
345
- * @typedef OneOfSetter
346
- * @type {function}
347
- * @param {string|undefined} value Field name
348
- * @returns {undefined}
349
- */
350
-
351
- /**
352
- * Builds a setter for a oneof's present field name.
353
- * @param {string[]} fieldNames Field names
354
- * @returns {OneOfSetter} Unbound setter
355
- */
356
- util.oneOfSetter = function setOneOf(fieldNames) {
357
-
358
- /**
359
- * @param {string} name Field name
360
- * @returns {undefined}
361
- * @this Object
362
- * @ignore
363
- */
364
- return function(name) {
365
- for (var i = 0; i < fieldNames.length; ++i)
366
- if (fieldNames[i] !== name)
367
- delete this[fieldNames[i]];
368
- };
369
- };
370
-
371
- /**
372
- * Default conversion options used for {@link Message#toJSON} implementations.
373
- *
374
- * These options are close to proto3's JSON mapping with the exception that internal types like Any are handled just like messages. More precisely:
375
- *
376
- * - Longs become strings
377
- * - Enums become string keys
378
- * - Bytes become base64 encoded strings
379
- * - (Sub-)Messages become plain objects
380
- * - Maps become plain objects with all string keys
381
- * - Repeated fields become arrays
382
- * - NaN and Infinity for float and double fields become strings
383
- *
384
- * @type {IConversionOptions}
385
- * @see https://developers.google.com/protocol-buffers/docs/proto3?hl=en#json
386
- */
387
- util.toJSONOptions = {
388
- longs: String,
389
- enums: String,
390
- bytes: String,
391
- json: true
392
- };
393
-
394
- // Sets up buffer utility according to the environment (called in index-minimal)
395
- util._configure = function() {
396
- var Buffer = util.Buffer;
397
- /* istanbul ignore if */
398
- if (!Buffer) {
399
- util._Buffer_from = util._Buffer_allocUnsafe = null;
400
- return;
401
- }
402
- // because node 4.x buffers are incompatible & immutable
403
- // see: https://github.com/dcodeIO/protobuf.js/pull/665
404
- util._Buffer_from = Buffer.from !== Uint8Array.from && Buffer.from ||
405
- /* istanbul ignore next */
406
- function Buffer_from(value, encoding) {
407
- return new Buffer(value, encoding);
408
- };
409
- util._Buffer_allocUnsafe = Buffer.allocUnsafe ||
410
- /* istanbul ignore next */
411
- function Buffer_allocUnsafe(size) {
412
- return new Buffer(size);
413
- };
414
- };
1
+ "use strict";
2
+ var util = exports;
3
+
4
+ // used to return a Promise where callback is omitted
5
+ util.asPromise = require("@protobufjs/aspromise");
6
+
7
+ // converts to / from base64 encoded strings
8
+ util.base64 = require("@protobufjs/base64");
9
+
10
+ // base class of rpc.Service
11
+ util.EventEmitter = require("@protobufjs/eventemitter");
12
+
13
+ // float handling accross browsers
14
+ util.float = require("@protobufjs/float");
15
+
16
+ // requires modules optionally and hides the call from bundlers
17
+ util.inquire = require("@protobufjs/inquire");
18
+
19
+ // converts to / from utf8 encoded strings
20
+ util.utf8 = require("@protobufjs/utf8");
21
+
22
+ // provides a node-like buffer pool in the browser
23
+ util.pool = require("@protobufjs/pool");
24
+
25
+ // utility to work with the low and high bits of a 64 bit value
26
+ util.LongBits = require("./longbits");
27
+
28
+ // global object reference
29
+ util.global = typeof window !== "undefined" && window
30
+ || typeof global !== "undefined" && global
31
+ || typeof self !== "undefined" && self
32
+ || this; // eslint-disable-line no-invalid-this
33
+
34
+ /**
35
+ * An immuable empty array.
36
+ * @memberof util
37
+ * @type {Array.<*>}
38
+ * @const
39
+ */
40
+ util.emptyArray = Object.freeze ? Object.freeze([]) : /* istanbul ignore next */ []; // used on prototypes
41
+
42
+ /**
43
+ * An immutable empty object.
44
+ * @type {Object}
45
+ * @const
46
+ */
47
+ util.emptyObject = Object.freeze ? Object.freeze({}) : /* istanbul ignore next */ {}; // used on prototypes
48
+
49
+ /**
50
+ * Whether running within node or not.
51
+ * @memberof util
52
+ * @type {boolean}
53
+ * @const
54
+ */
55
+ util.isNode = Boolean(util.global.process && util.global.process.versions && util.global.process.versions.node);
56
+
57
+ /**
58
+ * Tests if the specified value is an integer.
59
+ * @function
60
+ * @param {*} value Value to test
61
+ * @returns {boolean} `true` if the value is an integer
62
+ */
63
+ util.isInteger = Number.isInteger || /* istanbul ignore next */ function isInteger(value) {
64
+ return typeof value === "number" && isFinite(value) && Math.floor(value) === value;
65
+ };
66
+
67
+ /**
68
+ * Tests if the specified value is a string.
69
+ * @param {*} value Value to test
70
+ * @returns {boolean} `true` if the value is a string
71
+ */
72
+ util.isString = function isString(value) {
73
+ return typeof value === "string" || value instanceof String;
74
+ };
75
+
76
+ /**
77
+ * Tests if the specified value is a non-null object.
78
+ * @param {*} value Value to test
79
+ * @returns {boolean} `true` if the value is a non-null object
80
+ */
81
+ util.isObject = function isObject(value) {
82
+ return value && typeof value === "object";
83
+ };
84
+
85
+ /**
86
+ * Checks if a property on a message is considered to be present.
87
+ * This is an alias of {@link util.isSet}.
88
+ * @function
89
+ * @param {Object} obj Plain object or message instance
90
+ * @param {string} prop Property name
91
+ * @returns {boolean} `true` if considered to be present, otherwise `false`
92
+ */
93
+ util.isset =
94
+
95
+ /**
96
+ * Checks if a property on a message is considered to be present.
97
+ * @param {Object} obj Plain object or message instance
98
+ * @param {string} prop Property name
99
+ * @returns {boolean} `true` if considered to be present, otherwise `false`
100
+ */
101
+ util.isSet = function isSet(obj, prop) {
102
+ var value = obj[prop];
103
+ if (value != null && obj.hasOwnProperty(prop)) // eslint-disable-line eqeqeq, no-prototype-builtins
104
+ return typeof value !== "object" || (Array.isArray(value) ? value.length : Object.keys(value).length) > 0;
105
+ return false;
106
+ };
107
+
108
+ /**
109
+ * Any compatible Buffer instance.
110
+ * This is a minimal stand-alone definition of a Buffer instance. The actual type is that exported by node's typings.
111
+ * @interface Buffer
112
+ * @extends Uint8Array
113
+ */
114
+
115
+ /**
116
+ * Node's Buffer class if available.
117
+ * @type {Constructor<Buffer>}
118
+ */
119
+ util.Buffer = (function() {
120
+ try {
121
+ var Buffer = util.inquire("buffer").Buffer;
122
+ // refuse to use non-node buffers if not explicitly assigned (perf reasons):
123
+ return Buffer.prototype.utf8Write ? Buffer : /* istanbul ignore next */ null;
124
+ } catch (e) {
125
+ /* istanbul ignore next */
126
+ return null;
127
+ }
128
+ })();
129
+
130
+ // Internal alias of or polyfull for Buffer.from.
131
+ util._Buffer_from = null;
132
+
133
+ // Internal alias of or polyfill for Buffer.allocUnsafe.
134
+ util._Buffer_allocUnsafe = null;
135
+
136
+ /**
137
+ * Creates a new buffer of whatever type supported by the environment.
138
+ * @param {number|number[]} [sizeOrArray=0] Buffer size or number array
139
+ * @returns {Uint8Array|Buffer} Buffer
140
+ */
141
+ util.newBuffer = function newBuffer(sizeOrArray) {
142
+ /* istanbul ignore next */
143
+ return typeof sizeOrArray === "number"
144
+ ? util.Buffer
145
+ ? util._Buffer_allocUnsafe(sizeOrArray)
146
+ : new util.Array(sizeOrArray)
147
+ : util.Buffer
148
+ ? util._Buffer_from(sizeOrArray)
149
+ : typeof Uint8Array === "undefined"
150
+ ? sizeOrArray
151
+ : new Uint8Array(sizeOrArray);
152
+ };
153
+
154
+ /**
155
+ * Array implementation used in the browser. `Uint8Array` if supported, otherwise `Array`.
156
+ * @type {Constructor<Uint8Array>}
157
+ */
158
+ util.Array = typeof Uint8Array !== "undefined" ? Uint8Array /* istanbul ignore next */ : Array;
159
+
160
+ /**
161
+ * Any compatible Long instance.
162
+ * This is a minimal stand-alone definition of a Long instance. The actual type is that exported by long.js.
163
+ * @interface Long
164
+ * @property {number} low Low bits
165
+ * @property {number} high High bits
166
+ * @property {boolean} unsigned Whether unsigned or not
167
+ */
168
+
169
+ /**
170
+ * Long.js's Long class if available.
171
+ * @type {Constructor<Long>}
172
+ */
173
+ util.Long = /* istanbul ignore next */ util.global.dcodeIO && /* istanbul ignore next */ util.global.dcodeIO.Long
174
+ || /* istanbul ignore next */ util.global.Long
175
+ || util.inquire("long");
176
+
177
+ /**
178
+ * Regular expression used to verify 2 bit (`bool`) map keys.
179
+ * @type {RegExp}
180
+ * @const
181
+ */
182
+ util.key2Re = /^true|false|0|1$/;
183
+
184
+ /**
185
+ * Regular expression used to verify 32 bit (`int32` etc.) map keys.
186
+ * @type {RegExp}
187
+ * @const
188
+ */
189
+ util.key32Re = /^-?(?:0|[1-9][0-9]*)$/;
190
+
191
+ /**
192
+ * Regular expression used to verify 64 bit (`int64` etc.) map keys.
193
+ * @type {RegExp}
194
+ * @const
195
+ */
196
+ util.key64Re = /^(?:[\\x00-\\xff]{8}|-?(?:0|[1-9][0-9]*))$/;
197
+
198
+ /**
199
+ * Converts a number or long to an 8 characters long hash string.
200
+ * @param {Long|number} value Value to convert
201
+ * @returns {string} Hash
202
+ */
203
+ util.longToHash = function longToHash(value) {
204
+ return value
205
+ ? util.LongBits.from(value).toHash()
206
+ : util.LongBits.zeroHash;
207
+ };
208
+
209
+ /**
210
+ * Converts an 8 characters long hash string to a long or number.
211
+ * @param {string} hash Hash
212
+ * @param {boolean} [unsigned=false] Whether unsigned or not
213
+ * @returns {Long|number} Original value
214
+ */
215
+ util.longFromHash = function longFromHash(hash, unsigned) {
216
+ var bits = util.LongBits.fromHash(hash);
217
+ if (util.Long)
218
+ return util.Long.fromBits(bits.lo, bits.hi, unsigned);
219
+ return bits.toNumber(Boolean(unsigned));
220
+ };
221
+
222
+ /**
223
+ * Merges the properties of the source object into the destination object.
224
+ * @memberof util
225
+ * @param {Object.<string,*>} dst Destination object
226
+ * @param {Object.<string,*>} src Source object
227
+ * @param {boolean} [ifNotSet=false] Merges only if the key is not already set
228
+ * @returns {Object.<string,*>} Destination object
229
+ */
230
+ function merge(dst, src, ifNotSet) { // used by converters
231
+ for (var keys = Object.keys(src), i = 0; i < keys.length; ++i)
232
+ if (dst[keys[i]] === undefined || !ifNotSet)
233
+ dst[keys[i]] = src[keys[i]];
234
+ return dst;
235
+ }
236
+
237
+ util.merge = merge;
238
+
239
+ /**
240
+ * Converts the first character of a string to lower case.
241
+ * @param {string} str String to convert
242
+ * @returns {string} Converted string
243
+ */
244
+ util.lcFirst = function lcFirst(str) {
245
+ return str.charAt(0).toLowerCase() + str.substring(1);
246
+ };
247
+
248
+ /**
249
+ * Creates a custom error constructor.
250
+ * @memberof util
251
+ * @param {string} name Error name
252
+ * @returns {Constructor<Error>} Custom error constructor
253
+ */
254
+ function newError(name) {
255
+
256
+ function CustomError(message, properties) {
257
+
258
+ if (!(this instanceof CustomError))
259
+ return new CustomError(message, properties);
260
+
261
+ // Error.call(this, message);
262
+ // ^ just returns a new error instance because the ctor can be called as a function
263
+
264
+ Object.defineProperty(this, "message", { get: function() { return message; } });
265
+
266
+ /* istanbul ignore next */
267
+ if (Error.captureStackTrace) // node
268
+ Error.captureStackTrace(this, CustomError);
269
+ else
270
+ Object.defineProperty(this, "stack", { value: new Error().stack || "" });
271
+
272
+ if (properties)
273
+ merge(this, properties);
274
+ }
275
+
276
+ (CustomError.prototype = Object.create(Error.prototype)).constructor = CustomError;
277
+
278
+ Object.defineProperty(CustomError.prototype, "name", { get: function() { return name; } });
279
+
280
+ CustomError.prototype.toString = function toString() {
281
+ return this.name + ": " + this.message;
282
+ };
283
+
284
+ return CustomError;
285
+ }
286
+
287
+ util.newError = newError;
288
+
289
+ /**
290
+ * Constructs a new protocol error.
291
+ * @classdesc Error subclass indicating a protocol specifc error.
292
+ * @memberof util
293
+ * @extends Error
294
+ * @template T extends Message<T>
295
+ * @constructor
296
+ * @param {string} message Error message
297
+ * @param {Object.<string,*>} [properties] Additional properties
298
+ * @example
299
+ * try {
300
+ * MyMessage.decode(someBuffer); // throws if required fields are missing
301
+ * } catch (e) {
302
+ * if (e instanceof ProtocolError && e.instance)
303
+ * console.log("decoded so far: " + JSON.stringify(e.instance));
304
+ * }
305
+ */
306
+ util.ProtocolError = newError("ProtocolError");
307
+
308
+ /**
309
+ * So far decoded message instance.
310
+ * @name util.ProtocolError#instance
311
+ * @type {Message<T>}
312
+ */
313
+
314
+ /**
315
+ * A OneOf getter as returned by {@link util.oneOfGetter}.
316
+ * @typedef OneOfGetter
317
+ * @type {function}
318
+ * @returns {string|undefined} Set field name, if any
319
+ */
320
+
321
+ /**
322
+ * Builds a getter for a oneof's present field name.
323
+ * @param {string[]} fieldNames Field names
324
+ * @returns {OneOfGetter} Unbound getter
325
+ */
326
+ util.oneOfGetter = function getOneOf(fieldNames) {
327
+ var fieldMap = {};
328
+ for (var i = 0; i < fieldNames.length; ++i)
329
+ fieldMap[fieldNames[i]] = 1;
330
+
331
+ /**
332
+ * @returns {string|undefined} Set field name, if any
333
+ * @this Object
334
+ * @ignore
335
+ */
336
+ return function() { // eslint-disable-line consistent-return
337
+ for (var keys = Object.keys(this), i = keys.length - 1; i > -1; --i)
338
+ if (fieldMap[keys[i]] === 1 && this[keys[i]] !== undefined && this[keys[i]] !== null)
339
+ return keys[i];
340
+ };
341
+ };
342
+
343
+ /**
344
+ * A OneOf setter as returned by {@link util.oneOfSetter}.
345
+ * @typedef OneOfSetter
346
+ * @type {function}
347
+ * @param {string|undefined} value Field name
348
+ * @returns {undefined}
349
+ */
350
+
351
+ /**
352
+ * Builds a setter for a oneof's present field name.
353
+ * @param {string[]} fieldNames Field names
354
+ * @returns {OneOfSetter} Unbound setter
355
+ */
356
+ util.oneOfSetter = function setOneOf(fieldNames) {
357
+
358
+ /**
359
+ * @param {string} name Field name
360
+ * @returns {undefined}
361
+ * @this Object
362
+ * @ignore
363
+ */
364
+ return function(name) {
365
+ for (var i = 0; i < fieldNames.length; ++i)
366
+ if (fieldNames[i] !== name)
367
+ delete this[fieldNames[i]];
368
+ };
369
+ };
370
+
371
+ /**
372
+ * Default conversion options used for {@link Message#toJSON} implementations.
373
+ *
374
+ * These options are close to proto3's JSON mapping with the exception that internal types like Any are handled just like messages. More precisely:
375
+ *
376
+ * - Longs become strings
377
+ * - Enums become string keys
378
+ * - Bytes become base64 encoded strings
379
+ * - (Sub-)Messages become plain objects
380
+ * - Maps become plain objects with all string keys
381
+ * - Repeated fields become arrays
382
+ * - NaN and Infinity for float and double fields become strings
383
+ *
384
+ * @type {IConversionOptions}
385
+ * @see https://developers.google.com/protocol-buffers/docs/proto3?hl=en#json
386
+ */
387
+ util.toJSONOptions = {
388
+ longs: String,
389
+ enums: String,
390
+ bytes: String,
391
+ json: true
392
+ };
393
+
394
+ // Sets up buffer utility according to the environment (called in index-minimal)
395
+ util._configure = function() {
396
+ var Buffer = util.Buffer;
397
+ /* istanbul ignore if */
398
+ if (!Buffer) {
399
+ util._Buffer_from = util._Buffer_allocUnsafe = null;
400
+ return;
401
+ }
402
+ // because node 4.x buffers are incompatible & immutable
403
+ // see: https://github.com/dcodeIO/protobuf.js/pull/665
404
+ util._Buffer_from = Buffer.from !== Uint8Array.from && Buffer.from ||
405
+ /* istanbul ignore next */
406
+ function Buffer_from(value, encoding) {
407
+ return new Buffer(value, encoding);
408
+ };
409
+ util._Buffer_allocUnsafe = Buffer.allocUnsafe ||
410
+ /* istanbul ignore next */
411
+ function Buffer_allocUnsafe(size) {
412
+ return new Buffer(size);
413
+ };
414
+ };