protobufjs 8.1.6-experimental → 8.2.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 (76) hide show
  1. package/README.md +219 -565
  2. package/dist/light/protobuf.js +1986 -1483
  3. package/dist/light/protobuf.js.map +1 -1
  4. package/dist/light/protobuf.min.js +3 -3
  5. package/dist/light/protobuf.min.js.map +1 -1
  6. package/dist/minimal/protobuf.js +1122 -861
  7. package/dist/minimal/protobuf.js.map +1 -1
  8. package/dist/minimal/protobuf.min.js +3 -3
  9. package/dist/minimal/protobuf.min.js.map +1 -1
  10. package/dist/protobuf.js +2089 -1513
  11. package/dist/protobuf.js.map +1 -1
  12. package/dist/protobuf.min.js +3 -3
  13. package/dist/protobuf.min.js.map +1 -1
  14. package/ext/README.md +81 -0
  15. package/ext/descriptor/README.md +3 -70
  16. package/ext/descriptor/index.d.ts +1 -191
  17. package/ext/descriptor/index.js +1 -1161
  18. package/ext/descriptor.d.ts +309 -0
  19. package/ext/descriptor.js +1236 -0
  20. package/ext/textformat.d.ts +30 -0
  21. package/ext/textformat.js +1249 -0
  22. package/google/protobuf/compiler/plugin.json +126 -0
  23. package/google/protobuf/compiler/plugin.proto +47 -0
  24. package/google/protobuf/descriptor.json +2 -2
  25. package/google/protobuf/descriptor.proto +2 -1
  26. package/index.d.ts +590 -476
  27. package/package.json +23 -38
  28. package/src/converter.js +60 -24
  29. package/src/decoder.js +122 -49
  30. package/src/encoder.js +10 -2
  31. package/src/enum.js +4 -1
  32. package/src/field.js +10 -7
  33. package/src/mapfield.js +1 -0
  34. package/src/message.js +7 -6
  35. package/src/method.js +4 -3
  36. package/src/namespace.js +23 -12
  37. package/src/object.js +24 -19
  38. package/src/oneof.js +2 -0
  39. package/src/parse.js +114 -46
  40. package/src/reader.js +145 -30
  41. package/src/reader_buffer.js +24 -3
  42. package/src/root.js +7 -4
  43. package/src/service.js +12 -6
  44. package/src/tokenize.js +6 -1
  45. package/src/type.js +48 -25
  46. package/src/types.js +1 -1
  47. package/src/util/aspromise.d.ts +13 -0
  48. package/src/util/aspromise.js +52 -0
  49. package/src/util/base64.d.ts +32 -0
  50. package/src/util/base64.js +146 -0
  51. package/src/util/codegen.d.ts +31 -0
  52. package/src/util/codegen.js +113 -0
  53. package/src/util/eventemitter.d.ts +45 -0
  54. package/src/util/eventemitter.js +84 -0
  55. package/src/util/fetch.d.ts +56 -0
  56. package/src/util/fetch.js +112 -0
  57. package/src/util/float.d.ts +83 -0
  58. package/src/util/float.js +335 -0
  59. package/src/util/fs.js +11 -0
  60. package/src/util/inquire.d.ts +10 -0
  61. package/src/util/inquire.js +38 -0
  62. package/src/util/minimal.js +67 -12
  63. package/src/util/path.d.ts +22 -0
  64. package/src/util/path.js +72 -0
  65. package/src/util/patterns.js +8 -0
  66. package/src/util/pool.d.ts +32 -0
  67. package/src/util/pool.js +48 -0
  68. package/src/util/utf8.d.ts +24 -0
  69. package/src/util/utf8.js +104 -0
  70. package/src/util.js +30 -13
  71. package/src/verifier.js +7 -4
  72. package/src/wrappers.js +4 -3
  73. package/src/writer.js +27 -4
  74. package/src/writer_buffer.js +12 -0
  75. package/tsconfig.json +2 -2
  76. package/ext/descriptor/test.js +0 -54
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * protobuf.js v8.1.6-experimental (c) 2016, daniel wirtz
3
- * compiled tue, 27 may 2025 22:16:18 utc
2
+ * protobuf.js v8.2.0 (c) 2016, daniel wirtz
3
+ * compiled sat, 09 may 2026 19:37:43 utc
4
4
  * licensed under the bsd-3-clause license
5
5
  * see: https://github.com/dcodeio/protobuf.js for details
6
6
  */
@@ -38,1077 +38,8 @@
38
38
  module.exports = protobuf;
39
39
 
40
40
  })/* end of prelude */({1:[function(require,module,exports){
41
- "use strict";
42
- module.exports = asPromise;
43
-
44
- /**
45
- * Callback as used by {@link util.asPromise}.
46
- * @typedef asPromiseCallback
47
- * @type {function}
48
- * @param {Error|null} error Error, if any
49
- * @param {...*} params Additional arguments
50
- * @returns {undefined}
51
- */
52
-
53
- /**
54
- * Returns a promise from a node-style callback function.
55
- * @memberof util
56
- * @param {asPromiseCallback} fn Function to call
57
- * @param {*} ctx Function context
58
- * @param {...*} params Function arguments
59
- * @returns {Promise<*>} Promisified function
60
- */
61
- function asPromise(fn, ctx/*, varargs */) {
62
- var params = new Array(arguments.length - 1),
63
- offset = 0,
64
- index = 2,
65
- pending = true;
66
- while (index < arguments.length)
67
- params[offset++] = arguments[index++];
68
- return new Promise(function executor(resolve, reject) {
69
- params[offset] = function callback(err/*, varargs */) {
70
- if (pending) {
71
- pending = false;
72
- if (err)
73
- reject(err);
74
- else {
75
- var params = new Array(arguments.length - 1),
76
- offset = 0;
77
- while (offset < params.length)
78
- params[offset++] = arguments[offset];
79
- resolve.apply(null, params);
80
- }
81
- }
82
- };
83
- try {
84
- fn.apply(ctx || null, params);
85
- } catch (err) {
86
- if (pending) {
87
- pending = false;
88
- reject(err);
89
- }
90
- }
91
- });
92
- }
93
41
 
94
42
  },{}],2:[function(require,module,exports){
95
- "use strict";
96
-
97
- /**
98
- * A minimal base64 implementation for number arrays.
99
- * @memberof util
100
- * @namespace
101
- */
102
- var base64 = exports;
103
-
104
- /**
105
- * Calculates the byte length of a base64 encoded string.
106
- * @param {string} string Base64 encoded string
107
- * @returns {number} Byte length
108
- */
109
- base64.length = function length(string) {
110
- var p = string.length;
111
- if (!p)
112
- return 0;
113
- var n = 0;
114
- while (--p % 4 > 1 && string.charAt(p) === "=")
115
- ++n;
116
- return Math.ceil(string.length * 3) / 4 - n;
117
- };
118
-
119
- // Base64 encoding table
120
- var b64 = new Array(64);
121
-
122
- // Base64 decoding table
123
- var s64 = new Array(123);
124
-
125
- // 65..90, 97..122, 48..57, 43, 47
126
- for (var i = 0; i < 64;)
127
- s64[b64[i] = i < 26 ? i + 65 : i < 52 ? i + 71 : i < 62 ? i - 4 : i - 59 | 43] = i++;
128
-
129
- /**
130
- * Encodes a buffer to a base64 encoded string.
131
- * @param {Uint8Array} buffer Source buffer
132
- * @param {number} start Source start
133
- * @param {number} end Source end
134
- * @returns {string} Base64 encoded string
135
- */
136
- base64.encode = function encode(buffer, start, end) {
137
- var parts = null,
138
- chunk = [];
139
- var i = 0, // output index
140
- j = 0, // goto index
141
- t; // temporary
142
- while (start < end) {
143
- var b = buffer[start++];
144
- switch (j) {
145
- case 0:
146
- chunk[i++] = b64[b >> 2];
147
- t = (b & 3) << 4;
148
- j = 1;
149
- break;
150
- case 1:
151
- chunk[i++] = b64[t | b >> 4];
152
- t = (b & 15) << 2;
153
- j = 2;
154
- break;
155
- case 2:
156
- chunk[i++] = b64[t | b >> 6];
157
- chunk[i++] = b64[b & 63];
158
- j = 0;
159
- break;
160
- }
161
- if (i > 8191) {
162
- (parts || (parts = [])).push(String.fromCharCode.apply(String, chunk));
163
- i = 0;
164
- }
165
- }
166
- if (j) {
167
- chunk[i++] = b64[t];
168
- chunk[i++] = 61;
169
- if (j === 1)
170
- chunk[i++] = 61;
171
- }
172
- if (parts) {
173
- if (i)
174
- parts.push(String.fromCharCode.apply(String, chunk.slice(0, i)));
175
- return parts.join("");
176
- }
177
- return String.fromCharCode.apply(String, chunk.slice(0, i));
178
- };
179
-
180
- var invalidEncoding = "invalid encoding";
181
-
182
- /**
183
- * Decodes a base64 encoded string to a buffer.
184
- * @param {string} string Source string
185
- * @param {Uint8Array} buffer Destination buffer
186
- * @param {number} offset Destination offset
187
- * @returns {number} Number of bytes written
188
- * @throws {Error} If encoding is invalid
189
- */
190
- base64.decode = function decode(string, buffer, offset) {
191
- var start = offset;
192
- var j = 0, // goto index
193
- t; // temporary
194
- for (var i = 0; i < string.length;) {
195
- var c = string.charCodeAt(i++);
196
- if (c === 61 && j > 1)
197
- break;
198
- if ((c = s64[c]) === undefined)
199
- throw Error(invalidEncoding);
200
- switch (j) {
201
- case 0:
202
- t = c;
203
- j = 1;
204
- break;
205
- case 1:
206
- buffer[offset++] = t << 2 | (c & 48) >> 4;
207
- t = c;
208
- j = 2;
209
- break;
210
- case 2:
211
- buffer[offset++] = (t & 15) << 4 | (c & 60) >> 2;
212
- t = c;
213
- j = 3;
214
- break;
215
- case 3:
216
- buffer[offset++] = (t & 3) << 6 | c;
217
- j = 0;
218
- break;
219
- }
220
- }
221
- if (j === 1)
222
- throw Error(invalidEncoding);
223
- return offset - start;
224
- };
225
-
226
- /**
227
- * Tests if the specified string appears to be base64 encoded.
228
- * @param {string} string String to test
229
- * @returns {boolean} `true` if probably base64 encoded, otherwise false
230
- */
231
- base64.test = function test(string) {
232
- return /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(string);
233
- };
234
-
235
- },{}],3:[function(require,module,exports){
236
- "use strict";
237
- module.exports = codegen;
238
-
239
- /**
240
- * Begins generating a function.
241
- * @memberof util
242
- * @param {string[]} functionParams Function parameter names
243
- * @param {string} [functionName] Function name if not anonymous
244
- * @returns {Codegen} Appender that appends code to the function's body
245
- */
246
- function codegen(functionParams, functionName) {
247
-
248
- /* istanbul ignore if */
249
- if (typeof functionParams === "string") {
250
- functionName = functionParams;
251
- functionParams = undefined;
252
- }
253
-
254
- var body = [];
255
-
256
- /**
257
- * Appends code to the function's body or finishes generation.
258
- * @typedef Codegen
259
- * @type {function}
260
- * @param {string|Object.<string,*>} [formatStringOrScope] Format string or, to finish the function, an object of additional scope variables, if any
261
- * @param {...*} [formatParams] Format parameters
262
- * @returns {Codegen|Function} Itself or the generated function if finished
263
- * @throws {Error} If format parameter counts do not match
264
- */
265
-
266
- function Codegen(formatStringOrScope) {
267
- // note that explicit array handling below makes this ~50% faster
268
-
269
- // finish the function
270
- if (typeof formatStringOrScope !== "string") {
271
- var source = toString();
272
- if (codegen.verbose)
273
- console.log("codegen: " + source); // eslint-disable-line no-console
274
- source = "return " + source;
275
- if (formatStringOrScope) {
276
- var scopeKeys = Object.keys(formatStringOrScope),
277
- scopeParams = new Array(scopeKeys.length + 1),
278
- scopeValues = new Array(scopeKeys.length),
279
- scopeOffset = 0;
280
- while (scopeOffset < scopeKeys.length) {
281
- scopeParams[scopeOffset] = scopeKeys[scopeOffset];
282
- scopeValues[scopeOffset] = formatStringOrScope[scopeKeys[scopeOffset++]];
283
- }
284
- scopeParams[scopeOffset] = source;
285
- return Function.apply(null, scopeParams).apply(null, scopeValues); // eslint-disable-line no-new-func
286
- }
287
- return Function(source)(); // eslint-disable-line no-new-func
288
- }
289
-
290
- // otherwise append to body
291
- var formatParams = new Array(arguments.length - 1),
292
- formatOffset = 0;
293
- while (formatOffset < formatParams.length)
294
- formatParams[formatOffset] = arguments[++formatOffset];
295
- formatOffset = 0;
296
- formatStringOrScope = formatStringOrScope.replace(/%([%dfijs])/g, function replace($0, $1) {
297
- var value = formatParams[formatOffset++];
298
- switch ($1) {
299
- case "d": case "f": return String(Number(value));
300
- case "i": return String(Math.floor(value));
301
- case "j": return JSON.stringify(value);
302
- case "s": return String(value);
303
- }
304
- return "%";
305
- });
306
- if (formatOffset !== formatParams.length)
307
- throw Error("parameter count mismatch");
308
- body.push(formatStringOrScope);
309
- return Codegen;
310
- }
311
-
312
- function toString(functionNameOverride) {
313
- return "function " + (functionNameOverride || functionName || "") + "(" + (functionParams && functionParams.join(",") || "") + "){\n " + body.join("\n ") + "\n}";
314
- }
315
-
316
- Codegen.toString = toString;
317
- return Codegen;
318
- }
319
-
320
- /**
321
- * Begins generating a function.
322
- * @memberof util
323
- * @function codegen
324
- * @param {string} [functionName] Function name if not anonymous
325
- * @returns {Codegen} Appender that appends code to the function's body
326
- * @variation 2
327
- */
328
-
329
- /**
330
- * When set to `true`, codegen will log generated code to console. Useful for debugging.
331
- * @name util.codegen.verbose
332
- * @type {boolean}
333
- */
334
- codegen.verbose = false;
335
-
336
- },{}],4:[function(require,module,exports){
337
- "use strict";
338
- module.exports = EventEmitter;
339
-
340
- /**
341
- * Constructs a new event emitter instance.
342
- * @classdesc A minimal event emitter.
343
- * @memberof util
344
- * @constructor
345
- */
346
- function EventEmitter() {
347
-
348
- /**
349
- * Registered listeners.
350
- * @type {Object.<string,*>}
351
- * @private
352
- */
353
- this._listeners = {};
354
- }
355
-
356
- /**
357
- * Registers an event listener.
358
- * @param {string} evt Event name
359
- * @param {function} fn Listener
360
- * @param {*} [ctx] Listener context
361
- * @returns {util.EventEmitter} `this`
362
- */
363
- EventEmitter.prototype.on = function on(evt, fn, ctx) {
364
- (this._listeners[evt] || (this._listeners[evt] = [])).push({
365
- fn : fn,
366
- ctx : ctx || this
367
- });
368
- return this;
369
- };
370
-
371
- /**
372
- * Removes an event listener or any matching listeners if arguments are omitted.
373
- * @param {string} [evt] Event name. Removes all listeners if omitted.
374
- * @param {function} [fn] Listener to remove. Removes all listeners of `evt` if omitted.
375
- * @returns {util.EventEmitter} `this`
376
- */
377
- EventEmitter.prototype.off = function off(evt, fn) {
378
- if (evt === undefined)
379
- this._listeners = {};
380
- else {
381
- if (fn === undefined)
382
- this._listeners[evt] = [];
383
- else {
384
- var listeners = this._listeners[evt];
385
- for (var i = 0; i < listeners.length;)
386
- if (listeners[i].fn === fn)
387
- listeners.splice(i, 1);
388
- else
389
- ++i;
390
- }
391
- }
392
- return this;
393
- };
394
-
395
- /**
396
- * Emits an event by calling its listeners with the specified arguments.
397
- * @param {string} evt Event name
398
- * @param {...*} args Arguments
399
- * @returns {util.EventEmitter} `this`
400
- */
401
- EventEmitter.prototype.emit = function emit(evt) {
402
- var listeners = this._listeners[evt];
403
- if (listeners) {
404
- var args = [],
405
- i = 1;
406
- for (; i < arguments.length;)
407
- args.push(arguments[i++]);
408
- for (i = 0; i < listeners.length;)
409
- listeners[i].fn.apply(listeners[i++].ctx, args);
410
- }
411
- return this;
412
- };
413
-
414
- },{}],5:[function(require,module,exports){
415
- "use strict";
416
- module.exports = fetch;
417
-
418
- var asPromise = require(1),
419
- inquire = require(7);
420
-
421
- var fs = inquire("fs");
422
-
423
- /**
424
- * Node-style callback as used by {@link util.fetch}.
425
- * @typedef FetchCallback
426
- * @type {function}
427
- * @param {?Error} error Error, if any, otherwise `null`
428
- * @param {string} [contents] File contents, if there hasn't been an error
429
- * @returns {undefined}
430
- */
431
-
432
- /**
433
- * Options as used by {@link util.fetch}.
434
- * @typedef FetchOptions
435
- * @type {Object}
436
- * @property {boolean} [binary=false] Whether expecting a binary response
437
- * @property {boolean} [xhr=false] If `true`, forces the use of XMLHttpRequest
438
- */
439
-
440
- /**
441
- * Fetches the contents of a file.
442
- * @memberof util
443
- * @param {string} filename File path or url
444
- * @param {FetchOptions} options Fetch options
445
- * @param {FetchCallback} callback Callback function
446
- * @returns {undefined}
447
- */
448
- function fetch(filename, options, callback) {
449
- if (typeof options === "function") {
450
- callback = options;
451
- options = {};
452
- } else if (!options)
453
- options = {};
454
-
455
- if (!callback)
456
- return asPromise(fetch, this, filename, options); // eslint-disable-line no-invalid-this
457
-
458
- // if a node-like filesystem is present, try it first but fall back to XHR if nothing is found.
459
- if (!options.xhr && fs && fs.readFile)
460
- return fs.readFile(filename, function fetchReadFileCallback(err, contents) {
461
- return err && typeof XMLHttpRequest !== "undefined"
462
- ? fetch.xhr(filename, options, callback)
463
- : err
464
- ? callback(err)
465
- : callback(null, options.binary ? contents : contents.toString("utf8"));
466
- });
467
-
468
- // use the XHR version otherwise.
469
- return fetch.xhr(filename, options, callback);
470
- }
471
-
472
- /**
473
- * Fetches the contents of a file.
474
- * @name util.fetch
475
- * @function
476
- * @param {string} path File path or url
477
- * @param {FetchCallback} callback Callback function
478
- * @returns {undefined}
479
- * @variation 2
480
- */
481
-
482
- /**
483
- * Fetches the contents of a file.
484
- * @name util.fetch
485
- * @function
486
- * @param {string} path File path or url
487
- * @param {FetchOptions} [options] Fetch options
488
- * @returns {Promise<string|Uint8Array>} Promise
489
- * @variation 3
490
- */
491
-
492
- /**/
493
- fetch.xhr = function fetch_xhr(filename, options, callback) {
494
- var xhr = new XMLHttpRequest();
495
- xhr.onreadystatechange /* works everywhere */ = function fetchOnReadyStateChange() {
496
-
497
- if (xhr.readyState !== 4)
498
- return undefined;
499
-
500
- // local cors security errors return status 0 / empty string, too. afaik this cannot be
501
- // reliably distinguished from an actually empty file for security reasons. feel free
502
- // to send a pull request if you are aware of a solution.
503
- if (xhr.status !== 0 && xhr.status !== 200)
504
- return callback(Error("status " + xhr.status));
505
-
506
- // if binary data is expected, make sure that some sort of array is returned, even if
507
- // ArrayBuffers are not supported. the binary string fallback, however, is unsafe.
508
- if (options.binary) {
509
- var buffer = xhr.response;
510
- if (!buffer) {
511
- buffer = [];
512
- for (var i = 0; i < xhr.responseText.length; ++i)
513
- buffer.push(xhr.responseText.charCodeAt(i) & 255);
514
- }
515
- return callback(null, typeof Uint8Array !== "undefined" ? new Uint8Array(buffer) : buffer);
516
- }
517
- return callback(null, xhr.responseText);
518
- };
519
-
520
- if (options.binary) {
521
- // ref: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Sending_and_Receiving_Binary_Data#Receiving_binary_data_in_older_browsers
522
- if ("overrideMimeType" in xhr)
523
- xhr.overrideMimeType("text/plain; charset=x-user-defined");
524
- xhr.responseType = "arraybuffer";
525
- }
526
-
527
- xhr.open("GET", filename);
528
- xhr.send();
529
- };
530
-
531
- },{"1":1,"7":7}],6:[function(require,module,exports){
532
- "use strict";
533
-
534
- module.exports = factory(factory);
535
-
536
- /**
537
- * Reads / writes floats / doubles from / to buffers.
538
- * @name util.float
539
- * @namespace
540
- */
541
-
542
- /**
543
- * Writes a 32 bit float to a buffer using little endian byte order.
544
- * @name util.float.writeFloatLE
545
- * @function
546
- * @param {number} val Value to write
547
- * @param {Uint8Array} buf Target buffer
548
- * @param {number} pos Target buffer offset
549
- * @returns {undefined}
550
- */
551
-
552
- /**
553
- * Writes a 32 bit float to a buffer using big endian byte order.
554
- * @name util.float.writeFloatBE
555
- * @function
556
- * @param {number} val Value to write
557
- * @param {Uint8Array} buf Target buffer
558
- * @param {number} pos Target buffer offset
559
- * @returns {undefined}
560
- */
561
-
562
- /**
563
- * Reads a 32 bit float from a buffer using little endian byte order.
564
- * @name util.float.readFloatLE
565
- * @function
566
- * @param {Uint8Array} buf Source buffer
567
- * @param {number} pos Source buffer offset
568
- * @returns {number} Value read
569
- */
570
-
571
- /**
572
- * Reads a 32 bit float from a buffer using big endian byte order.
573
- * @name util.float.readFloatBE
574
- * @function
575
- * @param {Uint8Array} buf Source buffer
576
- * @param {number} pos Source buffer offset
577
- * @returns {number} Value read
578
- */
579
-
580
- /**
581
- * Writes a 64 bit double to a buffer using little endian byte order.
582
- * @name util.float.writeDoubleLE
583
- * @function
584
- * @param {number} val Value to write
585
- * @param {Uint8Array} buf Target buffer
586
- * @param {number} pos Target buffer offset
587
- * @returns {undefined}
588
- */
589
-
590
- /**
591
- * Writes a 64 bit double to a buffer using big endian byte order.
592
- * @name util.float.writeDoubleBE
593
- * @function
594
- * @param {number} val Value to write
595
- * @param {Uint8Array} buf Target buffer
596
- * @param {number} pos Target buffer offset
597
- * @returns {undefined}
598
- */
599
-
600
- /**
601
- * Reads a 64 bit double from a buffer using little endian byte order.
602
- * @name util.float.readDoubleLE
603
- * @function
604
- * @param {Uint8Array} buf Source buffer
605
- * @param {number} pos Source buffer offset
606
- * @returns {number} Value read
607
- */
608
-
609
- /**
610
- * Reads a 64 bit double from a buffer using big endian byte order.
611
- * @name util.float.readDoubleBE
612
- * @function
613
- * @param {Uint8Array} buf Source buffer
614
- * @param {number} pos Source buffer offset
615
- * @returns {number} Value read
616
- */
617
-
618
- // Factory function for the purpose of node-based testing in modified global environments
619
- function factory(exports) {
620
-
621
- // float: typed array
622
- if (typeof Float32Array !== "undefined") (function() {
623
-
624
- var f32 = new Float32Array([ -0 ]),
625
- f8b = new Uint8Array(f32.buffer),
626
- le = f8b[3] === 128;
627
-
628
- function writeFloat_f32_cpy(val, buf, pos) {
629
- f32[0] = val;
630
- buf[pos ] = f8b[0];
631
- buf[pos + 1] = f8b[1];
632
- buf[pos + 2] = f8b[2];
633
- buf[pos + 3] = f8b[3];
634
- }
635
-
636
- function writeFloat_f32_rev(val, buf, pos) {
637
- f32[0] = val;
638
- buf[pos ] = f8b[3];
639
- buf[pos + 1] = f8b[2];
640
- buf[pos + 2] = f8b[1];
641
- buf[pos + 3] = f8b[0];
642
- }
643
-
644
- /* istanbul ignore next */
645
- exports.writeFloatLE = le ? writeFloat_f32_cpy : writeFloat_f32_rev;
646
- /* istanbul ignore next */
647
- exports.writeFloatBE = le ? writeFloat_f32_rev : writeFloat_f32_cpy;
648
-
649
- function readFloat_f32_cpy(buf, pos) {
650
- f8b[0] = buf[pos ];
651
- f8b[1] = buf[pos + 1];
652
- f8b[2] = buf[pos + 2];
653
- f8b[3] = buf[pos + 3];
654
- return f32[0];
655
- }
656
-
657
- function readFloat_f32_rev(buf, pos) {
658
- f8b[3] = buf[pos ];
659
- f8b[2] = buf[pos + 1];
660
- f8b[1] = buf[pos + 2];
661
- f8b[0] = buf[pos + 3];
662
- return f32[0];
663
- }
664
-
665
- /* istanbul ignore next */
666
- exports.readFloatLE = le ? readFloat_f32_cpy : readFloat_f32_rev;
667
- /* istanbul ignore next */
668
- exports.readFloatBE = le ? readFloat_f32_rev : readFloat_f32_cpy;
669
-
670
- // float: ieee754
671
- })(); else (function() {
672
-
673
- function writeFloat_ieee754(writeUint, val, buf, pos) {
674
- var sign = val < 0 ? 1 : 0;
675
- if (sign)
676
- val = -val;
677
- if (val === 0)
678
- writeUint(1 / val > 0 ? /* positive */ 0 : /* negative 0 */ 2147483648, buf, pos);
679
- else if (isNaN(val))
680
- writeUint(2143289344, buf, pos);
681
- else if (val > 3.4028234663852886e+38) // +-Infinity
682
- writeUint((sign << 31 | 2139095040) >>> 0, buf, pos);
683
- else if (val < 1.1754943508222875e-38) // denormal
684
- writeUint((sign << 31 | Math.round(val / 1.401298464324817e-45)) >>> 0, buf, pos);
685
- else {
686
- var exponent = Math.floor(Math.log(val) / Math.LN2),
687
- mantissa = Math.round(val * Math.pow(2, -exponent) * 8388608) & 8388607;
688
- writeUint((sign << 31 | exponent + 127 << 23 | mantissa) >>> 0, buf, pos);
689
- }
690
- }
691
-
692
- exports.writeFloatLE = writeFloat_ieee754.bind(null, writeUintLE);
693
- exports.writeFloatBE = writeFloat_ieee754.bind(null, writeUintBE);
694
-
695
- function readFloat_ieee754(readUint, buf, pos) {
696
- var uint = readUint(buf, pos),
697
- sign = (uint >> 31) * 2 + 1,
698
- exponent = uint >>> 23 & 255,
699
- mantissa = uint & 8388607;
700
- return exponent === 255
701
- ? mantissa
702
- ? NaN
703
- : sign * Infinity
704
- : exponent === 0 // denormal
705
- ? sign * 1.401298464324817e-45 * mantissa
706
- : sign * Math.pow(2, exponent - 150) * (mantissa + 8388608);
707
- }
708
-
709
- exports.readFloatLE = readFloat_ieee754.bind(null, readUintLE);
710
- exports.readFloatBE = readFloat_ieee754.bind(null, readUintBE);
711
-
712
- })();
713
-
714
- // double: typed array
715
- if (typeof Float64Array !== "undefined") (function() {
716
-
717
- var f64 = new Float64Array([-0]),
718
- f8b = new Uint8Array(f64.buffer),
719
- le = f8b[7] === 128;
720
-
721
- function writeDouble_f64_cpy(val, buf, pos) {
722
- f64[0] = val;
723
- buf[pos ] = f8b[0];
724
- buf[pos + 1] = f8b[1];
725
- buf[pos + 2] = f8b[2];
726
- buf[pos + 3] = f8b[3];
727
- buf[pos + 4] = f8b[4];
728
- buf[pos + 5] = f8b[5];
729
- buf[pos + 6] = f8b[6];
730
- buf[pos + 7] = f8b[7];
731
- }
732
-
733
- function writeDouble_f64_rev(val, buf, pos) {
734
- f64[0] = val;
735
- buf[pos ] = f8b[7];
736
- buf[pos + 1] = f8b[6];
737
- buf[pos + 2] = f8b[5];
738
- buf[pos + 3] = f8b[4];
739
- buf[pos + 4] = f8b[3];
740
- buf[pos + 5] = f8b[2];
741
- buf[pos + 6] = f8b[1];
742
- buf[pos + 7] = f8b[0];
743
- }
744
-
745
- /* istanbul ignore next */
746
- exports.writeDoubleLE = le ? writeDouble_f64_cpy : writeDouble_f64_rev;
747
- /* istanbul ignore next */
748
- exports.writeDoubleBE = le ? writeDouble_f64_rev : writeDouble_f64_cpy;
749
-
750
- function readDouble_f64_cpy(buf, pos) {
751
- f8b[0] = buf[pos ];
752
- f8b[1] = buf[pos + 1];
753
- f8b[2] = buf[pos + 2];
754
- f8b[3] = buf[pos + 3];
755
- f8b[4] = buf[pos + 4];
756
- f8b[5] = buf[pos + 5];
757
- f8b[6] = buf[pos + 6];
758
- f8b[7] = buf[pos + 7];
759
- return f64[0];
760
- }
761
-
762
- function readDouble_f64_rev(buf, pos) {
763
- f8b[7] = buf[pos ];
764
- f8b[6] = buf[pos + 1];
765
- f8b[5] = buf[pos + 2];
766
- f8b[4] = buf[pos + 3];
767
- f8b[3] = buf[pos + 4];
768
- f8b[2] = buf[pos + 5];
769
- f8b[1] = buf[pos + 6];
770
- f8b[0] = buf[pos + 7];
771
- return f64[0];
772
- }
773
-
774
- /* istanbul ignore next */
775
- exports.readDoubleLE = le ? readDouble_f64_cpy : readDouble_f64_rev;
776
- /* istanbul ignore next */
777
- exports.readDoubleBE = le ? readDouble_f64_rev : readDouble_f64_cpy;
778
-
779
- // double: ieee754
780
- })(); else (function() {
781
-
782
- function writeDouble_ieee754(writeUint, off0, off1, val, buf, pos) {
783
- var sign = val < 0 ? 1 : 0;
784
- if (sign)
785
- val = -val;
786
- if (val === 0) {
787
- writeUint(0, buf, pos + off0);
788
- writeUint(1 / val > 0 ? /* positive */ 0 : /* negative 0 */ 2147483648, buf, pos + off1);
789
- } else if (isNaN(val)) {
790
- writeUint(0, buf, pos + off0);
791
- writeUint(2146959360, buf, pos + off1);
792
- } else if (val > 1.7976931348623157e+308) { // +-Infinity
793
- writeUint(0, buf, pos + off0);
794
- writeUint((sign << 31 | 2146435072) >>> 0, buf, pos + off1);
795
- } else {
796
- var mantissa;
797
- if (val < 2.2250738585072014e-308) { // denormal
798
- mantissa = val / 5e-324;
799
- writeUint(mantissa >>> 0, buf, pos + off0);
800
- writeUint((sign << 31 | mantissa / 4294967296) >>> 0, buf, pos + off1);
801
- } else {
802
- var exponent = Math.floor(Math.log(val) / Math.LN2);
803
- if (exponent === 1024)
804
- exponent = 1023;
805
- mantissa = val * Math.pow(2, -exponent);
806
- writeUint(mantissa * 4503599627370496 >>> 0, buf, pos + off0);
807
- writeUint((sign << 31 | exponent + 1023 << 20 | mantissa * 1048576 & 1048575) >>> 0, buf, pos + off1);
808
- }
809
- }
810
- }
811
-
812
- exports.writeDoubleLE = writeDouble_ieee754.bind(null, writeUintLE, 0, 4);
813
- exports.writeDoubleBE = writeDouble_ieee754.bind(null, writeUintBE, 4, 0);
814
-
815
- function readDouble_ieee754(readUint, off0, off1, buf, pos) {
816
- var lo = readUint(buf, pos + off0),
817
- hi = readUint(buf, pos + off1);
818
- var sign = (hi >> 31) * 2 + 1,
819
- exponent = hi >>> 20 & 2047,
820
- mantissa = 4294967296 * (hi & 1048575) + lo;
821
- return exponent === 2047
822
- ? mantissa
823
- ? NaN
824
- : sign * Infinity
825
- : exponent === 0 // denormal
826
- ? sign * 5e-324 * mantissa
827
- : sign * Math.pow(2, exponent - 1075) * (mantissa + 4503599627370496);
828
- }
829
-
830
- exports.readDoubleLE = readDouble_ieee754.bind(null, readUintLE, 0, 4);
831
- exports.readDoubleBE = readDouble_ieee754.bind(null, readUintBE, 4, 0);
832
-
833
- })();
834
-
835
- return exports;
836
- }
837
-
838
- // uint helpers
839
-
840
- function writeUintLE(val, buf, pos) {
841
- buf[pos ] = val & 255;
842
- buf[pos + 1] = val >>> 8 & 255;
843
- buf[pos + 2] = val >>> 16 & 255;
844
- buf[pos + 3] = val >>> 24;
845
- }
846
-
847
- function writeUintBE(val, buf, pos) {
848
- buf[pos ] = val >>> 24;
849
- buf[pos + 1] = val >>> 16 & 255;
850
- buf[pos + 2] = val >>> 8 & 255;
851
- buf[pos + 3] = val & 255;
852
- }
853
-
854
- function readUintLE(buf, pos) {
855
- return (buf[pos ]
856
- | buf[pos + 1] << 8
857
- | buf[pos + 2] << 16
858
- | buf[pos + 3] << 24) >>> 0;
859
- }
860
-
861
- function readUintBE(buf, pos) {
862
- return (buf[pos ] << 24
863
- | buf[pos + 1] << 16
864
- | buf[pos + 2] << 8
865
- | buf[pos + 3]) >>> 0;
866
- }
867
-
868
- },{}],7:[function(require,module,exports){
869
- "use strict";
870
- module.exports = inquire;
871
-
872
- /**
873
- * Requires a module only if available.
874
- * @memberof util
875
- * @param {string} moduleName Module to require
876
- * @returns {?Object} Required module if available and not empty, otherwise `null`
877
- */
878
- function inquire(moduleName) {
879
- try {
880
- var mod = eval("quire".replace(/^/,"re"))(moduleName); // eslint-disable-line no-eval
881
- if (mod && (mod.length || Object.keys(mod).length))
882
- return mod;
883
- } catch (e) {} // eslint-disable-line no-empty
884
- return null;
885
- }
886
-
887
- },{}],8:[function(require,module,exports){
888
- "use strict";
889
-
890
- /**
891
- * A minimal path module to resolve Unix, Windows and URL paths alike.
892
- * @memberof util
893
- * @namespace
894
- */
895
- var path = exports;
896
-
897
- var isAbsolute =
898
- /**
899
- * Tests if the specified path is absolute.
900
- * @param {string} path Path to test
901
- * @returns {boolean} `true` if path is absolute
902
- */
903
- path.isAbsolute = function isAbsolute(path) {
904
- return /^(?:\/|\w+:)/.test(path);
905
- };
906
-
907
- var normalize =
908
- /**
909
- * Normalizes the specified path.
910
- * @param {string} path Path to normalize
911
- * @returns {string} Normalized path
912
- */
913
- path.normalize = function normalize(path) {
914
- path = path.replace(/\\/g, "/")
915
- .replace(/\/{2,}/g, "/");
916
- var parts = path.split("/"),
917
- absolute = isAbsolute(path),
918
- prefix = "";
919
- if (absolute)
920
- prefix = parts.shift() + "/";
921
- for (var i = 0; i < parts.length;) {
922
- if (parts[i] === "..") {
923
- if (i > 0 && parts[i - 1] !== "..")
924
- parts.splice(--i, 2);
925
- else if (absolute)
926
- parts.splice(i, 1);
927
- else
928
- ++i;
929
- } else if (parts[i] === ".")
930
- parts.splice(i, 1);
931
- else
932
- ++i;
933
- }
934
- return prefix + parts.join("/");
935
- };
936
-
937
- /**
938
- * Resolves the specified include path against the specified origin path.
939
- * @param {string} originPath Path to the origin file
940
- * @param {string} includePath Include path relative to origin path
941
- * @param {boolean} [alreadyNormalized=false] `true` if both paths are already known to be normalized
942
- * @returns {string} Path to the include file
943
- */
944
- path.resolve = function resolve(originPath, includePath, alreadyNormalized) {
945
- if (!alreadyNormalized)
946
- includePath = normalize(includePath);
947
- if (isAbsolute(includePath))
948
- return includePath;
949
- if (!alreadyNormalized)
950
- originPath = normalize(originPath);
951
- return (originPath = originPath.replace(/(?:\/|^)[^/]+$/, "")).length ? normalize(originPath + "/" + includePath) : includePath;
952
- };
953
-
954
- },{}],9:[function(require,module,exports){
955
- "use strict";
956
- module.exports = pool;
957
-
958
- /**
959
- * An allocator as used by {@link util.pool}.
960
- * @typedef PoolAllocator
961
- * @type {function}
962
- * @param {number} size Buffer size
963
- * @returns {Uint8Array} Buffer
964
- */
965
-
966
- /**
967
- * A slicer as used by {@link util.pool}.
968
- * @typedef PoolSlicer
969
- * @type {function}
970
- * @param {number} start Start offset
971
- * @param {number} end End offset
972
- * @returns {Uint8Array} Buffer slice
973
- * @this {Uint8Array}
974
- */
975
-
976
- /**
977
- * A general purpose buffer pool.
978
- * @memberof util
979
- * @function
980
- * @param {PoolAllocator} alloc Allocator
981
- * @param {PoolSlicer} slice Slicer
982
- * @param {number} [size=8192] Slab size
983
- * @returns {PoolAllocator} Pooled allocator
984
- */
985
- function pool(alloc, slice, size) {
986
- var SIZE = size || 8192;
987
- var MAX = SIZE >>> 1;
988
- var slab = null;
989
- var offset = SIZE;
990
- return function pool_alloc(size) {
991
- if (size < 1 || size > MAX)
992
- return alloc(size);
993
- if (offset + size > SIZE) {
994
- slab = alloc(SIZE);
995
- offset = 0;
996
- }
997
- var buf = slice.call(slab, offset, offset += size);
998
- if (offset & 7) // align to 32 bit
999
- offset = (offset | 7) + 1;
1000
- return buf;
1001
- };
1002
- }
1003
-
1004
- },{}],10:[function(require,module,exports){
1005
- "use strict";
1006
-
1007
- /**
1008
- * A minimal UTF8 implementation for number arrays.
1009
- * @memberof util
1010
- * @namespace
1011
- */
1012
- var utf8 = exports;
1013
-
1014
- /**
1015
- * Calculates the UTF8 byte length of a string.
1016
- * @param {string} string String
1017
- * @returns {number} Byte length
1018
- */
1019
- utf8.length = function utf8_length(string) {
1020
- var len = 0,
1021
- c = 0;
1022
- for (var i = 0; i < string.length; ++i) {
1023
- c = string.charCodeAt(i);
1024
- if (c < 128)
1025
- len += 1;
1026
- else if (c < 2048)
1027
- len += 2;
1028
- else if ((c & 0xFC00) === 0xD800 && (string.charCodeAt(i + 1) & 0xFC00) === 0xDC00) {
1029
- ++i;
1030
- len += 4;
1031
- } else
1032
- len += 3;
1033
- }
1034
- return len;
1035
- };
1036
-
1037
- /**
1038
- * Reads UTF8 bytes as a string.
1039
- * @param {Uint8Array} buffer Source buffer
1040
- * @param {number} start Source start
1041
- * @param {number} end Source end
1042
- * @returns {string} String read
1043
- */
1044
- utf8.read = function utf8_read(buffer, start, end) {
1045
- var len = end - start;
1046
- if (len < 1)
1047
- return "";
1048
- var parts = null,
1049
- chunk = [],
1050
- i = 0, // char offset
1051
- t; // temporary
1052
- while (start < end) {
1053
- t = buffer[start++];
1054
- if (t < 128)
1055
- chunk[i++] = t;
1056
- else if (t > 191 && t < 224)
1057
- chunk[i++] = (t & 31) << 6 | buffer[start++] & 63;
1058
- else if (t > 239 && t < 365) {
1059
- t = ((t & 7) << 18 | (buffer[start++] & 63) << 12 | (buffer[start++] & 63) << 6 | buffer[start++] & 63) - 0x10000;
1060
- chunk[i++] = 0xD800 + (t >> 10);
1061
- chunk[i++] = 0xDC00 + (t & 1023);
1062
- } else
1063
- chunk[i++] = (t & 15) << 12 | (buffer[start++] & 63) << 6 | buffer[start++] & 63;
1064
- if (i > 8191) {
1065
- (parts || (parts = [])).push(String.fromCharCode.apply(String, chunk));
1066
- i = 0;
1067
- }
1068
- }
1069
- if (parts) {
1070
- if (i)
1071
- parts.push(String.fromCharCode.apply(String, chunk.slice(0, i)));
1072
- return parts.join("");
1073
- }
1074
- return String.fromCharCode.apply(String, chunk.slice(0, i));
1075
- };
1076
-
1077
- /**
1078
- * Writes a string as UTF8 bytes.
1079
- * @param {string} string Source string
1080
- * @param {Uint8Array} buffer Destination buffer
1081
- * @param {number} offset Destination offset
1082
- * @returns {number} Bytes written
1083
- */
1084
- utf8.write = function utf8_write(string, buffer, offset) {
1085
- var start = offset,
1086
- c1, // character 1
1087
- c2; // character 2
1088
- for (var i = 0; i < string.length; ++i) {
1089
- c1 = string.charCodeAt(i);
1090
- if (c1 < 128) {
1091
- buffer[offset++] = c1;
1092
- } else if (c1 < 2048) {
1093
- buffer[offset++] = c1 >> 6 | 192;
1094
- buffer[offset++] = c1 & 63 | 128;
1095
- } else if ((c1 & 0xFC00) === 0xD800 && ((c2 = string.charCodeAt(i + 1)) & 0xFC00) === 0xDC00) {
1096
- c1 = 0x10000 + ((c1 & 0x03FF) << 10) + (c2 & 0x03FF);
1097
- ++i;
1098
- buffer[offset++] = c1 >> 18 | 240;
1099
- buffer[offset++] = c1 >> 12 & 63 | 128;
1100
- buffer[offset++] = c1 >> 6 & 63 | 128;
1101
- buffer[offset++] = c1 & 63 | 128;
1102
- } else {
1103
- buffer[offset++] = c1 >> 12 | 224;
1104
- buffer[offset++] = c1 >> 6 & 63 | 128;
1105
- buffer[offset++] = c1 & 63 | 128;
1106
- }
1107
- }
1108
- return offset - start;
1109
- };
1110
-
1111
- },{}],11:[function(require,module,exports){
1112
43
  "use strict";
1113
44
  /**
1114
45
  * Runtime message from/to plain object converters.
@@ -1116,8 +47,9 @@ utf8.write = function utf8_write(string, buffer, offset) {
1116
47
  */
1117
48
  var converter = exports;
1118
49
 
1119
- var Enum = require(14),
1120
- util = require(33);
50
+ var Enum = require(5),
51
+ types = require(23),
52
+ util = require(24);
1121
53
 
1122
54
  /**
1123
55
  * Generates a partial value fromObject conveter.
@@ -1138,7 +70,7 @@ function genValuePartial_fromObject(gen, field, fieldIndex, prop) {
1138
70
  // enum unknown values passthrough
1139
71
  if (values[keys[i]] === field.typeDefault && !defaultAlreadyEmitted) { gen
1140
72
  ("default:")
1141
- ("if(typeof(d%s)===\"number\"){m%s=d%s;break}", prop, prop, prop);
73
+ ("if(typeof d%s===\"number\"){m%s=d%s;break}", prop, prop, prop);
1142
74
  if (!field.repeated) gen // fallback to default value only for
1143
75
  // arrays, to avoid leaving holes.
1144
76
  ("break"); // for non-repeated fields, just ignore
@@ -1154,7 +86,7 @@ function genValuePartial_fromObject(gen, field, fieldIndex, prop) {
1154
86
  } else gen
1155
87
  ("if(typeof d%s!==\"object\")", prop)
1156
88
  ("throw TypeError(%j)", field.fullName + ": object expected")
1157
- ("m%s=types[%i].fromObject(d%s)", prop, fieldIndex, prop);
89
+ ("m%s=types[%i].fromObject(d%s,q+1)", prop, fieldIndex, prop);
1158
90
  } else {
1159
91
  var isUnsigned = false;
1160
92
  switch (field.type) {
@@ -1190,7 +122,7 @@ function genValuePartial_fromObject(gen, field, fieldIndex, prop) {
1190
122
  case "bytes": gen
1191
123
  ("if(typeof d%s===\"string\")", prop)
1192
124
  ("util.base64.decode(d%s,m%s=util.newBuffer(util.base64.length(d%s)),0)", prop, prop, prop)
1193
- ("else if(d%s.length >= 0)", prop)
125
+ ("else if(d%s.length>=0)", prop)
1194
126
  ("m%s=d%s", prop, prop);
1195
127
  break;
1196
128
  case "string": gen
@@ -1216,16 +148,21 @@ function genValuePartial_fromObject(gen, field, fieldIndex, prop) {
1216
148
  converter.fromObject = function fromObject(mtype) {
1217
149
  /* eslint-disable no-unexpected-multiline, block-scoped-var, no-redeclare */
1218
150
  var fields = mtype.fieldsArray;
1219
- var gen = util.codegen(["d"], mtype.name + "$fromObject")
151
+ var gen = util.codegen(["d", "q"], mtype.name + "$fromObject")
1220
152
  ("if(d instanceof this.ctor)")
1221
- ("return d");
153
+ ("return d")
154
+ ("if(q===undefined)q=0")
155
+ ("if(q>util.recursionLimit)")
156
+ ("throw Error(\"max depth exceeded\")");
1222
157
  if (!fields.length) return gen
1223
158
  ("return new this.ctor");
1224
159
  gen
1225
160
  ("var m=new this.ctor");
1226
161
  for (var i = 0; i < fields.length; ++i) {
1227
162
  var field = fields[i].resolve(),
1228
- prop = util.safeProp(field.name);
163
+ prop = util.safeProp(field.name),
164
+ implicitPresence = !field.hasPresence && !field.repeated && !field.map
165
+ && (field.resolvedType instanceof Enum || types.basic[field.type] !== undefined);
1229
166
 
1230
167
  // Map fields
1231
168
  if (field.map) { gen
@@ -1234,6 +171,9 @@ converter.fromObject = function fromObject(mtype) {
1234
171
  ("throw TypeError(%j)", field.fullName + ": object expected")
1235
172
  ("m%s={}", prop)
1236
173
  ("for(var ks=Object.keys(d%s),i=0;i<ks.length;++i){", prop);
174
+ gen
175
+ ("if(ks[i]===\"__proto__\")")
176
+ ("util.makeProp(m%s,ks[i])", prop);
1237
177
  genValuePartial_fromObject(gen, field, /* not sorted */ i, prop + "[ks[i]]")
1238
178
  ("}")
1239
179
  ("}");
@@ -1243,7 +183,7 @@ converter.fromObject = function fromObject(mtype) {
1243
183
  ("if(d%s){", prop)
1244
184
  ("if(!Array.isArray(d%s))", prop)
1245
185
  ("throw TypeError(%j)", field.fullName + ": array expected")
1246
- ("m%s=[]", prop)
186
+ ("m%s=Array(d%s.length)", prop, prop)
1247
187
  ("for(var i=0;i<d%s.length;++i){", prop);
1248
188
  genValuePartial_fromObject(gen, field, /* not sorted */ i, prop + "[i]")
1249
189
  ("}")
@@ -1253,7 +193,23 @@ converter.fromObject = function fromObject(mtype) {
1253
193
  } else {
1254
194
  if (!(field.resolvedType instanceof Enum)) gen // no need to test for null/undefined if an enum (uses switch)
1255
195
  ("if(d%s!=null){", prop); // !== undefined && !== null
196
+ if (implicitPresence) {
197
+ if (field.resolvedType instanceof Enum) gen
198
+ ("if(d%s!==%j&&(typeof d%s!==\"string\"||types[%i].values[d%s]!==%j)){", prop, field.typeDefault, prop, i, prop, field.typeDefault);
199
+ else if (field.type === "string") gen
200
+ ("if(typeof d%s!==\"string\"||d%s.length){", prop, prop);
201
+ else if (field.type === "bytes") gen
202
+ ("if(d%s.length){", prop);
203
+ else if (field.type === "bool") gen
204
+ ("if(d%s){", prop);
205
+ else if (types.long[field.type] !== undefined) gen
206
+ ("if(typeof d%s===\"object\"?d%s.low||d%s.high:Number(d%s)!==0){", prop, prop, prop, prop);
207
+ else gen
208
+ ("if(Number(d%s)!==0){", prop);
209
+ }
1256
210
  genValuePartial_fromObject(gen, field, /* not sorted */ i, prop);
211
+ if (implicitPresence) gen
212
+ ("}");
1257
213
  if (!(field.resolvedType instanceof Enum)) gen
1258
214
  ("}");
1259
215
  }
@@ -1267,23 +223,26 @@ converter.fromObject = function fromObject(mtype) {
1267
223
  * @param {Codegen} gen Codegen instance
1268
224
  * @param {Field} field Reflected field
1269
225
  * @param {number} fieldIndex Field index
1270
- * @param {string} prop Property reference
226
+ * @param {string} dstProp Destination property reference
227
+ * @param {string} [srcProp] Source property reference
1271
228
  * @returns {Codegen} Codegen instance
1272
229
  * @ignore
1273
230
  */
1274
- function genValuePartial_toObject(gen, field, fieldIndex, prop) {
231
+ function genValuePartial_toObject(gen, field, fieldIndex, dstProp, srcProp) {
1275
232
  /* eslint-disable no-unexpected-multiline, block-scoped-var, no-redeclare */
233
+ if (!srcProp)
234
+ srcProp = dstProp;
1276
235
  if (field.resolvedType) {
1277
236
  if (field.resolvedType instanceof Enum) gen
1278
- ("d%s=o.enums===String?(types[%i].values[m%s]===undefined?m%s:types[%i].values[m%s]):m%s", prop, fieldIndex, prop, prop, fieldIndex, prop, prop);
237
+ ("d%s=o.enums===String?(types[%i].values[m%s]===undefined?m%s:types[%i].values[m%s]):m%s", dstProp, fieldIndex, srcProp, srcProp, fieldIndex, srcProp, srcProp);
1279
238
  else gen
1280
- ("d%s=types[%i].toObject(m%s,o)", prop, fieldIndex, prop);
239
+ ("d%s=types[%i].toObject(m%s,o)", dstProp, fieldIndex, srcProp);
1281
240
  } else {
1282
241
  var isUnsigned = false;
1283
242
  switch (field.type) {
1284
243
  case "double":
1285
244
  case "float": gen
1286
- ("d%s=o.json&&!isFinite(m%s)?String(m%s):m%s", prop, prop, prop, prop);
245
+ ("d%s=o.json&&!isFinite(m%s)?String(m%s):m%s", dstProp, srcProp, srcProp, srcProp);
1287
246
  break;
1288
247
  case "uint64":
1289
248
  isUnsigned = true;
@@ -1292,16 +251,16 @@ function genValuePartial_toObject(gen, field, fieldIndex, prop) {
1292
251
  case "sint64":
1293
252
  case "fixed64":
1294
253
  case "sfixed64": gen
1295
- ("if(typeof m%s===\"number\")", prop)
1296
- ("d%s=o.longs===String?String(m%s):m%s", prop, prop, prop)
254
+ ("if(typeof m%s===\"number\")", srcProp)
255
+ ("d%s=o.longs===String?String(m%s):m%s", dstProp, srcProp, srcProp)
1297
256
  ("else") // Long-like
1298
- ("d%s=o.longs===String?util.Long.prototype.toString.call(m%s):o.longs===Number?new util.LongBits(m%s.low>>>0,m%s.high>>>0).toNumber(%s):m%s", prop, prop, prop, prop, isUnsigned ? "true": "", prop);
257
+ ("d%s=o.longs===String?util.Long.prototype.toString.call(m%s):o.longs===Number?new util.LongBits(m%s.low>>>0,m%s.high>>>0).toNumber(%s):m%s", dstProp, srcProp, srcProp, srcProp, isUnsigned ? "true": "", srcProp);
1299
258
  break;
1300
259
  case "bytes": gen
1301
- ("d%s=o.bytes===String?util.base64.encode(m%s,0,m%s.length):o.bytes===Array?Array.prototype.slice.call(m%s):m%s", prop, prop, prop, prop, prop);
260
+ ("d%s=o.bytes===String?util.base64.encode(m%s,0,m%s.length):o.bytes===Array?Array.prototype.slice.call(m%s):m%s", dstProp, srcProp, srcProp, srcProp, srcProp);
1302
261
  break;
1303
262
  default: gen
1304
- ("d%s=m%s", prop, prop);
263
+ ("d%s=m%s", dstProp, srcProp);
1305
264
  break;
1306
265
  }
1307
266
  }
@@ -1364,11 +323,11 @@ converter.toObject = function toObject(mtype) {
1364
323
  ("}else")
1365
324
  ("d%s=o.longs===String?%j:%i", prop, field.typeDefault.toString(), field.typeDefault.toNumber());
1366
325
  else if (field.bytes) {
1367
- var arrayDefault = "[" + Array.prototype.slice.call(field.typeDefault).join(",") + "]";
326
+ var arrayDefault = Array.prototype.slice.call(field.typeDefault);
1368
327
  gen
1369
328
  ("if(o.bytes===String)d%s=%j", prop, String.fromCharCode.apply(String, field.typeDefault))
1370
329
  ("else{")
1371
- ("d%s=%s", prop, arrayDefault)
330
+ ("d%s=%j", prop, arrayDefault)
1372
331
  ("if(o.bytes!==Array)d%s=util.newBuffer(d%s)", prop, prop)
1373
332
  ("}");
1374
333
  } else gen
@@ -1386,13 +345,21 @@ converter.toObject = function toObject(mtype) {
1386
345
  ("var ks2");
1387
346
  } gen
1388
347
  ("if(m%s&&(ks2=Object.keys(m%s)).length){", prop, prop)
1389
- ("d%s={}", prop)
348
+ ("d%s={}", prop);
349
+ var longKey = types.long[field.keyType] !== undefined,
350
+ srcProp = prop + "[ks2[j]]";
351
+ gen
1390
352
  ("for(var j=0;j<ks2.length;++j){");
1391
- genValuePartial_toObject(gen, field, /* sorted */ index, prop + "[ks2[j]]")
353
+ if (longKey) gen
354
+ ("var k2=util.longFromKey(ks2[j],%j).toString()", field.keyType === "uint64" || field.keyType === "fixed64");
355
+ gen
356
+ ("if(ks2[j]===\"__proto__\")")
357
+ ("util.makeProp(d%s,ks2[j])", prop);
358
+ genValuePartial_toObject(gen, field, /* sorted */ index, longKey ? prop + "[k2]" : srcProp, srcProp)
1392
359
  ("}");
1393
360
  } else if (field.repeated) { gen
1394
361
  ("if(m%s&&m%s.length){", prop, prop)
1395
- ("d%s=[]", prop)
362
+ ("d%s=Array(m%s.length)", prop, prop)
1396
363
  ("for(var j=0;j<m%s.length;++j){", prop);
1397
364
  genValuePartial_toObject(gen, field, /* sorted */ index, prop + "[j]")
1398
365
  ("}");
@@ -1411,13 +378,13 @@ converter.toObject = function toObject(mtype) {
1411
378
  /* eslint-enable no-unexpected-multiline, block-scoped-var, no-redeclare */
1412
379
  };
1413
380
 
1414
- },{"14":14,"33":33}],12:[function(require,module,exports){
381
+ },{"23":23,"24":24,"5":5}],3:[function(require,module,exports){
1415
382
  "use strict";
1416
383
  module.exports = decoder;
1417
384
 
1418
- var Enum = require(14),
1419
- types = require(32),
1420
- util = require(33);
385
+ var Enum = require(5),
386
+ types = require(23),
387
+ util = require(24);
1421
388
 
1422
389
  function missing(field) {
1423
390
  return "missing required '" + field.name + "'";
@@ -1430,28 +397,47 @@ function missing(field) {
1430
397
  */
1431
398
  function decoder(mtype) {
1432
399
  /* eslint-disable no-unexpected-multiline */
1433
- var gen = util.codegen(["r", "l", "e"], mtype.name + "$decode")
400
+ var hasMapField = false,
401
+ hasImplicitPresenceField = false,
402
+ i = 0;
403
+ for (; i < mtype.fieldsArray.length; ++i) {
404
+ var pfield = mtype._fieldsArray[i];
405
+ if (pfield.map)
406
+ hasMapField = true;
407
+ if (!pfield.repeated && !pfield.map && !pfield.hasPresence)
408
+ hasImplicitPresenceField = true;
409
+ }
410
+ var gen = util.codegen(["r", "l", "z", "q", "g"], mtype.name + "$decode")
1434
411
  ("if(!(r instanceof Reader))")
1435
412
  ("r=Reader.create(r)")
1436
- ("var c=l===undefined?r.len:r.pos+l,m=new this.ctor" + (mtype.fieldsArray.filter(function(field) { return field.map; }).length ? ",k,value" : ""))
413
+ ("if(q===undefined)q=0")
414
+ ("if(q>Reader.recursionLimit)")
415
+ ("throw Error(\"max depth exceeded\")")
416
+ ("var c=l===undefined?r.len:r.pos+l,m=g||new this.ctor" + (hasMapField ? ",k,v" : hasImplicitPresenceField ? ",v" : ""))
1437
417
  ("while(r.pos<c){")
1438
- ("var t=r.uint32()")
1439
- ("if(t===e)")
418
+ ("var s=r.pos")
419
+ ("var t=r.tag()")
420
+ ("if(t===z){")
421
+ ("z=undefined")
1440
422
  ("break")
1441
- ("switch(t>>>3){");
1442
-
1443
- var i = 0;
1444
- for (; i < /* initializes */ mtype.fieldsArray.length; ++i) {
423
+ ("}");
424
+ if (mtype.fieldsArray.length) gen
425
+ ("var u=t&7")
426
+ ("switch(t>>>=3){");
427
+ for (i = 0; i < /* initializes */ mtype.fieldsArray.length; ++i) {
1445
428
  var field = mtype._fieldsArray[i].resolve(),
1446
429
  type = field.resolvedType instanceof Enum ? "int32" : field.type,
1447
- ref = "m" + util.safeProp(field.name); gen
1448
- ("case %i: {", field.id);
430
+ ref = "m" + util.safeProp(field.name);
1449
431
 
1450
432
  // Map fields
1451
- if (field.map) { gen
433
+ if (field.map) {
434
+ gen
435
+ ("case %i:{", field.id)
436
+ ("if(u!==2)")
437
+ ("break")
1452
438
  ("if(%s===util.emptyObject)", ref)
1453
439
  ("%s={}", ref)
1454
- ("var c2 = r.uint32()+r.pos");
440
+ ("var c2=r.uint32()+r.pos");
1455
441
 
1456
442
  if (types.defaults[field.keyType] !== undefined) gen
1457
443
  ("k=%j", types.defaults[field.keyType]);
@@ -1459,73 +445,127 @@ function decoder(mtype) {
1459
445
  ("k=null");
1460
446
 
1461
447
  if (types.defaults[type] !== undefined) gen
1462
- ("value=%j", types.defaults[type]);
448
+ ("v=%j", types.defaults[type]);
1463
449
  else gen
1464
- ("value=null");
450
+ ("v=null");
1465
451
 
1466
452
  gen
1467
453
  ("while(r.pos<c2){")
1468
- ("var tag2=r.uint32()")
1469
- ("switch(tag2>>>3){")
1470
- ("case 1: k=r.%s(); break", field.keyType)
1471
- ("case 2:");
454
+ ("var t2=r.tag()")
455
+ ("u=t2&7")
456
+ ("switch(t2>>>=3){")
457
+ ("case 1:")
458
+ ("if(u!==%i)", types.mapKey[field.keyType])
459
+ ("break")
460
+ ("k=r.%s()", field.keyType)
461
+ ("continue")
462
+ ("case 2:")
463
+ ("if(u!==%i)", types.basic[type] === undefined ? 2 : types.basic[type])
464
+ ("break");
1472
465
 
1473
466
  if (types.basic[type] === undefined) gen
1474
- ("value=types[%i].decode(r,r.uint32())", i); // can't be groups
467
+ ("v=types[%i].decode(r,r.uint32(),undefined,q+1)", i); // can't be groups
1475
468
  else gen
1476
- ("value=r.%s()", type);
469
+ ("v=r.%s()", type);
1477
470
 
1478
471
  gen
1479
- ("break")
1480
- ("default:")
1481
- ("r.skipType(tag2&7)")
1482
- ("break")
472
+ ("continue")
1483
473
  ("}")
474
+ ("r.skipType(u,q,t2)")
1484
475
  ("}");
1485
476
 
477
+ var val = types.basic[type] === undefined ? "v||new types[" + i + "].ctor" : "v";
1486
478
  if (types.long[field.keyType] !== undefined) gen
1487
- ("%s[typeof k===\"object\"?util.longToHash(k):k]=value", ref);
1488
- else gen
1489
- ("%s[k]=value", ref);
479
+ ("%s[typeof k===\"object\"?util.longToHash(k):k]=%s", ref, val);
480
+ else {
481
+ if (field.keyType === "string") gen
482
+ ("if(k===\"__proto__\")")
483
+ ("util.makeProp(%s,k)", ref);
484
+ gen
485
+ ("%s[k]=%s", ref, val);
486
+ }
1490
487
 
1491
488
  // Repeated fields
1492
489
  } else if (field.repeated) { gen
1493
-
1494
- ("if(!(%s&&%s.length))", ref, ref)
1495
- ("%s=[]", ref);
490
+ ("case %i:", field.id)
491
+ ("{");
1496
492
 
1497
493
  // Packable (always check for forward and backward compatiblity)
1498
494
  if (types.packed[type] !== undefined) gen
1499
- ("if((t&7)===2){")
495
+ ("if(u===2){")
496
+ ("if(!(%s&&%s.length))", ref, ref)
497
+ ("%s=[]", ref)
1500
498
  ("var c2=r.uint32()+r.pos")
1501
499
  ("while(r.pos<c2)")
1502
500
  ("%s.push(r.%s())", ref, type)
1503
- ("}else");
501
+ ("continue")
502
+ ("}");
1504
503
 
1505
504
  // Non-packed
1506
- if (types.basic[type] === undefined) gen(field.delimited
1507
- ? "%s.push(types[%i].decode(r,undefined,((t&~7)|4)))"
1508
- : "%s.push(types[%i].decode(r,r.uint32()))", ref, i);
1509
- else gen
505
+ gen
506
+ ("if(u!==%i)", types.basic[type] === undefined ? field.delimited ? 3 : 2 : types.basic[type])
507
+ ("break")
508
+ ("if(!(%s&&%s.length))", ref, ref)
509
+ ("%s=[]", ref);
510
+ if (types.basic[type] === undefined) {
511
+ if (field.delimited) gen
512
+ ("%s.push(types[%i].decode(r,undefined,%i,q+1))", ref, i, field.id * 8 + 4);
513
+ else gen
514
+ ("%s.push(types[%i].decode(r,r.uint32(),undefined,q+1))", ref, i);
515
+ } else gen
1510
516
  ("%s.push(r.%s())", ref, type);
1511
517
 
1512
518
  // Non-repeated
1513
- } else if (types.basic[type] === undefined) gen(field.delimited
1514
- ? "%s=types[%i].decode(r,undefined,((t&~7)|4))"
1515
- : "%s=types[%i].decode(r,r.uint32())", ref, i);
1516
- else gen
519
+ } else if (types.basic[type] === undefined) {
520
+ gen
521
+ ("case %i:{", field.id)
522
+ ("if(u!==%i)", field.delimited ? 3 : 2)
523
+ ("break");
524
+ if (field.delimited) gen
525
+ ("%s=types[%i].decode(r,undefined,%i,q+1,%s)", ref, i, field.id * 8 + 4, ref);
526
+ else gen
527
+ ("%s=types[%i].decode(r,r.uint32(),undefined,q+1,%s)", ref, i, ref);
528
+ }
529
+ else if (field.hasPresence) {
530
+ gen
531
+ ("case %i:{", field.id)
532
+ ("if(u!==%i)", types.basic[type])
533
+ ("break")
1517
534
  ("%s=r.%s()", ref, type);
535
+ } else {
536
+ gen
537
+ ("case %i:{", field.id)
538
+ ("if(u!==%i)", types.basic[type])
539
+ ("break");
540
+ if (type === "string" || type === "bytes") gen
541
+ ("if((v=r.%s()).length)", type);
542
+ else if (types.long[type] !== undefined) gen
543
+ ("if(typeof(v=r.%s())===\"object\"?v.low||v.high:v!==0)", type);
544
+ else if (type === "double" || type === "float") gen
545
+ ("if((v=r.%s())!==0)", type);
546
+ else gen
547
+ ("if(v=r.%s())", type);
548
+ gen
549
+ ("%s=v", ref)
550
+ ("else")
551
+ ("delete %s", ref); // rare/odd case: later default clears earlier non-default
552
+ }
553
+ if (field.partOf) gen
554
+ ("m%s=%j", util.safeProp(field.partOf.name), field.name);
1518
555
  gen
1519
- ("break")
556
+ ("continue")
1520
557
  ("}");
1521
- // Unknown fields
1522
- } gen
1523
- ("default:")
1524
- ("r.skipType(t&7)")
1525
- ("break")
1526
-
1527
- ("}")
1528
- ("}");
558
+ }
559
+ if (i) gen
560
+ ("}");
561
+ // Unknown fields
562
+ gen
563
+ ("r.skipType(%s,q,t)", i ? "u" : "t&7")
564
+ ("util.makeProp(m,\"$unknowns\",false);")
565
+ ("(m.$unknowns||(m.$unknowns=[])).push(r.raw(s,r.pos))")
566
+ ("}")
567
+ ("if(z!==undefined)")
568
+ ("throw Error(\"missing end group\")");
1529
569
 
1530
570
  // Field presence
1531
571
  for (i = 0; i < mtype._fieldsArray.length; ++i) {
@@ -1540,13 +580,13 @@ function decoder(mtype) {
1540
580
  /* eslint-enable no-unexpected-multiline */
1541
581
  }
1542
582
 
1543
- },{"14":14,"32":32,"33":33}],13:[function(require,module,exports){
583
+ },{"23":23,"24":24,"5":5}],4:[function(require,module,exports){
1544
584
  "use strict";
1545
585
  module.exports = encoder;
1546
586
 
1547
- var Enum = require(14),
1548
- types = require(32),
1549
- util = require(33);
587
+ var Enum = require(5),
588
+ types = require(23),
589
+ util = require(24);
1550
590
 
1551
591
  /**
1552
592
  * Generates a partial message type encoder.
@@ -1590,7 +630,12 @@ function encoder(mtype) {
1590
630
  if (field.map) {
1591
631
  gen
1592
632
  ("if(%s!=null&&Object.hasOwnProperty.call(m,%j)){", ref, field.name) // !== undefined && !== null
1593
- ("for(var ks=Object.keys(%s),i=0;i<ks.length;++i){", ref)
633
+ ("for(var ks=Object.keys(%s),i=0;i<ks.length;++i){", ref);
634
+ if (field.keyType === "bool") gen
635
+ ("w.uint32(%i).fork().uint32(%i).bool(util.boolFromKey(ks[i]))", (field.id << 3 | 2) >>> 0, 8 | types.mapKey[field.keyType]);
636
+ else if (types.long[field.keyType] !== undefined) gen
637
+ ("w.uint32(%i).fork().uint32(%i).%s(util.longFromKey(ks[i],%j))", (field.id << 3 | 2) >>> 0, 8 | types.mapKey[field.keyType], field.keyType, field.keyType === "uint64" || field.keyType === "fixed64");
638
+ else gen
1594
639
  ("w.uint32(%i).fork().uint32(%i).%s(ks[i])", (field.id << 3 | 2) >>> 0, 8 | types.mapKey[field.keyType], field.keyType);
1595
640
  if (wireType === undefined) gen
1596
641
  ("types[%i].encode(%s[ks[i]],w.uint32(18).fork()).ldelim().ldelim()", index, ref); // can't be groups
@@ -1626,7 +671,7 @@ function encoder(mtype) {
1626
671
 
1627
672
  // Non-repeated
1628
673
  } else {
1629
- if (field.optional) gen
674
+ if (!field.required) gen
1630
675
  ("if(%s!=null&&Object.hasOwnProperty.call(m,%j))", ref, field.name); // !== undefined && !== null
1631
676
 
1632
677
  if (wireType === undefined)
@@ -1638,20 +683,23 @@ function encoder(mtype) {
1638
683
  }
1639
684
 
1640
685
  return gen
686
+ ("if(m.$unknowns!=null&&Object.hasOwnProperty.call(m,\"$unknowns\"))")
687
+ ("for(var i=0;i<m.$unknowns.length;++i)")
688
+ ("w.raw(m.$unknowns[i])")
1641
689
  ("return w");
1642
690
  /* eslint-enable no-unexpected-multiline, block-scoped-var, no-redeclare */
1643
691
  }
1644
692
 
1645
- },{"14":14,"32":32,"33":33}],14:[function(require,module,exports){
693
+ },{"23":23,"24":24,"5":5}],5:[function(require,module,exports){
1646
694
  "use strict";
1647
695
  module.exports = Enum;
1648
696
 
1649
697
  // extends ReflectionObject
1650
- var ReflectionObject = require(22);
698
+ var ReflectionObject = require(13);
1651
699
  ((Enum.prototype = Object.create(ReflectionObject.prototype)).constructor = Enum).className = "Enum";
1652
700
 
1653
- var Namespace = require(21),
1654
- util = require(33);
701
+ var Namespace = require(12),
702
+ util = require(24);
1655
703
 
1656
704
  /**
1657
705
  * Constructs a new enum instance.
@@ -1719,7 +767,7 @@ function Enum(name, values, options, comment, comments, valuesOptions) {
1719
767
 
1720
768
  if (values)
1721
769
  for (var keys = Object.keys(values), i = 0; i < keys.length; ++i)
1722
- if (typeof values[keys[i]] === "number") // use forward entries only
770
+ if (keys[i] !== "__proto__" && typeof values[keys[i]] === "number") // use forward entries only
1723
771
  this.valuesById[ this.values[keys[i]] = values[keys[i]] ] = keys[i];
1724
772
  }
1725
773
 
@@ -1798,6 +846,9 @@ Enum.prototype.add = function add(name, id, comment, options) {
1798
846
  if (!util.isInteger(id))
1799
847
  throw TypeError("id must be an integer");
1800
848
 
849
+ if (name === "__proto__")
850
+ return this;
851
+
1801
852
  if (this.values[name] !== undefined)
1802
853
  throw Error("duplicate name '" + name + "' in " + this);
1803
854
 
@@ -1867,17 +918,17 @@ Enum.prototype.isReservedName = function isReservedName(name) {
1867
918
  return Namespace.isReservedName(this.reserved, name);
1868
919
  };
1869
920
 
1870
- },{"21":21,"22":22,"33":33}],15:[function(require,module,exports){
921
+ },{"12":12,"13":13,"24":24}],6:[function(require,module,exports){
1871
922
  "use strict";
1872
923
  module.exports = Field;
1873
924
 
1874
925
  // extends ReflectionObject
1875
- var ReflectionObject = require(22);
926
+ var ReflectionObject = require(13);
1876
927
  ((Field.prototype = Object.create(ReflectionObject.prototype)).constructor = Field).className = "Field";
1877
928
 
1878
- var Enum = require(14),
1879
- types = require(32),
1880
- util = require(33);
929
+ var Enum = require(5),
930
+ types = require(23),
931
+ util = require(24);
1881
932
 
1882
933
  var Type; // cyclic
1883
934
 
@@ -2222,8 +1273,8 @@ Field.prototype.resolve = function resolve() {
2222
1273
  this.defaultValue = this.typeDefault;
2223
1274
 
2224
1275
  // ensure proper value on prototype
2225
- if (this.parent instanceof Type)
2226
- this.parent.ctor.prototype[this.name] = this.defaultValue;
1276
+ if (this.parent instanceof Type && this.parent._ctor)
1277
+ this.parent._ctor.prototype[this.name] = this.defaultValue;
2227
1278
 
2228
1279
  return ReflectionObject.prototype.resolve.call(this);
2229
1280
  };
@@ -2275,6 +1326,7 @@ Field.prototype._resolveFeatures = function _resolveFeatures(edition) {
2275
1326
  * @param {Object} prototype Target prototype
2276
1327
  * @param {string} fieldName Field name
2277
1328
  * @returns {undefined}
1329
+ * @deprecated Legacy TypeScript decorator support. Will be removed in a future release.
2278
1330
  */
2279
1331
 
2280
1332
  /**
@@ -2287,6 +1339,7 @@ Field.prototype._resolveFeatures = function _resolveFeatures(edition) {
2287
1339
  * @param {T} [defaultValue] Default value
2288
1340
  * @returns {FieldDecorator} Decorator function
2289
1341
  * @template T extends number | number[] | Long | Long[] | string | string[] | boolean | boolean[] | Uint8Array | Uint8Array[] | Buffer | Buffer[]
1342
+ * @deprecated Legacy TypeScript decorator support. Will be removed in a future release.
2290
1343
  */
2291
1344
  Field.d = function decorateField(fieldId, fieldType, fieldRule, defaultValue) {
2292
1345
 
@@ -2304,6 +1357,11 @@ Field.d = function decorateField(fieldId, fieldType, fieldRule, defaultValue) {
2304
1357
  };
2305
1358
  };
2306
1359
 
1360
+ // Sets up cyclic dependencies (called in index-light)
1361
+ Field._configure = function configure(Type_) {
1362
+ Type = Type_;
1363
+ };
1364
+
2307
1365
  /**
2308
1366
  * Field decorator (TypeScript).
2309
1367
  * @name Field.d
@@ -2314,17 +1372,13 @@ Field.d = function decorateField(fieldId, fieldType, fieldRule, defaultValue) {
2314
1372
  * @returns {FieldDecorator} Decorator function
2315
1373
  * @template T extends Message<T>
2316
1374
  * @variation 2
1375
+ * @deprecated Legacy TypeScript decorator support. Will be removed in a future release.
2317
1376
  */
2318
1377
  // like Field.d but without a default value
2319
1378
 
2320
- // Sets up cyclic dependencies (called in index-light)
2321
- Field._configure = function configure(Type_) {
2322
- Type = Type_;
2323
- };
2324
-
2325
- },{"14":14,"22":22,"32":32,"33":33}],16:[function(require,module,exports){
1379
+ },{"13":13,"23":23,"24":24,"5":5}],7:[function(require,module,exports){
2326
1380
  "use strict";
2327
- var protobuf = module.exports = require(17);
1381
+ var protobuf = module.exports = require(8);
2328
1382
 
2329
1383
  protobuf.build = "light";
2330
1384
 
@@ -2397,30 +1451,30 @@ function loadSync(filename, root) {
2397
1451
  protobuf.loadSync = loadSync;
2398
1452
 
2399
1453
  // Serialization
2400
- protobuf.encoder = require(13);
2401
- protobuf.decoder = require(12);
2402
- protobuf.verifier = require(36);
2403
- protobuf.converter = require(11);
1454
+ protobuf.encoder = require(4);
1455
+ protobuf.decoder = require(3);
1456
+ protobuf.verifier = require(39);
1457
+ protobuf.converter = require(2);
2404
1458
 
2405
1459
  // Reflection
2406
- protobuf.ReflectionObject = require(22);
2407
- protobuf.Namespace = require(21);
2408
- protobuf.Root = require(26);
2409
- protobuf.Enum = require(14);
2410
- protobuf.Type = require(31);
2411
- protobuf.Field = require(15);
2412
- protobuf.OneOf = require(23);
2413
- protobuf.MapField = require(18);
2414
- protobuf.Service = require(30);
2415
- protobuf.Method = require(20);
1460
+ protobuf.ReflectionObject = require(13);
1461
+ protobuf.Namespace = require(12);
1462
+ protobuf.Root = require(17);
1463
+ protobuf.Enum = require(5);
1464
+ protobuf.Type = require(22);
1465
+ protobuf.Field = require(6);
1466
+ protobuf.OneOf = require(14);
1467
+ protobuf.MapField = require(9);
1468
+ protobuf.Service = require(21);
1469
+ protobuf.Method = require(11);
2416
1470
 
2417
1471
  // Runtime
2418
- protobuf.Message = require(19);
2419
- protobuf.wrappers = require(37);
1472
+ protobuf.Message = require(10);
1473
+ protobuf.wrappers = require(40);
2420
1474
 
2421
1475
  // Utility
2422
- protobuf.types = require(32);
2423
- protobuf.util = require(33);
1476
+ protobuf.types = require(23);
1477
+ protobuf.util = require(24);
2424
1478
 
2425
1479
  // Set up possibly cyclic reflection dependencies
2426
1480
  protobuf.ReflectionObject._configure(protobuf.Root);
@@ -2428,7 +1482,7 @@ protobuf.Namespace._configure(protobuf.Type, protobuf.Service, protobuf.Enum);
2428
1482
  protobuf.Root._configure(protobuf.Type);
2429
1483
  protobuf.Field._configure(protobuf.Type);
2430
1484
 
2431
- },{"11":11,"12":12,"13":13,"14":14,"15":15,"17":17,"18":18,"19":19,"20":20,"21":21,"22":22,"23":23,"26":26,"30":30,"31":31,"32":32,"33":33,"36":36,"37":37}],17:[function(require,module,exports){
1485
+ },{"10":10,"11":11,"12":12,"13":13,"14":14,"17":17,"2":2,"21":21,"22":22,"23":23,"24":24,"3":3,"39":39,"4":4,"40":40,"5":5,"6":6,"8":8,"9":9}],8:[function(require,module,exports){
2432
1486
  "use strict";
2433
1487
  var protobuf = exports;
2434
1488
 
@@ -2441,15 +1495,15 @@ var protobuf = exports;
2441
1495
  protobuf.build = "minimal";
2442
1496
 
2443
1497
  // Serialization
2444
- protobuf.Writer = require(38);
2445
- protobuf.BufferWriter = require(39);
2446
- protobuf.Reader = require(24);
2447
- protobuf.BufferReader = require(25);
1498
+ protobuf.Writer = require(41);
1499
+ protobuf.BufferWriter = require(42);
1500
+ protobuf.Reader = require(15);
1501
+ protobuf.BufferReader = require(16);
2448
1502
 
2449
1503
  // Utility
2450
- protobuf.util = require(35);
2451
- protobuf.rpc = require(28);
2452
- protobuf.roots = require(27);
1504
+ protobuf.util = require(34);
1505
+ protobuf.rpc = require(19);
1506
+ protobuf.roots = require(18);
2453
1507
  protobuf.configure = configure;
2454
1508
 
2455
1509
  /* istanbul ignore next */
@@ -2466,16 +1520,16 @@ function configure() {
2466
1520
  // Set up buffer utility according to the environment
2467
1521
  configure();
2468
1522
 
2469
- },{"24":24,"25":25,"27":27,"28":28,"35":35,"38":38,"39":39}],18:[function(require,module,exports){
1523
+ },{"15":15,"16":16,"18":18,"19":19,"34":34,"41":41,"42":42}],9:[function(require,module,exports){
2470
1524
  "use strict";
2471
1525
  module.exports = MapField;
2472
1526
 
2473
1527
  // extends Field
2474
- var Field = require(15);
1528
+ var Field = require(6);
2475
1529
  ((MapField.prototype = Object.create(Field.prototype)).constructor = MapField).className = "MapField";
2476
1530
 
2477
- var types = require(32),
2478
- util = require(33);
1531
+ var types = require(23),
1532
+ util = require(24);
2479
1533
 
2480
1534
  /**
2481
1535
  * Constructs a new map field instance.
@@ -2577,6 +1631,7 @@ MapField.prototype.resolve = function resolve() {
2577
1631
  * @param {"double"|"float"|"int32"|"uint32"|"sint32"|"fixed32"|"sfixed32"|"int64"|"uint64"|"sint64"|"fixed64"|"sfixed64"|"bool"|"string"|"bytes"|Object|Constructor<{}>} fieldValueType Field value type
2578
1632
  * @returns {FieldDecorator} Decorator function
2579
1633
  * @template T extends { [key: string]: number | Long | string | boolean | Uint8Array | Buffer | number[] | Message<{}> }
1634
+ * @deprecated Legacy TypeScript decorator support. Will be removed in a future release.
2580
1635
  */
2581
1636
  MapField.d = function decorateMapField(fieldId, fieldKeyType, fieldValueType) {
2582
1637
 
@@ -2594,24 +1649,29 @@ MapField.d = function decorateMapField(fieldId, fieldKeyType, fieldValueType) {
2594
1649
  };
2595
1650
  };
2596
1651
 
2597
- },{"15":15,"32":32,"33":33}],19:[function(require,module,exports){
1652
+ },{"23":23,"24":24,"6":6}],10:[function(require,module,exports){
2598
1653
  "use strict";
2599
1654
  module.exports = Message;
2600
1655
 
2601
- var util = require(35);
1656
+ var util = require(34);
2602
1657
 
2603
1658
  /**
2604
1659
  * Constructs a new message instance.
2605
1660
  * @classdesc Abstract runtime message.
2606
1661
  * @constructor
2607
1662
  * @param {Properties<T>} [properties] Properties to set
1663
+ * @property {Array.<Uint8Array>} [$unknowns] Unknown fields preserved while decoding
2608
1664
  * @template T extends object = object
2609
1665
  */
2610
1666
  function Message(properties) {
2611
1667
  // not used internally
2612
1668
  if (properties)
2613
- for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
2614
- this[keys[i]] = properties[keys[i]];
1669
+ for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) {
1670
+ var key = keys[i];
1671
+ if (key === "__proto__")
1672
+ continue;
1673
+ this[key] = properties[key];
1674
+ }
2615
1675
  }
2616
1676
 
2617
1677
  /**
@@ -2628,8 +1688,6 @@ function Message(properties) {
2628
1688
  * @readonly
2629
1689
  */
2630
1690
 
2631
- /*eslint-disable valid-jsdoc*/
2632
-
2633
1691
  /**
2634
1692
  * Creates a new message of this type using the specified properties.
2635
1693
  * @param {Object.<string,*>} [properties] Properties to set
@@ -2733,16 +1791,15 @@ Message.prototype.toJSON = function toJSON() {
2733
1791
  return this.$type.toObject(this, util.toJSONOptions);
2734
1792
  };
2735
1793
 
2736
- /*eslint-enable valid-jsdoc*/
2737
- },{"35":35}],20:[function(require,module,exports){
1794
+ },{"34":34}],11:[function(require,module,exports){
2738
1795
  "use strict";
2739
1796
  module.exports = Method;
2740
1797
 
2741
1798
  // extends ReflectionObject
2742
- var ReflectionObject = require(22);
1799
+ var ReflectionObject = require(13);
2743
1800
  ((Method.prototype = Object.create(ReflectionObject.prototype)).constructor = Method).className = "Method";
2744
1801
 
2745
- var util = require(33);
1802
+ var util = require(24);
2746
1803
 
2747
1804
  /**
2748
1805
  * Constructs a new service method instance.
@@ -2757,7 +1814,7 @@ var util = require(33);
2757
1814
  * @param {boolean|Object.<string,*>} [responseStream] Whether the response is streamed
2758
1815
  * @param {Object.<string,*>} [options] Declared options
2759
1816
  * @param {string} [comment] The comment for this method
2760
- * @param {Object.<string,*>} [parsedOptions] Declared options, properly parsed into an object
1817
+ * @param {Array.<Object.<string,*>>} [parsedOptions] Declared options, properly parsed into objects
2761
1818
  */
2762
1819
  function Method(name, type, requestType, responseType, requestStream, responseStream, options, comment, parsedOptions) {
2763
1820
 
@@ -2833,7 +1890,8 @@ function Method(name, type, requestType, responseType, requestStream, responseSt
2833
1890
  this.comment = comment;
2834
1891
 
2835
1892
  /**
2836
- * Options properly parsed into an object
1893
+ * Options properly parsed into objects
1894
+ * @type {Array.<Object.<string,*>>|undefined}
2837
1895
  */
2838
1896
  this.parsedOptions = parsedOptions;
2839
1897
  }
@@ -2848,7 +1906,7 @@ function Method(name, type, requestType, responseType, requestStream, responseSt
2848
1906
  * @property {boolean} [responseStream=false] Whether responses are streamed
2849
1907
  * @property {Object.<string,*>} [options] Method options
2850
1908
  * @property {string} comment Method comments
2851
- * @property {Object.<string,*>} [parsedOptions] Method options properly parsed into an object
1909
+ * @property {Array.<Object.<string,*>>} [parsedOptions] Method options properly parsed into objects
2852
1910
  */
2853
1911
 
2854
1912
  /**
@@ -2896,17 +1954,17 @@ Method.prototype.resolve = function resolve() {
2896
1954
  return ReflectionObject.prototype.resolve.call(this);
2897
1955
  };
2898
1956
 
2899
- },{"22":22,"33":33}],21:[function(require,module,exports){
1957
+ },{"13":13,"24":24}],12:[function(require,module,exports){
2900
1958
  "use strict";
2901
1959
  module.exports = Namespace;
2902
1960
 
2903
1961
  // extends ReflectionObject
2904
- var ReflectionObject = require(22);
1962
+ var ReflectionObject = require(13);
2905
1963
  ((Namespace.prototype = Object.create(ReflectionObject.prototype)).constructor = Namespace).className = "Namespace";
2906
1964
 
2907
- var Field = require(15),
2908
- util = require(33),
2909
- OneOf = require(23);
1965
+ var Field = require(6),
1966
+ util = require(24),
1967
+ OneOf = require(14);
2910
1968
 
2911
1969
  var Type, // cyclic
2912
1970
  Service,
@@ -2928,11 +1986,13 @@ var Type, // cyclic
2928
1986
  * @function
2929
1987
  * @param {string} name Namespace name
2930
1988
  * @param {Object.<string,*>} json JSON object
1989
+ * @param {number} [depth] Current nesting depth, defaults to `0`
2931
1990
  * @returns {Namespace} Created namespace
2932
1991
  * @throws {TypeError} If arguments are invalid
2933
1992
  */
2934
- Namespace.fromJSON = function fromJSON(name, json) {
2935
- return new Namespace(name, json.options).addJSON(json.nested);
1993
+ Namespace.fromJSON = function fromJSON(name, json, depth) {
1994
+ depth = util.checkDepth(depth);
1995
+ return new Namespace(name, json.options).addJSON(json.nested, depth);
2936
1996
  };
2937
1997
 
2938
1998
  /**
@@ -3015,7 +2075,7 @@ function Namespace(name, options) {
3015
2075
  * @type {Object.<string,ReflectionObject|null>}
3016
2076
  * @private
3017
2077
  */
3018
- this._lookupCache = {};
2078
+ this._lookupCache = Object.create(null);
3019
2079
 
3020
2080
  /**
3021
2081
  * Whether or not objects contained in this namespace need feature resolution.
@@ -3034,12 +2094,12 @@ function Namespace(name, options) {
3034
2094
 
3035
2095
  function clearCache(namespace) {
3036
2096
  namespace._nestedArray = null;
3037
- namespace._lookupCache = {};
2097
+ namespace._lookupCache = Object.create(null);
3038
2098
 
3039
2099
  // Also clear parent caches, since they include nested lookups.
3040
2100
  var parent = namespace;
3041
2101
  while(parent = parent.parent) {
3042
- parent._lookupCache = {};
2102
+ parent._lookupCache = Object.create(null);
3043
2103
  }
3044
2104
  return namespace;
3045
2105
  }
@@ -3090,9 +2150,11 @@ Namespace.prototype.toJSON = function toJSON(toJSONOptions) {
3090
2150
  /**
3091
2151
  * Adds nested objects to this namespace from nested object descriptors.
3092
2152
  * @param {Object.<string,AnyNestedObject>} nestedJson Any nested object descriptors
2153
+ * @param {number} [depth] Current nesting depth, defaults to `0`
3093
2154
  * @returns {Namespace} `this`
3094
2155
  */
3095
- Namespace.prototype.addJSON = function addJSON(nestedJson) {
2156
+ Namespace.prototype.addJSON = function addJSON(nestedJson, depth) {
2157
+ depth = util.checkDepth(depth);
3096
2158
  var ns = this;
3097
2159
  /* istanbul ignore else */
3098
2160
  if (nestedJson) {
@@ -3107,7 +2169,7 @@ Namespace.prototype.addJSON = function addJSON(nestedJson) {
3107
2169
  ? Service.fromJSON
3108
2170
  : nested.id !== undefined
3109
2171
  ? Field.fromJSON
3110
- : Namespace.fromJSON )(names[i], nested)
2172
+ : Namespace.fromJSON )(names[i], nested, depth + 1)
3111
2173
  );
3112
2174
  }
3113
2175
  }
@@ -3120,8 +2182,9 @@ Namespace.prototype.addJSON = function addJSON(nestedJson) {
3120
2182
  * @returns {ReflectionObject|null} The reflection object or `null` if it doesn't exist
3121
2183
  */
3122
2184
  Namespace.prototype.get = function get(name) {
3123
- return this.nested && this.nested[name]
3124
- || null;
2185
+ return this.nested && Object.prototype.hasOwnProperty.call(this.nested, name)
2186
+ ? this.nested[name]
2187
+ : null;
3125
2188
  };
3126
2189
 
3127
2190
  /**
@@ -3132,7 +2195,7 @@ Namespace.prototype.get = function get(name) {
3132
2195
  * @throws {Error} If there is no such enum
3133
2196
  */
3134
2197
  Namespace.prototype.getEnum = function getEnum(name) {
3135
- if (this.nested && this.nested[name] instanceof Enum)
2198
+ if (this.nested && Object.prototype.hasOwnProperty.call(this.nested, name) && this.nested[name] instanceof Enum)
3136
2199
  return this.nested[name].values;
3137
2200
  throw Error("no such enum: " + name);
3138
2201
  };
@@ -3149,6 +2212,9 @@ Namespace.prototype.add = function add(object) {
3149
2212
  if (!(object instanceof Field && object.extend !== undefined || object instanceof Type || object instanceof OneOf || object instanceof Enum || object instanceof Service || object instanceof Namespace))
3150
2213
  throw TypeError("object must be a valid nested object");
3151
2214
 
2215
+ if (object.name === "__proto__")
2216
+ return this;
2217
+
3152
2218
  if (!this.nested)
3153
2219
  this.nested = {};
3154
2220
  else {
@@ -3251,7 +2317,8 @@ Namespace.prototype.define = function define(path, json) {
3251
2317
  Namespace.prototype.resolveAll = function resolveAll() {
3252
2318
  if (!this._needsRecursiveResolve) return this;
3253
2319
 
3254
- this._resolveFeaturesRecursive(this._edition);
2320
+ if (this._needsRecursiveFeatureResolution)
2321
+ this._resolveFeaturesRecursive(this._edition);
3255
2322
 
3256
2323
  var nested = this.nestedArray, i = 0;
3257
2324
  this.resolve();
@@ -3361,8 +2428,10 @@ Namespace.prototype._lookupImpl = function lookup(path, flatPath) {
3361
2428
  // Otherwise try each nested namespace
3362
2429
  } else {
3363
2430
  for (var i = 0; i < this.nestedArray.length; ++i)
3364
- if (this._nestedArray[i] instanceof Namespace && (found = this._nestedArray[i]._lookupImpl(path, flatPath)))
2431
+ if (this._nestedArray[i] instanceof Namespace && (found = this._nestedArray[i]._lookupImpl(path, flatPath))) {
3365
2432
  exact = found;
2433
+ break;
2434
+ }
3366
2435
  }
3367
2436
 
3368
2437
  // Set this even when null, so that when we walk up the tree we can quickly bail on repeated checks back down.
@@ -3444,22 +2513,23 @@ Namespace._configure = function(Type_, Service_, Enum_) {
3444
2513
  Enum = Enum_;
3445
2514
  };
3446
2515
 
3447
- },{"15":15,"22":22,"23":23,"33":33}],22:[function(require,module,exports){
2516
+ },{"13":13,"14":14,"24":24,"6":6}],13:[function(require,module,exports){
3448
2517
  "use strict";
3449
2518
  module.exports = ReflectionObject;
3450
2519
 
3451
2520
  ReflectionObject.className = "ReflectionObject";
3452
2521
 
3453
- const OneOf = require(23);
3454
- var util = require(33);
2522
+ const OneOf = require(14);
2523
+ var util = require(24);
3455
2524
 
3456
2525
  var Root; // cyclic
3457
2526
 
3458
2527
  /* eslint-disable no-warning-comments */
3459
2528
  // TODO: Replace with embedded proto.
3460
- var editions2023Defaults = {enum_type: "OPEN", field_presence: "EXPLICIT", json_format: "ALLOW", message_encoding: "LENGTH_PREFIXED", repeated_field_encoding: "PACKED", utf8_validation: "VERIFY"};
3461
- var proto2Defaults = {enum_type: "CLOSED", field_presence: "EXPLICIT", json_format: "LEGACY_BEST_EFFORT", message_encoding: "LENGTH_PREFIXED", repeated_field_encoding: "EXPANDED", utf8_validation: "NONE"};
3462
- var proto3Defaults = {enum_type: "OPEN", field_presence: "IMPLICIT", json_format: "ALLOW", message_encoding: "LENGTH_PREFIXED", repeated_field_encoding: "PACKED", utf8_validation: "VERIFY"};
2529
+ var editions2024Defaults = {enum_type: "OPEN", field_presence: "EXPLICIT", json_format: "ALLOW", message_encoding: "LENGTH_PREFIXED", repeated_field_encoding: "PACKED", utf8_validation: "VERIFY", enforce_naming_style: "STYLE2024", default_symbol_visibility: "EXPORT_TOP_LEVEL" };
2530
+ var editions2023Defaults = {enum_type: "OPEN", field_presence: "EXPLICIT", json_format: "ALLOW", message_encoding: "LENGTH_PREFIXED", repeated_field_encoding: "PACKED", utf8_validation: "VERIFY", enforce_naming_style: "STYLE_LEGACY", default_symbol_visibility: "EXPORT_ALL" };
2531
+ var proto2Defaults = {enum_type: "CLOSED", field_presence: "EXPLICIT", json_format: "LEGACY_BEST_EFFORT", message_encoding: "LENGTH_PREFIXED", repeated_field_encoding: "EXPANDED", utf8_validation: "NONE", enforce_naming_style: "STYLE_LEGACY", default_symbol_visibility: "EXPORT_ALL" };
2532
+ var proto3Defaults = {enum_type: "OPEN", field_presence: "IMPLICIT", json_format: "ALLOW", message_encoding: "LENGTH_PREFIXED", repeated_field_encoding: "PACKED", utf8_validation: "VERIFY", enforce_naming_style: "STYLE_LEGACY", default_symbol_visibility: "EXPORT_ALL" };
3463
2533
 
3464
2534
  /**
3465
2535
  * Constructs a new reflection object instance.
@@ -3672,27 +2742,27 @@ ReflectionObject.prototype._resolveFeatures = function _resolveFeatures(edition)
3672
2742
  defaults = Object.assign({}, proto3Defaults);
3673
2743
  } else if (edition === "2023") {
3674
2744
  defaults = Object.assign({}, editions2023Defaults);
2745
+ } else if (edition === "2024") {
2746
+ defaults = Object.assign({}, editions2024Defaults);
3675
2747
  } else {
3676
2748
  throw new Error("Unknown edition: " + edition);
3677
2749
  }
3678
2750
  this._features = Object.assign(defaults, protoFeatures || {});
3679
- this._featuresResolved = true;
3680
- return;
3681
- }
3682
-
3683
- // fields in Oneofs aren't actually children of them, so we have to
3684
- // special-case it
3685
- /* istanbul ignore else */
3686
- if (this.partOf instanceof OneOf) {
3687
- var lexicalParentFeaturesCopy = Object.assign({}, this.partOf._features);
3688
- this._features = Object.assign(lexicalParentFeaturesCopy, protoFeatures || {});
3689
- } else if (this.declaringField) {
3690
- // Skip feature resolution of sister fields.
3691
- } else if (this.parent) {
3692
- var parentFeaturesCopy = Object.assign({}, this.parent._features);
3693
- this._features = Object.assign(parentFeaturesCopy, protoFeatures || {});
3694
2751
  } else {
3695
- throw new Error("Unable to find a parent for " + this.fullName);
2752
+ // fields in Oneofs aren't actually children of them, so we have to
2753
+ // special-case it
2754
+ /* istanbul ignore else */
2755
+ if (this.partOf instanceof OneOf) {
2756
+ var lexicalParentFeaturesCopy = Object.assign({}, this.partOf._features);
2757
+ this._features = Object.assign(lexicalParentFeaturesCopy, protoFeatures || {});
2758
+ } else if (this.declaringField) {
2759
+ // Skip feature resolution of sister fields.
2760
+ } else if (this.parent) {
2761
+ var parentFeaturesCopy = Object.assign({}, this.parent._features);
2762
+ this._features = Object.assign(parentFeaturesCopy, protoFeatures || {});
2763
+ } else {
2764
+ throw new Error("Unable to find a parent for " + this.fullName);
2765
+ }
3696
2766
  }
3697
2767
  if (this.extensionField) {
3698
2768
  // Sister fields should have the same features as their extensions.
@@ -3730,6 +2800,8 @@ ReflectionObject.prototype.getOption = function getOption(name) {
3730
2800
  * @returns {ReflectionObject} `this`
3731
2801
  */
3732
2802
  ReflectionObject.prototype.setOption = function setOption(name, value, ifNotSet) {
2803
+ if (name === "__proto__")
2804
+ return this;
3733
2805
  if (!this.options)
3734
2806
  this.options = {};
3735
2807
  if (/^features\./.test(name)) {
@@ -3750,6 +2822,8 @@ ReflectionObject.prototype.setOption = function setOption(name, value, ifNotSet)
3750
2822
  * @returns {ReflectionObject} `this`
3751
2823
  */
3752
2824
  ReflectionObject.prototype.setParsedOption = function setParsedOption(name, value, propName) {
2825
+ if (name === "__proto__")
2826
+ return this;
3753
2827
  if (!this.parsedOptions) {
3754
2828
  this.parsedOptions = [];
3755
2829
  }
@@ -3824,16 +2898,16 @@ ReflectionObject._configure = function(Root_) {
3824
2898
  Root = Root_;
3825
2899
  };
3826
2900
 
3827
- },{"23":23,"33":33}],23:[function(require,module,exports){
2901
+ },{"14":14,"24":24}],14:[function(require,module,exports){
3828
2902
  "use strict";
3829
2903
  module.exports = OneOf;
3830
2904
 
3831
2905
  // extends ReflectionObject
3832
- var ReflectionObject = require(22);
2906
+ var ReflectionObject = require(13);
3833
2907
  ((OneOf.prototype = Object.create(ReflectionObject.prototype)).constructor = OneOf).className = "OneOf";
3834
2908
 
3835
- var Field = require(15),
3836
- util = require(33);
2909
+ var Field = require(6),
2910
+ util = require(24);
3837
2911
 
3838
2912
  /**
3839
2913
  * Constructs a new oneof instance.
@@ -4024,6 +3098,7 @@ Object.defineProperty(OneOf.prototype, "isProto3Optional", {
4024
3098
  * @param {Object} prototype Target prototype
4025
3099
  * @param {string} oneofName OneOf name
4026
3100
  * @returns {undefined}
3101
+ * @deprecated Legacy TypeScript decorator support. Will be removed in a future release.
4027
3102
  */
4028
3103
 
4029
3104
  /**
@@ -4032,6 +3107,7 @@ Object.defineProperty(OneOf.prototype, "isProto3Optional", {
4032
3107
  * @param {...string} fieldNames Field names
4033
3108
  * @returns {OneOfDecorator} Decorator function
4034
3109
  * @template T extends string
3110
+ * @deprecated Legacy TypeScript decorator support. Will be removed in a future release.
4035
3111
  */
4036
3112
  OneOf.d = function decorateOneOf() {
4037
3113
  var fieldNames = new Array(arguments.length),
@@ -4048,11 +3124,11 @@ OneOf.d = function decorateOneOf() {
4048
3124
  };
4049
3125
  };
4050
3126
 
4051
- },{"15":15,"22":22,"33":33}],24:[function(require,module,exports){
3127
+ },{"13":13,"24":24,"6":6}],15:[function(require,module,exports){
4052
3128
  "use strict";
4053
3129
  module.exports = Reader;
4054
3130
 
4055
- var util = require(35);
3131
+ var util = require(34);
4056
3132
 
4057
3133
  var BufferReader; // cyclic
4058
3134
 
@@ -4129,28 +3205,108 @@ Reader.create = create();
4129
3205
 
4130
3206
  Reader.prototype._slice = util.Array.prototype.subarray || /* istanbul ignore next */ util.Array.prototype.slice;
4131
3207
 
3208
+ /**
3209
+ * Returns raw bytes from the backing buffer without advancing the reader.
3210
+ * @param {number} start Start offset
3211
+ * @param {number} end End offset
3212
+ * @returns {Uint8Array} Raw bytes
3213
+ */
3214
+ Reader.prototype.raw = function read_raw(start, end) {
3215
+ if (Array.isArray(this.buf)) // plain array
3216
+ return this.buf.slice(start, end);
3217
+
3218
+ if (start === end) // fix for IE 10/Win8 and others' subarray returning array of size 1
3219
+ return new this.buf.constructor(0);
3220
+ return this._slice.call(this.buf, start, end);
3221
+ };
3222
+
4132
3223
  /**
4133
3224
  * Reads a varint as an unsigned 32 bit value.
4134
3225
  * @function
4135
3226
  * @returns {number} Value read
4136
3227
  */
4137
- Reader.prototype.uint32 = (function read_uint32_setup() {
4138
- var value = 4294967295; // optimizer type-hint, tends to deopt otherwise (?!)
4139
- return function read_uint32() {
4140
- value = ( this.buf[this.pos] & 127 ) >>> 0; if (this.buf[this.pos++] < 128) return value;
4141
- value = (value | (this.buf[this.pos] & 127) << 7) >>> 0; if (this.buf[this.pos++] < 128) return value;
4142
- value = (value | (this.buf[this.pos] & 127) << 14) >>> 0; if (this.buf[this.pos++] < 128) return value;
4143
- value = (value | (this.buf[this.pos] & 127) << 21) >>> 0; if (this.buf[this.pos++] < 128) return value;
4144
- value = (value | (this.buf[this.pos] & 15) << 28) >>> 0; if (this.buf[this.pos++] < 128) return value;
3228
+ Reader.prototype.uint32 = function read_uint32() {
3229
+ var buf = this.buf,
3230
+ pos = this.pos,
3231
+ value = (buf[pos] & 127) >>> 0;
3232
+ if (buf[pos++] < 128) {
3233
+ this.pos = pos;
3234
+ return value;
3235
+ }
3236
+ value = (value | (buf[pos] & 127) << 7) >>> 0;
3237
+ if (buf[pos++] < 128) {
3238
+ this.pos = pos;
3239
+ return value;
3240
+ }
3241
+ value = (value | (buf[pos] & 127) << 14) >>> 0;
3242
+ if (buf[pos++] < 128) {
3243
+ this.pos = pos;
3244
+ return value;
3245
+ }
3246
+ value = (value | (buf[pos] & 127) << 21) >>> 0;
3247
+ if (buf[pos++] < 128) {
3248
+ this.pos = pos;
3249
+ return value;
3250
+ }
3251
+ value = (value | (buf[pos] & 15) << 28) >>> 0;
3252
+ if (buf[pos++] < 128) {
3253
+ this.pos = pos;
3254
+ return value;
3255
+ }
4145
3256
 
3257
+ for (var i = 0; i < 5; ++i) {
4146
3258
  /* istanbul ignore if */
4147
- if ((this.pos += 5) > this.len) {
4148
- this.pos = this.len;
4149
- throw indexOutOfRange(this, 10);
3259
+ if (pos >= this.len) {
3260
+ this.pos = pos;
3261
+ throw indexOutOfRange(this);
3262
+ }
3263
+ if (buf[pos++] < 128) {
3264
+ this.pos = pos;
3265
+ return value;
4150
3266
  }
3267
+ }
3268
+ /* istanbul ignore next */
3269
+ this.pos = pos;
3270
+ throw Error("invalid varint encoding");
3271
+ };
3272
+
3273
+ /**
3274
+ * Reads a field tag.
3275
+ * @function
3276
+ * @returns {number} Tag read
3277
+ */
3278
+ Reader.prototype.tag = function read_tag() {
3279
+ var buf = this.buf,
3280
+ pos = this.pos,
3281
+ value = (buf[pos] & 127) >>> 0;
3282
+ if (buf[pos++] < 128) {
3283
+ this.pos = pos;
4151
3284
  return value;
4152
- };
4153
- })();
3285
+ }
3286
+ value = (value | (buf[pos] & 127) << 7) >>> 0;
3287
+ if (buf[pos++] < 128) {
3288
+ this.pos = pos;
3289
+ return value;
3290
+ }
3291
+ value = (value | (buf[pos] & 127) << 14) >>> 0;
3292
+ if (buf[pos++] < 128) {
3293
+ this.pos = pos;
3294
+ return value;
3295
+ }
3296
+ value = (value | (buf[pos] & 127) << 21) >>> 0;
3297
+ if (buf[pos++] < 128) {
3298
+ this.pos = pos;
3299
+ return value;
3300
+ }
3301
+ value = (value | (buf[pos] & 15) << 28) >>> 0;
3302
+ if (buf[pos] < 128 && (buf[pos] & 112) === 0) {
3303
+ this.pos = pos + 1;
3304
+ return value;
3305
+ }
3306
+
3307
+ this.pos = pos + 1;
3308
+ throw Error("invalid tag encoding");
3309
+ };
4154
3310
 
4155
3311
  /**
4156
3312
  * Reads a varint as a signed 32 bit value.
@@ -4252,7 +3408,20 @@ function readLongVarint() {
4252
3408
  * @returns {boolean} Value read
4253
3409
  */
4254
3410
  Reader.prototype.bool = function read_bool() {
4255
- return this.uint32() !== 0;
3411
+ var value = false,
3412
+ b;
3413
+ for (var i = 0; i < 10; ++i) {
3414
+ /* istanbul ignore if */
3415
+ if (this.pos >= this.len)
3416
+ throw indexOutOfRange(this);
3417
+ b = this.buf[this.pos++];
3418
+ if (b & 127)
3419
+ value = true;
3420
+ if (b < 128)
3421
+ return value;
3422
+ }
3423
+ /* istanbul ignore next */
3424
+ throw Error("invalid varint encoding");
4256
3425
  };
4257
3426
 
4258
3427
  function readFixed32_end(buf, end) { // note that this uses `end`, not `pos`
@@ -4360,17 +3529,8 @@ Reader.prototype.bytes = function read_bytes() {
4360
3529
  if (end > this.len)
4361
3530
  throw indexOutOfRange(this, length);
4362
3531
 
4363
- this.pos += length;
4364
- if (Array.isArray(this.buf)) // plain array
4365
- return this.buf.slice(start, end);
4366
-
4367
- if (start === end) { // fix for IE 10/Win8 and others' subarray returning array of size 1
4368
- var nativeBuffer = util.Buffer;
4369
- return nativeBuffer
4370
- ? nativeBuffer.alloc(0)
4371
- : new this.buf.constructor(0);
4372
- }
4373
- return this._slice.call(this.buf, start, end);
3532
+ this.pos = end;
3533
+ return this.raw(start, end);
4374
3534
  };
4375
3535
 
4376
3536
  /**
@@ -4378,8 +3538,16 @@ Reader.prototype.bytes = function read_bytes() {
4378
3538
  * @returns {string} Value read
4379
3539
  */
4380
3540
  Reader.prototype.string = function read_string() {
4381
- var bytes = this.bytes();
4382
- return utf8.read(bytes, 0, bytes.length);
3541
+ var length = this.uint32(),
3542
+ start = this.pos,
3543
+ end = this.pos + length;
3544
+
3545
+ /* istanbul ignore if */
3546
+ if (end > this.len)
3547
+ throw indexOutOfRange(this, length);
3548
+
3549
+ this.pos = end;
3550
+ return utf8.read(this.buf, start, end);
4383
3551
  };
4384
3552
 
4385
3553
  /**
@@ -4403,12 +3571,25 @@ Reader.prototype.skip = function skip(length) {
4403
3571
  return this;
4404
3572
  };
4405
3573
 
3574
+ /**
3575
+ * Recursion limit.
3576
+ * @type {number}
3577
+ */
3578
+ Reader.recursionLimit = util.recursionLimit;
3579
+
4406
3580
  /**
4407
3581
  * Skips the next element of the specified wire type.
4408
3582
  * @param {number} wireType Wire type received
3583
+ * @param {number} [depth] Depth of recursion to control nested calls; 0 if omitted
3584
+ * @param {number} [fieldNumber] Field number for validating group end tags
4409
3585
  * @returns {Reader} `this`
4410
3586
  */
4411
- Reader.prototype.skipType = function(wireType) {
3587
+ Reader.prototype.skipType = function(wireType, depth, fieldNumber) {
3588
+ if (depth === undefined) depth = 0;
3589
+ if (depth > Reader.recursionLimit)
3590
+ throw Error("max depth exceeded");
3591
+ if (fieldNumber === 0)
3592
+ throw Error("illegal tag: field number 0");
4412
3593
  switch (wireType) {
4413
3594
  case 0:
4414
3595
  this.skip();
@@ -4420,8 +3601,18 @@ Reader.prototype.skipType = function(wireType) {
4420
3601
  this.skip(this.uint32());
4421
3602
  break;
4422
3603
  case 3:
4423
- while ((wireType = this.uint32() & 7) !== 4) {
4424
- this.skipType(wireType);
3604
+ while (true) {
3605
+ var tag = this.tag();
3606
+ var nestedField = tag >>> 3;
3607
+ wireType = tag & 7;
3608
+ if (!nestedField)
3609
+ throw Error("illegal tag: field number 0");
3610
+ if (wireType === 4) {
3611
+ if (fieldNumber !== undefined && nestedField !== fieldNumber)
3612
+ throw Error("invalid end group tag");
3613
+ break;
3614
+ }
3615
+ this.skipType(wireType, depth + 1, nestedField);
4425
3616
  }
4426
3617
  break;
4427
3618
  case 5:
@@ -4466,15 +3657,15 @@ Reader._configure = function(BufferReader_) {
4466
3657
  });
4467
3658
  };
4468
3659
 
4469
- },{"35":35}],25:[function(require,module,exports){
3660
+ },{"34":34}],16:[function(require,module,exports){
4470
3661
  "use strict";
4471
3662
  module.exports = BufferReader;
4472
3663
 
4473
3664
  // extends Reader
4474
- var Reader = require(24);
3665
+ var Reader = require(15);
4475
3666
  (BufferReader.prototype = Object.create(Reader.prototype)).constructor = BufferReader;
4476
3667
 
4477
- var util = require(35);
3668
+ var util = require(34);
4478
3669
 
4479
3670
  /**
4480
3671
  * Constructs a new buffer reader instance.
@@ -4499,15 +3690,36 @@ BufferReader._configure = function () {
4499
3690
  BufferReader.prototype._slice = util.Buffer.prototype.slice;
4500
3691
  };
4501
3692
 
3693
+ /**
3694
+ * Returns raw bytes from the backing buffer without advancing the reader.
3695
+ * @name BufferReader#raw
3696
+ * @function
3697
+ * @param {number} start Start offset
3698
+ * @param {number} end End offset
3699
+ * @returns {Buffer} Raw bytes
3700
+ */
3701
+ BufferReader.prototype.raw = function read_raw_buffer(start, end) {
3702
+ if (start === end)
3703
+ return util.Buffer.alloc(0);
3704
+ return this._slice.call(this.buf, start, end);
3705
+ };
4502
3706
 
4503
3707
  /**
4504
3708
  * @override
4505
3709
  */
4506
3710
  BufferReader.prototype.string = function read_string_buffer() {
4507
- var len = this.uint32(); // modifies pos
3711
+ var len = this.uint32(), // modifies pos
3712
+ start = this.pos,
3713
+ end = this.pos + len;
3714
+
3715
+ /* istanbul ignore if */
3716
+ if (end > this.len)
3717
+ throw RangeError("index out of range: " + this.pos + " + " + len + " > " + this.len);
3718
+
3719
+ this.pos = end;
4508
3720
  return this.buf.utf8Slice
4509
- ? this.buf.utf8Slice(this.pos, this.pos = Math.min(this.pos + len, this.len))
4510
- : this.buf.toString("utf-8", this.pos, this.pos = Math.min(this.pos + len, this.len));
3721
+ ? this.buf.utf8Slice(start, end)
3722
+ : this.buf.toString("utf-8", start, end);
4511
3723
  };
4512
3724
 
4513
3725
  /**
@@ -4519,18 +3731,18 @@ BufferReader.prototype.string = function read_string_buffer() {
4519
3731
 
4520
3732
  BufferReader._configure();
4521
3733
 
4522
- },{"24":24,"35":35}],26:[function(require,module,exports){
3734
+ },{"15":15,"34":34}],17:[function(require,module,exports){
4523
3735
  "use strict";
4524
3736
  module.exports = Root;
4525
3737
 
4526
3738
  // extends Namespace
4527
- var Namespace = require(21);
3739
+ var Namespace = require(12);
4528
3740
  ((Root.prototype = Object.create(Namespace.prototype)).constructor = Root).className = "Root";
4529
3741
 
4530
- var Field = require(15),
4531
- Enum = require(14),
4532
- OneOf = require(23),
4533
- util = require(33);
3742
+ var Field = require(6),
3743
+ Enum = require(5),
3744
+ OneOf = require(14),
3745
+ util = require(24);
4534
3746
 
4535
3747
  var Type, // cyclic
4536
3748
  parse, // might be excluded
@@ -4577,14 +3789,16 @@ function Root(options) {
4577
3789
  * Loads a namespace descriptor into a root namespace.
4578
3790
  * @param {INamespace} json Namespace descriptor
4579
3791
  * @param {Root} [root] Root namespace, defaults to create a new one if omitted
3792
+ * @param {number} [depth] Current nesting depth, defaults to `0`
4580
3793
  * @returns {Root} Root namespace
4581
3794
  */
4582
- Root.fromJSON = function fromJSON(json, root) {
3795
+ Root.fromJSON = function fromJSON(json, root, depth) {
3796
+ depth = util.checkDepth(depth);
4583
3797
  if (!root)
4584
3798
  root = new Root();
4585
3799
  if (json.options)
4586
3800
  root.setOptions(json.options);
4587
- return root.addJSON(json.nested).resolveAll();
3801
+ return root.addJSON(json.nested, depth).resolveAll();
4588
3802
  };
4589
3803
 
4590
3804
  /**
@@ -4652,8 +3866,9 @@ Root.prototype.load = function load(filename, options, callback) {
4652
3866
  var idx = filename.lastIndexOf("google/protobuf/");
4653
3867
  if (idx > -1) {
4654
3868
  var altname = filename.substring(idx);
4655
- if (altname in common) return altname;
3869
+ if (Object.prototype.hasOwnProperty.call(common, altname)) return altname;
4656
3870
  }
3871
+ if (Object.prototype.hasOwnProperty.call(common, filename)) return filename;
4657
3872
  return null;
4658
3873
  }
4659
3874
 
@@ -4697,7 +3912,7 @@ Root.prototype.load = function load(filename, options, callback) {
4697
3912
  self.files.push(filename);
4698
3913
 
4699
3914
  // Shortcut bundled definitions
4700
- if (filename in common) {
3915
+ if (Object.prototype.hasOwnProperty.call(common, filename)) {
4701
3916
  if (sync) {
4702
3917
  process(filename, common[filename]);
4703
3918
  } else {
@@ -4925,7 +4140,7 @@ Root._configure = function(Type_, parse_, common_) {
4925
4140
  common = common_;
4926
4141
  };
4927
4142
 
4928
- },{"14":14,"15":15,"21":21,"23":23,"33":33}],27:[function(require,module,exports){
4143
+ },{"12":12,"14":14,"24":24,"5":5,"6":6}],18:[function(require,module,exports){
4929
4144
  "use strict";
4930
4145
  module.exports = {};
4931
4146
 
@@ -4945,7 +4160,7 @@ module.exports = {};
4945
4160
  * var root = protobuf.roots["myroot"];
4946
4161
  */
4947
4162
 
4948
- },{}],28:[function(require,module,exports){
4163
+ },{}],19:[function(require,module,exports){
4949
4164
  "use strict";
4950
4165
 
4951
4166
  /**
@@ -4981,13 +4196,13 @@ var rpc = exports;
4981
4196
  * @returns {undefined}
4982
4197
  */
4983
4198
 
4984
- rpc.Service = require(29);
4199
+ rpc.Service = require(20);
4985
4200
 
4986
- },{"29":29}],29:[function(require,module,exports){
4201
+ },{"20":20}],20:[function(require,module,exports){
4987
4202
  "use strict";
4988
4203
  module.exports = Service;
4989
4204
 
4990
- var util = require(35);
4205
+ var util = require(34);
4991
4206
 
4992
4207
  // Extends EventEmitter
4993
4208
  (Service.prototype = Object.create(util.EventEmitter.prototype)).constructor = Service;
@@ -5127,17 +4342,19 @@ Service.prototype.end = function end(endedByRPC) {
5127
4342
  return this;
5128
4343
  };
5129
4344
 
5130
- },{"35":35}],30:[function(require,module,exports){
4345
+ },{"34":34}],21:[function(require,module,exports){
5131
4346
  "use strict";
5132
4347
  module.exports = Service;
5133
4348
 
5134
4349
  // extends Namespace
5135
- var Namespace = require(21);
4350
+ var Namespace = require(12);
5136
4351
  ((Service.prototype = Object.create(Namespace.prototype)).constructor = Service).className = "Service";
5137
4352
 
5138
- var Method = require(20),
5139
- util = require(33),
5140
- rpc = require(28);
4353
+ var Method = require(11),
4354
+ util = require(24),
4355
+ rpc = require(19);
4356
+
4357
+ var reservedRe = util.patterns.reservedRe;
5141
4358
 
5142
4359
  /**
5143
4360
  * Constructs a new service instance.
@@ -5176,17 +4393,19 @@ function Service(name, options) {
5176
4393
  * Constructs a service from a service descriptor.
5177
4394
  * @param {string} name Service name
5178
4395
  * @param {IService} json Service descriptor
4396
+ * @param {number} [depth] Current nesting depth, defaults to `0`
5179
4397
  * @returns {Service} Created service
5180
4398
  * @throws {TypeError} If arguments are invalid
5181
4399
  */
5182
- Service.fromJSON = function fromJSON(name, json) {
4400
+ Service.fromJSON = function fromJSON(name, json, depth) {
4401
+ depth = util.checkDepth(depth);
5183
4402
  var service = new Service(name, json.options);
5184
4403
  /* istanbul ignore else */
5185
4404
  if (json.methods)
5186
4405
  for (var names = Object.keys(json.methods), i = 0; i < names.length; ++i)
5187
4406
  service.add(Method.fromJSON(names[i], json.methods[names[i]]));
5188
4407
  if (json.nested)
5189
- service.addJSON(json.nested);
4408
+ service.addJSON(json.nested, depth);
5190
4409
  if (json.edition)
5191
4410
  service._edition = json.edition;
5192
4411
  service.comment = json.comment;
@@ -5232,8 +4451,9 @@ function clearCache(service) {
5232
4451
  * @override
5233
4452
  */
5234
4453
  Service.prototype.get = function get(name) {
5235
- return this.methods[name]
5236
- || Namespace.prototype.get.call(this, name);
4454
+ return Object.prototype.hasOwnProperty.call(this.methods, name)
4455
+ ? this.methods[name]
4456
+ : Namespace.prototype.get.call(this, name);
5237
4457
  };
5238
4458
 
5239
4459
  /**
@@ -5268,12 +4488,13 @@ Service.prototype._resolveFeaturesRecursive = function _resolveFeaturesRecursive
5268
4488
  * @override
5269
4489
  */
5270
4490
  Service.prototype.add = function add(object) {
5271
-
5272
4491
  /* istanbul ignore if */
5273
4492
  if (this.get(object.name))
5274
4493
  throw Error("duplicate name '" + object.name + "' in " + this);
5275
4494
 
5276
4495
  if (object instanceof Method) {
4496
+ if (object.name === "__proto__")
4497
+ return this;
5277
4498
  this.methods[object.name] = object;
5278
4499
  object.parent = this;
5279
4500
  return clearCache(this);
@@ -5309,7 +4530,7 @@ Service.prototype.create = function create(rpcImpl, requestDelimited, responseDe
5309
4530
  var rpcService = new rpc.Service(rpcImpl, requestDelimited, responseDelimited);
5310
4531
  for (var i = 0, method; i < /* initializes */ this.methodsArray.length; ++i) {
5311
4532
  var methodName = util.lcFirst((method = this._methodsArray[i]).resolve().name).replace(/[^$\w_]/g, "");
5312
- rpcService[methodName] = util.codegen(["r","c"], util.isReserved(methodName) ? methodName + "_" : methodName)("return this.rpcCall(m,q,s,r,c)")({
4533
+ rpcService[methodName] = util.codegen(["r","c"], reservedRe.test(methodName) ? methodName + "_" : methodName)("return this.rpcCall(m,q,s,r,c)")({
5313
4534
  m: method,
5314
4535
  q: method.resolvedRequestType.ctor,
5315
4536
  s: method.resolvedResponseType.ctor
@@ -5318,28 +4539,28 @@ Service.prototype.create = function create(rpcImpl, requestDelimited, responseDe
5318
4539
  return rpcService;
5319
4540
  };
5320
4541
 
5321
- },{"20":20,"21":21,"28":28,"33":33}],31:[function(require,module,exports){
4542
+ },{"11":11,"12":12,"19":19,"24":24}],22:[function(require,module,exports){
5322
4543
  "use strict";
5323
4544
  module.exports = Type;
5324
4545
 
5325
4546
  // extends Namespace
5326
- var Namespace = require(21);
4547
+ var Namespace = require(12);
5327
4548
  ((Type.prototype = Object.create(Namespace.prototype)).constructor = Type).className = "Type";
5328
4549
 
5329
- var Enum = require(14),
5330
- OneOf = require(23),
5331
- Field = require(15),
5332
- MapField = require(18),
5333
- Service = require(30),
5334
- Message = require(19),
5335
- Reader = require(24),
5336
- Writer = require(38),
5337
- util = require(33),
5338
- encoder = require(13),
5339
- decoder = require(12),
5340
- verifier = require(36),
5341
- converter = require(11),
5342
- wrappers = require(37);
4550
+ var Enum = require(5),
4551
+ OneOf = require(14),
4552
+ Field = require(6),
4553
+ MapField = require(9),
4554
+ Service = require(21),
4555
+ Message = require(10),
4556
+ Reader = require(15),
4557
+ Writer = require(41),
4558
+ util = require(24),
4559
+ encoder = require(4),
4560
+ decoder = require(3),
4561
+ verifier = require(39),
4562
+ converter = require(2),
4563
+ wrappers = require(40);
5343
4564
 
5344
4565
  /**
5345
4566
  * Constructs a new reflected message type instance.
@@ -5350,6 +4571,7 @@ var Enum = require(14),
5350
4571
  * @param {Object.<string,*>} [options] Declared options
5351
4572
  */
5352
4573
  function Type(name, options) {
4574
+ name = name.replace(/\W/g, "");
5353
4575
  Namespace.call(this, name, options);
5354
4576
 
5355
4577
  /**
@@ -5494,8 +4716,10 @@ Object.defineProperties(Type.prototype, {
5494
4716
 
5495
4717
  // Messages have non-enumerable default values on their prototype
5496
4718
  var i = 0;
5497
- for (; i < /* initializes */ this.fieldsArray.length; ++i)
5498
- this._fieldsArray[i].resolve(); // ensures a proper value
4719
+ for (var field; i < /* initializes */ this.fieldsArray.length; ++i) {
4720
+ field = this._fieldsArray[i].resolve(); // ensures a proper value
4721
+ ctor.prototype[field.name] = field.defaultValue;
4722
+ }
5499
4723
 
5500
4724
  // Messages have non-enumerable getters and setters for each virtual oneof field
5501
4725
  var ctorProperties = {};
@@ -5525,7 +4749,7 @@ Type.generateConstructor = function generateConstructor(mtype) {
5525
4749
  else if (field.repeated) gen
5526
4750
  ("this%s=[]", util.safeProp(field.name));
5527
4751
  return gen
5528
- ("if(p)for(var ks=Object.keys(p),i=0;i<ks.length;++i)if(p[ks[i]]!=null)") // omit undefined or null
4752
+ ("if(p)for(var ks=Object.keys(p),i=0;i<ks.length;++i)if(p[ks[i]]!=null&&ks[i]!==\"__proto__\")") // omit undefined or null
5529
4753
  ("this[ks[i]]=p[ks[i]]");
5530
4754
  /* eslint-enable no-unexpected-multiline */
5531
4755
  };
@@ -5553,9 +4777,11 @@ function clearCache(type) {
5553
4777
  * Creates a message type from a message type descriptor.
5554
4778
  * @param {string} name Message name
5555
4779
  * @param {IType} json Message type descriptor
4780
+ * @param {number} [depth] Current nesting depth, defaults to `0`
5556
4781
  * @returns {Type} Created message type
5557
4782
  */
5558
- Type.fromJSON = function fromJSON(name, json) {
4783
+ Type.fromJSON = function fromJSON(name, json, depth) {
4784
+ depth = util.checkDepth(depth);
5559
4785
  var type = new Type(name, json.options);
5560
4786
  type.extensions = json.extensions;
5561
4787
  type.reserved = json.reserved;
@@ -5582,7 +4808,7 @@ Type.fromJSON = function fromJSON(name, json) {
5582
4808
  ? Enum.fromJSON
5583
4809
  : nested.methods !== undefined
5584
4810
  ? Service.fromJSON
5585
- : Namespace.fromJSON )(names[i], nested)
4811
+ : Namespace.fromJSON )(names[i], nested, depth + 1)
5586
4812
  );
5587
4813
  }
5588
4814
  if (json.extensions && json.extensions.length)
@@ -5658,10 +4884,13 @@ Type.prototype._resolveFeaturesRecursive = function _resolveFeaturesRecursive(ed
5658
4884
  * @override
5659
4885
  */
5660
4886
  Type.prototype.get = function get(name) {
5661
- return this.fields[name]
5662
- || this.oneofs && this.oneofs[name]
5663
- || this.nested && this.nested[name]
5664
- || null;
4887
+ if (Object.prototype.hasOwnProperty.call(this.fields, name))
4888
+ return this.fields[name];
4889
+ if (this.oneofs && Object.prototype.hasOwnProperty.call(this.oneofs, name))
4890
+ return this.oneofs[name];
4891
+ if (this.nested && Object.prototype.hasOwnProperty.call(this.nested, name))
4892
+ return this.nested[name];
4893
+ return null;
5665
4894
  };
5666
4895
 
5667
4896
  /**
@@ -5672,7 +4901,6 @@ Type.prototype.get = function get(name) {
5672
4901
  * @throws {Error} If there is already a nested object with this name or, if a field, when there is already a field with this id
5673
4902
  */
5674
4903
  Type.prototype.add = function add(object) {
5675
-
5676
4904
  if (this.get(object.name))
5677
4905
  throw Error("duplicate name '" + object.name + "' in " + this);
5678
4906
 
@@ -5688,6 +4916,8 @@ Type.prototype.add = function add(object) {
5688
4916
  throw Error("id " + object.id + " is reserved in " + this);
5689
4917
  if (this.isReservedName(object.name))
5690
4918
  throw Error("name '" + object.name + "' is reserved in " + this);
4919
+ if (object.name === "__proto__")
4920
+ return this;
5691
4921
 
5692
4922
  if (object.parent)
5693
4923
  object.parent.remove(object);
@@ -5697,6 +4927,8 @@ Type.prototype.add = function add(object) {
5697
4927
  return clearCache(this);
5698
4928
  }
5699
4929
  if (object instanceof OneOf) {
4930
+ if (object.name === "__proto__")
4931
+ return this;
5700
4932
  if (!this.oneofs)
5701
4933
  this.oneofs = {};
5702
4934
  this.oneofs[object.name] = object;
@@ -5807,15 +5039,13 @@ Type.prototype.setup = function setup() {
5807
5039
  // Inject custom wrappers for common types
5808
5040
  var wrapper = wrappers[fullName];
5809
5041
  if (wrapper) {
5810
- var originalThis = Object.create(this);
5811
- // if (wrapper.fromObject) {
5812
- originalThis.fromObject = this.fromObject;
5813
- this.fromObject = wrapper.fromObject.bind(originalThis);
5814
- // }
5815
- // if (wrapper.toObject) {
5816
- originalThis.toObject = this.toObject;
5817
- this.toObject = wrapper.toObject.bind(originalThis);
5818
- // }
5042
+ var wrapperThis = Object.create(this);
5043
+ // Reuse this type's runtime constructor in wrapper fromObject/toObject
5044
+ wrapperThis._ctor = this.ctor;
5045
+ wrapperThis.fromObject = this.fromObject;
5046
+ this.fromObject = wrapper.fromObject.bind(wrapperThis);
5047
+ wrapperThis.toObject = this.toObject;
5048
+ this.toObject = wrapper.toObject.bind(wrapperThis);
5819
5049
  }
5820
5050
 
5821
5051
  return this;
@@ -5849,8 +5079,8 @@ Type.prototype.encodeDelimited = function encodeDelimited(message, writer) {
5849
5079
  * @throws {Error} If the payload is not a reader or valid buffer
5850
5080
  * @throws {util.ProtocolError<{}>} If required fields are missing
5851
5081
  */
5852
- Type.prototype.decode = function decode_setup(reader, length) {
5853
- return this.setup().decode(reader, length); // overrides this method
5082
+ Type.prototype.decode = function decode_setup(reader, length) { // eslint-disable-line no-unused-vars
5083
+ return this.setup().decode.apply(this, arguments); // overrides this method
5854
5084
  };
5855
5085
 
5856
5086
  /**
@@ -5871,8 +5101,8 @@ Type.prototype.decodeDelimited = function decodeDelimited(reader) {
5871
5101
  * @param {Object.<string,*>} message Plain object to verify
5872
5102
  * @returns {null|string} `null` if valid, otherwise the reason why it is not
5873
5103
  */
5874
- Type.prototype.verify = function verify_setup(message) {
5875
- return this.setup().verify(message); // overrides this method
5104
+ Type.prototype.verify = function verify_setup(message) { // eslint-disable-line no-unused-vars
5105
+ return this.setup().verify.apply(this, arguments); // overrides this method
5876
5106
  };
5877
5107
 
5878
5108
  /**
@@ -5880,8 +5110,8 @@ Type.prototype.verify = function verify_setup(message) {
5880
5110
  * @param {Object.<string,*>} object Plain object to convert
5881
5111
  * @returns {Message<{}>} Message instance
5882
5112
  */
5883
- Type.prototype.fromObject = function fromObject(object) {
5884
- return this.setup().fromObject(object);
5113
+ Type.prototype.fromObject = function fromObject(object) { // eslint-disable-line no-unused-vars
5114
+ return this.setup().fromObject.apply(this, arguments);
5885
5115
  };
5886
5116
 
5887
5117
  /**
@@ -5913,6 +5143,18 @@ Type.prototype.toObject = function toObject(message, options) {
5913
5143
  return this.setup().toObject(message, options);
5914
5144
  };
5915
5145
 
5146
+ /**
5147
+ * Gets the type url for this type.
5148
+ * @param {string} [prefix] Custom type url prefix, defaults to `"type.googleapis.com"`
5149
+ * @returns {string} The type url
5150
+ */
5151
+ Type.prototype.getTypeUrl = function getTypeUrl(prefix) {
5152
+ if (prefix === undefined)
5153
+ prefix = "type.googleapis.com";
5154
+ var fullName = this.fullName;
5155
+ return prefix + "/" + (fullName.charAt(0) === "." ? fullName.substring(1) : fullName);
5156
+ };
5157
+
5916
5158
  /**
5917
5159
  * Decorator function as returned by {@link Type.d} (TypeScript).
5918
5160
  * @typedef TypeDecorator
@@ -5920,6 +5162,7 @@ Type.prototype.toObject = function toObject(message, options) {
5920
5162
  * @param {Constructor<T>} target Target constructor
5921
5163
  * @returns {undefined}
5922
5164
  * @template T extends Message<T>
5165
+ * @deprecated Legacy TypeScript decorator support. Will be removed in a future release.
5923
5166
  */
5924
5167
 
5925
5168
  /**
@@ -5927,6 +5170,7 @@ Type.prototype.toObject = function toObject(message, options) {
5927
5170
  * @param {string} [typeName] Type name, defaults to the constructor's name
5928
5171
  * @returns {TypeDecorator<T>} Decorator function
5929
5172
  * @template T extends Message<T>
5173
+ * @deprecated Legacy TypeScript decorator support. Will be removed in a future release.
5930
5174
  */
5931
5175
  Type.d = function decorateType(typeName) {
5932
5176
  return function typeDecorator(target) {
@@ -5934,7 +5178,7 @@ Type.d = function decorateType(typeName) {
5934
5178
  };
5935
5179
  };
5936
5180
 
5937
- },{"11":11,"12":12,"13":13,"14":14,"15":15,"18":18,"19":19,"21":21,"23":23,"24":24,"30":30,"33":33,"36":36,"37":37,"38":38}],32:[function(require,module,exports){
5181
+ },{"10":10,"12":12,"14":14,"15":15,"2":2,"21":21,"24":24,"3":3,"39":39,"4":4,"40":40,"41":41,"5":5,"6":6,"9":9}],23:[function(require,module,exports){
5938
5182
  "use strict";
5939
5183
 
5940
5184
  /**
@@ -5943,7 +5187,7 @@ Type.d = function decorateType(typeName) {
5943
5187
  */
5944
5188
  var types = exports;
5945
5189
 
5946
- var util = require(33);
5190
+ var util = require(24);
5947
5191
 
5948
5192
  var s = [
5949
5193
  "double", // 0
@@ -5964,7 +5208,7 @@ var s = [
5964
5208
  ];
5965
5209
 
5966
5210
  function bake(values, offset) {
5967
- var i = 0, o = {};
5211
+ var i = 0, o = Object.create(null);
5968
5212
  offset |= 0;
5969
5213
  while (i < values.length) o[s[i + offset]] = values[i++];
5970
5214
  return o;
@@ -6132,29 +5376,47 @@ types.packed = bake([
6132
5376
  /* bool */ 0
6133
5377
  ]);
6134
5378
 
6135
- },{"33":33}],33:[function(require,module,exports){
5379
+ },{"24":24}],24:[function(require,module,exports){
6136
5380
  "use strict";
6137
5381
 
6138
5382
  /**
6139
5383
  * Various utility functions.
6140
5384
  * @namespace
6141
5385
  */
6142
- var util = module.exports = require(35);
5386
+ var util = module.exports = require(34);
6143
5387
 
6144
- var roots = require(27);
5388
+ var roots = require(18);
6145
5389
 
6146
5390
  var Type, // cyclic
6147
5391
  Enum;
6148
5392
 
6149
- util.codegen = require(3);
6150
- util.fetch = require(5);
6151
- util.path = require(8);
5393
+ util.codegen = require(27);
5394
+ util.fetch = require(29);
5395
+ util.path = require(35);
5396
+ util.patterns = require(36);
5397
+
5398
+ var reservedRe = util.patterns.reservedRe,
5399
+ unsafePropertyRe = util.patterns.unsafePropertyRe;
6152
5400
 
6153
5401
  /**
6154
5402
  * Node's fs module if available.
6155
5403
  * @type {Object.<string,*>}
6156
5404
  */
6157
- util.fs = util.inquire("fs");
5405
+ util.fs = require(31);
5406
+
5407
+ /**
5408
+ * Checks a recursion depth.
5409
+ * @param {number|undefined} depth Depth of recursion
5410
+ * @returns {number} Depth of recursion
5411
+ * @throws {Error} If depth exceeds util.recursionLimit
5412
+ */
5413
+ util.checkDepth = function checkDepth(depth) {
5414
+ if (depth === undefined)
5415
+ depth = 0;
5416
+ if (depth > util.recursionLimit)
5417
+ throw Error("max depth exceeded");
5418
+ return depth;
5419
+ };
6158
5420
 
6159
5421
  /**
6160
5422
  * Converts an object's values to an array.
@@ -6190,16 +5452,13 @@ util.toObject = function toObject(array) {
6190
5452
  return object;
6191
5453
  };
6192
5454
 
6193
- var safePropBackslashRe = /\\/g,
6194
- safePropQuoteRe = /"/g;
6195
-
6196
5455
  /**
6197
5456
  * Tests whether the specified name is a reserved word in JS.
6198
5457
  * @param {string} name Name to test
6199
5458
  * @returns {boolean} `true` if reserved, otherwise `false`
6200
5459
  */
6201
5460
  util.isReserved = function isReserved(name) {
6202
- return /^(?:do|if|in|for|let|new|try|var|case|else|enum|eval|false|null|this|true|void|with|break|catch|class|const|super|throw|while|yield|delete|export|import|public|return|static|switch|typeof|default|extends|finally|package|private|continue|debugger|function|arguments|interface|protected|implements|instanceof)$/.test(name);
5461
+ return reservedRe.test(name);
6203
5462
  };
6204
5463
 
6205
5464
  /**
@@ -6208,8 +5467,8 @@ util.isReserved = function isReserved(name) {
6208
5467
  * @returns {string} Safe accessor
6209
5468
  */
6210
5469
  util.safeProp = function safeProp(prop) {
6211
- if (!/^[$\w_]+$/.test(prop) || util.isReserved(prop))
6212
- return "[\"" + prop.replace(safePropBackslashRe, "\\\\").replace(safePropQuoteRe, "\\\"") + "\"]";
5470
+ if (!/^[$\w_]+$/.test(prop) || reservedRe.test(prop))
5471
+ return "[" + JSON.stringify(prop) + "]";
6213
5472
  return "." + prop;
6214
5473
  };
6215
5474
 
@@ -6252,6 +5511,7 @@ util.compareFieldsById = function compareFieldsById(a, b) {
6252
5511
  * @returns {Type} Reflected type
6253
5512
  * @template T extends Message<T>
6254
5513
  * @property {Root} root Decorators root
5514
+ * @deprecated Legacy TypeScript decorator support. Will be removed in a future release.
6255
5515
  */
6256
5516
  util.decorateType = function decorateType(ctor, typeName) {
6257
5517
 
@@ -6267,7 +5527,7 @@ util.decorateType = function decorateType(ctor, typeName) {
6267
5527
 
6268
5528
  /* istanbul ignore next */
6269
5529
  if (!Type)
6270
- Type = require(31);
5530
+ Type = require(22);
6271
5531
 
6272
5532
  var type = new Type(typeName || ctor.name);
6273
5533
  util.decorateRoot.add(type);
@@ -6283,6 +5543,7 @@ var decorateEnumIndex = 0;
6283
5543
  * Decorator helper for enums (TypeScript).
6284
5544
  * @param {Object} object Enum object
6285
5545
  * @returns {Enum} Reflected enum
5546
+ * @deprecated Legacy TypeScript decorator support. Will be removed in a future release.
6286
5547
  */
6287
5548
  util.decorateEnum = function decorateEnum(object) {
6288
5549
 
@@ -6292,7 +5553,7 @@ util.decorateEnum = function decorateEnum(object) {
6292
5553
 
6293
5554
  /* istanbul ignore next */
6294
5555
  if (!Enum)
6295
- Enum = require(14);
5556
+ Enum = require(5);
6296
5557
 
6297
5558
  var enm = new Enum("Enum" + decorateEnumIndex++, object);
6298
5559
  util.decorateRoot.add(enm);
@@ -6312,9 +5573,8 @@ util.decorateEnum = function decorateEnum(object) {
6312
5573
  util.setProperty = function setProperty(dst, path, value, ifNotSet) {
6313
5574
  function setProp(dst, path, value) {
6314
5575
  var part = path.shift();
6315
- if (part === "__proto__" || part === "prototype") {
6316
- return dst;
6317
- }
5576
+ if (unsafePropertyRe.test(part))
5577
+ return dst;
6318
5578
  if (path.length > 0) {
6319
5579
  dst[part] = setProp(dst[part] || {}, path, value);
6320
5580
  } else {
@@ -6342,96 +5602,1004 @@ util.setProperty = function setProperty(dst, path, value, ifNotSet) {
6342
5602
  * @name util.decorateRoot
6343
5603
  * @type {Root}
6344
5604
  * @readonly
5605
+ * @deprecated Legacy TypeScript decorator support. Will be removed in a future release.
6345
5606
  */
6346
5607
  Object.defineProperty(util, "decorateRoot", {
6347
5608
  get: function() {
6348
- return roots["decorated"] || (roots["decorated"] = new (require(26))());
5609
+ return roots["decorated"] || (roots["decorated"] = new (require(17))());
6349
5610
  }
6350
5611
  });
6351
5612
 
6352
- },{"14":14,"26":26,"27":27,"3":3,"31":31,"35":35,"5":5,"8":8}],34:[function(require,module,exports){
5613
+ },{"17":17,"18":18,"22":22,"27":27,"29":29,"31":31,"34":34,"35":35,"36":36,"5":5}],25:[function(require,module,exports){
6353
5614
  "use strict";
6354
- module.exports = LongBits;
6355
-
6356
- var util = require(35);
5615
+ module.exports = asPromise;
6357
5616
 
6358
5617
  /**
6359
- * Constructs new long bits.
6360
- * @classdesc Helper class for working with the low and high bits of a 64 bit value.
6361
- * @memberof util
6362
- * @constructor
6363
- * @param {number} lo Low 32 bits, unsigned
6364
- * @param {number} hi High 32 bits, unsigned
5618
+ * Callback as used by {@link util.asPromise}.
5619
+ * @typedef asPromiseCallback
5620
+ * @type {function}
5621
+ * @param {Error|null} error Error, if any
5622
+ * @param {...*} params Additional arguments
5623
+ * @returns {undefined}
6365
5624
  */
6366
- function LongBits(lo, hi) {
6367
-
6368
- // note that the casts below are theoretically unnecessary as of today, but older statically
6369
- // generated converter code might still call the ctor with signed 32bits. kept for compat.
6370
-
6371
- /**
6372
- * Low bits.
6373
- * @type {number}
6374
- */
6375
- this.lo = lo >>> 0;
6376
5625
 
6377
- /**
6378
- * High bits.
6379
- * @type {number}
6380
- */
6381
- this.hi = hi >>> 0;
5626
+ /**
5627
+ * Returns a promise from a node-style callback function.
5628
+ * @memberof util
5629
+ * @param {asPromiseCallback} fn Function to call
5630
+ * @param {*} ctx Function context
5631
+ * @param {...*} params Function arguments
5632
+ * @returns {Promise<*>} Promisified function
5633
+ */
5634
+ function asPromise(fn, ctx/*, varargs */) {
5635
+ var params = new Array(arguments.length - 1),
5636
+ offset = 0,
5637
+ index = 2,
5638
+ pending = true;
5639
+ while (index < arguments.length)
5640
+ params[offset++] = arguments[index++];
5641
+ return new Promise(function executor(resolve, reject) {
5642
+ params[offset] = function callback(err/*, varargs */) {
5643
+ if (pending) {
5644
+ pending = false;
5645
+ if (err)
5646
+ reject(err);
5647
+ else {
5648
+ var params = new Array(arguments.length - 1),
5649
+ offset = 0;
5650
+ while (offset < params.length)
5651
+ params[offset++] = arguments[offset];
5652
+ resolve.apply(null, params);
5653
+ }
5654
+ }
5655
+ };
5656
+ try {
5657
+ fn.apply(ctx || null, params);
5658
+ } catch (err) {
5659
+ if (pending) {
5660
+ pending = false;
5661
+ reject(err);
5662
+ }
5663
+ }
5664
+ });
6382
5665
  }
6383
5666
 
5667
+ },{}],26:[function(require,module,exports){
5668
+ "use strict";
5669
+
6384
5670
  /**
6385
- * Zero bits.
6386
- * @memberof util.LongBits
6387
- * @type {util.LongBits}
5671
+ * A minimal base64 implementation for number arrays.
5672
+ * @memberof util
5673
+ * @namespace
6388
5674
  */
6389
- var zero = LongBits.zero = new LongBits(0, 0);
6390
-
6391
- zero.toNumber = function() { return 0; };
6392
- zero.zzEncode = zero.zzDecode = function() { return this; };
6393
- zero.length = function() { return 1; };
5675
+ var base64 = exports;
6394
5676
 
6395
5677
  /**
6396
- * Zero hash.
6397
- * @memberof util.LongBits
6398
- * @type {string}
5678
+ * Calculates the byte length of a base64 encoded string.
5679
+ * @param {string} string Base64 encoded string
5680
+ * @returns {number} Byte length
6399
5681
  */
6400
- var zeroHash = LongBits.zeroHash = "\0\0\0\0\0\0\0\0";
5682
+ base64.length = function length(string) {
5683
+ var p = string.length;
5684
+ if (!p)
5685
+ return 0;
5686
+ while (p > 0 && string.charAt(p - 1) === "=")
5687
+ --p;
5688
+ return Math.floor(p * 3 / 4);
5689
+ };
5690
+
5691
+ // Base64 encoding table
5692
+ var b64 = new Array(64);
5693
+
5694
+ // Base64 decoding table
5695
+ var s64 = new Array(123);
5696
+
5697
+ // 65..90, 97..122, 48..57, 43, 47
5698
+ for (var i = 0; i < 64;)
5699
+ s64[b64[i] = i < 26 ? i + 65 : i < 52 ? i + 71 : i < 62 ? i - 4 : i - 59 | 43] = i++;
5700
+
5701
+ s64[45] = 62; // - -> +
5702
+ s64[95] = 63; // _ -> /
6401
5703
 
6402
5704
  /**
6403
- * Constructs new long bits from the specified number.
6404
- * @param {number} value Value
6405
- * @returns {util.LongBits} Instance
5705
+ * Encodes a buffer to a base64 encoded string.
5706
+ * @param {Uint8Array} buffer Source buffer
5707
+ * @param {number} start Source start
5708
+ * @param {number} end Source end
5709
+ * @returns {string} Base64 encoded string
6406
5710
  */
6407
- LongBits.fromNumber = function fromNumber(value) {
6408
- if (value === 0)
6409
- return zero;
6410
- var sign = value < 0;
6411
- if (sign)
6412
- value = -value;
6413
- var lo = value >>> 0,
6414
- hi = (value - lo) / 4294967296 >>> 0;
6415
- if (sign) {
6416
- hi = ~hi >>> 0;
6417
- lo = ~lo >>> 0;
6418
- if (++lo > 4294967295) {
6419
- lo = 0;
6420
- if (++hi > 4294967295)
6421
- hi = 0;
5711
+ base64.encode = function encode(buffer, start, end) {
5712
+ var parts = null,
5713
+ chunk = [];
5714
+ var i = 0, // output index
5715
+ j = 0, // goto index
5716
+ t; // temporary
5717
+ while (start < end) {
5718
+ var b = buffer[start++];
5719
+ switch (j) {
5720
+ case 0:
5721
+ chunk[i++] = b64[b >> 2];
5722
+ t = (b & 3) << 4;
5723
+ j = 1;
5724
+ break;
5725
+ case 1:
5726
+ chunk[i++] = b64[t | b >> 4];
5727
+ t = (b & 15) << 2;
5728
+ j = 2;
5729
+ break;
5730
+ case 2:
5731
+ chunk[i++] = b64[t | b >> 6];
5732
+ chunk[i++] = b64[b & 63];
5733
+ j = 0;
5734
+ break;
5735
+ }
5736
+ if (i > 8191) {
5737
+ (parts || (parts = [])).push(String.fromCharCode.apply(String, chunk));
5738
+ i = 0;
6422
5739
  }
6423
5740
  }
6424
- return new LongBits(lo, hi);
5741
+ if (j) {
5742
+ chunk[i++] = b64[t];
5743
+ chunk[i++] = 61;
5744
+ if (j === 1)
5745
+ chunk[i++] = 61;
5746
+ }
5747
+ if (parts) {
5748
+ if (i)
5749
+ parts.push(String.fromCharCode.apply(String, chunk.slice(0, i)));
5750
+ return parts.join("");
5751
+ }
5752
+ return String.fromCharCode.apply(String, chunk.slice(0, i));
6425
5753
  };
6426
5754
 
5755
+ var invalidEncoding = "invalid encoding";
5756
+
6427
5757
  /**
6428
- * Constructs new long bits from a number, long or string.
6429
- * @param {Long|number|string} value Value
6430
- * @returns {util.LongBits} Instance
5758
+ * Decodes a base64 encoded string to a buffer.
5759
+ * @param {string} string Source string
5760
+ * @param {Uint8Array} buffer Destination buffer
5761
+ * @param {number} offset Destination offset
5762
+ * @returns {number} Number of bytes written
5763
+ * @throws {Error} If encoding is invalid
6431
5764
  */
6432
- LongBits.from = function from(value) {
6433
- if (typeof value === "number")
6434
- return LongBits.fromNumber(value);
5765
+ base64.decode = function decode(string, buffer, offset) {
5766
+ var start = offset;
5767
+ var j = 0, // goto index
5768
+ t; // temporary
5769
+ for (var i = 0; i < string.length;) {
5770
+ var c = string.charCodeAt(i++);
5771
+ if (c === 61 && j > 1)
5772
+ break;
5773
+ if ((c = s64[c]) === undefined)
5774
+ throw Error(invalidEncoding);
5775
+ switch (j) {
5776
+ case 0:
5777
+ t = c;
5778
+ j = 1;
5779
+ break;
5780
+ case 1:
5781
+ buffer[offset++] = t << 2 | (c & 48) >> 4;
5782
+ t = c;
5783
+ j = 2;
5784
+ break;
5785
+ case 2:
5786
+ buffer[offset++] = (t & 15) << 4 | (c & 60) >> 2;
5787
+ t = c;
5788
+ j = 3;
5789
+ break;
5790
+ case 3:
5791
+ buffer[offset++] = (t & 3) << 6 | c;
5792
+ j = 0;
5793
+ break;
5794
+ }
5795
+ }
5796
+ if (j === 1)
5797
+ throw Error(invalidEncoding);
5798
+ return offset - start;
5799
+ };
5800
+
5801
+ var base64Re = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,
5802
+ base64UrlRe = /[-_]/,
5803
+ base64UrlNoPaddingRe = /^(?:[A-Za-z0-9_-]{4})*(?:[A-Za-z0-9_-]{2}(?:==)?|[A-Za-z0-9_-]{3}=?)?$/;
5804
+
5805
+ /**
5806
+ * Tests if the specified string appears to be base64 encoded.
5807
+ * @param {string} string String to test
5808
+ * @returns {boolean} `true` if probably base64 encoded, otherwise false
5809
+ */
5810
+ base64.test = function test(string) {
5811
+ return base64Re.test(string)
5812
+ || base64UrlRe.test(string) && base64UrlNoPaddingRe.test(string);
5813
+ };
5814
+
5815
+ },{}],27:[function(require,module,exports){
5816
+ "use strict";
5817
+ module.exports = codegen;
5818
+
5819
+ var patterns = require(36);
5820
+ var reservedRe = patterns.reservedRe;
5821
+
5822
+ /**
5823
+ * Begins generating a function.
5824
+ * @memberof util
5825
+ * @param {string[]} functionParams Function parameter names
5826
+ * @param {string} [functionName] Function name if not anonymous
5827
+ * @returns {Codegen} Appender that appends code to the function's body
5828
+ */
5829
+ function codegen(functionParams, functionName) {
5830
+
5831
+ /* istanbul ignore if */
5832
+ if (typeof functionParams === "string") {
5833
+ functionName = functionParams;
5834
+ functionParams = undefined;
5835
+ }
5836
+
5837
+ var body = [];
5838
+
5839
+ /**
5840
+ * Appends code to the function's body or finishes generation.
5841
+ * @typedef Codegen
5842
+ * @type {function}
5843
+ * @param {string|Object.<string,*>} [formatStringOrScope] Format string or, to finish the function, an object of additional scope variables, if any
5844
+ * @param {...*} [formatParams] Format parameters
5845
+ * @returns {Codegen|Function} Itself or the generated function if finished
5846
+ * @throws {Error} If format parameter counts do not match
5847
+ */
5848
+
5849
+ function Codegen(formatStringOrScope) {
5850
+ // note that explicit array handling below makes this ~50% faster
5851
+
5852
+ // finish the function
5853
+ if (typeof formatStringOrScope !== "string") {
5854
+ var source = toString();
5855
+ if (codegen.verbose)
5856
+ console.log("codegen: " + source); // eslint-disable-line no-console
5857
+ source = "return " + source;
5858
+ if (formatStringOrScope) {
5859
+ var scopeKeys = Object.keys(formatStringOrScope),
5860
+ scopeParams = new Array(scopeKeys.length + 1),
5861
+ scopeValues = new Array(scopeKeys.length),
5862
+ scopeOffset = 0;
5863
+ while (scopeOffset < scopeKeys.length) {
5864
+ scopeParams[scopeOffset] = scopeKeys[scopeOffset];
5865
+ scopeValues[scopeOffset] = formatStringOrScope[scopeKeys[scopeOffset++]];
5866
+ }
5867
+ scopeParams[scopeOffset] = source;
5868
+ return Function.apply(null, scopeParams).apply(null, scopeValues); // eslint-disable-line no-new-func
5869
+ }
5870
+ return Function(source)(); // eslint-disable-line no-new-func
5871
+ }
5872
+
5873
+ // otherwise append to body
5874
+ var formatParams = new Array(arguments.length - 1),
5875
+ formatOffset = 0;
5876
+ while (formatOffset < formatParams.length)
5877
+ formatParams[formatOffset] = arguments[++formatOffset];
5878
+ formatOffset = 0;
5879
+ formatStringOrScope = formatStringOrScope.replace(/%([%dfijs])/g, function replace($0, $1) {
5880
+ var value = formatParams[formatOffset++];
5881
+ switch ($1) {
5882
+ case "d": case "f": return String(Number(value));
5883
+ case "i": return String(Math.floor(value));
5884
+ case "j": return JSON.stringify(value);
5885
+ case "s": return String(value);
5886
+ }
5887
+ return "%";
5888
+ });
5889
+ if (formatOffset !== formatParams.length)
5890
+ throw Error("parameter count mismatch");
5891
+ body.push(formatStringOrScope);
5892
+ return Codegen;
5893
+ }
5894
+
5895
+ function toString(functionNameOverride) {
5896
+ return "function " + safeFunctionName(functionNameOverride || functionName) + "(" + (functionParams && functionParams.join(",") || "") + "){\n " + body.join("\n ") + "\n}";
5897
+ }
5898
+
5899
+ Codegen.toString = toString;
5900
+ return Codegen;
5901
+ }
5902
+
5903
+ /**
5904
+ * Begins generating a function.
5905
+ * @memberof util
5906
+ * @function codegen
5907
+ * @param {string} [functionName] Function name if not anonymous
5908
+ * @returns {Codegen} Appender that appends code to the function's body
5909
+ * @variation 2
5910
+ */
5911
+
5912
+ /**
5913
+ * When set to `true`, codegen will log generated code to console. Useful for debugging.
5914
+ * @name util.codegen.verbose
5915
+ * @type {boolean}
5916
+ */
5917
+ codegen.verbose = false;
5918
+
5919
+ function safeFunctionName(name) {
5920
+ if (!name)
5921
+ return "";
5922
+ name = String(name).replace(/[^\w$]/g, "");
5923
+ if (!name)
5924
+ return "";
5925
+ if (/^\d/.test(name))
5926
+ name = "_" + name;
5927
+ return reservedRe.test(name) ? name + "_" : name;
5928
+ }
5929
+
5930
+ },{"36":36}],28:[function(require,module,exports){
5931
+ "use strict";
5932
+ module.exports = EventEmitter;
5933
+
5934
+ /**
5935
+ * Constructs a new event emitter instance.
5936
+ * @classdesc A minimal event emitter.
5937
+ * @memberof util
5938
+ * @constructor
5939
+ */
5940
+ function EventEmitter() {
5941
+
5942
+ /**
5943
+ * Registered listeners.
5944
+ * @type {Object.<string,*>}
5945
+ * @private
5946
+ */
5947
+ this._listeners = {};
5948
+ }
5949
+
5950
+ /**
5951
+ * Event listener as used by {@link util.EventEmitter}.
5952
+ * @typedef EventEmitterListener
5953
+ * @type {function}
5954
+ * @param {...*} args Arguments
5955
+ * @returns {undefined}
5956
+ */
5957
+
5958
+ /**
5959
+ * Registers an event listener.
5960
+ * @param {string} evt Event name
5961
+ * @param {EventEmitterListener} fn Listener
5962
+ * @param {*} [ctx] Listener context
5963
+ * @returns {this} `this`
5964
+ */
5965
+ EventEmitter.prototype.on = function on(evt, fn, ctx) {
5966
+ (this._listeners[evt] || (this._listeners[evt] = [])).push({
5967
+ fn : fn,
5968
+ ctx : ctx || this
5969
+ });
5970
+ return this;
5971
+ };
5972
+
5973
+ /**
5974
+ * Removes an event listener or any matching listeners if arguments are omitted.
5975
+ * @param {string} [evt] Event name. Removes all listeners if omitted.
5976
+ * @param {EventEmitterListener} [fn] Listener to remove. Removes all listeners of `evt` if omitted.
5977
+ * @returns {this} `this`
5978
+ */
5979
+ EventEmitter.prototype.off = function off(evt, fn) {
5980
+ if (evt === undefined)
5981
+ this._listeners = {};
5982
+ else {
5983
+ if (fn === undefined)
5984
+ this._listeners[evt] = [];
5985
+ else {
5986
+ var listeners = this._listeners[evt];
5987
+ for (var i = 0; i < listeners.length;)
5988
+ if (listeners[i].fn === fn)
5989
+ listeners.splice(i, 1);
5990
+ else
5991
+ ++i;
5992
+ }
5993
+ }
5994
+ return this;
5995
+ };
5996
+
5997
+ /**
5998
+ * Emits an event by calling its listeners with the specified arguments.
5999
+ * @param {string} evt Event name
6000
+ * @param {...*} args Arguments
6001
+ * @returns {this} `this`
6002
+ */
6003
+ EventEmitter.prototype.emit = function emit(evt) {
6004
+ var listeners = this._listeners[evt];
6005
+ if (listeners) {
6006
+ var args = [],
6007
+ i = 1;
6008
+ for (; i < arguments.length;)
6009
+ args.push(arguments[i++]);
6010
+ for (i = 0; i < listeners.length;)
6011
+ listeners[i].fn.apply(listeners[i++].ctx, args);
6012
+ }
6013
+ return this;
6014
+ };
6015
+
6016
+ },{}],29:[function(require,module,exports){
6017
+ "use strict";
6018
+ module.exports = fetch;
6019
+
6020
+ var asPromise = require(25),
6021
+ fs = require(31);
6022
+
6023
+ /**
6024
+ * Node-style callback as used by {@link util.fetch}.
6025
+ * @typedef FetchCallback
6026
+ * @type {function}
6027
+ * @param {?Error} error Error, if any, otherwise `null`
6028
+ * @param {string} [contents] File contents, if there hasn't been an error
6029
+ * @returns {undefined}
6030
+ */
6031
+
6032
+ /**
6033
+ * Options as used by {@link util.fetch}.
6034
+ * @interface IFetchOptions
6035
+ * @property {boolean} [binary=false] Whether expecting a binary response
6036
+ * @property {boolean} [xhr=false] If `true`, forces the use of XMLHttpRequest
6037
+ */
6038
+
6039
+ /**
6040
+ * Fetches the contents of a file.
6041
+ * @memberof util
6042
+ * @param {string} filename File path or url
6043
+ * @param {IFetchOptions} options Fetch options
6044
+ * @param {FetchCallback} callback Callback function
6045
+ * @returns {undefined}
6046
+ */
6047
+ function fetch(filename, options, callback) {
6048
+ if (typeof options === "function") {
6049
+ callback = options;
6050
+ options = {};
6051
+ } else if (!options)
6052
+ options = {};
6053
+
6054
+ if (!callback)
6055
+ return asPromise(fetch, this, filename, options); // eslint-disable-line no-invalid-this
6056
+
6057
+ // if a node-like filesystem is present, try it first but fall back to XHR if nothing is found.
6058
+ if (!options.xhr && fs && fs.readFile)
6059
+ return fs.readFile(filename, function fetchReadFileCallback(err, contents) {
6060
+ return err && typeof XMLHttpRequest !== "undefined"
6061
+ ? fetch.xhr(filename, options, callback)
6062
+ : err
6063
+ ? callback(err)
6064
+ : callback(null, options.binary ? contents : contents.toString("utf8"));
6065
+ });
6066
+
6067
+ // use the XHR version otherwise.
6068
+ return fetch.xhr(filename, options, callback);
6069
+ }
6070
+
6071
+ /**
6072
+ * Fetches the contents of a file.
6073
+ * @name util.fetch
6074
+ * @function
6075
+ * @param {string} path File path or url
6076
+ * @param {FetchCallback} callback Callback function
6077
+ * @returns {undefined}
6078
+ * @variation 2
6079
+ */
6080
+
6081
+ /**
6082
+ * Fetches the contents of a file.
6083
+ * @name util.fetch
6084
+ * @function
6085
+ * @param {string} path File path or url
6086
+ * @param {IFetchOptions} [options] Fetch options
6087
+ * @returns {Promise<string|Uint8Array>} Promise
6088
+ * @variation 3
6089
+ */
6090
+
6091
+ /**/
6092
+ fetch.xhr = function fetch_xhr(filename, options, callback) {
6093
+ var xhr = new XMLHttpRequest();
6094
+ xhr.onreadystatechange /* works everywhere */ = function fetchOnReadyStateChange() {
6095
+
6096
+ if (xhr.readyState !== 4)
6097
+ return undefined;
6098
+
6099
+ // local cors security errors return status 0 / empty string, too. afaik this cannot be
6100
+ // reliably distinguished from an actually empty file for security reasons. feel free
6101
+ // to send a pull request if you are aware of a solution.
6102
+ if (xhr.status !== 0 && xhr.status !== 200)
6103
+ return callback(Error("status " + xhr.status));
6104
+
6105
+ // if binary data is expected, make sure that some sort of array is returned, even if
6106
+ // ArrayBuffers are not supported. the binary string fallback, however, is unsafe.
6107
+ if (options.binary) {
6108
+ var buffer = xhr.response;
6109
+ if (!buffer) {
6110
+ buffer = [];
6111
+ for (var i = 0; i < xhr.responseText.length; ++i)
6112
+ buffer.push(xhr.responseText.charCodeAt(i) & 255);
6113
+ }
6114
+ return callback(null, typeof Uint8Array !== "undefined" ? new Uint8Array(buffer) : buffer);
6115
+ }
6116
+ return callback(null, xhr.responseText);
6117
+ };
6118
+
6119
+ if (options.binary) {
6120
+ // ref: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Sending_and_Receiving_Binary_Data#Receiving_binary_data_in_older_browsers
6121
+ if ("overrideMimeType" in xhr)
6122
+ xhr.overrideMimeType("text/plain; charset=x-user-defined");
6123
+ xhr.responseType = "arraybuffer";
6124
+ }
6125
+
6126
+ xhr.open("GET", filename);
6127
+ xhr.send();
6128
+ };
6129
+
6130
+ },{"25":25,"31":31}],30:[function(require,module,exports){
6131
+ "use strict";
6132
+
6133
+ module.exports = factory(factory);
6134
+
6135
+ /**
6136
+ * Reads / writes floats / doubles from / to buffers.
6137
+ * @name util.float
6138
+ * @namespace
6139
+ */
6140
+
6141
+ /**
6142
+ * Writes a 32 bit float to a buffer using little endian byte order.
6143
+ * @name util.float.writeFloatLE
6144
+ * @function
6145
+ * @param {number} val Value to write
6146
+ * @param {Uint8Array} buf Target buffer
6147
+ * @param {number} pos Target buffer offset
6148
+ * @returns {undefined}
6149
+ */
6150
+
6151
+ /**
6152
+ * Writes a 32 bit float to a buffer using big endian byte order.
6153
+ * @name util.float.writeFloatBE
6154
+ * @function
6155
+ * @param {number} val Value to write
6156
+ * @param {Uint8Array} buf Target buffer
6157
+ * @param {number} pos Target buffer offset
6158
+ * @returns {undefined}
6159
+ */
6160
+
6161
+ /**
6162
+ * Reads a 32 bit float from a buffer using little endian byte order.
6163
+ * @name util.float.readFloatLE
6164
+ * @function
6165
+ * @param {Uint8Array} buf Source buffer
6166
+ * @param {number} pos Source buffer offset
6167
+ * @returns {number} Value read
6168
+ */
6169
+
6170
+ /**
6171
+ * Reads a 32 bit float from a buffer using big endian byte order.
6172
+ * @name util.float.readFloatBE
6173
+ * @function
6174
+ * @param {Uint8Array} buf Source buffer
6175
+ * @param {number} pos Source buffer offset
6176
+ * @returns {number} Value read
6177
+ */
6178
+
6179
+ /**
6180
+ * Writes a 64 bit double to a buffer using little endian byte order.
6181
+ * @name util.float.writeDoubleLE
6182
+ * @function
6183
+ * @param {number} val Value to write
6184
+ * @param {Uint8Array} buf Target buffer
6185
+ * @param {number} pos Target buffer offset
6186
+ * @returns {undefined}
6187
+ */
6188
+
6189
+ /**
6190
+ * Writes a 64 bit double to a buffer using big endian byte order.
6191
+ * @name util.float.writeDoubleBE
6192
+ * @function
6193
+ * @param {number} val Value to write
6194
+ * @param {Uint8Array} buf Target buffer
6195
+ * @param {number} pos Target buffer offset
6196
+ * @returns {undefined}
6197
+ */
6198
+
6199
+ /**
6200
+ * Reads a 64 bit double from a buffer using little endian byte order.
6201
+ * @name util.float.readDoubleLE
6202
+ * @function
6203
+ * @param {Uint8Array} buf Source buffer
6204
+ * @param {number} pos Source buffer offset
6205
+ * @returns {number} Value read
6206
+ */
6207
+
6208
+ /**
6209
+ * Reads a 64 bit double from a buffer using big endian byte order.
6210
+ * @name util.float.readDoubleBE
6211
+ * @function
6212
+ * @param {Uint8Array} buf Source buffer
6213
+ * @param {number} pos Source buffer offset
6214
+ * @returns {number} Value read
6215
+ */
6216
+
6217
+ // Factory function for the purpose of node-based testing in modified global environments
6218
+ function factory(exports) {
6219
+
6220
+ // float: typed array
6221
+ if (typeof Float32Array !== "undefined") (function() {
6222
+
6223
+ var f32 = new Float32Array([ -0 ]),
6224
+ f8b = new Uint8Array(f32.buffer),
6225
+ le = f8b[3] === 128;
6226
+
6227
+ function writeFloat_f32_cpy(val, buf, pos) {
6228
+ f32[0] = val;
6229
+ buf[pos ] = f8b[0];
6230
+ buf[pos + 1] = f8b[1];
6231
+ buf[pos + 2] = f8b[2];
6232
+ buf[pos + 3] = f8b[3];
6233
+ }
6234
+
6235
+ function writeFloat_f32_rev(val, buf, pos) {
6236
+ f32[0] = val;
6237
+ buf[pos ] = f8b[3];
6238
+ buf[pos + 1] = f8b[2];
6239
+ buf[pos + 2] = f8b[1];
6240
+ buf[pos + 3] = f8b[0];
6241
+ }
6242
+
6243
+ /* istanbul ignore next */
6244
+ exports.writeFloatLE = le ? writeFloat_f32_cpy : writeFloat_f32_rev;
6245
+ /* istanbul ignore next */
6246
+ exports.writeFloatBE = le ? writeFloat_f32_rev : writeFloat_f32_cpy;
6247
+
6248
+ function readFloat_f32_cpy(buf, pos) {
6249
+ f8b[0] = buf[pos ];
6250
+ f8b[1] = buf[pos + 1];
6251
+ f8b[2] = buf[pos + 2];
6252
+ f8b[3] = buf[pos + 3];
6253
+ return f32[0];
6254
+ }
6255
+
6256
+ function readFloat_f32_rev(buf, pos) {
6257
+ f8b[3] = buf[pos ];
6258
+ f8b[2] = buf[pos + 1];
6259
+ f8b[1] = buf[pos + 2];
6260
+ f8b[0] = buf[pos + 3];
6261
+ return f32[0];
6262
+ }
6263
+
6264
+ /* istanbul ignore next */
6265
+ exports.readFloatLE = le ? readFloat_f32_cpy : readFloat_f32_rev;
6266
+ /* istanbul ignore next */
6267
+ exports.readFloatBE = le ? readFloat_f32_rev : readFloat_f32_cpy;
6268
+
6269
+ // float: ieee754
6270
+ })(); else (function() {
6271
+
6272
+ function writeFloat_ieee754(writeUint, val, buf, pos) {
6273
+ var sign = val < 0 ? 1 : 0;
6274
+ if (sign)
6275
+ val = -val;
6276
+ if (val === 0)
6277
+ writeUint(1 / val > 0 ? /* positive */ 0 : /* negative 0 */ 2147483648, buf, pos);
6278
+ else if (isNaN(val))
6279
+ writeUint(2143289344, buf, pos);
6280
+ else if (val > 3.4028234663852886e+38) // +-Infinity
6281
+ writeUint((sign << 31 | 2139095040) >>> 0, buf, pos);
6282
+ else if (val < 1.1754943508222875e-38) // denormal
6283
+ writeUint((sign << 31 | Math.round(val / 1.401298464324817e-45)) >>> 0, buf, pos);
6284
+ else {
6285
+ var exponent = Math.floor(Math.log(val) / Math.LN2),
6286
+ mantissa = Math.round(val * Math.pow(2, -exponent) * 8388608) & 8388607;
6287
+ writeUint((sign << 31 | exponent + 127 << 23 | mantissa) >>> 0, buf, pos);
6288
+ }
6289
+ }
6290
+
6291
+ exports.writeFloatLE = writeFloat_ieee754.bind(null, writeUintLE);
6292
+ exports.writeFloatBE = writeFloat_ieee754.bind(null, writeUintBE);
6293
+
6294
+ function readFloat_ieee754(readUint, buf, pos) {
6295
+ var uint = readUint(buf, pos),
6296
+ sign = (uint >> 31) * 2 + 1,
6297
+ exponent = uint >>> 23 & 255,
6298
+ mantissa = uint & 8388607;
6299
+ return exponent === 255
6300
+ ? mantissa
6301
+ ? NaN
6302
+ : sign * Infinity
6303
+ : exponent === 0 // denormal
6304
+ ? sign * 1.401298464324817e-45 * mantissa
6305
+ : sign * Math.pow(2, exponent - 150) * (mantissa + 8388608);
6306
+ }
6307
+
6308
+ exports.readFloatLE = readFloat_ieee754.bind(null, readUintLE);
6309
+ exports.readFloatBE = readFloat_ieee754.bind(null, readUintBE);
6310
+
6311
+ })();
6312
+
6313
+ // double: typed array
6314
+ if (typeof Float64Array !== "undefined") (function() {
6315
+
6316
+ var f64 = new Float64Array([-0]),
6317
+ f8b = new Uint8Array(f64.buffer),
6318
+ le = f8b[7] === 128;
6319
+
6320
+ function writeDouble_f64_cpy(val, buf, pos) {
6321
+ f64[0] = val;
6322
+ buf[pos ] = f8b[0];
6323
+ buf[pos + 1] = f8b[1];
6324
+ buf[pos + 2] = f8b[2];
6325
+ buf[pos + 3] = f8b[3];
6326
+ buf[pos + 4] = f8b[4];
6327
+ buf[pos + 5] = f8b[5];
6328
+ buf[pos + 6] = f8b[6];
6329
+ buf[pos + 7] = f8b[7];
6330
+ }
6331
+
6332
+ function writeDouble_f64_rev(val, buf, pos) {
6333
+ f64[0] = val;
6334
+ buf[pos ] = f8b[7];
6335
+ buf[pos + 1] = f8b[6];
6336
+ buf[pos + 2] = f8b[5];
6337
+ buf[pos + 3] = f8b[4];
6338
+ buf[pos + 4] = f8b[3];
6339
+ buf[pos + 5] = f8b[2];
6340
+ buf[pos + 6] = f8b[1];
6341
+ buf[pos + 7] = f8b[0];
6342
+ }
6343
+
6344
+ /* istanbul ignore next */
6345
+ exports.writeDoubleLE = le ? writeDouble_f64_cpy : writeDouble_f64_rev;
6346
+ /* istanbul ignore next */
6347
+ exports.writeDoubleBE = le ? writeDouble_f64_rev : writeDouble_f64_cpy;
6348
+
6349
+ function readDouble_f64_cpy(buf, pos) {
6350
+ f8b[0] = buf[pos ];
6351
+ f8b[1] = buf[pos + 1];
6352
+ f8b[2] = buf[pos + 2];
6353
+ f8b[3] = buf[pos + 3];
6354
+ f8b[4] = buf[pos + 4];
6355
+ f8b[5] = buf[pos + 5];
6356
+ f8b[6] = buf[pos + 6];
6357
+ f8b[7] = buf[pos + 7];
6358
+ return f64[0];
6359
+ }
6360
+
6361
+ function readDouble_f64_rev(buf, pos) {
6362
+ f8b[7] = buf[pos ];
6363
+ f8b[6] = buf[pos + 1];
6364
+ f8b[5] = buf[pos + 2];
6365
+ f8b[4] = buf[pos + 3];
6366
+ f8b[3] = buf[pos + 4];
6367
+ f8b[2] = buf[pos + 5];
6368
+ f8b[1] = buf[pos + 6];
6369
+ f8b[0] = buf[pos + 7];
6370
+ return f64[0];
6371
+ }
6372
+
6373
+ /* istanbul ignore next */
6374
+ exports.readDoubleLE = le ? readDouble_f64_cpy : readDouble_f64_rev;
6375
+ /* istanbul ignore next */
6376
+ exports.readDoubleBE = le ? readDouble_f64_rev : readDouble_f64_cpy;
6377
+
6378
+ // double: ieee754
6379
+ })(); else (function() {
6380
+
6381
+ function writeDouble_ieee754(writeUint, off0, off1, val, buf, pos) {
6382
+ var sign = val < 0 ? 1 : 0;
6383
+ if (sign)
6384
+ val = -val;
6385
+ if (val === 0) {
6386
+ writeUint(0, buf, pos + off0);
6387
+ writeUint(1 / val > 0 ? /* positive */ 0 : /* negative 0 */ 2147483648, buf, pos + off1);
6388
+ } else if (isNaN(val)) {
6389
+ writeUint(0, buf, pos + off0);
6390
+ writeUint(2146959360, buf, pos + off1);
6391
+ } else if (val > 1.7976931348623157e+308) { // +-Infinity
6392
+ writeUint(0, buf, pos + off0);
6393
+ writeUint((sign << 31 | 2146435072) >>> 0, buf, pos + off1);
6394
+ } else {
6395
+ var mantissa;
6396
+ if (val < 2.2250738585072014e-308) { // denormal
6397
+ mantissa = val / 5e-324;
6398
+ writeUint(mantissa >>> 0, buf, pos + off0);
6399
+ writeUint((sign << 31 | mantissa / 4294967296) >>> 0, buf, pos + off1);
6400
+ } else {
6401
+ var exponent = Math.floor(Math.log(val) / Math.LN2);
6402
+ if (exponent === 1024)
6403
+ exponent = 1023;
6404
+ mantissa = val * Math.pow(2, -exponent);
6405
+ writeUint(mantissa * 4503599627370496 >>> 0, buf, pos + off0);
6406
+ writeUint((sign << 31 | exponent + 1023 << 20 | mantissa * 1048576 & 1048575) >>> 0, buf, pos + off1);
6407
+ }
6408
+ }
6409
+ }
6410
+
6411
+ exports.writeDoubleLE = writeDouble_ieee754.bind(null, writeUintLE, 0, 4);
6412
+ exports.writeDoubleBE = writeDouble_ieee754.bind(null, writeUintBE, 4, 0);
6413
+
6414
+ function readDouble_ieee754(readUint, off0, off1, buf, pos) {
6415
+ var lo = readUint(buf, pos + off0),
6416
+ hi = readUint(buf, pos + off1);
6417
+ var sign = (hi >> 31) * 2 + 1,
6418
+ exponent = hi >>> 20 & 2047,
6419
+ mantissa = 4294967296 * (hi & 1048575) + lo;
6420
+ return exponent === 2047
6421
+ ? mantissa
6422
+ ? NaN
6423
+ : sign * Infinity
6424
+ : exponent === 0 // denormal
6425
+ ? sign * 5e-324 * mantissa
6426
+ : sign * Math.pow(2, exponent - 1075) * (mantissa + 4503599627370496);
6427
+ }
6428
+
6429
+ exports.readDoubleLE = readDouble_ieee754.bind(null, readUintLE, 0, 4);
6430
+ exports.readDoubleBE = readDouble_ieee754.bind(null, readUintBE, 4, 0);
6431
+
6432
+ })();
6433
+
6434
+ return exports;
6435
+ }
6436
+
6437
+ // uint helpers
6438
+
6439
+ function writeUintLE(val, buf, pos) {
6440
+ buf[pos ] = val & 255;
6441
+ buf[pos + 1] = val >>> 8 & 255;
6442
+ buf[pos + 2] = val >>> 16 & 255;
6443
+ buf[pos + 3] = val >>> 24;
6444
+ }
6445
+
6446
+ function writeUintBE(val, buf, pos) {
6447
+ buf[pos ] = val >>> 24;
6448
+ buf[pos + 1] = val >>> 16 & 255;
6449
+ buf[pos + 2] = val >>> 8 & 255;
6450
+ buf[pos + 3] = val & 255;
6451
+ }
6452
+
6453
+ function readUintLE(buf, pos) {
6454
+ return (buf[pos ]
6455
+ | buf[pos + 1] << 8
6456
+ | buf[pos + 2] << 16
6457
+ | buf[pos + 3] << 24) >>> 0;
6458
+ }
6459
+
6460
+ function readUintBE(buf, pos) {
6461
+ return (buf[pos ] << 24
6462
+ | buf[pos + 1] << 16
6463
+ | buf[pos + 2] << 8
6464
+ | buf[pos + 3]) >>> 0;
6465
+ }
6466
+
6467
+ },{}],31:[function(require,module,exports){
6468
+ "use strict";
6469
+
6470
+ var fs = null;
6471
+ try {
6472
+ fs = require(1);
6473
+ if (!fs || !fs.readFile || !fs.readFileSync)
6474
+ fs = null;
6475
+ } catch (e) {
6476
+ // `fs` is unavailable in browsers and browser-like bundles.
6477
+ }
6478
+ module.exports = fs;
6479
+
6480
+ },{"1":1}],32:[function(require,module,exports){
6481
+ "use strict";
6482
+ module.exports = inquire;
6483
+
6484
+ /**
6485
+ * Requires a module only if available.
6486
+ * @memberof util
6487
+ * @param {string} moduleName Module to require
6488
+ * @returns {?Object} Required module if available and not empty, otherwise `null`
6489
+ * @deprecated Legacy optional require helper. Will be removed in a future release.
6490
+ */
6491
+ function inquire(moduleName) {
6492
+ try {
6493
+ if (typeof require !== "function") {
6494
+ return null;
6495
+ }
6496
+ var mod = require(moduleName);
6497
+ if (mod && (mod.length || Object.keys(mod).length)) return mod;
6498
+ return null;
6499
+ } catch (err) {
6500
+ // ignore
6501
+ return null;
6502
+ }
6503
+ }
6504
+
6505
+ /*
6506
+ // maybe worth a shot to prevent renaming issues:
6507
+ // see: https://github.com/webpack/webpack/blob/master/lib/dependencies/CommonJsRequireDependencyParserPlugin.js
6508
+ // triggers on:
6509
+ // - expression require.cache
6510
+ // - expression require (???)
6511
+ // - call require
6512
+ // - call require:commonjs:item
6513
+ // - call require:commonjs:context
6514
+
6515
+ Object.defineProperty(Function.prototype, "__self", { get: function() { return this; } });
6516
+ var r = require.__self;
6517
+ delete Function.prototype.__self;
6518
+ */
6519
+
6520
+ },{}],33:[function(require,module,exports){
6521
+ "use strict";
6522
+ module.exports = LongBits;
6523
+
6524
+ var util = require(34);
6525
+
6526
+ /**
6527
+ * Constructs new long bits.
6528
+ * @classdesc Helper class for working with the low and high bits of a 64 bit value.
6529
+ * @memberof util
6530
+ * @constructor
6531
+ * @param {number} lo Low 32 bits, unsigned
6532
+ * @param {number} hi High 32 bits, unsigned
6533
+ */
6534
+ function LongBits(lo, hi) {
6535
+
6536
+ // note that the casts below are theoretically unnecessary as of today, but older statically
6537
+ // generated converter code might still call the ctor with signed 32bits. kept for compat.
6538
+
6539
+ /**
6540
+ * Low bits.
6541
+ * @type {number}
6542
+ */
6543
+ this.lo = lo >>> 0;
6544
+
6545
+ /**
6546
+ * High bits.
6547
+ * @type {number}
6548
+ */
6549
+ this.hi = hi >>> 0;
6550
+ }
6551
+
6552
+ /**
6553
+ * Zero bits.
6554
+ * @memberof util.LongBits
6555
+ * @type {util.LongBits}
6556
+ */
6557
+ var zero = LongBits.zero = new LongBits(0, 0);
6558
+
6559
+ zero.toNumber = function() { return 0; };
6560
+ zero.zzEncode = zero.zzDecode = function() { return this; };
6561
+ zero.length = function() { return 1; };
6562
+
6563
+ /**
6564
+ * Zero hash.
6565
+ * @memberof util.LongBits
6566
+ * @type {string}
6567
+ */
6568
+ var zeroHash = LongBits.zeroHash = "\0\0\0\0\0\0\0\0";
6569
+
6570
+ /**
6571
+ * Constructs new long bits from the specified number.
6572
+ * @param {number} value Value
6573
+ * @returns {util.LongBits} Instance
6574
+ */
6575
+ LongBits.fromNumber = function fromNumber(value) {
6576
+ if (value === 0)
6577
+ return zero;
6578
+ var sign = value < 0;
6579
+ if (sign)
6580
+ value = -value;
6581
+ var lo = value >>> 0,
6582
+ hi = (value - lo) / 4294967296 >>> 0;
6583
+ if (sign) {
6584
+ hi = ~hi >>> 0;
6585
+ lo = ~lo >>> 0;
6586
+ if (++lo > 4294967295) {
6587
+ lo = 0;
6588
+ if (++hi > 4294967295)
6589
+ hi = 0;
6590
+ }
6591
+ }
6592
+ return new LongBits(lo, hi);
6593
+ };
6594
+
6595
+ /**
6596
+ * Constructs new long bits from a number, long or string.
6597
+ * @param {Long|number|string} value Value
6598
+ * @returns {util.LongBits} Instance
6599
+ */
6600
+ LongBits.from = function from(value) {
6601
+ if (typeof value === "number")
6602
+ return LongBits.fromNumber(value);
6435
6603
  if (util.isString(value)) {
6436
6604
  /* istanbul ignore else */
6437
6605
  if (util.Long)
@@ -6551,33 +6719,33 @@ LongBits.prototype.length = function length() {
6551
6719
  : part2 < 128 ? 9 : 10;
6552
6720
  };
6553
6721
 
6554
- },{"35":35}],35:[function(require,module,exports){
6722
+ },{"34":34}],34:[function(require,module,exports){
6555
6723
  "use strict";
6556
6724
  var util = exports;
6557
6725
 
6558
6726
  // used to return a Promise where callback is omitted
6559
- util.asPromise = require(1);
6727
+ util.asPromise = require(25);
6560
6728
 
6561
6729
  // converts to / from base64 encoded strings
6562
- util.base64 = require(2);
6730
+ util.base64 = require(26);
6563
6731
 
6564
6732
  // base class of rpc.Service
6565
- util.EventEmitter = require(4);
6733
+ util.EventEmitter = require(28);
6566
6734
 
6567
6735
  // float handling accross browsers
6568
- util.float = require(6);
6736
+ util.float = require(30);
6569
6737
 
6570
6738
  // requires modules optionally and hides the call from bundlers
6571
- util.inquire = require(7);
6739
+ util.inquire = require(32);
6572
6740
 
6573
6741
  // converts to / from utf8 encoded strings
6574
- util.utf8 = require(10);
6742
+ util.utf8 = require(38);
6575
6743
 
6576
6744
  // provides a node-like buffer pool in the browser
6577
- util.pool = require(9);
6745
+ util.pool = require(37);
6578
6746
 
6579
6747
  // utility to work with the low and high bits of a 64 bit value
6580
- util.LongBits = require(34);
6748
+ util.LongBits = require(33);
6581
6749
 
6582
6750
  /**
6583
6751
  * Whether running within node or not.
@@ -6679,7 +6847,7 @@ util.isSet = function isSet(obj, prop) {
6679
6847
  */
6680
6848
  util.Buffer = (function() {
6681
6849
  try {
6682
- var Buffer = util.inquire("buffer").Buffer;
6850
+ var Buffer = util.global.Buffer;
6683
6851
  // refuse to use non-node buffers if not explicitly assigned (perf reasons):
6684
6852
  return Buffer.prototype.utf8Write ? Buffer : /* istanbul ignore next */ null;
6685
6853
  } catch (e) {
@@ -6733,14 +6901,22 @@ util.Array = typeof Uint8Array !== "undefined" ? Uint8Array /* istanbul ignore n
6733
6901
  */
6734
6902
  util.Long = /* istanbul ignore next */ util.global.dcodeIO && /* istanbul ignore next */ util.global.dcodeIO.Long
6735
6903
  || /* istanbul ignore next */ util.global.Long
6736
- || util.inquire("long");
6904
+ || (function() {
6905
+ try {
6906
+ var Long = require("long");
6907
+ return Long && Long.isLong ? Long : null;
6908
+ } catch (e) {
6909
+ /* istanbul ignore next */
6910
+ return null;
6911
+ }
6912
+ })();
6737
6913
 
6738
6914
  /**
6739
6915
  * Regular expression used to verify 2 bit (`bool`) map keys.
6740
6916
  * @type {RegExp}
6741
6917
  * @const
6742
6918
  */
6743
- util.key2Re = /^true|false|0|1$/;
6919
+ util.key2Re = /^(?:true|false|0|1)$/;
6744
6920
 
6745
6921
  /**
6746
6922
  * Regular expression used to verify 32 bit (`int32` etc.) map keys.
@@ -6754,7 +6930,7 @@ util.key32Re = /^-?(?:0|[1-9][0-9]*)$/;
6754
6930
  * @type {RegExp}
6755
6931
  * @const
6756
6932
  */
6757
- util.key64Re = /^(?:[\\x00-\\xff]{8}|-?(?:0|[1-9][0-9]*))$/;
6933
+ util.key64Re = /^(?:[\x00-\xff]{8}|-?(?:0|[1-9][0-9]*))$/; // eslint-disable-line no-control-regex
6758
6934
 
6759
6935
  /**
6760
6936
  * Converts a number or long to an 8 characters long hash string.
@@ -6780,6 +6956,27 @@ util.longFromHash = function longFromHash(hash, unsigned) {
6780
6956
  return bits.toNumber(Boolean(unsigned));
6781
6957
  };
6782
6958
 
6959
+ /**
6960
+ * Converts a 64 bit key to a long or number if it is an 8 characters long hash string.
6961
+ * @param {string} key Map key
6962
+ * @param {boolean} [unsigned=false] Whether unsigned or not
6963
+ * @returns {Long|number|string} Original value
6964
+ */
6965
+ util.longFromKey = function longFromKey(key, unsigned) {
6966
+ return util.key64Re.test(key) && !util.key32Re.test(key)
6967
+ ? util.longFromHash(key, unsigned)
6968
+ : key;
6969
+ };
6970
+
6971
+ /**
6972
+ * Converts a boolean key to a boolean value.
6973
+ * @param {string} key Map key
6974
+ * @returns {boolean} Boolean value
6975
+ */
6976
+ util.boolFromKey = function boolFromKey(key) {
6977
+ return key === "true" || key === "1";
6978
+ };
6979
+
6783
6980
  /**
6784
6981
  * Merges the properties of the source object into the destination object.
6785
6982
  * @memberof util
@@ -6791,12 +6988,38 @@ util.longFromHash = function longFromHash(hash, unsigned) {
6791
6988
  function merge(dst, src, ifNotSet) { // used by converters
6792
6989
  for (var keys = Object.keys(src), i = 0; i < keys.length; ++i)
6793
6990
  if (dst[keys[i]] === undefined || !ifNotSet)
6794
- dst[keys[i]] = src[keys[i]];
6991
+ if (keys[i] !== "__proto__")
6992
+ dst[keys[i]] = src[keys[i]];
6795
6993
  return dst;
6796
6994
  }
6797
6995
 
6798
6996
  util.merge = merge;
6799
6997
 
6998
+ /**
6999
+ * Recursion limit.
7000
+ * @memberof util
7001
+ * @type {number}
7002
+ */
7003
+ util.recursionLimit = 100;
7004
+
7005
+ /**
7006
+ * Makes a property safe for assignment as an own property.
7007
+ * @memberof util
7008
+ * @param {Object.<string,*>} obj Object
7009
+ * @param {string} key Property key
7010
+ * @param {boolean} [enumerable=true] Whether the property should be enumerable
7011
+ * @returns {undefined}
7012
+ */
7013
+ util.makeProp = function makeProp(obj, key, enumerable) {
7014
+ if (Object.prototype.hasOwnProperty.call(obj, key))
7015
+ return;
7016
+ Object.defineProperty(obj, key, {
7017
+ enumerable: enumerable === undefined ? true : enumerable,
7018
+ configurable: true,
7019
+ writable: true
7020
+ });
7021
+ };
7022
+
6800
7023
  /**
6801
7024
  * Converts the first character of a string to lower case.
6802
7025
  * @param {string} str String to convert
@@ -6991,12 +7214,252 @@ util._configure = function() {
6991
7214
  };
6992
7215
  };
6993
7216
 
6994
- },{"1":1,"10":10,"2":2,"34":34,"4":4,"6":6,"7":7,"9":9}],36:[function(require,module,exports){
7217
+ },{"25":25,"26":26,"28":28,"30":30,"32":32,"33":33,"37":37,"38":38,"long":"long"}],35:[function(require,module,exports){
7218
+ "use strict";
7219
+
7220
+ /**
7221
+ * A minimal path module to resolve Unix, Windows and URL paths alike.
7222
+ * @memberof util
7223
+ * @namespace
7224
+ */
7225
+ var path = exports;
7226
+
7227
+ var isAbsolute =
7228
+ /**
7229
+ * Tests if the specified path is absolute.
7230
+ * @param {string} path Path to test
7231
+ * @returns {boolean} `true` if path is absolute
7232
+ */
7233
+ path.isAbsolute = function isAbsolute(path) {
7234
+ return /^(?:\/|\w+:|\\\\\w+)/.test(path);
7235
+ };
7236
+
7237
+ var normalize =
7238
+ /**
7239
+ * Normalizes the specified path.
7240
+ * @param {string} path Path to normalize
7241
+ * @returns {string} Normalized path
7242
+ */
7243
+ path.normalize = function normalize(path) {
7244
+ var firstTwoCharacters = path.substring(0,2);
7245
+ var uncPrefix = "";
7246
+ if (firstTwoCharacters === "\\\\") {
7247
+ uncPrefix = firstTwoCharacters;
7248
+ path = path.substring(2);
7249
+ }
7250
+
7251
+ path = path.replace(/\\/g, "/")
7252
+ .replace(/\/{2,}/g, "/");
7253
+ var parts = path.split("/"),
7254
+ absolute = isAbsolute(path),
7255
+ prefix = "";
7256
+ if (absolute)
7257
+ prefix = parts.shift() + "/";
7258
+ for (var i = 0; i < parts.length;) {
7259
+ if (parts[i] === "..") {
7260
+ if (i > 0 && parts[i - 1] !== "..")
7261
+ parts.splice(--i, 2);
7262
+ else if (absolute)
7263
+ parts.splice(i, 1);
7264
+ else
7265
+ ++i;
7266
+ } else if (parts[i] === ".")
7267
+ parts.splice(i, 1);
7268
+ else
7269
+ ++i;
7270
+ }
7271
+ return uncPrefix + prefix + parts.join("/");
7272
+ };
7273
+
7274
+ /**
7275
+ * Resolves the specified include path against the specified origin path.
7276
+ * @param {string} originPath Path to the origin file
7277
+ * @param {string} includePath Include path relative to origin path
7278
+ * @param {boolean} [alreadyNormalized=false] `true` if both paths are already known to be normalized
7279
+ * @returns {string} Path to the include file
7280
+ */
7281
+ path.resolve = function resolve(originPath, includePath, alreadyNormalized) {
7282
+ if (!alreadyNormalized)
7283
+ includePath = normalize(includePath);
7284
+ if (isAbsolute(includePath))
7285
+ return includePath;
7286
+ if (!alreadyNormalized)
7287
+ originPath = normalize(originPath);
7288
+ return (originPath = originPath.replace(/(?:\/|^)[^/]+$/, "")).length ? normalize(originPath + "/" + includePath) : includePath;
7289
+ };
7290
+
7291
+ },{}],36:[function(require,module,exports){
7292
+ "use strict";
7293
+
7294
+ var patterns = exports;
7295
+
7296
+ patterns.numberRe = /^(?![eE])[0-9]*(?:\.[0-9]*)?(?:[eE][+-]?[0-9]+)?$/;
7297
+ patterns.typeRefRe = /^(?:\.?[a-zA-Z_][a-zA-Z_0-9]*)(?:\.[a-zA-Z_][a-zA-Z_0-9]*)*$/;
7298
+ patterns.reservedRe = /^(?:do|if|in|for|let|new|try|var|case|else|enum|eval|false|null|this|true|void|with|break|catch|class|const|super|throw|while|yield|delete|export|import|public|return|static|switch|typeof|default|extends|finally|package|private|continue|debugger|function|arguments|interface|protected|implements|instanceof)$/;
7299
+ patterns.unsafePropertyRe = /^(?:__proto__|prototype|constructor)$/;
7300
+
7301
+ },{}],37:[function(require,module,exports){
7302
+ "use strict";
7303
+ module.exports = pool;
7304
+
7305
+ /**
7306
+ * An allocator as used by {@link util.pool}.
7307
+ * @typedef PoolAllocator
7308
+ * @type {function}
7309
+ * @param {number} size Buffer size
7310
+ * @returns {Uint8Array} Buffer
7311
+ */
7312
+
7313
+ /**
7314
+ * A slicer as used by {@link util.pool}.
7315
+ * @typedef PoolSlicer
7316
+ * @type {function}
7317
+ * @param {number} start Start offset
7318
+ * @param {number} end End offset
7319
+ * @returns {Uint8Array} Buffer slice
7320
+ * @this {Uint8Array}
7321
+ */
7322
+
7323
+ /**
7324
+ * A general purpose buffer pool.
7325
+ * @memberof util
7326
+ * @function
7327
+ * @param {PoolAllocator} alloc Allocator
7328
+ * @param {PoolSlicer} slice Slicer
7329
+ * @param {number} [size=8192] Slab size
7330
+ * @returns {PoolAllocator} Pooled allocator
7331
+ */
7332
+ function pool(alloc, slice, size) {
7333
+ var SIZE = size || 8192;
7334
+ var MAX = SIZE >>> 1;
7335
+ var slab = null;
7336
+ var offset = SIZE;
7337
+ return function pool_alloc(size) {
7338
+ if (size < 1 || size > MAX)
7339
+ return alloc(size);
7340
+ if (offset + size > SIZE) {
7341
+ slab = alloc(SIZE);
7342
+ offset = 0;
7343
+ }
7344
+ var buf = slice.call(slab, offset, offset += size);
7345
+ if (offset & 7) // align to 32 bit
7346
+ offset = (offset | 7) + 1;
7347
+ return buf;
7348
+ };
7349
+ }
7350
+
7351
+ },{}],38:[function(require,module,exports){
7352
+ "use strict";
7353
+
7354
+ /**
7355
+ * A minimal UTF8 implementation for number arrays.
7356
+ * @memberof util
7357
+ * @namespace
7358
+ */
7359
+ var utf8 = exports,
7360
+ replacementChar = "\ufffd";
7361
+
7362
+ /**
7363
+ * Calculates the UTF8 byte length of a string.
7364
+ * @param {string} string String
7365
+ * @returns {number} Byte length
7366
+ */
7367
+ utf8.length = function utf8_length(string) {
7368
+ var len = 0,
7369
+ c = 0;
7370
+ for (var i = 0; i < string.length; ++i) {
7371
+ c = string.charCodeAt(i);
7372
+ if (c < 128)
7373
+ len += 1;
7374
+ else if (c < 2048)
7375
+ len += 2;
7376
+ else if ((c & 0xFC00) === 0xD800 && (string.charCodeAt(i + 1) & 0xFC00) === 0xDC00) {
7377
+ ++i;
7378
+ len += 4;
7379
+ } else
7380
+ len += 3;
7381
+ }
7382
+ return len;
7383
+ };
7384
+
7385
+ /**
7386
+ * Reads UTF8 bytes as a string.
7387
+ * @param {Uint8Array} buffer Source buffer
7388
+ * @param {number} start Source start
7389
+ * @param {number} end Source end
7390
+ * @returns {string} String read
7391
+ */
7392
+ utf8.read = function utf8_read(buffer, start, end) {
7393
+ if (end - start < 1) {
7394
+ return "";
7395
+ }
7396
+
7397
+ var str = "";
7398
+ for (var i = start; i < end;) {
7399
+ var t = buffer[i++];
7400
+ if (t <= 0x7F) {
7401
+ str += String.fromCharCode(t);
7402
+ } else if (t >= 0xC0 && t < 0xE0) {
7403
+ var c2 = (t & 0x1F) << 6 | buffer[i++] & 0x3F;
7404
+ str += c2 >= 0x80 ? String.fromCharCode(c2) : replacementChar;
7405
+ } else if (t >= 0xE0 && t < 0xF0) {
7406
+ var c3 = (t & 0xF) << 12 | (buffer[i++] & 0x3F) << 6 | buffer[i++] & 0x3F;
7407
+ str += c3 >= 0x800 ? String.fromCharCode(c3) : replacementChar;
7408
+ } else if (t >= 0xF0) {
7409
+ var t2 = (t & 7) << 18 | (buffer[i++] & 0x3F) << 12 | (buffer[i++] & 0x3F) << 6 | buffer[i++] & 0x3F;
7410
+ if (t2 < 0x10000 || t2 > 0x10FFFF)
7411
+ str += replacementChar;
7412
+ else {
7413
+ t2 -= 0x10000;
7414
+ str += String.fromCharCode(0xD800 + (t2 >> 10));
7415
+ str += String.fromCharCode(0xDC00 + (t2 & 0x3FF));
7416
+ }
7417
+ }
7418
+ }
7419
+
7420
+ return str;
7421
+ };
7422
+
7423
+ /**
7424
+ * Writes a string as UTF8 bytes.
7425
+ * @param {string} string Source string
7426
+ * @param {Uint8Array} buffer Destination buffer
7427
+ * @param {number} offset Destination offset
7428
+ * @returns {number} Bytes written
7429
+ */
7430
+ utf8.write = function utf8_write(string, buffer, offset) {
7431
+ var start = offset,
7432
+ c1, // character 1
7433
+ c2; // character 2
7434
+ for (var i = 0; i < string.length; ++i) {
7435
+ c1 = string.charCodeAt(i);
7436
+ if (c1 < 128) {
7437
+ buffer[offset++] = c1;
7438
+ } else if (c1 < 2048) {
7439
+ buffer[offset++] = c1 >> 6 | 192;
7440
+ buffer[offset++] = c1 & 63 | 128;
7441
+ } else if ((c1 & 0xFC00) === 0xD800 && ((c2 = string.charCodeAt(i + 1)) & 0xFC00) === 0xDC00) {
7442
+ c1 = 0x10000 + ((c1 & 0x03FF) << 10) + (c2 & 0x03FF);
7443
+ ++i;
7444
+ buffer[offset++] = c1 >> 18 | 240;
7445
+ buffer[offset++] = c1 >> 12 & 63 | 128;
7446
+ buffer[offset++] = c1 >> 6 & 63 | 128;
7447
+ buffer[offset++] = c1 & 63 | 128;
7448
+ } else {
7449
+ buffer[offset++] = c1 >> 12 | 224;
7450
+ buffer[offset++] = c1 >> 6 & 63 | 128;
7451
+ buffer[offset++] = c1 & 63 | 128;
7452
+ }
7453
+ }
7454
+ return offset - start;
7455
+ };
7456
+
7457
+ },{}],39:[function(require,module,exports){
6995
7458
  "use strict";
6996
7459
  module.exports = verifier;
6997
7460
 
6998
- var Enum = require(14),
6999
- util = require(33);
7461
+ var Enum = require(5),
7462
+ util = require(24);
7000
7463
 
7001
7464
  function invalid(field, expected) {
7002
7465
  return field.name + ": " + expected + (field.repeated && expected !== "array" ? "[]" : field.map && expected !== "object" ? "{k:"+field.keyType+"}" : "") + " expected";
@@ -7026,7 +7489,7 @@ function genVerifyValue(gen, field, fieldIndex, ref) {
7026
7489
  } else {
7027
7490
  gen
7028
7491
  ("{")
7029
- ("var e=types[%i].verify(%s);", fieldIndex, ref)
7492
+ ("var e=types[%i].verify(%s,q+1);", fieldIndex, ref)
7030
7493
  ("if(e)")
7031
7494
  ("return%j+e", field.name + ".")
7032
7495
  ("}");
@@ -7116,9 +7579,12 @@ function genVerifyKey(gen, field, ref) {
7116
7579
  function verifier(mtype) {
7117
7580
  /* eslint-disable no-unexpected-multiline */
7118
7581
 
7119
- var gen = util.codegen(["m"], mtype.name + "$verify")
7582
+ var gen = util.codegen(["m", "q"], mtype.name + "$verify")
7120
7583
  ("if(typeof m!==\"object\"||m===null)")
7121
- ("return%j", "object expected");
7584
+ ("return%j", "object expected")
7585
+ ("if(q===undefined)q=0")
7586
+ ("if(q>util.recursionLimit)")
7587
+ ("return%j", "max depth exceeded");
7122
7588
  var oneofs = mtype.oneofsArray,
7123
7589
  seenFirstField = {};
7124
7590
  if (oneofs.length) gen
@@ -7169,7 +7635,8 @@ function verifier(mtype) {
7169
7635
  ("return null");
7170
7636
  /* eslint-enable no-unexpected-multiline */
7171
7637
  }
7172
- },{"14":14,"33":33}],37:[function(require,module,exports){
7638
+
7639
+ },{"24":24,"5":5}],40:[function(require,module,exports){
7173
7640
  "use strict";
7174
7641
 
7175
7642
  /**
@@ -7179,7 +7646,7 @@ function verifier(mtype) {
7179
7646
  */
7180
7647
  var wrappers = exports;
7181
7648
 
7182
- var Message = require(19);
7649
+ var Message = require(10);
7183
7650
 
7184
7651
  /**
7185
7652
  * From object converter part of an {@link IWrapper}.
@@ -7210,7 +7677,7 @@ var Message = require(19);
7210
7677
  // Custom wrapper for Any
7211
7678
  wrappers[".google.protobuf.Any"] = {
7212
7679
 
7213
- fromObject: function(object) {
7680
+ fromObject: function(object, depth) {
7214
7681
 
7215
7682
  // unwrap value type if mapped
7216
7683
  if (object && object["@type"]) {
@@ -7226,14 +7693,15 @@ wrappers[".google.protobuf.Any"] = {
7226
7693
  if (type_url.indexOf("/") === -1) {
7227
7694
  type_url = "/" + type_url;
7228
7695
  }
7696
+ var nextDepth = depth === undefined ? 1 : depth + 1;
7229
7697
  return this.create({
7230
7698
  type_url: type_url,
7231
- value: type.encode(type.fromObject(object)).finish()
7699
+ value: type.encode(type.fromObject(object, nextDepth)).finish()
7232
7700
  });
7233
7701
  }
7234
7702
  }
7235
7703
 
7236
- return this.fromObject(object);
7704
+ return this.fromObject(object, depth);
7237
7705
  },
7238
7706
 
7239
7707
  toObject: function(message, options) {
@@ -7273,11 +7741,11 @@ wrappers[".google.protobuf.Any"] = {
7273
7741
  }
7274
7742
  };
7275
7743
 
7276
- },{"19":19}],38:[function(require,module,exports){
7744
+ },{"10":10}],41:[function(require,module,exports){
7277
7745
  "use strict";
7278
7746
  module.exports = Writer;
7279
7747
 
7280
- var util = require(35);
7748
+ var util = require(34);
7281
7749
 
7282
7750
  var BufferWriter; // cyclic
7283
7751
 
@@ -7659,6 +8127,16 @@ Writer.prototype.bytes = function write_bytes(value) {
7659
8127
  return this.uint32(len)._push(writeBytes, len, value);
7660
8128
  };
7661
8129
 
8130
+ /**
8131
+ * Writes raw bytes without a tag or length prefix.
8132
+ * @param {Uint8Array} value Raw bytes
8133
+ * @returns {Writer} `this`
8134
+ */
8135
+ Writer.prototype.raw = function write_raw(value) {
8136
+ var len = value.length >>> 0;
8137
+ return len ? this._push(writeBytes, len, value) : this;
8138
+ };
8139
+
7662
8140
  /**
7663
8141
  * Writes a string.
7664
8142
  * @param {string} value Value to write
@@ -7722,15 +8200,28 @@ Writer.prototype.ldelim = function ldelim() {
7722
8200
  * @returns {Uint8Array} Finished buffer
7723
8201
  */
7724
8202
  Writer.prototype.finish = function finish() {
7725
- var head = this.head.next, // skip noop
7726
- buf = this.constructor.alloc(this.len),
7727
- pos = 0;
8203
+ return this.finishInto(this.constructor.alloc(this.len), 0);
8204
+ };
8205
+
8206
+ /**
8207
+ * Finishes the write operation, writing into the provided buffer.
8208
+ * The caller must ensure that `buf` has enough space starting at `offset`
8209
+ * to hold {@link Writer#len} bytes.
8210
+ * @param {T} buf Target buffer
8211
+ * @param {number} [offset=0] Offset to start writing at
8212
+ * @returns {T} The provided buffer
8213
+ * @template T extends Uint8Array
8214
+ */
8215
+ Writer.prototype.finishInto = function finishInto(buf, offset) {
8216
+ if (offset === undefined)
8217
+ offset = 0;
8218
+ var head = this.head.next,
8219
+ pos = offset;
7728
8220
  while (head) {
7729
8221
  head.fn(head.val, buf, pos);
7730
8222
  pos += head.len;
7731
8223
  head = head.next;
7732
8224
  }
7733
- // this.head = this.tail = null;
7734
8225
  return buf;
7735
8226
  };
7736
8227
 
@@ -7740,15 +8231,15 @@ Writer._configure = function(BufferWriter_) {
7740
8231
  BufferWriter._configure();
7741
8232
  };
7742
8233
 
7743
- },{"35":35}],39:[function(require,module,exports){
8234
+ },{"34":34}],42:[function(require,module,exports){
7744
8235
  "use strict";
7745
8236
  module.exports = BufferWriter;
7746
8237
 
7747
8238
  // extends Writer
7748
- var Writer = require(38);
8239
+ var Writer = require(41);
7749
8240
  (BufferWriter.prototype = Object.create(Writer.prototype)).constructor = BufferWriter;
7750
8241
 
7751
- var util = require(35);
8242
+ var util = require(34);
7752
8243
 
7753
8244
  /**
7754
8245
  * Constructs a new buffer writer instance.
@@ -7797,6 +8288,18 @@ BufferWriter.prototype.bytes = function write_bytes_buffer(value) {
7797
8288
  return this;
7798
8289
  };
7799
8290
 
8291
+ /**
8292
+ * Writes raw bytes without a tag or length prefix.
8293
+ * @name BufferWriter#raw
8294
+ * @function
8295
+ * @param {Uint8Array} value Raw bytes
8296
+ * @returns {BufferWriter} `this`
8297
+ */
8298
+ BufferWriter.prototype.raw = function write_raw_buffer(value) {
8299
+ var len = value.length >>> 0;
8300
+ return len ? this._push(BufferWriter.writeBytesBuffer, len, value) : this;
8301
+ };
8302
+
7800
8303
  function writeStringBuffer(val, buf, pos) {
7801
8304
  if (val.length < 40) // plain js is faster for short strings (probably due to redundant assertions)
7802
8305
  util.utf8.write(val, buf, pos);
@@ -7827,7 +8330,7 @@ BufferWriter.prototype.string = function write_string_buffer(value) {
7827
8330
 
7828
8331
  BufferWriter._configure();
7829
8332
 
7830
- },{"35":35,"38":38}]},{},[16])
8333
+ },{"34":34,"41":41}]},{},[7])
7831
8334
 
7832
8335
  })();
7833
8336
  //# sourceMappingURL=protobuf.js.map