protobufjs 8.1.6-experimental → 8.2.1

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 +225 -570
  2. package/dist/light/protobuf.js +2041 -1482
  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 +1167 -863
  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 +2173 -1527
  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 -190
  17. package/ext/descriptor/index.js +1 -1161
  18. package/ext/descriptor.d.ts +309 -0
  19. package/ext/descriptor.js +1241 -0
  20. package/ext/textformat.d.ts +24 -0
  21. package/ext/textformat.js +1227 -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 +585 -476
  27. package/package.json +22 -40
  28. package/src/converter.js +63 -27
  29. package/src/decoder.js +126 -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 +31 -12
  37. package/src/object.js +24 -19
  38. package/src/oneof.js +2 -0
  39. package/src/parse.js +128 -46
  40. package/src/reader.js +145 -30
  41. package/src/reader_buffer.js +24 -3
  42. package/src/root.js +10 -4
  43. package/src/service.js +15 -6
  44. package/src/tokenize.js +6 -1
  45. package/src/type.js +57 -27
  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 +74 -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 +130 -0
  70. package/src/util.js +18 -13
  71. package/src/verifier.js +7 -4
  72. package/src/wrappers.js +4 -3
  73. package/src/writer.js +33 -5
  74. package/src/writer_buffer.js +18 -1
  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.1 (c) 2016, daniel wirtz
3
+ * compiled wed, 13 may 2026 10:17:57 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")
1220
- ("if(d instanceof this.ctor)")
1221
- ("return d");
151
+ var gen = util.codegen(["d", "q"], mtype.name + "$fromObject")
152
+ ("if(d instanceof C)")
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
- ("return new this.ctor");
158
+ ("return new C");
1224
159
  gen
1225
- ("var m=new this.ctor");
160
+ ("var m=new C");
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 C" + (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,131 @@ 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 (field.resolvedType instanceof Enum && field.typeDefault !== 0) gen
541
+ // TODO: Protoc rejects open enums whose first value is not zero.
542
+ // We should do the same, but for v8 this would be a regression.
543
+ ("if((v=r.%s())!==%j)", type, field.typeDefault);
544
+ else if (type === "string" || type === "bytes") gen
545
+ ("if((v=r.%s()).length)", type);
546
+ else if (types.long[type] !== undefined) gen
547
+ ("if(typeof(v=r.%s())===\"object\"?v.low||v.high:v!==0)", type);
548
+ else if (type === "double" || type === "float") gen
549
+ ("if((v=r.%s())!==0)", type);
550
+ else gen
551
+ ("if(v=r.%s())", type);
552
+ gen
553
+ ("%s=v", ref)
554
+ ("else")
555
+ ("delete %s", ref); // rare/odd case: later default clears earlier non-default
556
+ }
557
+ if (field.partOf) gen
558
+ ("m%s=%j", util.safeProp(field.partOf.name), field.name);
1518
559
  gen
1519
- ("break")
560
+ ("continue")
1520
561
  ("}");
1521
- // Unknown fields
1522
- } gen
1523
- ("default:")
1524
- ("r.skipType(t&7)")
1525
- ("break")
1526
-
1527
- ("}")
1528
- ("}");
562
+ }
563
+ if (i) gen
564
+ ("}");
565
+ // Unknown fields
566
+ gen
567
+ ("r.skipType(%s,q,t)", i ? "u" : "t&7")
568
+ ("util.makeProp(m,\"$unknowns\",false);")
569
+ ("(m.$unknowns||(m.$unknowns=[])).push(r.raw(s,r.pos))")
570
+ ("}")
571
+ ("if(z!==undefined)")
572
+ ("throw Error(\"missing end group\")");
1529
573
 
1530
574
  // Field presence
1531
575
  for (i = 0; i < mtype._fieldsArray.length; ++i) {
@@ -1540,13 +584,13 @@ function decoder(mtype) {
1540
584
  /* eslint-enable no-unexpected-multiline */
1541
585
  }
1542
586
 
1543
- },{"14":14,"32":32,"33":33}],13:[function(require,module,exports){
587
+ },{"23":23,"24":24,"5":5}],4:[function(require,module,exports){
1544
588
  "use strict";
1545
589
  module.exports = encoder;
1546
590
 
1547
- var Enum = require(14),
1548
- types = require(32),
1549
- util = require(33);
591
+ var Enum = require(5),
592
+ types = require(23),
593
+ util = require(24);
1550
594
 
1551
595
  /**
1552
596
  * Generates a partial message type encoder.
@@ -1590,7 +634,12 @@ function encoder(mtype) {
1590
634
  if (field.map) {
1591
635
  gen
1592
636
  ("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)
637
+ ("for(var ks=Object.keys(%s),i=0;i<ks.length;++i){", ref);
638
+ if (field.keyType === "bool") gen
639
+ ("w.uint32(%i).fork().uint32(%i).bool(util.boolFromKey(ks[i]))", (field.id << 3 | 2) >>> 0, 8 | types.mapKey[field.keyType]);
640
+ else if (types.long[field.keyType] !== undefined) gen
641
+ ("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");
642
+ else gen
1594
643
  ("w.uint32(%i).fork().uint32(%i).%s(ks[i])", (field.id << 3 | 2) >>> 0, 8 | types.mapKey[field.keyType], field.keyType);
1595
644
  if (wireType === undefined) gen
1596
645
  ("types[%i].encode(%s[ks[i]],w.uint32(18).fork()).ldelim().ldelim()", index, ref); // can't be groups
@@ -1626,7 +675,7 @@ function encoder(mtype) {
1626
675
 
1627
676
  // Non-repeated
1628
677
  } else {
1629
- if (field.optional) gen
678
+ if (!field.required) gen
1630
679
  ("if(%s!=null&&Object.hasOwnProperty.call(m,%j))", ref, field.name); // !== undefined && !== null
1631
680
 
1632
681
  if (wireType === undefined)
@@ -1638,20 +687,23 @@ function encoder(mtype) {
1638
687
  }
1639
688
 
1640
689
  return gen
690
+ ("if(m.$unknowns!=null&&Object.hasOwnProperty.call(m,\"$unknowns\"))")
691
+ ("for(var i=0;i<m.$unknowns.length;++i)")
692
+ ("w.raw(m.$unknowns[i])")
1641
693
  ("return w");
1642
694
  /* eslint-enable no-unexpected-multiline, block-scoped-var, no-redeclare */
1643
695
  }
1644
696
 
1645
- },{"14":14,"32":32,"33":33}],14:[function(require,module,exports){
697
+ },{"23":23,"24":24,"5":5}],5:[function(require,module,exports){
1646
698
  "use strict";
1647
699
  module.exports = Enum;
1648
700
 
1649
701
  // extends ReflectionObject
1650
- var ReflectionObject = require(22);
702
+ var ReflectionObject = require(13);
1651
703
  ((Enum.prototype = Object.create(ReflectionObject.prototype)).constructor = Enum).className = "Enum";
1652
704
 
1653
- var Namespace = require(21),
1654
- util = require(33);
705
+ var Namespace = require(12),
706
+ util = require(24);
1655
707
 
1656
708
  /**
1657
709
  * Constructs a new enum instance.
@@ -1719,7 +771,7 @@ function Enum(name, values, options, comment, comments, valuesOptions) {
1719
771
 
1720
772
  if (values)
1721
773
  for (var keys = Object.keys(values), i = 0; i < keys.length; ++i)
1722
- if (typeof values[keys[i]] === "number") // use forward entries only
774
+ if (keys[i] !== "__proto__" && typeof values[keys[i]] === "number") // use forward entries only
1723
775
  this.valuesById[ this.values[keys[i]] = values[keys[i]] ] = keys[i];
1724
776
  }
1725
777
 
@@ -1798,6 +850,9 @@ Enum.prototype.add = function add(name, id, comment, options) {
1798
850
  if (!util.isInteger(id))
1799
851
  throw TypeError("id must be an integer");
1800
852
 
853
+ if (name === "__proto__")
854
+ return this;
855
+
1801
856
  if (this.values[name] !== undefined)
1802
857
  throw Error("duplicate name '" + name + "' in " + this);
1803
858
 
@@ -1867,17 +922,17 @@ Enum.prototype.isReservedName = function isReservedName(name) {
1867
922
  return Namespace.isReservedName(this.reserved, name);
1868
923
  };
1869
924
 
1870
- },{"21":21,"22":22,"33":33}],15:[function(require,module,exports){
925
+ },{"12":12,"13":13,"24":24}],6:[function(require,module,exports){
1871
926
  "use strict";
1872
927
  module.exports = Field;
1873
928
 
1874
929
  // extends ReflectionObject
1875
- var ReflectionObject = require(22);
930
+ var ReflectionObject = require(13);
1876
931
  ((Field.prototype = Object.create(ReflectionObject.prototype)).constructor = Field).className = "Field";
1877
932
 
1878
- var Enum = require(14),
1879
- types = require(32),
1880
- util = require(33);
933
+ var Enum = require(5),
934
+ types = require(23),
935
+ util = require(24);
1881
936
 
1882
937
  var Type; // cyclic
1883
938
 
@@ -2222,8 +1277,8 @@ Field.prototype.resolve = function resolve() {
2222
1277
  this.defaultValue = this.typeDefault;
2223
1278
 
2224
1279
  // ensure proper value on prototype
2225
- if (this.parent instanceof Type)
2226
- this.parent.ctor.prototype[this.name] = this.defaultValue;
1280
+ if (this.parent instanceof Type && this.parent._ctor)
1281
+ this.parent._ctor.prototype[this.name] = this.defaultValue;
2227
1282
 
2228
1283
  return ReflectionObject.prototype.resolve.call(this);
2229
1284
  };
@@ -2275,6 +1330,7 @@ Field.prototype._resolveFeatures = function _resolveFeatures(edition) {
2275
1330
  * @param {Object} prototype Target prototype
2276
1331
  * @param {string} fieldName Field name
2277
1332
  * @returns {undefined}
1333
+ * @deprecated Legacy TypeScript decorator support. Will be removed in a future release.
2278
1334
  */
2279
1335
 
2280
1336
  /**
@@ -2287,6 +1343,7 @@ Field.prototype._resolveFeatures = function _resolveFeatures(edition) {
2287
1343
  * @param {T} [defaultValue] Default value
2288
1344
  * @returns {FieldDecorator} Decorator function
2289
1345
  * @template T extends number | number[] | Long | Long[] | string | string[] | boolean | boolean[] | Uint8Array | Uint8Array[] | Buffer | Buffer[]
1346
+ * @deprecated Legacy TypeScript decorator support. Will be removed in a future release.
2290
1347
  */
2291
1348
  Field.d = function decorateField(fieldId, fieldType, fieldRule, defaultValue) {
2292
1349
 
@@ -2304,6 +1361,11 @@ Field.d = function decorateField(fieldId, fieldType, fieldRule, defaultValue) {
2304
1361
  };
2305
1362
  };
2306
1363
 
1364
+ // Sets up cyclic dependencies (called in index-light)
1365
+ Field._configure = function configure(Type_) {
1366
+ Type = Type_;
1367
+ };
1368
+
2307
1369
  /**
2308
1370
  * Field decorator (TypeScript).
2309
1371
  * @name Field.d
@@ -2314,17 +1376,13 @@ Field.d = function decorateField(fieldId, fieldType, fieldRule, defaultValue) {
2314
1376
  * @returns {FieldDecorator} Decorator function
2315
1377
  * @template T extends Message<T>
2316
1378
  * @variation 2
1379
+ * @deprecated Legacy TypeScript decorator support. Will be removed in a future release.
2317
1380
  */
2318
1381
  // like Field.d but without a default value
2319
1382
 
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){
1383
+ },{"13":13,"23":23,"24":24,"5":5}],7:[function(require,module,exports){
2326
1384
  "use strict";
2327
- var protobuf = module.exports = require(17);
1385
+ var protobuf = module.exports = require(8);
2328
1386
 
2329
1387
  protobuf.build = "light";
2330
1388
 
@@ -2397,30 +1455,30 @@ function loadSync(filename, root) {
2397
1455
  protobuf.loadSync = loadSync;
2398
1456
 
2399
1457
  // Serialization
2400
- protobuf.encoder = require(13);
2401
- protobuf.decoder = require(12);
2402
- protobuf.verifier = require(36);
2403
- protobuf.converter = require(11);
1458
+ protobuf.encoder = require(4);
1459
+ protobuf.decoder = require(3);
1460
+ protobuf.verifier = require(39);
1461
+ protobuf.converter = require(2);
2404
1462
 
2405
1463
  // 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);
1464
+ protobuf.ReflectionObject = require(13);
1465
+ protobuf.Namespace = require(12);
1466
+ protobuf.Root = require(17);
1467
+ protobuf.Enum = require(5);
1468
+ protobuf.Type = require(22);
1469
+ protobuf.Field = require(6);
1470
+ protobuf.OneOf = require(14);
1471
+ protobuf.MapField = require(9);
1472
+ protobuf.Service = require(21);
1473
+ protobuf.Method = require(11);
2416
1474
 
2417
1475
  // Runtime
2418
- protobuf.Message = require(19);
2419
- protobuf.wrappers = require(37);
1476
+ protobuf.Message = require(10);
1477
+ protobuf.wrappers = require(40);
2420
1478
 
2421
1479
  // Utility
2422
- protobuf.types = require(32);
2423
- protobuf.util = require(33);
1480
+ protobuf.types = require(23);
1481
+ protobuf.util = require(24);
2424
1482
 
2425
1483
  // Set up possibly cyclic reflection dependencies
2426
1484
  protobuf.ReflectionObject._configure(protobuf.Root);
@@ -2428,7 +1486,7 @@ protobuf.Namespace._configure(protobuf.Type, protobuf.Service, protobuf.Enum);
2428
1486
  protobuf.Root._configure(protobuf.Type);
2429
1487
  protobuf.Field._configure(protobuf.Type);
2430
1488
 
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){
1489
+ },{"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
1490
  "use strict";
2433
1491
  var protobuf = exports;
2434
1492
 
@@ -2441,15 +1499,15 @@ var protobuf = exports;
2441
1499
  protobuf.build = "minimal";
2442
1500
 
2443
1501
  // Serialization
2444
- protobuf.Writer = require(38);
2445
- protobuf.BufferWriter = require(39);
2446
- protobuf.Reader = require(24);
2447
- protobuf.BufferReader = require(25);
1502
+ protobuf.Writer = require(41);
1503
+ protobuf.BufferWriter = require(42);
1504
+ protobuf.Reader = require(15);
1505
+ protobuf.BufferReader = require(16);
2448
1506
 
2449
1507
  // Utility
2450
- protobuf.util = require(35);
2451
- protobuf.rpc = require(28);
2452
- protobuf.roots = require(27);
1508
+ protobuf.util = require(34);
1509
+ protobuf.rpc = require(19);
1510
+ protobuf.roots = require(18);
2453
1511
  protobuf.configure = configure;
2454
1512
 
2455
1513
  /* istanbul ignore next */
@@ -2466,16 +1524,16 @@ function configure() {
2466
1524
  // Set up buffer utility according to the environment
2467
1525
  configure();
2468
1526
 
2469
- },{"24":24,"25":25,"27":27,"28":28,"35":35,"38":38,"39":39}],18:[function(require,module,exports){
1527
+ },{"15":15,"16":16,"18":18,"19":19,"34":34,"41":41,"42":42}],9:[function(require,module,exports){
2470
1528
  "use strict";
2471
1529
  module.exports = MapField;
2472
1530
 
2473
1531
  // extends Field
2474
- var Field = require(15);
1532
+ var Field = require(6);
2475
1533
  ((MapField.prototype = Object.create(Field.prototype)).constructor = MapField).className = "MapField";
2476
1534
 
2477
- var types = require(32),
2478
- util = require(33);
1535
+ var types = require(23),
1536
+ util = require(24);
2479
1537
 
2480
1538
  /**
2481
1539
  * Constructs a new map field instance.
@@ -2577,6 +1635,7 @@ MapField.prototype.resolve = function resolve() {
2577
1635
  * @param {"double"|"float"|"int32"|"uint32"|"sint32"|"fixed32"|"sfixed32"|"int64"|"uint64"|"sint64"|"fixed64"|"sfixed64"|"bool"|"string"|"bytes"|Object|Constructor<{}>} fieldValueType Field value type
2578
1636
  * @returns {FieldDecorator} Decorator function
2579
1637
  * @template T extends { [key: string]: number | Long | string | boolean | Uint8Array | Buffer | number[] | Message<{}> }
1638
+ * @deprecated Legacy TypeScript decorator support. Will be removed in a future release.
2580
1639
  */
2581
1640
  MapField.d = function decorateMapField(fieldId, fieldKeyType, fieldValueType) {
2582
1641
 
@@ -2594,24 +1653,29 @@ MapField.d = function decorateMapField(fieldId, fieldKeyType, fieldValueType) {
2594
1653
  };
2595
1654
  };
2596
1655
 
2597
- },{"15":15,"32":32,"33":33}],19:[function(require,module,exports){
1656
+ },{"23":23,"24":24,"6":6}],10:[function(require,module,exports){
2598
1657
  "use strict";
2599
1658
  module.exports = Message;
2600
1659
 
2601
- var util = require(35);
1660
+ var util = require(34);
2602
1661
 
2603
1662
  /**
2604
1663
  * Constructs a new message instance.
2605
1664
  * @classdesc Abstract runtime message.
2606
1665
  * @constructor
2607
1666
  * @param {Properties<T>} [properties] Properties to set
1667
+ * @property {Array.<Uint8Array>} [$unknowns] Unknown fields preserved while decoding
2608
1668
  * @template T extends object = object
2609
1669
  */
2610
1670
  function Message(properties) {
2611
1671
  // not used internally
2612
1672
  if (properties)
2613
- for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
2614
- this[keys[i]] = properties[keys[i]];
1673
+ for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) {
1674
+ var key = keys[i];
1675
+ if (key === "__proto__")
1676
+ continue;
1677
+ this[key] = properties[key];
1678
+ }
2615
1679
  }
2616
1680
 
2617
1681
  /**
@@ -2628,8 +1692,6 @@ function Message(properties) {
2628
1692
  * @readonly
2629
1693
  */
2630
1694
 
2631
- /*eslint-disable valid-jsdoc*/
2632
-
2633
1695
  /**
2634
1696
  * Creates a new message of this type using the specified properties.
2635
1697
  * @param {Object.<string,*>} [properties] Properties to set
@@ -2733,16 +1795,15 @@ Message.prototype.toJSON = function toJSON() {
2733
1795
  return this.$type.toObject(this, util.toJSONOptions);
2734
1796
  };
2735
1797
 
2736
- /*eslint-enable valid-jsdoc*/
2737
- },{"35":35}],20:[function(require,module,exports){
1798
+ },{"34":34}],11:[function(require,module,exports){
2738
1799
  "use strict";
2739
1800
  module.exports = Method;
2740
1801
 
2741
1802
  // extends ReflectionObject
2742
- var ReflectionObject = require(22);
1803
+ var ReflectionObject = require(13);
2743
1804
  ((Method.prototype = Object.create(ReflectionObject.prototype)).constructor = Method).className = "Method";
2744
1805
 
2745
- var util = require(33);
1806
+ var util = require(24);
2746
1807
 
2747
1808
  /**
2748
1809
  * Constructs a new service method instance.
@@ -2757,7 +1818,7 @@ var util = require(33);
2757
1818
  * @param {boolean|Object.<string,*>} [responseStream] Whether the response is streamed
2758
1819
  * @param {Object.<string,*>} [options] Declared options
2759
1820
  * @param {string} [comment] The comment for this method
2760
- * @param {Object.<string,*>} [parsedOptions] Declared options, properly parsed into an object
1821
+ * @param {Array.<Object.<string,*>>} [parsedOptions] Declared options, properly parsed into objects
2761
1822
  */
2762
1823
  function Method(name, type, requestType, responseType, requestStream, responseStream, options, comment, parsedOptions) {
2763
1824
 
@@ -2833,7 +1894,8 @@ function Method(name, type, requestType, responseType, requestStream, responseSt
2833
1894
  this.comment = comment;
2834
1895
 
2835
1896
  /**
2836
- * Options properly parsed into an object
1897
+ * Options properly parsed into objects
1898
+ * @type {Array.<Object.<string,*>>|undefined}
2837
1899
  */
2838
1900
  this.parsedOptions = parsedOptions;
2839
1901
  }
@@ -2848,7 +1910,7 @@ function Method(name, type, requestType, responseType, requestStream, responseSt
2848
1910
  * @property {boolean} [responseStream=false] Whether responses are streamed
2849
1911
  * @property {Object.<string,*>} [options] Method options
2850
1912
  * @property {string} comment Method comments
2851
- * @property {Object.<string,*>} [parsedOptions] Method options properly parsed into an object
1913
+ * @property {Array.<Object.<string,*>>} [parsedOptions] Method options properly parsed into objects
2852
1914
  */
2853
1915
 
2854
1916
  /**
@@ -2896,17 +1958,17 @@ Method.prototype.resolve = function resolve() {
2896
1958
  return ReflectionObject.prototype.resolve.call(this);
2897
1959
  };
2898
1960
 
2899
- },{"22":22,"33":33}],21:[function(require,module,exports){
1961
+ },{"13":13,"24":24}],12:[function(require,module,exports){
2900
1962
  "use strict";
2901
1963
  module.exports = Namespace;
2902
1964
 
2903
1965
  // extends ReflectionObject
2904
- var ReflectionObject = require(22);
1966
+ var ReflectionObject = require(13);
2905
1967
  ((Namespace.prototype = Object.create(ReflectionObject.prototype)).constructor = Namespace).className = "Namespace";
2906
1968
 
2907
- var Field = require(15),
2908
- util = require(33),
2909
- OneOf = require(23);
1969
+ var Field = require(6),
1970
+ util = require(24),
1971
+ OneOf = require(14);
2910
1972
 
2911
1973
  var Type, // cyclic
2912
1974
  Service,
@@ -2928,11 +1990,16 @@ var Type, // cyclic
2928
1990
  * @function
2929
1991
  * @param {string} name Namespace name
2930
1992
  * @param {Object.<string,*>} json JSON object
1993
+ * @param {number} [depth] Current nesting depth, defaults to `0`
2931
1994
  * @returns {Namespace} Created namespace
2932
1995
  * @throws {TypeError} If arguments are invalid
2933
1996
  */
2934
- Namespace.fromJSON = function fromJSON(name, json) {
2935
- return new Namespace(name, json.options).addJSON(json.nested);
1997
+ Namespace.fromJSON = function fromJSON(name, json, depth) {
1998
+ if (depth === undefined)
1999
+ depth = 0;
2000
+ if (depth > util.recursionLimit)
2001
+ throw Error("max depth exceeded");
2002
+ return new Namespace(name, json.options).addJSON(json.nested, depth);
2936
2003
  };
2937
2004
 
2938
2005
  /**
@@ -3015,7 +2082,7 @@ function Namespace(name, options) {
3015
2082
  * @type {Object.<string,ReflectionObject|null>}
3016
2083
  * @private
3017
2084
  */
3018
- this._lookupCache = {};
2085
+ this._lookupCache = Object.create(null);
3019
2086
 
3020
2087
  /**
3021
2088
  * Whether or not objects contained in this namespace need feature resolution.
@@ -3034,12 +2101,12 @@ function Namespace(name, options) {
3034
2101
 
3035
2102
  function clearCache(namespace) {
3036
2103
  namespace._nestedArray = null;
3037
- namespace._lookupCache = {};
2104
+ namespace._lookupCache = Object.create(null);
3038
2105
 
3039
2106
  // Also clear parent caches, since they include nested lookups.
3040
2107
  var parent = namespace;
3041
2108
  while(parent = parent.parent) {
3042
- parent._lookupCache = {};
2109
+ parent._lookupCache = Object.create(null);
3043
2110
  }
3044
2111
  return namespace;
3045
2112
  }
@@ -3090,9 +2157,14 @@ Namespace.prototype.toJSON = function toJSON(toJSONOptions) {
3090
2157
  /**
3091
2158
  * Adds nested objects to this namespace from nested object descriptors.
3092
2159
  * @param {Object.<string,AnyNestedObject>} nestedJson Any nested object descriptors
2160
+ * @param {number} [depth] Current nesting depth, defaults to `0`
3093
2161
  * @returns {Namespace} `this`
3094
2162
  */
3095
- Namespace.prototype.addJSON = function addJSON(nestedJson) {
2163
+ Namespace.prototype.addJSON = function addJSON(nestedJson, depth) {
2164
+ if (depth === undefined)
2165
+ depth = 0;
2166
+ if (depth > util.recursionLimit)
2167
+ throw Error("max depth exceeded");
3096
2168
  var ns = this;
3097
2169
  /* istanbul ignore else */
3098
2170
  if (nestedJson) {
@@ -3107,7 +2179,7 @@ Namespace.prototype.addJSON = function addJSON(nestedJson) {
3107
2179
  ? Service.fromJSON
3108
2180
  : nested.id !== undefined
3109
2181
  ? Field.fromJSON
3110
- : Namespace.fromJSON )(names[i], nested)
2182
+ : Namespace.fromJSON )(names[i], nested, depth + 1)
3111
2183
  );
3112
2184
  }
3113
2185
  }
@@ -3120,8 +2192,9 @@ Namespace.prototype.addJSON = function addJSON(nestedJson) {
3120
2192
  * @returns {ReflectionObject|null} The reflection object or `null` if it doesn't exist
3121
2193
  */
3122
2194
  Namespace.prototype.get = function get(name) {
3123
- return this.nested && this.nested[name]
3124
- || null;
2195
+ return this.nested && Object.prototype.hasOwnProperty.call(this.nested, name)
2196
+ ? this.nested[name]
2197
+ : null;
3125
2198
  };
3126
2199
 
3127
2200
  /**
@@ -3132,7 +2205,7 @@ Namespace.prototype.get = function get(name) {
3132
2205
  * @throws {Error} If there is no such enum
3133
2206
  */
3134
2207
  Namespace.prototype.getEnum = function getEnum(name) {
3135
- if (this.nested && this.nested[name] instanceof Enum)
2208
+ if (this.nested && Object.prototype.hasOwnProperty.call(this.nested, name) && this.nested[name] instanceof Enum)
3136
2209
  return this.nested[name].values;
3137
2210
  throw Error("no such enum: " + name);
3138
2211
  };
@@ -3149,6 +2222,9 @@ Namespace.prototype.add = function add(object) {
3149
2222
  if (!(object instanceof Field && object.extend !== undefined || object instanceof Type || object instanceof OneOf || object instanceof Enum || object instanceof Service || object instanceof Namespace))
3150
2223
  throw TypeError("object must be a valid nested object");
3151
2224
 
2225
+ if (object.name === "__proto__")
2226
+ return this;
2227
+
3152
2228
  if (!this.nested)
3153
2229
  this.nested = {};
3154
2230
  else {
@@ -3228,6 +2304,8 @@ Namespace.prototype.define = function define(path, json) {
3228
2304
  throw TypeError("illegal path");
3229
2305
  if (path && path.length && path[0] === "")
3230
2306
  throw Error("path must be relative");
2307
+ if (path.length > util.recursionLimit)
2308
+ throw Error("max depth exceeded");
3231
2309
 
3232
2310
  var ptr = this;
3233
2311
  while (path.length > 0) {
@@ -3251,7 +2329,8 @@ Namespace.prototype.define = function define(path, json) {
3251
2329
  Namespace.prototype.resolveAll = function resolveAll() {
3252
2330
  if (!this._needsRecursiveResolve) return this;
3253
2331
 
3254
- this._resolveFeaturesRecursive(this._edition);
2332
+ if (this._needsRecursiveFeatureResolution)
2333
+ this._resolveFeaturesRecursive(this._edition);
3255
2334
 
3256
2335
  var nested = this.nestedArray, i = 0;
3257
2336
  this.resolve();
@@ -3361,8 +2440,10 @@ Namespace.prototype._lookupImpl = function lookup(path, flatPath) {
3361
2440
  // Otherwise try each nested namespace
3362
2441
  } else {
3363
2442
  for (var i = 0; i < this.nestedArray.length; ++i)
3364
- if (this._nestedArray[i] instanceof Namespace && (found = this._nestedArray[i]._lookupImpl(path, flatPath)))
2443
+ if (this._nestedArray[i] instanceof Namespace && (found = this._nestedArray[i]._lookupImpl(path, flatPath))) {
3365
2444
  exact = found;
2445
+ break;
2446
+ }
3366
2447
  }
3367
2448
 
3368
2449
  // Set this even when null, so that when we walk up the tree we can quickly bail on repeated checks back down.
@@ -3444,22 +2525,23 @@ Namespace._configure = function(Type_, Service_, Enum_) {
3444
2525
  Enum = Enum_;
3445
2526
  };
3446
2527
 
3447
- },{"15":15,"22":22,"23":23,"33":33}],22:[function(require,module,exports){
2528
+ },{"13":13,"14":14,"24":24,"6":6}],13:[function(require,module,exports){
3448
2529
  "use strict";
3449
2530
  module.exports = ReflectionObject;
3450
2531
 
3451
2532
  ReflectionObject.className = "ReflectionObject";
3452
2533
 
3453
- const OneOf = require(23);
3454
- var util = require(33);
2534
+ const OneOf = require(14);
2535
+ var util = require(24);
3455
2536
 
3456
2537
  var Root; // cyclic
3457
2538
 
3458
2539
  /* eslint-disable no-warning-comments */
3459
2540
  // 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"};
2541
+ 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" };
2542
+ 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" };
2543
+ 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" };
2544
+ 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
2545
 
3464
2546
  /**
3465
2547
  * Constructs a new reflection object instance.
@@ -3672,27 +2754,27 @@ ReflectionObject.prototype._resolveFeatures = function _resolveFeatures(edition)
3672
2754
  defaults = Object.assign({}, proto3Defaults);
3673
2755
  } else if (edition === "2023") {
3674
2756
  defaults = Object.assign({}, editions2023Defaults);
2757
+ } else if (edition === "2024") {
2758
+ defaults = Object.assign({}, editions2024Defaults);
3675
2759
  } else {
3676
2760
  throw new Error("Unknown edition: " + edition);
3677
2761
  }
3678
2762
  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
2763
  } else {
3695
- throw new Error("Unable to find a parent for " + this.fullName);
2764
+ // fields in Oneofs aren't actually children of them, so we have to
2765
+ // special-case it
2766
+ /* istanbul ignore else */
2767
+ if (this.partOf instanceof OneOf) {
2768
+ var lexicalParentFeaturesCopy = Object.assign({}, this.partOf._features);
2769
+ this._features = Object.assign(lexicalParentFeaturesCopy, protoFeatures || {});
2770
+ } else if (this.declaringField) {
2771
+ // Skip feature resolution of sister fields.
2772
+ } else if (this.parent) {
2773
+ var parentFeaturesCopy = Object.assign({}, this.parent._features);
2774
+ this._features = Object.assign(parentFeaturesCopy, protoFeatures || {});
2775
+ } else {
2776
+ throw new Error("Unable to find a parent for " + this.fullName);
2777
+ }
3696
2778
  }
3697
2779
  if (this.extensionField) {
3698
2780
  // Sister fields should have the same features as their extensions.
@@ -3730,6 +2812,8 @@ ReflectionObject.prototype.getOption = function getOption(name) {
3730
2812
  * @returns {ReflectionObject} `this`
3731
2813
  */
3732
2814
  ReflectionObject.prototype.setOption = function setOption(name, value, ifNotSet) {
2815
+ if (name === "__proto__")
2816
+ return this;
3733
2817
  if (!this.options)
3734
2818
  this.options = {};
3735
2819
  if (/^features\./.test(name)) {
@@ -3750,6 +2834,8 @@ ReflectionObject.prototype.setOption = function setOption(name, value, ifNotSet)
3750
2834
  * @returns {ReflectionObject} `this`
3751
2835
  */
3752
2836
  ReflectionObject.prototype.setParsedOption = function setParsedOption(name, value, propName) {
2837
+ if (name === "__proto__")
2838
+ return this;
3753
2839
  if (!this.parsedOptions) {
3754
2840
  this.parsedOptions = [];
3755
2841
  }
@@ -3824,16 +2910,16 @@ ReflectionObject._configure = function(Root_) {
3824
2910
  Root = Root_;
3825
2911
  };
3826
2912
 
3827
- },{"23":23,"33":33}],23:[function(require,module,exports){
2913
+ },{"14":14,"24":24}],14:[function(require,module,exports){
3828
2914
  "use strict";
3829
2915
  module.exports = OneOf;
3830
2916
 
3831
2917
  // extends ReflectionObject
3832
- var ReflectionObject = require(22);
2918
+ var ReflectionObject = require(13);
3833
2919
  ((OneOf.prototype = Object.create(ReflectionObject.prototype)).constructor = OneOf).className = "OneOf";
3834
2920
 
3835
- var Field = require(15),
3836
- util = require(33);
2921
+ var Field = require(6),
2922
+ util = require(24);
3837
2923
 
3838
2924
  /**
3839
2925
  * Constructs a new oneof instance.
@@ -4024,6 +3110,7 @@ Object.defineProperty(OneOf.prototype, "isProto3Optional", {
4024
3110
  * @param {Object} prototype Target prototype
4025
3111
  * @param {string} oneofName OneOf name
4026
3112
  * @returns {undefined}
3113
+ * @deprecated Legacy TypeScript decorator support. Will be removed in a future release.
4027
3114
  */
4028
3115
 
4029
3116
  /**
@@ -4032,6 +3119,7 @@ Object.defineProperty(OneOf.prototype, "isProto3Optional", {
4032
3119
  * @param {...string} fieldNames Field names
4033
3120
  * @returns {OneOfDecorator} Decorator function
4034
3121
  * @template T extends string
3122
+ * @deprecated Legacy TypeScript decorator support. Will be removed in a future release.
4035
3123
  */
4036
3124
  OneOf.d = function decorateOneOf() {
4037
3125
  var fieldNames = new Array(arguments.length),
@@ -4048,11 +3136,11 @@ OneOf.d = function decorateOneOf() {
4048
3136
  };
4049
3137
  };
4050
3138
 
4051
- },{"15":15,"22":22,"33":33}],24:[function(require,module,exports){
3139
+ },{"13":13,"24":24,"6":6}],15:[function(require,module,exports){
4052
3140
  "use strict";
4053
3141
  module.exports = Reader;
4054
3142
 
4055
- var util = require(35);
3143
+ var util = require(34);
4056
3144
 
4057
3145
  var BufferReader; // cyclic
4058
3146
 
@@ -4129,28 +3217,108 @@ Reader.create = create();
4129
3217
 
4130
3218
  Reader.prototype._slice = util.Array.prototype.subarray || /* istanbul ignore next */ util.Array.prototype.slice;
4131
3219
 
3220
+ /**
3221
+ * Returns raw bytes from the backing buffer without advancing the reader.
3222
+ * @param {number} start Start offset
3223
+ * @param {number} end End offset
3224
+ * @returns {Uint8Array} Raw bytes
3225
+ */
3226
+ Reader.prototype.raw = function read_raw(start, end) {
3227
+ if (Array.isArray(this.buf)) // plain array
3228
+ return this.buf.slice(start, end);
3229
+
3230
+ if (start === end) // fix for IE 10/Win8 and others' subarray returning array of size 1
3231
+ return new this.buf.constructor(0);
3232
+ return this._slice.call(this.buf, start, end);
3233
+ };
3234
+
4132
3235
  /**
4133
3236
  * Reads a varint as an unsigned 32 bit value.
4134
3237
  * @function
4135
3238
  * @returns {number} Value read
4136
3239
  */
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;
3240
+ Reader.prototype.uint32 = function read_uint32() {
3241
+ var buf = this.buf,
3242
+ pos = this.pos,
3243
+ value = (buf[pos] & 127) >>> 0;
3244
+ if (buf[pos++] < 128) {
3245
+ this.pos = pos;
3246
+ return value;
3247
+ }
3248
+ value = (value | (buf[pos] & 127) << 7) >>> 0;
3249
+ if (buf[pos++] < 128) {
3250
+ this.pos = pos;
3251
+ return value;
3252
+ }
3253
+ value = (value | (buf[pos] & 127) << 14) >>> 0;
3254
+ if (buf[pos++] < 128) {
3255
+ this.pos = pos;
3256
+ return value;
3257
+ }
3258
+ value = (value | (buf[pos] & 127) << 21) >>> 0;
3259
+ if (buf[pos++] < 128) {
3260
+ this.pos = pos;
3261
+ return value;
3262
+ }
3263
+ value = (value | (buf[pos] & 15) << 28) >>> 0;
3264
+ if (buf[pos++] < 128) {
3265
+ this.pos = pos;
3266
+ return value;
3267
+ }
4145
3268
 
3269
+ for (var i = 0; i < 5; ++i) {
4146
3270
  /* istanbul ignore if */
4147
- if ((this.pos += 5) > this.len) {
4148
- this.pos = this.len;
4149
- throw indexOutOfRange(this, 10);
3271
+ if (pos >= this.len) {
3272
+ this.pos = pos;
3273
+ throw indexOutOfRange(this);
3274
+ }
3275
+ if (buf[pos++] < 128) {
3276
+ this.pos = pos;
3277
+ return value;
4150
3278
  }
3279
+ }
3280
+ /* istanbul ignore next */
3281
+ this.pos = pos;
3282
+ throw Error("invalid varint encoding");
3283
+ };
3284
+
3285
+ /**
3286
+ * Reads a field tag.
3287
+ * @function
3288
+ * @returns {number} Tag read
3289
+ */
3290
+ Reader.prototype.tag = function read_tag() {
3291
+ var buf = this.buf,
3292
+ pos = this.pos,
3293
+ value = (buf[pos] & 127) >>> 0;
3294
+ if (buf[pos++] < 128) {
3295
+ this.pos = pos;
4151
3296
  return value;
4152
- };
4153
- })();
3297
+ }
3298
+ value = (value | (buf[pos] & 127) << 7) >>> 0;
3299
+ if (buf[pos++] < 128) {
3300
+ this.pos = pos;
3301
+ return value;
3302
+ }
3303
+ value = (value | (buf[pos] & 127) << 14) >>> 0;
3304
+ if (buf[pos++] < 128) {
3305
+ this.pos = pos;
3306
+ return value;
3307
+ }
3308
+ value = (value | (buf[pos] & 127) << 21) >>> 0;
3309
+ if (buf[pos++] < 128) {
3310
+ this.pos = pos;
3311
+ return value;
3312
+ }
3313
+ value = (value | (buf[pos] & 15) << 28) >>> 0;
3314
+ if (buf[pos] < 128 && (buf[pos] & 112) === 0) {
3315
+ this.pos = pos + 1;
3316
+ return value;
3317
+ }
3318
+
3319
+ this.pos = pos + 1;
3320
+ throw Error("invalid tag encoding");
3321
+ };
4154
3322
 
4155
3323
  /**
4156
3324
  * Reads a varint as a signed 32 bit value.
@@ -4252,7 +3420,20 @@ function readLongVarint() {
4252
3420
  * @returns {boolean} Value read
4253
3421
  */
4254
3422
  Reader.prototype.bool = function read_bool() {
4255
- return this.uint32() !== 0;
3423
+ var value = false,
3424
+ b;
3425
+ for (var i = 0; i < 10; ++i) {
3426
+ /* istanbul ignore if */
3427
+ if (this.pos >= this.len)
3428
+ throw indexOutOfRange(this);
3429
+ b = this.buf[this.pos++];
3430
+ if (b & 127)
3431
+ value = true;
3432
+ if (b < 128)
3433
+ return value;
3434
+ }
3435
+ /* istanbul ignore next */
3436
+ throw Error("invalid varint encoding");
4256
3437
  };
4257
3438
 
4258
3439
  function readFixed32_end(buf, end) { // note that this uses `end`, not `pos`
@@ -4360,17 +3541,8 @@ Reader.prototype.bytes = function read_bytes() {
4360
3541
  if (end > this.len)
4361
3542
  throw indexOutOfRange(this, length);
4362
3543
 
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);
3544
+ this.pos = end;
3545
+ return this.raw(start, end);
4374
3546
  };
4375
3547
 
4376
3548
  /**
@@ -4378,8 +3550,16 @@ Reader.prototype.bytes = function read_bytes() {
4378
3550
  * @returns {string} Value read
4379
3551
  */
4380
3552
  Reader.prototype.string = function read_string() {
4381
- var bytes = this.bytes();
4382
- return utf8.read(bytes, 0, bytes.length);
3553
+ var length = this.uint32(),
3554
+ start = this.pos,
3555
+ end = this.pos + length;
3556
+
3557
+ /* istanbul ignore if */
3558
+ if (end > this.len)
3559
+ throw indexOutOfRange(this, length);
3560
+
3561
+ this.pos = end;
3562
+ return utf8.read(this.buf, start, end);
4383
3563
  };
4384
3564
 
4385
3565
  /**
@@ -4403,12 +3583,25 @@ Reader.prototype.skip = function skip(length) {
4403
3583
  return this;
4404
3584
  };
4405
3585
 
3586
+ /**
3587
+ * Recursion limit.
3588
+ * @type {number}
3589
+ */
3590
+ Reader.recursionLimit = util.recursionLimit;
3591
+
4406
3592
  /**
4407
3593
  * Skips the next element of the specified wire type.
4408
3594
  * @param {number} wireType Wire type received
3595
+ * @param {number} [depth] Depth of recursion to control nested calls; 0 if omitted
3596
+ * @param {number} [fieldNumber] Field number for validating group end tags
4409
3597
  * @returns {Reader} `this`
4410
3598
  */
4411
- Reader.prototype.skipType = function(wireType) {
3599
+ Reader.prototype.skipType = function(wireType, depth, fieldNumber) {
3600
+ if (depth === undefined) depth = 0;
3601
+ if (depth > Reader.recursionLimit)
3602
+ throw Error("max depth exceeded");
3603
+ if (fieldNumber === 0)
3604
+ throw Error("illegal tag: field number 0");
4412
3605
  switch (wireType) {
4413
3606
  case 0:
4414
3607
  this.skip();
@@ -4420,8 +3613,18 @@ Reader.prototype.skipType = function(wireType) {
4420
3613
  this.skip(this.uint32());
4421
3614
  break;
4422
3615
  case 3:
4423
- while ((wireType = this.uint32() & 7) !== 4) {
4424
- this.skipType(wireType);
3616
+ while (true) {
3617
+ var tag = this.tag();
3618
+ var nestedField = tag >>> 3;
3619
+ wireType = tag & 7;
3620
+ if (!nestedField)
3621
+ throw Error("illegal tag: field number 0");
3622
+ if (wireType === 4) {
3623
+ if (fieldNumber !== undefined && nestedField !== fieldNumber)
3624
+ throw Error("invalid end group tag");
3625
+ break;
3626
+ }
3627
+ this.skipType(wireType, depth + 1, nestedField);
4425
3628
  }
4426
3629
  break;
4427
3630
  case 5:
@@ -4466,15 +3669,15 @@ Reader._configure = function(BufferReader_) {
4466
3669
  });
4467
3670
  };
4468
3671
 
4469
- },{"35":35}],25:[function(require,module,exports){
3672
+ },{"34":34}],16:[function(require,module,exports){
4470
3673
  "use strict";
4471
3674
  module.exports = BufferReader;
4472
3675
 
4473
3676
  // extends Reader
4474
- var Reader = require(24);
3677
+ var Reader = require(15);
4475
3678
  (BufferReader.prototype = Object.create(Reader.prototype)).constructor = BufferReader;
4476
3679
 
4477
- var util = require(35);
3680
+ var util = require(34);
4478
3681
 
4479
3682
  /**
4480
3683
  * Constructs a new buffer reader instance.
@@ -4499,15 +3702,36 @@ BufferReader._configure = function () {
4499
3702
  BufferReader.prototype._slice = util.Buffer.prototype.slice;
4500
3703
  };
4501
3704
 
3705
+ /**
3706
+ * Returns raw bytes from the backing buffer without advancing the reader.
3707
+ * @name BufferReader#raw
3708
+ * @function
3709
+ * @param {number} start Start offset
3710
+ * @param {number} end End offset
3711
+ * @returns {Buffer} Raw bytes
3712
+ */
3713
+ BufferReader.prototype.raw = function read_raw_buffer(start, end) {
3714
+ if (start === end)
3715
+ return util.Buffer.alloc(0);
3716
+ return this._slice.call(this.buf, start, end);
3717
+ };
4502
3718
 
4503
3719
  /**
4504
3720
  * @override
4505
3721
  */
4506
3722
  BufferReader.prototype.string = function read_string_buffer() {
4507
- var len = this.uint32(); // modifies pos
3723
+ var len = this.uint32(), // modifies pos
3724
+ start = this.pos,
3725
+ end = this.pos + len;
3726
+
3727
+ /* istanbul ignore if */
3728
+ if (end > this.len)
3729
+ throw RangeError("index out of range: " + this.pos + " + " + len + " > " + this.len);
3730
+
3731
+ this.pos = end;
4508
3732
  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));
3733
+ ? this.buf.utf8Slice(start, end)
3734
+ : this.buf.toString("utf-8", start, end);
4511
3735
  };
4512
3736
 
4513
3737
  /**
@@ -4519,18 +3743,18 @@ BufferReader.prototype.string = function read_string_buffer() {
4519
3743
 
4520
3744
  BufferReader._configure();
4521
3745
 
4522
- },{"24":24,"35":35}],26:[function(require,module,exports){
3746
+ },{"15":15,"34":34}],17:[function(require,module,exports){
4523
3747
  "use strict";
4524
3748
  module.exports = Root;
4525
3749
 
4526
3750
  // extends Namespace
4527
- var Namespace = require(21);
3751
+ var Namespace = require(12);
4528
3752
  ((Root.prototype = Object.create(Namespace.prototype)).constructor = Root).className = "Root";
4529
3753
 
4530
- var Field = require(15),
4531
- Enum = require(14),
4532
- OneOf = require(23),
4533
- util = require(33);
3754
+ var Field = require(6),
3755
+ Enum = require(5),
3756
+ OneOf = require(14),
3757
+ util = require(24);
4534
3758
 
4535
3759
  var Type, // cyclic
4536
3760
  parse, // might be excluded
@@ -4577,14 +3801,19 @@ function Root(options) {
4577
3801
  * Loads a namespace descriptor into a root namespace.
4578
3802
  * @param {INamespace} json Namespace descriptor
4579
3803
  * @param {Root} [root] Root namespace, defaults to create a new one if omitted
3804
+ * @param {number} [depth] Current nesting depth, defaults to `0`
4580
3805
  * @returns {Root} Root namespace
4581
3806
  */
4582
- Root.fromJSON = function fromJSON(json, root) {
3807
+ Root.fromJSON = function fromJSON(json, root, depth) {
3808
+ if (depth === undefined)
3809
+ depth = 0;
3810
+ if (depth > util.recursionLimit)
3811
+ throw Error("max depth exceeded");
4583
3812
  if (!root)
4584
3813
  root = new Root();
4585
3814
  if (json.options)
4586
3815
  root.setOptions(json.options);
4587
- return root.addJSON(json.nested).resolveAll();
3816
+ return root.addJSON(json.nested, depth).resolveAll();
4588
3817
  };
4589
3818
 
4590
3819
  /**
@@ -4652,8 +3881,9 @@ Root.prototype.load = function load(filename, options, callback) {
4652
3881
  var idx = filename.lastIndexOf("google/protobuf/");
4653
3882
  if (idx > -1) {
4654
3883
  var altname = filename.substring(idx);
4655
- if (altname in common) return altname;
3884
+ if (Object.prototype.hasOwnProperty.call(common, altname)) return altname;
4656
3885
  }
3886
+ if (Object.prototype.hasOwnProperty.call(common, filename)) return filename;
4657
3887
  return null;
4658
3888
  }
4659
3889
 
@@ -4697,7 +3927,7 @@ Root.prototype.load = function load(filename, options, callback) {
4697
3927
  self.files.push(filename);
4698
3928
 
4699
3929
  // Shortcut bundled definitions
4700
- if (filename in common) {
3930
+ if (Object.prototype.hasOwnProperty.call(common, filename)) {
4701
3931
  if (sync) {
4702
3932
  process(filename, common[filename]);
4703
3933
  } else {
@@ -4925,7 +4155,7 @@ Root._configure = function(Type_, parse_, common_) {
4925
4155
  common = common_;
4926
4156
  };
4927
4157
 
4928
- },{"14":14,"15":15,"21":21,"23":23,"33":33}],27:[function(require,module,exports){
4158
+ },{"12":12,"14":14,"24":24,"5":5,"6":6}],18:[function(require,module,exports){
4929
4159
  "use strict";
4930
4160
  module.exports = {};
4931
4161
 
@@ -4945,7 +4175,7 @@ module.exports = {};
4945
4175
  * var root = protobuf.roots["myroot"];
4946
4176
  */
4947
4177
 
4948
- },{}],28:[function(require,module,exports){
4178
+ },{}],19:[function(require,module,exports){
4949
4179
  "use strict";
4950
4180
 
4951
4181
  /**
@@ -4981,13 +4211,13 @@ var rpc = exports;
4981
4211
  * @returns {undefined}
4982
4212
  */
4983
4213
 
4984
- rpc.Service = require(29);
4214
+ rpc.Service = require(20);
4985
4215
 
4986
- },{"29":29}],29:[function(require,module,exports){
4216
+ },{"20":20}],20:[function(require,module,exports){
4987
4217
  "use strict";
4988
4218
  module.exports = Service;
4989
4219
 
4990
- var util = require(35);
4220
+ var util = require(34);
4991
4221
 
4992
4222
  // Extends EventEmitter
4993
4223
  (Service.prototype = Object.create(util.EventEmitter.prototype)).constructor = Service;
@@ -5127,17 +4357,19 @@ Service.prototype.end = function end(endedByRPC) {
5127
4357
  return this;
5128
4358
  };
5129
4359
 
5130
- },{"35":35}],30:[function(require,module,exports){
4360
+ },{"34":34}],21:[function(require,module,exports){
5131
4361
  "use strict";
5132
4362
  module.exports = Service;
5133
4363
 
5134
4364
  // extends Namespace
5135
- var Namespace = require(21);
4365
+ var Namespace = require(12);
5136
4366
  ((Service.prototype = Object.create(Namespace.prototype)).constructor = Service).className = "Service";
5137
4367
 
5138
- var Method = require(20),
5139
- util = require(33),
5140
- rpc = require(28);
4368
+ var Method = require(11),
4369
+ util = require(24),
4370
+ rpc = require(19);
4371
+
4372
+ var reservedRe = util.patterns.reservedRe;
5141
4373
 
5142
4374
  /**
5143
4375
  * Constructs a new service instance.
@@ -5176,17 +4408,22 @@ function Service(name, options) {
5176
4408
  * Constructs a service from a service descriptor.
5177
4409
  * @param {string} name Service name
5178
4410
  * @param {IService} json Service descriptor
4411
+ * @param {number} [depth] Current nesting depth, defaults to `0`
5179
4412
  * @returns {Service} Created service
5180
4413
  * @throws {TypeError} If arguments are invalid
5181
4414
  */
5182
- Service.fromJSON = function fromJSON(name, json) {
4415
+ Service.fromJSON = function fromJSON(name, json, depth) {
4416
+ if (depth === undefined)
4417
+ depth = 0;
4418
+ if (depth > util.recursionLimit)
4419
+ throw Error("max depth exceeded");
5183
4420
  var service = new Service(name, json.options);
5184
4421
  /* istanbul ignore else */
5185
4422
  if (json.methods)
5186
4423
  for (var names = Object.keys(json.methods), i = 0; i < names.length; ++i)
5187
4424
  service.add(Method.fromJSON(names[i], json.methods[names[i]]));
5188
4425
  if (json.nested)
5189
- service.addJSON(json.nested);
4426
+ service.addJSON(json.nested, depth);
5190
4427
  if (json.edition)
5191
4428
  service._edition = json.edition;
5192
4429
  service.comment = json.comment;
@@ -5232,8 +4469,9 @@ function clearCache(service) {
5232
4469
  * @override
5233
4470
  */
5234
4471
  Service.prototype.get = function get(name) {
5235
- return this.methods[name]
5236
- || Namespace.prototype.get.call(this, name);
4472
+ return Object.prototype.hasOwnProperty.call(this.methods, name)
4473
+ ? this.methods[name]
4474
+ : Namespace.prototype.get.call(this, name);
5237
4475
  };
5238
4476
 
5239
4477
  /**
@@ -5268,12 +4506,13 @@ Service.prototype._resolveFeaturesRecursive = function _resolveFeaturesRecursive
5268
4506
  * @override
5269
4507
  */
5270
4508
  Service.prototype.add = function add(object) {
5271
-
5272
4509
  /* istanbul ignore if */
5273
4510
  if (this.get(object.name))
5274
4511
  throw Error("duplicate name '" + object.name + "' in " + this);
5275
4512
 
5276
4513
  if (object instanceof Method) {
4514
+ if (object.name === "__proto__")
4515
+ return this;
5277
4516
  this.methods[object.name] = object;
5278
4517
  object.parent = this;
5279
4518
  return clearCache(this);
@@ -5309,7 +4548,7 @@ Service.prototype.create = function create(rpcImpl, requestDelimited, responseDe
5309
4548
  var rpcService = new rpc.Service(rpcImpl, requestDelimited, responseDelimited);
5310
4549
  for (var i = 0, method; i < /* initializes */ this.methodsArray.length; ++i) {
5311
4550
  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)")({
4551
+ rpcService[methodName] = util.codegen(["r","c"], reservedRe.test(methodName) ? methodName + "_" : methodName)("return this.rpcCall(m,q,s,r,c)")({
5313
4552
  m: method,
5314
4553
  q: method.resolvedRequestType.ctor,
5315
4554
  s: method.resolvedResponseType.ctor
@@ -5318,28 +4557,28 @@ Service.prototype.create = function create(rpcImpl, requestDelimited, responseDe
5318
4557
  return rpcService;
5319
4558
  };
5320
4559
 
5321
- },{"20":20,"21":21,"28":28,"33":33}],31:[function(require,module,exports){
4560
+ },{"11":11,"12":12,"19":19,"24":24}],22:[function(require,module,exports){
5322
4561
  "use strict";
5323
4562
  module.exports = Type;
5324
4563
 
5325
4564
  // extends Namespace
5326
- var Namespace = require(21);
4565
+ var Namespace = require(12);
5327
4566
  ((Type.prototype = Object.create(Namespace.prototype)).constructor = Type).className = "Type";
5328
4567
 
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);
4568
+ var Enum = require(5),
4569
+ OneOf = require(14),
4570
+ Field = require(6),
4571
+ MapField = require(9),
4572
+ Service = require(21),
4573
+ Message = require(10),
4574
+ Reader = require(15),
4575
+ Writer = require(41),
4576
+ util = require(24),
4577
+ encoder = require(4),
4578
+ decoder = require(3),
4579
+ verifier = require(39),
4580
+ converter = require(2),
4581
+ wrappers = require(40);
5343
4582
 
5344
4583
  /**
5345
4584
  * Constructs a new reflected message type instance.
@@ -5350,6 +4589,7 @@ var Enum = require(14),
5350
4589
  * @param {Object.<string,*>} [options] Declared options
5351
4590
  */
5352
4591
  function Type(name, options) {
4592
+ name = name.replace(/\W/g, "");
5353
4593
  Namespace.call(this, name, options);
5354
4594
 
5355
4595
  /**
@@ -5491,11 +4731,15 @@ Object.defineProperties(Type.prototype, {
5491
4731
  util.merge(ctor, Message, true);
5492
4732
 
5493
4733
  this._ctor = ctor;
4734
+ delete this.decode;
4735
+ delete this.fromObject;
5494
4736
 
5495
4737
  // Messages have non-enumerable default values on their prototype
5496
4738
  var i = 0;
5497
- for (; i < /* initializes */ this.fieldsArray.length; ++i)
5498
- this._fieldsArray[i].resolve(); // ensures a proper value
4739
+ for (var field; i < /* initializes */ this.fieldsArray.length; ++i) {
4740
+ field = this._fieldsArray[i].resolve(); // ensures a proper value
4741
+ ctor.prototype[field.name] = field.defaultValue;
4742
+ }
5499
4743
 
5500
4744
  // Messages have non-enumerable getters and setters for each virtual oneof field
5501
4745
  var ctorProperties = {};
@@ -5525,7 +4769,7 @@ Type.generateConstructor = function generateConstructor(mtype) {
5525
4769
  else if (field.repeated) gen
5526
4770
  ("this%s=[]", util.safeProp(field.name));
5527
4771
  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
4772
+ ("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
4773
  ("this[ks[i]]=p[ks[i]]");
5530
4774
  /* eslint-enable no-unexpected-multiline */
5531
4775
  };
@@ -5553,9 +4797,14 @@ function clearCache(type) {
5553
4797
  * Creates a message type from a message type descriptor.
5554
4798
  * @param {string} name Message name
5555
4799
  * @param {IType} json Message type descriptor
4800
+ * @param {number} [depth] Current nesting depth, defaults to `0`
5556
4801
  * @returns {Type} Created message type
5557
4802
  */
5558
- Type.fromJSON = function fromJSON(name, json) {
4803
+ Type.fromJSON = function fromJSON(name, json, depth) {
4804
+ if (depth === undefined)
4805
+ depth = 0;
4806
+ if (depth > util.nestingLimit)
4807
+ throw Error("max depth exceeded");
5559
4808
  var type = new Type(name, json.options);
5560
4809
  type.extensions = json.extensions;
5561
4810
  type.reserved = json.reserved;
@@ -5582,7 +4831,7 @@ Type.fromJSON = function fromJSON(name, json) {
5582
4831
  ? Enum.fromJSON
5583
4832
  : nested.methods !== undefined
5584
4833
  ? Service.fromJSON
5585
- : Namespace.fromJSON )(names[i], nested)
4834
+ : Namespace.fromJSON )(names[i], nested, depth + 1)
5586
4835
  );
5587
4836
  }
5588
4837
  if (json.extensions && json.extensions.length)
@@ -5658,10 +4907,13 @@ Type.prototype._resolveFeaturesRecursive = function _resolveFeaturesRecursive(ed
5658
4907
  * @override
5659
4908
  */
5660
4909
  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;
4910
+ if (Object.prototype.hasOwnProperty.call(this.fields, name))
4911
+ return this.fields[name];
4912
+ if (this.oneofs && Object.prototype.hasOwnProperty.call(this.oneofs, name))
4913
+ return this.oneofs[name];
4914
+ if (this.nested && Object.prototype.hasOwnProperty.call(this.nested, name))
4915
+ return this.nested[name];
4916
+ return null;
5665
4917
  };
5666
4918
 
5667
4919
  /**
@@ -5672,7 +4924,6 @@ Type.prototype.get = function get(name) {
5672
4924
  * @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
4925
  */
5674
4926
  Type.prototype.add = function add(object) {
5675
-
5676
4927
  if (this.get(object.name))
5677
4928
  throw Error("duplicate name '" + object.name + "' in " + this);
5678
4929
 
@@ -5688,6 +4939,8 @@ Type.prototype.add = function add(object) {
5688
4939
  throw Error("id " + object.id + " is reserved in " + this);
5689
4940
  if (this.isReservedName(object.name))
5690
4941
  throw Error("name '" + object.name + "' is reserved in " + this);
4942
+ if (object.name === "__proto__")
4943
+ return this;
5691
4944
 
5692
4945
  if (object.parent)
5693
4946
  object.parent.remove(object);
@@ -5697,6 +4950,8 @@ Type.prototype.add = function add(object) {
5697
4950
  return clearCache(this);
5698
4951
  }
5699
4952
  if (object instanceof OneOf) {
4953
+ if (object.name === "__proto__")
4954
+ return this;
5700
4955
  if (!this.oneofs)
5701
4956
  this.oneofs = {};
5702
4957
  this.oneofs[object.name] = object;
@@ -5789,7 +5044,8 @@ Type.prototype.setup = function setup() {
5789
5044
  this.decode = decoder(this)({
5790
5045
  Reader : Reader,
5791
5046
  types : types,
5792
- util : util
5047
+ util : util,
5048
+ C : this.ctor
5793
5049
  });
5794
5050
  this.verify = verifier(this)({
5795
5051
  types : types,
@@ -5797,7 +5053,8 @@ Type.prototype.setup = function setup() {
5797
5053
  });
5798
5054
  this.fromObject = converter.fromObject(this)({
5799
5055
  types : types,
5800
- util : util
5056
+ util : util,
5057
+ C : this.ctor
5801
5058
  });
5802
5059
  this.toObject = converter.toObject(this)({
5803
5060
  types : types,
@@ -5807,15 +5064,13 @@ Type.prototype.setup = function setup() {
5807
5064
  // Inject custom wrappers for common types
5808
5065
  var wrapper = wrappers[fullName];
5809
5066
  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
- // }
5067
+ var wrapperThis = Object.create(this);
5068
+ // Reuse this type's runtime constructor in wrapper fromObject/toObject
5069
+ wrapperThis._ctor = this.ctor;
5070
+ wrapperThis.fromObject = this.fromObject;
5071
+ this.fromObject = wrapper.fromObject.bind(wrapperThis);
5072
+ wrapperThis.toObject = this.toObject;
5073
+ this.toObject = wrapper.toObject.bind(wrapperThis);
5819
5074
  }
5820
5075
 
5821
5076
  return this;
@@ -5849,8 +5104,8 @@ Type.prototype.encodeDelimited = function encodeDelimited(message, writer) {
5849
5104
  * @throws {Error} If the payload is not a reader or valid buffer
5850
5105
  * @throws {util.ProtocolError<{}>} If required fields are missing
5851
5106
  */
5852
- Type.prototype.decode = function decode_setup(reader, length) {
5853
- return this.setup().decode(reader, length); // overrides this method
5107
+ Type.prototype.decode = function decode_setup(reader, length) { // eslint-disable-line no-unused-vars
5108
+ return this.setup().decode.apply(this, arguments); // overrides this method
5854
5109
  };
5855
5110
 
5856
5111
  /**
@@ -5871,8 +5126,8 @@ Type.prototype.decodeDelimited = function decodeDelimited(reader) {
5871
5126
  * @param {Object.<string,*>} message Plain object to verify
5872
5127
  * @returns {null|string} `null` if valid, otherwise the reason why it is not
5873
5128
  */
5874
- Type.prototype.verify = function verify_setup(message) {
5875
- return this.setup().verify(message); // overrides this method
5129
+ Type.prototype.verify = function verify_setup(message) { // eslint-disable-line no-unused-vars
5130
+ return this.setup().verify.apply(this, arguments); // overrides this method
5876
5131
  };
5877
5132
 
5878
5133
  /**
@@ -5880,8 +5135,8 @@ Type.prototype.verify = function verify_setup(message) {
5880
5135
  * @param {Object.<string,*>} object Plain object to convert
5881
5136
  * @returns {Message<{}>} Message instance
5882
5137
  */
5883
- Type.prototype.fromObject = function fromObject(object) {
5884
- return this.setup().fromObject(object);
5138
+ Type.prototype.fromObject = function fromObject(object) { // eslint-disable-line no-unused-vars
5139
+ return this.setup().fromObject.apply(this, arguments);
5885
5140
  };
5886
5141
 
5887
5142
  /**
@@ -5913,6 +5168,18 @@ Type.prototype.toObject = function toObject(message, options) {
5913
5168
  return this.setup().toObject(message, options);
5914
5169
  };
5915
5170
 
5171
+ /**
5172
+ * Gets the type url for this type.
5173
+ * @param {string} [prefix] Custom type url prefix, defaults to `"type.googleapis.com"`
5174
+ * @returns {string} The type url
5175
+ */
5176
+ Type.prototype.getTypeUrl = function getTypeUrl(prefix) {
5177
+ if (prefix === undefined)
5178
+ prefix = "type.googleapis.com";
5179
+ var fullName = this.fullName;
5180
+ return prefix + "/" + (fullName.charAt(0) === "." ? fullName.substring(1) : fullName);
5181
+ };
5182
+
5916
5183
  /**
5917
5184
  * Decorator function as returned by {@link Type.d} (TypeScript).
5918
5185
  * @typedef TypeDecorator
@@ -5920,6 +5187,7 @@ Type.prototype.toObject = function toObject(message, options) {
5920
5187
  * @param {Constructor<T>} target Target constructor
5921
5188
  * @returns {undefined}
5922
5189
  * @template T extends Message<T>
5190
+ * @deprecated Legacy TypeScript decorator support. Will be removed in a future release.
5923
5191
  */
5924
5192
 
5925
5193
  /**
@@ -5927,6 +5195,7 @@ Type.prototype.toObject = function toObject(message, options) {
5927
5195
  * @param {string} [typeName] Type name, defaults to the constructor's name
5928
5196
  * @returns {TypeDecorator<T>} Decorator function
5929
5197
  * @template T extends Message<T>
5198
+ * @deprecated Legacy TypeScript decorator support. Will be removed in a future release.
5930
5199
  */
5931
5200
  Type.d = function decorateType(typeName) {
5932
5201
  return function typeDecorator(target) {
@@ -5934,7 +5203,7 @@ Type.d = function decorateType(typeName) {
5934
5203
  };
5935
5204
  };
5936
5205
 
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){
5206
+ },{"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
5207
  "use strict";
5939
5208
 
5940
5209
  /**
@@ -5943,7 +5212,7 @@ Type.d = function decorateType(typeName) {
5943
5212
  */
5944
5213
  var types = exports;
5945
5214
 
5946
- var util = require(33);
5215
+ var util = require(24);
5947
5216
 
5948
5217
  var s = [
5949
5218
  "double", // 0
@@ -5964,7 +5233,7 @@ var s = [
5964
5233
  ];
5965
5234
 
5966
5235
  function bake(values, offset) {
5967
- var i = 0, o = {};
5236
+ var i = 0, o = Object.create(null);
5968
5237
  offset |= 0;
5969
5238
  while (i < values.length) o[s[i + offset]] = values[i++];
5970
5239
  return o;
@@ -6132,29 +5401,33 @@ types.packed = bake([
6132
5401
  /* bool */ 0
6133
5402
  ]);
6134
5403
 
6135
- },{"33":33}],33:[function(require,module,exports){
5404
+ },{"24":24}],24:[function(require,module,exports){
6136
5405
  "use strict";
6137
5406
 
6138
5407
  /**
6139
5408
  * Various utility functions.
6140
5409
  * @namespace
6141
5410
  */
6142
- var util = module.exports = require(35);
5411
+ var util = module.exports = require(34);
6143
5412
 
6144
- var roots = require(27);
5413
+ var roots = require(18);
6145
5414
 
6146
5415
  var Type, // cyclic
6147
5416
  Enum;
6148
5417
 
6149
- util.codegen = require(3);
6150
- util.fetch = require(5);
6151
- util.path = require(8);
5418
+ util.codegen = require(27);
5419
+ util.fetch = require(29);
5420
+ util.path = require(35);
5421
+ util.patterns = require(36);
5422
+
5423
+ var reservedRe = util.patterns.reservedRe,
5424
+ unsafePropertyRe = util.patterns.unsafePropertyRe;
6152
5425
 
6153
5426
  /**
6154
5427
  * Node's fs module if available.
6155
5428
  * @type {Object.<string,*>}
6156
5429
  */
6157
- util.fs = util.inquire("fs");
5430
+ util.fs = require(31);
6158
5431
 
6159
5432
  /**
6160
5433
  * Converts an object's values to an array.
@@ -6190,16 +5463,13 @@ util.toObject = function toObject(array) {
6190
5463
  return object;
6191
5464
  };
6192
5465
 
6193
- var safePropBackslashRe = /\\/g,
6194
- safePropQuoteRe = /"/g;
6195
-
6196
5466
  /**
6197
5467
  * Tests whether the specified name is a reserved word in JS.
6198
5468
  * @param {string} name Name to test
6199
5469
  * @returns {boolean} `true` if reserved, otherwise `false`
6200
5470
  */
6201
5471
  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);
5472
+ return reservedRe.test(name);
6203
5473
  };
6204
5474
 
6205
5475
  /**
@@ -6208,8 +5478,8 @@ util.isReserved = function isReserved(name) {
6208
5478
  * @returns {string} Safe accessor
6209
5479
  */
6210
5480
  util.safeProp = function safeProp(prop) {
6211
- if (!/^[$\w_]+$/.test(prop) || util.isReserved(prop))
6212
- return "[\"" + prop.replace(safePropBackslashRe, "\\\\").replace(safePropQuoteRe, "\\\"") + "\"]";
5481
+ if (!/^[$\w_]+$/.test(prop) || reservedRe.test(prop))
5482
+ return "[" + JSON.stringify(prop) + "]";
6213
5483
  return "." + prop;
6214
5484
  };
6215
5485
 
@@ -6252,6 +5522,7 @@ util.compareFieldsById = function compareFieldsById(a, b) {
6252
5522
  * @returns {Type} Reflected type
6253
5523
  * @template T extends Message<T>
6254
5524
  * @property {Root} root Decorators root
5525
+ * @deprecated Legacy TypeScript decorator support. Will be removed in a future release.
6255
5526
  */
6256
5527
  util.decorateType = function decorateType(ctor, typeName) {
6257
5528
 
@@ -6267,7 +5538,7 @@ util.decorateType = function decorateType(ctor, typeName) {
6267
5538
 
6268
5539
  /* istanbul ignore next */
6269
5540
  if (!Type)
6270
- Type = require(31);
5541
+ Type = require(22);
6271
5542
 
6272
5543
  var type = new Type(typeName || ctor.name);
6273
5544
  util.decorateRoot.add(type);
@@ -6283,6 +5554,7 @@ var decorateEnumIndex = 0;
6283
5554
  * Decorator helper for enums (TypeScript).
6284
5555
  * @param {Object} object Enum object
6285
5556
  * @returns {Enum} Reflected enum
5557
+ * @deprecated Legacy TypeScript decorator support. Will be removed in a future release.
6286
5558
  */
6287
5559
  util.decorateEnum = function decorateEnum(object) {
6288
5560
 
@@ -6292,7 +5564,7 @@ util.decorateEnum = function decorateEnum(object) {
6292
5564
 
6293
5565
  /* istanbul ignore next */
6294
5566
  if (!Enum)
6295
- Enum = require(14);
5567
+ Enum = require(5);
6296
5568
 
6297
5569
  var enm = new Enum("Enum" + decorateEnumIndex++, object);
6298
5570
  util.decorateRoot.add(enm);
@@ -6312,9 +5584,8 @@ util.decorateEnum = function decorateEnum(object) {
6312
5584
  util.setProperty = function setProperty(dst, path, value, ifNotSet) {
6313
5585
  function setProp(dst, path, value) {
6314
5586
  var part = path.shift();
6315
- if (part === "__proto__" || part === "prototype") {
6316
- return dst;
6317
- }
5587
+ if (unsafePropertyRe.test(part))
5588
+ return dst;
6318
5589
  if (path.length > 0) {
6319
5590
  dst[part] = setProp(dst[part] || {}, path, value);
6320
5591
  } else {
@@ -6334,6 +5605,8 @@ util.setProperty = function setProperty(dst, path, value, ifNotSet) {
6334
5605
  throw TypeError("path must be specified");
6335
5606
 
6336
5607
  path = path.split(".");
5608
+ if (path.length > util.recursionLimit)
5609
+ throw Error("max depth exceeded");
6337
5610
  return setProp(dst, path, value);
6338
5611
  };
6339
5612
 
@@ -6342,86 +5615,994 @@ util.setProperty = function setProperty(dst, path, value, ifNotSet) {
6342
5615
  * @name util.decorateRoot
6343
5616
  * @type {Root}
6344
5617
  * @readonly
5618
+ * @deprecated Legacy TypeScript decorator support. Will be removed in a future release.
6345
5619
  */
6346
5620
  Object.defineProperty(util, "decorateRoot", {
6347
5621
  get: function() {
6348
- return roots["decorated"] || (roots["decorated"] = new (require(26))());
5622
+ return roots["decorated"] || (roots["decorated"] = new (require(17))());
6349
5623
  }
6350
5624
  });
6351
5625
 
6352
- },{"14":14,"26":26,"27":27,"3":3,"31":31,"35":35,"5":5,"8":8}],34:[function(require,module,exports){
5626
+ },{"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
5627
  "use strict";
6354
- module.exports = LongBits;
6355
-
6356
- var util = require(35);
5628
+ module.exports = asPromise;
6357
5629
 
6358
5630
  /**
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
5631
+ * Callback as used by {@link util.asPromise}.
5632
+ * @typedef asPromiseCallback
5633
+ * @type {function}
5634
+ * @param {Error|null} error Error, if any
5635
+ * @param {...*} params Additional arguments
5636
+ * @returns {undefined}
6365
5637
  */
6366
- function LongBits(lo, hi) {
6367
5638
 
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.
5639
+ /**
5640
+ * Returns a promise from a node-style callback function.
5641
+ * @memberof util
5642
+ * @param {asPromiseCallback} fn Function to call
5643
+ * @param {*} ctx Function context
5644
+ * @param {...*} params Function arguments
5645
+ * @returns {Promise<*>} Promisified function
5646
+ */
5647
+ function asPromise(fn, ctx/*, varargs */) {
5648
+ var params = new Array(arguments.length - 1),
5649
+ offset = 0,
5650
+ index = 2,
5651
+ pending = true;
5652
+ while (index < arguments.length)
5653
+ params[offset++] = arguments[index++];
5654
+ return new Promise(function executor(resolve, reject) {
5655
+ params[offset] = function callback(err/*, varargs */) {
5656
+ if (pending) {
5657
+ pending = false;
5658
+ if (err)
5659
+ reject(err);
5660
+ else {
5661
+ var params = new Array(arguments.length - 1),
5662
+ offset = 0;
5663
+ while (offset < params.length)
5664
+ params[offset++] = arguments[offset];
5665
+ resolve.apply(null, params);
5666
+ }
5667
+ }
5668
+ };
5669
+ try {
5670
+ fn.apply(ctx || null, params);
5671
+ } catch (err) {
5672
+ if (pending) {
5673
+ pending = false;
5674
+ reject(err);
5675
+ }
5676
+ }
5677
+ });
5678
+ }
6370
5679
 
6371
- /**
6372
- * Low bits.
6373
- * @type {number}
6374
- */
6375
- this.lo = lo >>> 0;
5680
+ },{}],26:[function(require,module,exports){
5681
+ "use strict";
6376
5682
 
6377
- /**
6378
- * High bits.
6379
- * @type {number}
6380
- */
6381
- this.hi = hi >>> 0;
6382
- }
5683
+ /**
5684
+ * A minimal base64 implementation for number arrays.
5685
+ * @memberof util
5686
+ * @namespace
5687
+ */
5688
+ var base64 = exports;
6383
5689
 
6384
5690
  /**
6385
- * Zero bits.
6386
- * @memberof util.LongBits
6387
- * @type {util.LongBits}
5691
+ * Calculates the byte length of a base64 encoded string.
5692
+ * @param {string} string Base64 encoded string
5693
+ * @returns {number} Byte length
6388
5694
  */
6389
- var zero = LongBits.zero = new LongBits(0, 0);
5695
+ base64.length = function length(string) {
5696
+ var p = string.length;
5697
+ if (!p)
5698
+ return 0;
5699
+ while (p > 0 && string.charAt(p - 1) === "=")
5700
+ --p;
5701
+ return Math.floor(p * 3 / 4);
5702
+ };
6390
5703
 
6391
- zero.toNumber = function() { return 0; };
6392
- zero.zzEncode = zero.zzDecode = function() { return this; };
6393
- zero.length = function() { return 1; };
5704
+ // Base64 encoding table
5705
+ var b64 = new Array(64);
5706
+
5707
+ // Base64 decoding table
5708
+ var s64 = new Array(123);
5709
+
5710
+ // 65..90, 97..122, 48..57, 43, 47
5711
+ for (var i = 0; i < 64;)
5712
+ s64[b64[i] = i < 26 ? i + 65 : i < 52 ? i + 71 : i < 62 ? i - 4 : i - 59 | 43] = i++;
5713
+
5714
+ s64[45] = 62; // - -> +
5715
+ s64[95] = 63; // _ -> /
6394
5716
 
6395
5717
  /**
6396
- * Zero hash.
6397
- * @memberof util.LongBits
6398
- * @type {string}
5718
+ * Encodes a buffer to a base64 encoded string.
5719
+ * @param {Uint8Array} buffer Source buffer
5720
+ * @param {number} start Source start
5721
+ * @param {number} end Source end
5722
+ * @returns {string} Base64 encoded string
6399
5723
  */
6400
- var zeroHash = LongBits.zeroHash = "\0\0\0\0\0\0\0\0";
5724
+ base64.encode = function encode(buffer, start, end) {
5725
+ var parts = null,
5726
+ chunk = [];
5727
+ var i = 0, // output index
5728
+ j = 0, // goto index
5729
+ t; // temporary
5730
+ while (start < end) {
5731
+ var b = buffer[start++];
5732
+ switch (j) {
5733
+ case 0:
5734
+ chunk[i++] = b64[b >> 2];
5735
+ t = (b & 3) << 4;
5736
+ j = 1;
5737
+ break;
5738
+ case 1:
5739
+ chunk[i++] = b64[t | b >> 4];
5740
+ t = (b & 15) << 2;
5741
+ j = 2;
5742
+ break;
5743
+ case 2:
5744
+ chunk[i++] = b64[t | b >> 6];
5745
+ chunk[i++] = b64[b & 63];
5746
+ j = 0;
5747
+ break;
5748
+ }
5749
+ if (i > 8191) {
5750
+ (parts || (parts = [])).push(String.fromCharCode.apply(String, chunk));
5751
+ i = 0;
5752
+ }
5753
+ }
5754
+ if (j) {
5755
+ chunk[i++] = b64[t];
5756
+ chunk[i++] = 61;
5757
+ if (j === 1)
5758
+ chunk[i++] = 61;
5759
+ }
5760
+ if (parts) {
5761
+ if (i)
5762
+ parts.push(String.fromCharCode.apply(String, chunk.slice(0, i)));
5763
+ return parts.join("");
5764
+ }
5765
+ return String.fromCharCode.apply(String, chunk.slice(0, i));
5766
+ };
5767
+
5768
+ var invalidEncoding = "invalid encoding";
6401
5769
 
6402
5770
  /**
6403
- * Constructs new long bits from the specified number.
6404
- * @param {number} value Value
6405
- * @returns {util.LongBits} Instance
5771
+ * Decodes a base64 encoded string to a buffer.
5772
+ * @param {string} string Source string
5773
+ * @param {Uint8Array} buffer Destination buffer
5774
+ * @param {number} offset Destination offset
5775
+ * @returns {number} Number of bytes written
5776
+ * @throws {Error} If encoding is invalid
6406
5777
  */
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;
5778
+ base64.decode = function decode(string, buffer, offset) {
5779
+ var start = offset;
5780
+ var j = 0, // goto index
5781
+ t; // temporary
5782
+ for (var i = 0; i < string.length;) {
5783
+ var c = string.charCodeAt(i++);
5784
+ if (c === 61 && j > 1)
5785
+ break;
5786
+ if ((c = s64[c]) === undefined)
5787
+ throw Error(invalidEncoding);
5788
+ switch (j) {
5789
+ case 0:
5790
+ t = c;
5791
+ j = 1;
5792
+ break;
5793
+ case 1:
5794
+ buffer[offset++] = t << 2 | (c & 48) >> 4;
5795
+ t = c;
5796
+ j = 2;
5797
+ break;
5798
+ case 2:
5799
+ buffer[offset++] = (t & 15) << 4 | (c & 60) >> 2;
5800
+ t = c;
5801
+ j = 3;
5802
+ break;
5803
+ case 3:
5804
+ buffer[offset++] = (t & 3) << 6 | c;
5805
+ j = 0;
5806
+ break;
6422
5807
  }
6423
5808
  }
6424
- return new LongBits(lo, hi);
5809
+ if (j === 1)
5810
+ throw Error(invalidEncoding);
5811
+ return offset - start;
5812
+ };
5813
+
5814
+ var base64Re = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,
5815
+ base64UrlRe = /[-_]/,
5816
+ base64UrlNoPaddingRe = /^(?:[A-Za-z0-9_-]{4})*(?:[A-Za-z0-9_-]{2}(?:==)?|[A-Za-z0-9_-]{3}=?)?$/;
5817
+
5818
+ /**
5819
+ * Tests if the specified string appears to be base64 encoded.
5820
+ * @param {string} string String to test
5821
+ * @returns {boolean} `true` if probably base64 encoded, otherwise false
5822
+ */
5823
+ base64.test = function test(string) {
5824
+ return base64Re.test(string)
5825
+ || base64UrlRe.test(string) && base64UrlNoPaddingRe.test(string);
5826
+ };
5827
+
5828
+ },{}],27:[function(require,module,exports){
5829
+ "use strict";
5830
+ module.exports = codegen;
5831
+
5832
+ var patterns = require(36);
5833
+ var reservedRe = patterns.reservedRe;
5834
+
5835
+ /**
5836
+ * Begins generating a function.
5837
+ * @memberof util
5838
+ * @param {string[]} functionParams Function parameter names
5839
+ * @param {string} [functionName] Function name if not anonymous
5840
+ * @returns {Codegen} Appender that appends code to the function's body
5841
+ */
5842
+ function codegen(functionParams, functionName) {
5843
+
5844
+ /* istanbul ignore if */
5845
+ if (typeof functionParams === "string") {
5846
+ functionName = functionParams;
5847
+ functionParams = undefined;
5848
+ }
5849
+
5850
+ var body = [];
5851
+
5852
+ /**
5853
+ * Appends code to the function's body or finishes generation.
5854
+ * @typedef Codegen
5855
+ * @type {function}
5856
+ * @param {string|Object.<string,*>} [formatStringOrScope] Format string or, to finish the function, an object of additional scope variables, if any
5857
+ * @param {...*} [formatParams] Format parameters
5858
+ * @returns {Codegen|Function} Itself or the generated function if finished
5859
+ * @throws {Error} If format parameter counts do not match
5860
+ */
5861
+
5862
+ function Codegen(formatStringOrScope) {
5863
+ // note that explicit array handling below makes this ~50% faster
5864
+
5865
+ // finish the function
5866
+ if (typeof formatStringOrScope !== "string") {
5867
+ var source = toString();
5868
+ if (codegen.verbose)
5869
+ console.log("codegen: " + source); // eslint-disable-line no-console
5870
+ source = "return " + source;
5871
+ if (formatStringOrScope) {
5872
+ var scopeKeys = Object.keys(formatStringOrScope),
5873
+ scopeParams = new Array(scopeKeys.length + 1),
5874
+ scopeValues = new Array(scopeKeys.length),
5875
+ scopeOffset = 0;
5876
+ while (scopeOffset < scopeKeys.length) {
5877
+ scopeParams[scopeOffset] = scopeKeys[scopeOffset];
5878
+ scopeValues[scopeOffset] = formatStringOrScope[scopeKeys[scopeOffset++]];
5879
+ }
5880
+ scopeParams[scopeOffset] = source;
5881
+ return Function.apply(null, scopeParams).apply(null, scopeValues); // eslint-disable-line no-new-func
5882
+ }
5883
+ return Function(source)(); // eslint-disable-line no-new-func
5884
+ }
5885
+
5886
+ // otherwise append to body
5887
+ var formatParams = new Array(arguments.length - 1),
5888
+ formatOffset = 0;
5889
+ while (formatOffset < formatParams.length)
5890
+ formatParams[formatOffset] = arguments[++formatOffset];
5891
+ formatOffset = 0;
5892
+ formatStringOrScope = formatStringOrScope.replace(/%([%dfijs])/g, function replace($0, $1) {
5893
+ var value = formatParams[formatOffset++];
5894
+ switch ($1) {
5895
+ case "d": case "f": return String(Number(value));
5896
+ case "i": return String(Math.floor(value));
5897
+ case "j": return JSON.stringify(value);
5898
+ case "s": return String(value);
5899
+ }
5900
+ return "%";
5901
+ });
5902
+ if (formatOffset !== formatParams.length)
5903
+ throw Error("parameter count mismatch");
5904
+ body.push(formatStringOrScope);
5905
+ return Codegen;
5906
+ }
5907
+
5908
+ function toString(functionNameOverride) {
5909
+ return "function " + safeFunctionName(functionNameOverride || functionName) + "(" + (functionParams && functionParams.join(",") || "") + "){\n " + body.join("\n ") + "\n}";
5910
+ }
5911
+
5912
+ Codegen.toString = toString;
5913
+ return Codegen;
5914
+ }
5915
+
5916
+ /**
5917
+ * Begins generating a function.
5918
+ * @memberof util
5919
+ * @function codegen
5920
+ * @param {string} [functionName] Function name if not anonymous
5921
+ * @returns {Codegen} Appender that appends code to the function's body
5922
+ * @variation 2
5923
+ */
5924
+
5925
+ /**
5926
+ * When set to `true`, codegen will log generated code to console. Useful for debugging.
5927
+ * @name util.codegen.verbose
5928
+ * @type {boolean}
5929
+ */
5930
+ codegen.verbose = false;
5931
+
5932
+ function safeFunctionName(name) {
5933
+ if (!name)
5934
+ return "";
5935
+ name = String(name).replace(/[^\w$]/g, "");
5936
+ if (!name)
5937
+ return "";
5938
+ if (/^\d/.test(name))
5939
+ name = "_" + name;
5940
+ return reservedRe.test(name) ? name + "_" : name;
5941
+ }
5942
+
5943
+ },{"36":36}],28:[function(require,module,exports){
5944
+ "use strict";
5945
+ module.exports = EventEmitter;
5946
+
5947
+ /**
5948
+ * Constructs a new event emitter instance.
5949
+ * @classdesc A minimal event emitter.
5950
+ * @memberof util
5951
+ * @constructor
5952
+ */
5953
+ function EventEmitter() {
5954
+
5955
+ /**
5956
+ * Registered listeners.
5957
+ * @type {Object.<string,*>}
5958
+ * @private
5959
+ */
5960
+ this._listeners = {};
5961
+ }
5962
+
5963
+ /**
5964
+ * Event listener as used by {@link util.EventEmitter}.
5965
+ * @typedef EventEmitterListener
5966
+ * @type {function}
5967
+ * @param {...*} args Arguments
5968
+ * @returns {undefined}
5969
+ */
5970
+
5971
+ /**
5972
+ * Registers an event listener.
5973
+ * @param {string} evt Event name
5974
+ * @param {EventEmitterListener} fn Listener
5975
+ * @param {*} [ctx] Listener context
5976
+ * @returns {this} `this`
5977
+ */
5978
+ EventEmitter.prototype.on = function on(evt, fn, ctx) {
5979
+ (this._listeners[evt] || (this._listeners[evt] = [])).push({
5980
+ fn : fn,
5981
+ ctx : ctx || this
5982
+ });
5983
+ return this;
5984
+ };
5985
+
5986
+ /**
5987
+ * Removes an event listener or any matching listeners if arguments are omitted.
5988
+ * @param {string} [evt] Event name. Removes all listeners if omitted.
5989
+ * @param {EventEmitterListener} [fn] Listener to remove. Removes all listeners of `evt` if omitted.
5990
+ * @returns {this} `this`
5991
+ */
5992
+ EventEmitter.prototype.off = function off(evt, fn) {
5993
+ if (evt === undefined)
5994
+ this._listeners = {};
5995
+ else {
5996
+ if (fn === undefined)
5997
+ this._listeners[evt] = [];
5998
+ else {
5999
+ var listeners = this._listeners[evt];
6000
+ for (var i = 0; i < listeners.length;)
6001
+ if (listeners[i].fn === fn)
6002
+ listeners.splice(i, 1);
6003
+ else
6004
+ ++i;
6005
+ }
6006
+ }
6007
+ return this;
6008
+ };
6009
+
6010
+ /**
6011
+ * Emits an event by calling its listeners with the specified arguments.
6012
+ * @param {string} evt Event name
6013
+ * @param {...*} args Arguments
6014
+ * @returns {this} `this`
6015
+ */
6016
+ EventEmitter.prototype.emit = function emit(evt) {
6017
+ var listeners = this._listeners[evt];
6018
+ if (listeners) {
6019
+ var args = [],
6020
+ i = 1;
6021
+ for (; i < arguments.length;)
6022
+ args.push(arguments[i++]);
6023
+ for (i = 0; i < listeners.length;)
6024
+ listeners[i].fn.apply(listeners[i++].ctx, args);
6025
+ }
6026
+ return this;
6027
+ };
6028
+
6029
+ },{}],29:[function(require,module,exports){
6030
+ "use strict";
6031
+ module.exports = fetch;
6032
+
6033
+ var asPromise = require(25),
6034
+ fs = require(31);
6035
+
6036
+ /**
6037
+ * Node-style callback as used by {@link util.fetch}.
6038
+ * @typedef FetchCallback
6039
+ * @type {function}
6040
+ * @param {?Error} error Error, if any, otherwise `null`
6041
+ * @param {string} [contents] File contents, if there hasn't been an error
6042
+ * @returns {undefined}
6043
+ */
6044
+
6045
+ /**
6046
+ * Options as used by {@link util.fetch}.
6047
+ * @interface IFetchOptions
6048
+ * @property {boolean} [binary=false] Whether expecting a binary response
6049
+ * @property {boolean} [xhr=false] If `true`, forces the use of XMLHttpRequest
6050
+ */
6051
+
6052
+ /**
6053
+ * Fetches the contents of a file.
6054
+ * @memberof util
6055
+ * @param {string} filename File path or url
6056
+ * @param {IFetchOptions} options Fetch options
6057
+ * @param {FetchCallback} callback Callback function
6058
+ * @returns {undefined}
6059
+ */
6060
+ function fetch(filename, options, callback) {
6061
+ if (typeof options === "function") {
6062
+ callback = options;
6063
+ options = {};
6064
+ } else if (!options)
6065
+ options = {};
6066
+
6067
+ if (!callback)
6068
+ return asPromise(fetch, this, filename, options); // eslint-disable-line no-invalid-this
6069
+
6070
+ // if a node-like filesystem is present, try it first but fall back to XHR if nothing is found.
6071
+ if (!options.xhr && fs && fs.readFile)
6072
+ return fs.readFile(filename, function fetchReadFileCallback(err, contents) {
6073
+ return err && typeof XMLHttpRequest !== "undefined"
6074
+ ? fetch.xhr(filename, options, callback)
6075
+ : err
6076
+ ? callback(err)
6077
+ : callback(null, options.binary ? contents : contents.toString("utf8"));
6078
+ });
6079
+
6080
+ // use the XHR version otherwise.
6081
+ return fetch.xhr(filename, options, callback);
6082
+ }
6083
+
6084
+ /**
6085
+ * Fetches the contents of a file.
6086
+ * @name util.fetch
6087
+ * @function
6088
+ * @param {string} path File path or url
6089
+ * @param {FetchCallback} callback Callback function
6090
+ * @returns {undefined}
6091
+ * @variation 2
6092
+ */
6093
+
6094
+ /**
6095
+ * Fetches the contents of a file.
6096
+ * @name util.fetch
6097
+ * @function
6098
+ * @param {string} path File path or url
6099
+ * @param {IFetchOptions} [options] Fetch options
6100
+ * @returns {Promise<string|Uint8Array>} Promise
6101
+ * @variation 3
6102
+ */
6103
+
6104
+ /**/
6105
+ fetch.xhr = function fetch_xhr(filename, options, callback) {
6106
+ var xhr = new XMLHttpRequest();
6107
+ xhr.onreadystatechange /* works everywhere */ = function fetchOnReadyStateChange() {
6108
+
6109
+ if (xhr.readyState !== 4)
6110
+ return undefined;
6111
+
6112
+ // local cors security errors return status 0 / empty string, too. afaik this cannot be
6113
+ // reliably distinguished from an actually empty file for security reasons. feel free
6114
+ // to send a pull request if you are aware of a solution.
6115
+ if (xhr.status !== 0 && xhr.status !== 200)
6116
+ return callback(Error("status " + xhr.status));
6117
+
6118
+ // if binary data is expected, make sure that some sort of array is returned, even if
6119
+ // ArrayBuffers are not supported. the binary string fallback, however, is unsafe.
6120
+ if (options.binary) {
6121
+ var buffer = xhr.response;
6122
+ if (!buffer) {
6123
+ buffer = [];
6124
+ for (var i = 0; i < xhr.responseText.length; ++i)
6125
+ buffer.push(xhr.responseText.charCodeAt(i) & 255);
6126
+ }
6127
+ return callback(null, typeof Uint8Array !== "undefined" ? new Uint8Array(buffer) : buffer);
6128
+ }
6129
+ return callback(null, xhr.responseText);
6130
+ };
6131
+
6132
+ if (options.binary) {
6133
+ // ref: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Sending_and_Receiving_Binary_Data#Receiving_binary_data_in_older_browsers
6134
+ if ("overrideMimeType" in xhr)
6135
+ xhr.overrideMimeType("text/plain; charset=x-user-defined");
6136
+ xhr.responseType = "arraybuffer";
6137
+ }
6138
+
6139
+ xhr.open("GET", filename);
6140
+ xhr.send();
6141
+ };
6142
+
6143
+ },{"25":25,"31":31}],30:[function(require,module,exports){
6144
+ "use strict";
6145
+
6146
+ module.exports = factory(factory);
6147
+
6148
+ /**
6149
+ * Reads / writes floats / doubles from / to buffers.
6150
+ * @name util.float
6151
+ * @namespace
6152
+ */
6153
+
6154
+ /**
6155
+ * Writes a 32 bit float to a buffer using little endian byte order.
6156
+ * @name util.float.writeFloatLE
6157
+ * @function
6158
+ * @param {number} val Value to write
6159
+ * @param {Uint8Array} buf Target buffer
6160
+ * @param {number} pos Target buffer offset
6161
+ * @returns {undefined}
6162
+ */
6163
+
6164
+ /**
6165
+ * Writes a 32 bit float to a buffer using big endian byte order.
6166
+ * @name util.float.writeFloatBE
6167
+ * @function
6168
+ * @param {number} val Value to write
6169
+ * @param {Uint8Array} buf Target buffer
6170
+ * @param {number} pos Target buffer offset
6171
+ * @returns {undefined}
6172
+ */
6173
+
6174
+ /**
6175
+ * Reads a 32 bit float from a buffer using little endian byte order.
6176
+ * @name util.float.readFloatLE
6177
+ * @function
6178
+ * @param {Uint8Array} buf Source buffer
6179
+ * @param {number} pos Source buffer offset
6180
+ * @returns {number} Value read
6181
+ */
6182
+
6183
+ /**
6184
+ * Reads a 32 bit float from a buffer using big endian byte order.
6185
+ * @name util.float.readFloatBE
6186
+ * @function
6187
+ * @param {Uint8Array} buf Source buffer
6188
+ * @param {number} pos Source buffer offset
6189
+ * @returns {number} Value read
6190
+ */
6191
+
6192
+ /**
6193
+ * Writes a 64 bit double to a buffer using little endian byte order.
6194
+ * @name util.float.writeDoubleLE
6195
+ * @function
6196
+ * @param {number} val Value to write
6197
+ * @param {Uint8Array} buf Target buffer
6198
+ * @param {number} pos Target buffer offset
6199
+ * @returns {undefined}
6200
+ */
6201
+
6202
+ /**
6203
+ * Writes a 64 bit double to a buffer using big endian byte order.
6204
+ * @name util.float.writeDoubleBE
6205
+ * @function
6206
+ * @param {number} val Value to write
6207
+ * @param {Uint8Array} buf Target buffer
6208
+ * @param {number} pos Target buffer offset
6209
+ * @returns {undefined}
6210
+ */
6211
+
6212
+ /**
6213
+ * Reads a 64 bit double from a buffer using little endian byte order.
6214
+ * @name util.float.readDoubleLE
6215
+ * @function
6216
+ * @param {Uint8Array} buf Source buffer
6217
+ * @param {number} pos Source buffer offset
6218
+ * @returns {number} Value read
6219
+ */
6220
+
6221
+ /**
6222
+ * Reads a 64 bit double from a buffer using big endian byte order.
6223
+ * @name util.float.readDoubleBE
6224
+ * @function
6225
+ * @param {Uint8Array} buf Source buffer
6226
+ * @param {number} pos Source buffer offset
6227
+ * @returns {number} Value read
6228
+ */
6229
+
6230
+ // Factory function for the purpose of node-based testing in modified global environments
6231
+ function factory(exports) {
6232
+
6233
+ // float: typed array
6234
+ if (typeof Float32Array !== "undefined") (function() {
6235
+
6236
+ var f32 = new Float32Array([ -0 ]),
6237
+ f8b = new Uint8Array(f32.buffer),
6238
+ le = f8b[3] === 128;
6239
+
6240
+ function writeFloat_f32_cpy(val, buf, pos) {
6241
+ f32[0] = val;
6242
+ buf[pos ] = f8b[0];
6243
+ buf[pos + 1] = f8b[1];
6244
+ buf[pos + 2] = f8b[2];
6245
+ buf[pos + 3] = f8b[3];
6246
+ }
6247
+
6248
+ function writeFloat_f32_rev(val, buf, pos) {
6249
+ f32[0] = val;
6250
+ buf[pos ] = f8b[3];
6251
+ buf[pos + 1] = f8b[2];
6252
+ buf[pos + 2] = f8b[1];
6253
+ buf[pos + 3] = f8b[0];
6254
+ }
6255
+
6256
+ /* istanbul ignore next */
6257
+ exports.writeFloatLE = le ? writeFloat_f32_cpy : writeFloat_f32_rev;
6258
+ /* istanbul ignore next */
6259
+ exports.writeFloatBE = le ? writeFloat_f32_rev : writeFloat_f32_cpy;
6260
+
6261
+ function readFloat_f32_cpy(buf, pos) {
6262
+ f8b[0] = buf[pos ];
6263
+ f8b[1] = buf[pos + 1];
6264
+ f8b[2] = buf[pos + 2];
6265
+ f8b[3] = buf[pos + 3];
6266
+ return f32[0];
6267
+ }
6268
+
6269
+ function readFloat_f32_rev(buf, pos) {
6270
+ f8b[3] = buf[pos ];
6271
+ f8b[2] = buf[pos + 1];
6272
+ f8b[1] = buf[pos + 2];
6273
+ f8b[0] = buf[pos + 3];
6274
+ return f32[0];
6275
+ }
6276
+
6277
+ /* istanbul ignore next */
6278
+ exports.readFloatLE = le ? readFloat_f32_cpy : readFloat_f32_rev;
6279
+ /* istanbul ignore next */
6280
+ exports.readFloatBE = le ? readFloat_f32_rev : readFloat_f32_cpy;
6281
+
6282
+ // float: ieee754
6283
+ })(); else (function() {
6284
+
6285
+ function writeFloat_ieee754(writeUint, val, buf, pos) {
6286
+ var sign = val < 0 ? 1 : 0;
6287
+ if (sign)
6288
+ val = -val;
6289
+ if (val === 0)
6290
+ writeUint(1 / val > 0 ? /* positive */ 0 : /* negative 0 */ 2147483648, buf, pos);
6291
+ else if (isNaN(val))
6292
+ writeUint(2143289344, buf, pos);
6293
+ else if (val > 3.4028234663852886e+38) // +-Infinity
6294
+ writeUint((sign << 31 | 2139095040) >>> 0, buf, pos);
6295
+ else if (val < 1.1754943508222875e-38) // denormal
6296
+ writeUint((sign << 31 | Math.round(val / 1.401298464324817e-45)) >>> 0, buf, pos);
6297
+ else {
6298
+ var exponent = Math.floor(Math.log(val) / Math.LN2),
6299
+ mantissa = Math.round(val * Math.pow(2, -exponent) * 8388608) & 8388607;
6300
+ writeUint((sign << 31 | exponent + 127 << 23 | mantissa) >>> 0, buf, pos);
6301
+ }
6302
+ }
6303
+
6304
+ exports.writeFloatLE = writeFloat_ieee754.bind(null, writeUintLE);
6305
+ exports.writeFloatBE = writeFloat_ieee754.bind(null, writeUintBE);
6306
+
6307
+ function readFloat_ieee754(readUint, buf, pos) {
6308
+ var uint = readUint(buf, pos),
6309
+ sign = (uint >> 31) * 2 + 1,
6310
+ exponent = uint >>> 23 & 255,
6311
+ mantissa = uint & 8388607;
6312
+ return exponent === 255
6313
+ ? mantissa
6314
+ ? NaN
6315
+ : sign * Infinity
6316
+ : exponent === 0 // denormal
6317
+ ? sign * 1.401298464324817e-45 * mantissa
6318
+ : sign * Math.pow(2, exponent - 150) * (mantissa + 8388608);
6319
+ }
6320
+
6321
+ exports.readFloatLE = readFloat_ieee754.bind(null, readUintLE);
6322
+ exports.readFloatBE = readFloat_ieee754.bind(null, readUintBE);
6323
+
6324
+ })();
6325
+
6326
+ // double: typed array
6327
+ if (typeof Float64Array !== "undefined") (function() {
6328
+
6329
+ var f64 = new Float64Array([-0]),
6330
+ f8b = new Uint8Array(f64.buffer),
6331
+ le = f8b[7] === 128;
6332
+
6333
+ function writeDouble_f64_cpy(val, buf, pos) {
6334
+ f64[0] = val;
6335
+ buf[pos ] = f8b[0];
6336
+ buf[pos + 1] = f8b[1];
6337
+ buf[pos + 2] = f8b[2];
6338
+ buf[pos + 3] = f8b[3];
6339
+ buf[pos + 4] = f8b[4];
6340
+ buf[pos + 5] = f8b[5];
6341
+ buf[pos + 6] = f8b[6];
6342
+ buf[pos + 7] = f8b[7];
6343
+ }
6344
+
6345
+ function writeDouble_f64_rev(val, buf, pos) {
6346
+ f64[0] = val;
6347
+ buf[pos ] = f8b[7];
6348
+ buf[pos + 1] = f8b[6];
6349
+ buf[pos + 2] = f8b[5];
6350
+ buf[pos + 3] = f8b[4];
6351
+ buf[pos + 4] = f8b[3];
6352
+ buf[pos + 5] = f8b[2];
6353
+ buf[pos + 6] = f8b[1];
6354
+ buf[pos + 7] = f8b[0];
6355
+ }
6356
+
6357
+ /* istanbul ignore next */
6358
+ exports.writeDoubleLE = le ? writeDouble_f64_cpy : writeDouble_f64_rev;
6359
+ /* istanbul ignore next */
6360
+ exports.writeDoubleBE = le ? writeDouble_f64_rev : writeDouble_f64_cpy;
6361
+
6362
+ function readDouble_f64_cpy(buf, pos) {
6363
+ f8b[0] = buf[pos ];
6364
+ f8b[1] = buf[pos + 1];
6365
+ f8b[2] = buf[pos + 2];
6366
+ f8b[3] = buf[pos + 3];
6367
+ f8b[4] = buf[pos + 4];
6368
+ f8b[5] = buf[pos + 5];
6369
+ f8b[6] = buf[pos + 6];
6370
+ f8b[7] = buf[pos + 7];
6371
+ return f64[0];
6372
+ }
6373
+
6374
+ function readDouble_f64_rev(buf, pos) {
6375
+ f8b[7] = buf[pos ];
6376
+ f8b[6] = buf[pos + 1];
6377
+ f8b[5] = buf[pos + 2];
6378
+ f8b[4] = buf[pos + 3];
6379
+ f8b[3] = buf[pos + 4];
6380
+ f8b[2] = buf[pos + 5];
6381
+ f8b[1] = buf[pos + 6];
6382
+ f8b[0] = buf[pos + 7];
6383
+ return f64[0];
6384
+ }
6385
+
6386
+ /* istanbul ignore next */
6387
+ exports.readDoubleLE = le ? readDouble_f64_cpy : readDouble_f64_rev;
6388
+ /* istanbul ignore next */
6389
+ exports.readDoubleBE = le ? readDouble_f64_rev : readDouble_f64_cpy;
6390
+
6391
+ // double: ieee754
6392
+ })(); else (function() {
6393
+
6394
+ function writeDouble_ieee754(writeUint, off0, off1, val, buf, pos) {
6395
+ var sign = val < 0 ? 1 : 0;
6396
+ if (sign)
6397
+ val = -val;
6398
+ if (val === 0) {
6399
+ writeUint(0, buf, pos + off0);
6400
+ writeUint(1 / val > 0 ? /* positive */ 0 : /* negative 0 */ 2147483648, buf, pos + off1);
6401
+ } else if (isNaN(val)) {
6402
+ writeUint(0, buf, pos + off0);
6403
+ writeUint(2146959360, buf, pos + off1);
6404
+ } else if (val > 1.7976931348623157e+308) { // +-Infinity
6405
+ writeUint(0, buf, pos + off0);
6406
+ writeUint((sign << 31 | 2146435072) >>> 0, buf, pos + off1);
6407
+ } else {
6408
+ var mantissa;
6409
+ if (val < 2.2250738585072014e-308) { // denormal
6410
+ mantissa = val / 5e-324;
6411
+ writeUint(mantissa >>> 0, buf, pos + off0);
6412
+ writeUint((sign << 31 | mantissa / 4294967296) >>> 0, buf, pos + off1);
6413
+ } else {
6414
+ var exponent = Math.floor(Math.log(val) / Math.LN2);
6415
+ if (exponent === 1024)
6416
+ exponent = 1023;
6417
+ mantissa = val * Math.pow(2, -exponent);
6418
+ writeUint(mantissa * 4503599627370496 >>> 0, buf, pos + off0);
6419
+ writeUint((sign << 31 | exponent + 1023 << 20 | mantissa * 1048576 & 1048575) >>> 0, buf, pos + off1);
6420
+ }
6421
+ }
6422
+ }
6423
+
6424
+ exports.writeDoubleLE = writeDouble_ieee754.bind(null, writeUintLE, 0, 4);
6425
+ exports.writeDoubleBE = writeDouble_ieee754.bind(null, writeUintBE, 4, 0);
6426
+
6427
+ function readDouble_ieee754(readUint, off0, off1, buf, pos) {
6428
+ var lo = readUint(buf, pos + off0),
6429
+ hi = readUint(buf, pos + off1);
6430
+ var sign = (hi >> 31) * 2 + 1,
6431
+ exponent = hi >>> 20 & 2047,
6432
+ mantissa = 4294967296 * (hi & 1048575) + lo;
6433
+ return exponent === 2047
6434
+ ? mantissa
6435
+ ? NaN
6436
+ : sign * Infinity
6437
+ : exponent === 0 // denormal
6438
+ ? sign * 5e-324 * mantissa
6439
+ : sign * Math.pow(2, exponent - 1075) * (mantissa + 4503599627370496);
6440
+ }
6441
+
6442
+ exports.readDoubleLE = readDouble_ieee754.bind(null, readUintLE, 0, 4);
6443
+ exports.readDoubleBE = readDouble_ieee754.bind(null, readUintBE, 4, 0);
6444
+
6445
+ })();
6446
+
6447
+ return exports;
6448
+ }
6449
+
6450
+ // uint helpers
6451
+
6452
+ function writeUintLE(val, buf, pos) {
6453
+ buf[pos ] = val & 255;
6454
+ buf[pos + 1] = val >>> 8 & 255;
6455
+ buf[pos + 2] = val >>> 16 & 255;
6456
+ buf[pos + 3] = val >>> 24;
6457
+ }
6458
+
6459
+ function writeUintBE(val, buf, pos) {
6460
+ buf[pos ] = val >>> 24;
6461
+ buf[pos + 1] = val >>> 16 & 255;
6462
+ buf[pos + 2] = val >>> 8 & 255;
6463
+ buf[pos + 3] = val & 255;
6464
+ }
6465
+
6466
+ function readUintLE(buf, pos) {
6467
+ return (buf[pos ]
6468
+ | buf[pos + 1] << 8
6469
+ | buf[pos + 2] << 16
6470
+ | buf[pos + 3] << 24) >>> 0;
6471
+ }
6472
+
6473
+ function readUintBE(buf, pos) {
6474
+ return (buf[pos ] << 24
6475
+ | buf[pos + 1] << 16
6476
+ | buf[pos + 2] << 8
6477
+ | buf[pos + 3]) >>> 0;
6478
+ }
6479
+
6480
+ },{}],31:[function(require,module,exports){
6481
+ "use strict";
6482
+
6483
+ var fs = null;
6484
+ try {
6485
+ fs = require(1);
6486
+ if (!fs || !fs.readFile || !fs.readFileSync)
6487
+ fs = null;
6488
+ } catch (e) {
6489
+ // `fs` is unavailable in browsers and browser-like bundles.
6490
+ }
6491
+ module.exports = fs;
6492
+
6493
+ },{"1":1}],32:[function(require,module,exports){
6494
+ "use strict";
6495
+ module.exports = inquire;
6496
+
6497
+ /**
6498
+ * Requires a module only if available.
6499
+ * @memberof util
6500
+ * @param {string} moduleName Module to require
6501
+ * @returns {?Object} Required module if available and not empty, otherwise `null`
6502
+ * @deprecated Legacy optional require helper. Will be removed in a future release.
6503
+ */
6504
+ function inquire(moduleName) {
6505
+ try {
6506
+ if (typeof require !== "function") {
6507
+ return null;
6508
+ }
6509
+ var mod = require(moduleName);
6510
+ if (mod && (mod.length || Object.keys(mod).length)) return mod;
6511
+ return null;
6512
+ } catch (err) {
6513
+ // ignore
6514
+ return null;
6515
+ }
6516
+ }
6517
+
6518
+ /*
6519
+ // maybe worth a shot to prevent renaming issues:
6520
+ // see: https://github.com/webpack/webpack/blob/master/lib/dependencies/CommonJsRequireDependencyParserPlugin.js
6521
+ // triggers on:
6522
+ // - expression require.cache
6523
+ // - expression require (???)
6524
+ // - call require
6525
+ // - call require:commonjs:item
6526
+ // - call require:commonjs:context
6527
+
6528
+ Object.defineProperty(Function.prototype, "__self", { get: function() { return this; } });
6529
+ var r = require.__self;
6530
+ delete Function.prototype.__self;
6531
+ */
6532
+
6533
+ },{}],33:[function(require,module,exports){
6534
+ "use strict";
6535
+ module.exports = LongBits;
6536
+
6537
+ var util = require(34);
6538
+
6539
+ /**
6540
+ * Constructs new long bits.
6541
+ * @classdesc Helper class for working with the low and high bits of a 64 bit value.
6542
+ * @memberof util
6543
+ * @constructor
6544
+ * @param {number} lo Low 32 bits, unsigned
6545
+ * @param {number} hi High 32 bits, unsigned
6546
+ */
6547
+ function LongBits(lo, hi) {
6548
+
6549
+ // note that the casts below are theoretically unnecessary as of today, but older statically
6550
+ // generated converter code might still call the ctor with signed 32bits. kept for compat.
6551
+
6552
+ /**
6553
+ * Low bits.
6554
+ * @type {number}
6555
+ */
6556
+ this.lo = lo >>> 0;
6557
+
6558
+ /**
6559
+ * High bits.
6560
+ * @type {number}
6561
+ */
6562
+ this.hi = hi >>> 0;
6563
+ }
6564
+
6565
+ /**
6566
+ * Zero bits.
6567
+ * @memberof util.LongBits
6568
+ * @type {util.LongBits}
6569
+ */
6570
+ var zero = LongBits.zero = new LongBits(0, 0);
6571
+
6572
+ zero.toNumber = function() { return 0; };
6573
+ zero.zzEncode = zero.zzDecode = function() { return this; };
6574
+ zero.length = function() { return 1; };
6575
+
6576
+ /**
6577
+ * Zero hash.
6578
+ * @memberof util.LongBits
6579
+ * @type {string}
6580
+ */
6581
+ var zeroHash = LongBits.zeroHash = "\0\0\0\0\0\0\0\0";
6582
+
6583
+ /**
6584
+ * Constructs new long bits from the specified number.
6585
+ * @param {number} value Value
6586
+ * @returns {util.LongBits} Instance
6587
+ */
6588
+ LongBits.fromNumber = function fromNumber(value) {
6589
+ if (value === 0)
6590
+ return zero;
6591
+ var sign = value < 0;
6592
+ if (sign)
6593
+ value = -value;
6594
+ var lo = value >>> 0,
6595
+ hi = (value - lo) / 4294967296 >>> 0;
6596
+ if (sign) {
6597
+ hi = ~hi >>> 0;
6598
+ lo = ~lo >>> 0;
6599
+ if (++lo > 4294967295) {
6600
+ lo = 0;
6601
+ if (++hi > 4294967295)
6602
+ hi = 0;
6603
+ }
6604
+ }
6605
+ return new LongBits(lo, hi);
6425
6606
  };
6426
6607
 
6427
6608
  /**
@@ -6551,33 +6732,33 @@ LongBits.prototype.length = function length() {
6551
6732
  : part2 < 128 ? 9 : 10;
6552
6733
  };
6553
6734
 
6554
- },{"35":35}],35:[function(require,module,exports){
6735
+ },{"34":34}],34:[function(require,module,exports){
6555
6736
  "use strict";
6556
6737
  var util = exports;
6557
6738
 
6558
6739
  // used to return a Promise where callback is omitted
6559
- util.asPromise = require(1);
6740
+ util.asPromise = require(25);
6560
6741
 
6561
6742
  // converts to / from base64 encoded strings
6562
- util.base64 = require(2);
6743
+ util.base64 = require(26);
6563
6744
 
6564
6745
  // base class of rpc.Service
6565
- util.EventEmitter = require(4);
6746
+ util.EventEmitter = require(28);
6566
6747
 
6567
6748
  // float handling accross browsers
6568
- util.float = require(6);
6749
+ util.float = require(30);
6569
6750
 
6570
6751
  // requires modules optionally and hides the call from bundlers
6571
- util.inquire = require(7);
6752
+ util.inquire = require(32);
6572
6753
 
6573
6754
  // converts to / from utf8 encoded strings
6574
- util.utf8 = require(10);
6755
+ util.utf8 = require(38);
6575
6756
 
6576
6757
  // provides a node-like buffer pool in the browser
6577
- util.pool = require(9);
6758
+ util.pool = require(37);
6578
6759
 
6579
6760
  // utility to work with the low and high bits of a 64 bit value
6580
- util.LongBits = require(34);
6761
+ util.LongBits = require(33);
6581
6762
 
6582
6763
  /**
6583
6764
  * Whether running within node or not.
@@ -6679,7 +6860,7 @@ util.isSet = function isSet(obj, prop) {
6679
6860
  */
6680
6861
  util.Buffer = (function() {
6681
6862
  try {
6682
- var Buffer = util.inquire("buffer").Buffer;
6863
+ var Buffer = util.global.Buffer;
6683
6864
  // refuse to use non-node buffers if not explicitly assigned (perf reasons):
6684
6865
  return Buffer.prototype.utf8Write ? Buffer : /* istanbul ignore next */ null;
6685
6866
  } catch (e) {
@@ -6733,14 +6914,22 @@ util.Array = typeof Uint8Array !== "undefined" ? Uint8Array /* istanbul ignore n
6733
6914
  */
6734
6915
  util.Long = /* istanbul ignore next */ util.global.dcodeIO && /* istanbul ignore next */ util.global.dcodeIO.Long
6735
6916
  || /* istanbul ignore next */ util.global.Long
6736
- || util.inquire("long");
6917
+ || (function() {
6918
+ try {
6919
+ var Long = require("long");
6920
+ return Long && Long.isLong ? Long : null;
6921
+ } catch (e) {
6922
+ /* istanbul ignore next */
6923
+ return null;
6924
+ }
6925
+ })();
6737
6926
 
6738
6927
  /**
6739
6928
  * Regular expression used to verify 2 bit (`bool`) map keys.
6740
6929
  * @type {RegExp}
6741
6930
  * @const
6742
6931
  */
6743
- util.key2Re = /^true|false|0|1$/;
6932
+ util.key2Re = /^(?:true|false|0|1)$/;
6744
6933
 
6745
6934
  /**
6746
6935
  * Regular expression used to verify 32 bit (`int32` etc.) map keys.
@@ -6754,7 +6943,7 @@ util.key32Re = /^-?(?:0|[1-9][0-9]*)$/;
6754
6943
  * @type {RegExp}
6755
6944
  * @const
6756
6945
  */
6757
- util.key64Re = /^(?:[\\x00-\\xff]{8}|-?(?:0|[1-9][0-9]*))$/;
6946
+ util.key64Re = /^(?:[\x00-\xff]{8}|-?(?:0|[1-9][0-9]*))$/; // eslint-disable-line no-control-regex
6758
6947
 
6759
6948
  /**
6760
6949
  * Converts a number or long to an 8 characters long hash string.
@@ -6780,6 +6969,27 @@ util.longFromHash = function longFromHash(hash, unsigned) {
6780
6969
  return bits.toNumber(Boolean(unsigned));
6781
6970
  };
6782
6971
 
6972
+ /**
6973
+ * Converts a 64 bit key to a long or number if it is an 8 characters long hash string.
6974
+ * @param {string} key Map key
6975
+ * @param {boolean} [unsigned=false] Whether unsigned or not
6976
+ * @returns {Long|number|string} Original value
6977
+ */
6978
+ util.longFromKey = function longFromKey(key, unsigned) {
6979
+ return util.key64Re.test(key) && !util.key32Re.test(key)
6980
+ ? util.longFromHash(key, unsigned)
6981
+ : key;
6982
+ };
6983
+
6984
+ /**
6985
+ * Converts a boolean key to a boolean value.
6986
+ * @param {string} key Map key
6987
+ * @returns {boolean} Boolean value
6988
+ */
6989
+ util.boolFromKey = function boolFromKey(key) {
6990
+ return key === "true" || key === "1";
6991
+ };
6992
+
6783
6993
  /**
6784
6994
  * Merges the properties of the source object into the destination object.
6785
6995
  * @memberof util
@@ -6791,12 +7001,45 @@ util.longFromHash = function longFromHash(hash, unsigned) {
6791
7001
  function merge(dst, src, ifNotSet) { // used by converters
6792
7002
  for (var keys = Object.keys(src), i = 0; i < keys.length; ++i)
6793
7003
  if (dst[keys[i]] === undefined || !ifNotSet)
6794
- dst[keys[i]] = src[keys[i]];
7004
+ if (keys[i] !== "__proto__")
7005
+ dst[keys[i]] = src[keys[i]];
6795
7006
  return dst;
6796
7007
  }
6797
7008
 
6798
7009
  util.merge = merge;
6799
7010
 
7011
+ /**
7012
+ * Schema declaration nesting limit.
7013
+ * @memberof util
7014
+ * @type {number}
7015
+ */
7016
+ util.nestingLimit = 32; // protoc: MaxMessageDeclarationNestingDepth
7017
+
7018
+ /**
7019
+ * Recursion limit.
7020
+ * @memberof util
7021
+ * @type {number}
7022
+ */
7023
+ util.recursionLimit = 100; // protoc: CodedInputStream::default_recursion_limit_
7024
+
7025
+ /**
7026
+ * Makes a property safe for assignment as an own property.
7027
+ * @memberof util
7028
+ * @param {Object.<string,*>} obj Object
7029
+ * @param {string} key Property key
7030
+ * @param {boolean} [enumerable=true] Whether the property should be enumerable
7031
+ * @returns {undefined}
7032
+ */
7033
+ util.makeProp = function makeProp(obj, key, enumerable) {
7034
+ if (Object.prototype.hasOwnProperty.call(obj, key))
7035
+ return;
7036
+ Object.defineProperty(obj, key, {
7037
+ enumerable: enumerable === undefined ? true : enumerable,
7038
+ configurable: true,
7039
+ writable: true
7040
+ });
7041
+ };
7042
+
6800
7043
  /**
6801
7044
  * Converts the first character of a string to lower case.
6802
7045
  * @param {string} str String to convert
@@ -6991,12 +7234,278 @@ util._configure = function() {
6991
7234
  };
6992
7235
  };
6993
7236
 
6994
- },{"1":1,"10":10,"2":2,"34":34,"4":4,"6":6,"7":7,"9":9}],36:[function(require,module,exports){
7237
+ },{"25":25,"26":26,"28":28,"30":30,"32":32,"33":33,"37":37,"38":38,"long":"long"}],35:[function(require,module,exports){
7238
+ "use strict";
7239
+
7240
+ /**
7241
+ * A minimal path module to resolve Unix, Windows and URL paths alike.
7242
+ * @memberof util
7243
+ * @namespace
7244
+ */
7245
+ var path = exports;
7246
+
7247
+ var isAbsolute =
7248
+ /**
7249
+ * Tests if the specified path is absolute.
7250
+ * @param {string} path Path to test
7251
+ * @returns {boolean} `true` if path is absolute
7252
+ */
7253
+ path.isAbsolute = function isAbsolute(path) {
7254
+ return /^(?:\/|\w+:|\\\\\w+)/.test(path);
7255
+ };
7256
+
7257
+ var normalize =
7258
+ /**
7259
+ * Normalizes the specified path.
7260
+ * @param {string} path Path to normalize
7261
+ * @returns {string} Normalized path
7262
+ */
7263
+ path.normalize = function normalize(path) {
7264
+ var firstTwoCharacters = path.substring(0,2);
7265
+ var uncPrefix = "";
7266
+ if (firstTwoCharacters === "\\\\") {
7267
+ uncPrefix = firstTwoCharacters;
7268
+ path = path.substring(2);
7269
+ }
7270
+
7271
+ path = path.replace(/\\/g, "/")
7272
+ .replace(/\/{2,}/g, "/");
7273
+ var parts = path.split("/"),
7274
+ absolute = isAbsolute(path),
7275
+ prefix = "";
7276
+ if (absolute)
7277
+ prefix = parts.shift() + "/";
7278
+ for (var i = 0; i < parts.length;) {
7279
+ if (parts[i] === "..") {
7280
+ if (i > 0 && parts[i - 1] !== "..")
7281
+ parts.splice(--i, 2);
7282
+ else if (absolute)
7283
+ parts.splice(i, 1);
7284
+ else
7285
+ ++i;
7286
+ } else if (parts[i] === ".")
7287
+ parts.splice(i, 1);
7288
+ else
7289
+ ++i;
7290
+ }
7291
+ return uncPrefix + prefix + parts.join("/");
7292
+ };
7293
+
7294
+ /**
7295
+ * Resolves the specified include path against the specified origin path.
7296
+ * @param {string} originPath Path to the origin file
7297
+ * @param {string} includePath Include path relative to origin path
7298
+ * @param {boolean} [alreadyNormalized=false] `true` if both paths are already known to be normalized
7299
+ * @returns {string} Path to the include file
7300
+ */
7301
+ path.resolve = function resolve(originPath, includePath, alreadyNormalized) {
7302
+ if (!alreadyNormalized)
7303
+ includePath = normalize(includePath);
7304
+ if (isAbsolute(includePath))
7305
+ return includePath;
7306
+ if (!alreadyNormalized)
7307
+ originPath = normalize(originPath);
7308
+ return (originPath = originPath.replace(/(?:\/|^)[^/]+$/, "")).length ? normalize(originPath + "/" + includePath) : includePath;
7309
+ };
7310
+
7311
+ },{}],36:[function(require,module,exports){
7312
+ "use strict";
7313
+
7314
+ var patterns = exports;
7315
+
7316
+ patterns.numberRe = /^(?![eE])[0-9]*(?:\.[0-9]*)?(?:[eE][+-]?[0-9]+)?$/;
7317
+ patterns.typeRefRe = /^(?:\.?[a-zA-Z_][a-zA-Z_0-9]*)(?:\.[a-zA-Z_][a-zA-Z_0-9]*)*$/;
7318
+ 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)$/;
7319
+ patterns.unsafePropertyRe = /^(?:__proto__|prototype|constructor)$/;
7320
+
7321
+ },{}],37:[function(require,module,exports){
7322
+ "use strict";
7323
+ module.exports = pool;
7324
+
7325
+ /**
7326
+ * An allocator as used by {@link util.pool}.
7327
+ * @typedef PoolAllocator
7328
+ * @type {function}
7329
+ * @param {number} size Buffer size
7330
+ * @returns {Uint8Array} Buffer
7331
+ */
7332
+
7333
+ /**
7334
+ * A slicer as used by {@link util.pool}.
7335
+ * @typedef PoolSlicer
7336
+ * @type {function}
7337
+ * @param {number} start Start offset
7338
+ * @param {number} end End offset
7339
+ * @returns {Uint8Array} Buffer slice
7340
+ * @this {Uint8Array}
7341
+ */
7342
+
7343
+ /**
7344
+ * A general purpose buffer pool.
7345
+ * @memberof util
7346
+ * @function
7347
+ * @param {PoolAllocator} alloc Allocator
7348
+ * @param {PoolSlicer} slice Slicer
7349
+ * @param {number} [size=8192] Slab size
7350
+ * @returns {PoolAllocator} Pooled allocator
7351
+ */
7352
+ function pool(alloc, slice, size) {
7353
+ var SIZE = size || 8192;
7354
+ var MAX = SIZE >>> 1;
7355
+ var slab = null;
7356
+ var offset = SIZE;
7357
+ return function pool_alloc(size) {
7358
+ if (size < 1 || size > MAX)
7359
+ return alloc(size);
7360
+ if (offset + size > SIZE) {
7361
+ slab = alloc(SIZE);
7362
+ offset = 0;
7363
+ }
7364
+ var buf = slice.call(slab, offset, offset += size);
7365
+ if (offset & 7) // align to 32 bit
7366
+ offset = (offset | 7) + 1;
7367
+ return buf;
7368
+ };
7369
+ }
7370
+
7371
+ },{}],38:[function(require,module,exports){
7372
+ "use strict";
7373
+
7374
+ /**
7375
+ * A minimal UTF8 implementation for number arrays.
7376
+ * @memberof util
7377
+ * @namespace
7378
+ */
7379
+ var utf8 = exports,
7380
+ replacementChar = "\ufffd";
7381
+
7382
+ /**
7383
+ * Calculates the UTF8 byte length of a string.
7384
+ * @param {string} string String
7385
+ * @returns {number} Byte length
7386
+ */
7387
+ utf8.length = function utf8_length(string) {
7388
+ var len = 0,
7389
+ c = 0;
7390
+ for (var i = 0; i < string.length; ++i) {
7391
+ c = string.charCodeAt(i);
7392
+ if (c < 128)
7393
+ len += 1;
7394
+ else if (c < 2048)
7395
+ len += 2;
7396
+ else if ((c & 0xFC00) === 0xD800 && (string.charCodeAt(i + 1) & 0xFC00) === 0xDC00) {
7397
+ ++i;
7398
+ len += 4;
7399
+ } else
7400
+ len += 3;
7401
+ }
7402
+ return len;
7403
+ };
7404
+
7405
+ function utf8_read_js(buffer, start, end, str) {
7406
+ for (var i = start; i < end;) {
7407
+ var t = buffer[i++];
7408
+ if (t <= 0x7F) {
7409
+ str += String.fromCharCode(t);
7410
+ } else if (t >= 0xC0 && t < 0xE0) {
7411
+ var c2 = (t & 0x1F) << 6 | buffer[i++] & 0x3F;
7412
+ str += c2 >= 0x80 ? String.fromCharCode(c2) : replacementChar;
7413
+ } else if (t >= 0xE0 && t < 0xF0) {
7414
+ var c3 = (t & 0xF) << 12 | (buffer[i++] & 0x3F) << 6 | buffer[i++] & 0x3F;
7415
+ str += c3 >= 0x800 ? String.fromCharCode(c3) : replacementChar;
7416
+ } else if (t >= 0xF0) {
7417
+ var t2 = (t & 7) << 18 | (buffer[i++] & 0x3F) << 12 | (buffer[i++] & 0x3F) << 6 | buffer[i++] & 0x3F;
7418
+ if (t2 < 0x10000 || t2 > 0x10FFFF)
7419
+ str += replacementChar;
7420
+ else {
7421
+ t2 -= 0x10000;
7422
+ str += String.fromCharCode(0xD800 + (t2 >> 10));
7423
+ str += String.fromCharCode(0xDC00 + (t2 & 0x3FF));
7424
+ }
7425
+ }
7426
+ }
7427
+ return str;
7428
+ }
7429
+
7430
+ /**
7431
+ * Reads UTF8 bytes as a string.
7432
+ * @param {Uint8Array} buffer Source buffer
7433
+ * @param {number} start Source start
7434
+ * @param {number} end Source end
7435
+ * @returns {string} String read
7436
+ */
7437
+ utf8.read = function utf8_read_ascii(buffer, start, end) {
7438
+ if (end - start < 1)
7439
+ return "";
7440
+
7441
+ var str = "",
7442
+ i = start,
7443
+ c1, c2, c3, c4, c5, c6, c7, c8;
7444
+
7445
+ for (; i + 7 < end; i += 8) {
7446
+ c1 = buffer[i];
7447
+ c2 = buffer[i + 1];
7448
+ c3 = buffer[i + 2];
7449
+ c4 = buffer[i + 3];
7450
+ c5 = buffer[i + 4];
7451
+ c6 = buffer[i + 5];
7452
+ c7 = buffer[i + 6];
7453
+ c8 = buffer[i + 7];
7454
+ if ((c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8) & 0x80)
7455
+ return utf8_read_js(buffer, i, end, str);
7456
+ str += String.fromCharCode(c1, c2, c3, c4, c5, c6, c7, c8);
7457
+ }
7458
+
7459
+ for (; i < end; ++i) {
7460
+ c1 = buffer[i];
7461
+ if (c1 & 0x80)
7462
+ return utf8_read_js(buffer, i, end, str);
7463
+ str += String.fromCharCode(c1);
7464
+ }
7465
+
7466
+ return str;
7467
+ };
7468
+
7469
+ /**
7470
+ * Writes a string as UTF8 bytes.
7471
+ * @param {string} string Source string
7472
+ * @param {Uint8Array} buffer Destination buffer
7473
+ * @param {number} offset Destination offset
7474
+ * @returns {number} Bytes written
7475
+ */
7476
+ utf8.write = function utf8_write(string, buffer, offset) {
7477
+ var start = offset,
7478
+ c1, // character 1
7479
+ c2; // character 2
7480
+ for (var i = 0; i < string.length; ++i) {
7481
+ c1 = string.charCodeAt(i);
7482
+ if (c1 < 128) {
7483
+ buffer[offset++] = c1;
7484
+ } else if (c1 < 2048) {
7485
+ buffer[offset++] = c1 >> 6 | 192;
7486
+ buffer[offset++] = c1 & 63 | 128;
7487
+ } else if ((c1 & 0xFC00) === 0xD800 && ((c2 = string.charCodeAt(i + 1)) & 0xFC00) === 0xDC00) {
7488
+ c1 = 0x10000 + ((c1 & 0x03FF) << 10) + (c2 & 0x03FF);
7489
+ ++i;
7490
+ buffer[offset++] = c1 >> 18 | 240;
7491
+ buffer[offset++] = c1 >> 12 & 63 | 128;
7492
+ buffer[offset++] = c1 >> 6 & 63 | 128;
7493
+ buffer[offset++] = c1 & 63 | 128;
7494
+ } else {
7495
+ buffer[offset++] = c1 >> 12 | 224;
7496
+ buffer[offset++] = c1 >> 6 & 63 | 128;
7497
+ buffer[offset++] = c1 & 63 | 128;
7498
+ }
7499
+ }
7500
+ return offset - start;
7501
+ };
7502
+
7503
+ },{}],39:[function(require,module,exports){
6995
7504
  "use strict";
6996
7505
  module.exports = verifier;
6997
7506
 
6998
- var Enum = require(14),
6999
- util = require(33);
7507
+ var Enum = require(5),
7508
+ util = require(24);
7000
7509
 
7001
7510
  function invalid(field, expected) {
7002
7511
  return field.name + ": " + expected + (field.repeated && expected !== "array" ? "[]" : field.map && expected !== "object" ? "{k:"+field.keyType+"}" : "") + " expected";
@@ -7026,7 +7535,7 @@ function genVerifyValue(gen, field, fieldIndex, ref) {
7026
7535
  } else {
7027
7536
  gen
7028
7537
  ("{")
7029
- ("var e=types[%i].verify(%s);", fieldIndex, ref)
7538
+ ("var e=types[%i].verify(%s,q+1);", fieldIndex, ref)
7030
7539
  ("if(e)")
7031
7540
  ("return%j+e", field.name + ".")
7032
7541
  ("}");
@@ -7116,9 +7625,12 @@ function genVerifyKey(gen, field, ref) {
7116
7625
  function verifier(mtype) {
7117
7626
  /* eslint-disable no-unexpected-multiline */
7118
7627
 
7119
- var gen = util.codegen(["m"], mtype.name + "$verify")
7628
+ var gen = util.codegen(["m", "q"], mtype.name + "$verify")
7120
7629
  ("if(typeof m!==\"object\"||m===null)")
7121
- ("return%j", "object expected");
7630
+ ("return%j", "object expected")
7631
+ ("if(q===undefined)q=0")
7632
+ ("if(q>util.recursionLimit)")
7633
+ ("return%j", "max depth exceeded");
7122
7634
  var oneofs = mtype.oneofsArray,
7123
7635
  seenFirstField = {};
7124
7636
  if (oneofs.length) gen
@@ -7169,7 +7681,8 @@ function verifier(mtype) {
7169
7681
  ("return null");
7170
7682
  /* eslint-enable no-unexpected-multiline */
7171
7683
  }
7172
- },{"14":14,"33":33}],37:[function(require,module,exports){
7684
+
7685
+ },{"24":24,"5":5}],40:[function(require,module,exports){
7173
7686
  "use strict";
7174
7687
 
7175
7688
  /**
@@ -7179,7 +7692,7 @@ function verifier(mtype) {
7179
7692
  */
7180
7693
  var wrappers = exports;
7181
7694
 
7182
- var Message = require(19);
7695
+ var Message = require(10);
7183
7696
 
7184
7697
  /**
7185
7698
  * From object converter part of an {@link IWrapper}.
@@ -7210,7 +7723,7 @@ var Message = require(19);
7210
7723
  // Custom wrapper for Any
7211
7724
  wrappers[".google.protobuf.Any"] = {
7212
7725
 
7213
- fromObject: function(object) {
7726
+ fromObject: function(object, depth) {
7214
7727
 
7215
7728
  // unwrap value type if mapped
7216
7729
  if (object && object["@type"]) {
@@ -7226,14 +7739,15 @@ wrappers[".google.protobuf.Any"] = {
7226
7739
  if (type_url.indexOf("/") === -1) {
7227
7740
  type_url = "/" + type_url;
7228
7741
  }
7742
+ var nextDepth = depth === undefined ? 1 : depth + 1;
7229
7743
  return this.create({
7230
7744
  type_url: type_url,
7231
- value: type.encode(type.fromObject(object)).finish()
7745
+ value: type.encode(type.fromObject(object, nextDepth)).finish()
7232
7746
  });
7233
7747
  }
7234
7748
  }
7235
7749
 
7236
- return this.fromObject(object);
7750
+ return this.fromObject(object, depth);
7237
7751
  },
7238
7752
 
7239
7753
  toObject: function(message, options) {
@@ -7273,11 +7787,11 @@ wrappers[".google.protobuf.Any"] = {
7273
7787
  }
7274
7788
  };
7275
7789
 
7276
- },{"19":19}],38:[function(require,module,exports){
7790
+ },{"10":10}],41:[function(require,module,exports){
7277
7791
  "use strict";
7278
7792
  module.exports = Writer;
7279
7793
 
7280
- var util = require(35);
7794
+ var util = require(34);
7281
7795
 
7282
7796
  var BufferWriter; // cyclic
7283
7797
 
@@ -7449,6 +7963,11 @@ function writeByte(val, buf, pos) {
7449
7963
  buf[pos] = val & 255;
7450
7964
  }
7451
7965
 
7966
+ function writeStringAscii(val, buf, pos) {
7967
+ for (var i = 0; i < val.length;)
7968
+ buf[pos++] = val.charCodeAt(i++);
7969
+ }
7970
+
7452
7971
  function writeVarint32(val, buf, pos) {
7453
7972
  while (val > 127) {
7454
7973
  buf[pos++] = val & 127 | 128;
@@ -7659,6 +8178,16 @@ Writer.prototype.bytes = function write_bytes(value) {
7659
8178
  return this.uint32(len)._push(writeBytes, len, value);
7660
8179
  };
7661
8180
 
8181
+ /**
8182
+ * Writes raw bytes without a tag or length prefix.
8183
+ * @param {Uint8Array} value Raw bytes
8184
+ * @returns {Writer} `this`
8185
+ */
8186
+ Writer.prototype.raw = function write_raw(value) {
8187
+ var len = value.length >>> 0;
8188
+ return len ? this._push(writeBytes, len, value) : this;
8189
+ };
8190
+
7662
8191
  /**
7663
8192
  * Writes a string.
7664
8193
  * @param {string} value Value to write
@@ -7667,7 +8196,7 @@ Writer.prototype.bytes = function write_bytes(value) {
7667
8196
  Writer.prototype.string = function write_string(value) {
7668
8197
  var len = utf8.length(value);
7669
8198
  return len
7670
- ? this.uint32(len)._push(utf8.write, len, value)
8199
+ ? this.uint32(len)._push(len === value.length ? writeStringAscii : utf8.write, len, value)
7671
8200
  : this._push(writeByte, 1, 0);
7672
8201
  };
7673
8202
 
@@ -7722,15 +8251,28 @@ Writer.prototype.ldelim = function ldelim() {
7722
8251
  * @returns {Uint8Array} Finished buffer
7723
8252
  */
7724
8253
  Writer.prototype.finish = function finish() {
7725
- var head = this.head.next, // skip noop
7726
- buf = this.constructor.alloc(this.len),
7727
- pos = 0;
8254
+ return this.finishInto(this.constructor.alloc(this.len), 0);
8255
+ };
8256
+
8257
+ /**
8258
+ * Finishes the write operation, writing into the provided buffer.
8259
+ * The caller must ensure that `buf` has enough space starting at `offset`
8260
+ * to hold {@link Writer#len} bytes.
8261
+ * @param {T} buf Target buffer
8262
+ * @param {number} [offset=0] Offset to start writing at
8263
+ * @returns {T} The provided buffer
8264
+ * @template T extends Uint8Array
8265
+ */
8266
+ Writer.prototype.finishInto = function finishInto(buf, offset) {
8267
+ if (offset === undefined)
8268
+ offset = 0;
8269
+ var head = this.head.next,
8270
+ pos = offset;
7728
8271
  while (head) {
7729
8272
  head.fn(head.val, buf, pos);
7730
8273
  pos += head.len;
7731
8274
  head = head.next;
7732
8275
  }
7733
- // this.head = this.tail = null;
7734
8276
  return buf;
7735
8277
  };
7736
8278
 
@@ -7740,15 +8282,15 @@ Writer._configure = function(BufferWriter_) {
7740
8282
  BufferWriter._configure();
7741
8283
  };
7742
8284
 
7743
- },{"35":35}],39:[function(require,module,exports){
8285
+ },{"34":34}],42:[function(require,module,exports){
7744
8286
  "use strict";
7745
8287
  module.exports = BufferWriter;
7746
8288
 
7747
8289
  // extends Writer
7748
- var Writer = require(38);
8290
+ var Writer = require(41);
7749
8291
  (BufferWriter.prototype = Object.create(Writer.prototype)).constructor = BufferWriter;
7750
8292
 
7751
- var util = require(35);
8293
+ var util = require(34);
7752
8294
 
7753
8295
  /**
7754
8296
  * Constructs a new buffer writer instance.
@@ -7797,6 +8339,23 @@ BufferWriter.prototype.bytes = function write_bytes_buffer(value) {
7797
8339
  return this;
7798
8340
  };
7799
8341
 
8342
+ /**
8343
+ * Writes raw bytes without a tag or length prefix.
8344
+ * @name BufferWriter#raw
8345
+ * @function
8346
+ * @param {Uint8Array} value Raw bytes
8347
+ * @returns {BufferWriter} `this`
8348
+ */
8349
+ BufferWriter.prototype.raw = function write_raw_buffer(value) {
8350
+ var len = value.length >>> 0;
8351
+ return len ? this._push(BufferWriter.writeBytesBuffer, len, value) : this;
8352
+ };
8353
+
8354
+ function writeStringBufferAscii(val, buf, pos) {
8355
+ for (var i = 0; i < val.length;)
8356
+ buf[pos++] = val.charCodeAt(i++);
8357
+ }
8358
+
7800
8359
  function writeStringBuffer(val, buf, pos) {
7801
8360
  if (val.length < 40) // plain js is faster for short strings (probably due to redundant assertions)
7802
8361
  util.utf8.write(val, buf, pos);
@@ -7813,7 +8372,7 @@ BufferWriter.prototype.string = function write_string_buffer(value) {
7813
8372
  var len = util.Buffer.byteLength(value);
7814
8373
  this.uint32(len);
7815
8374
  if (len)
7816
- this._push(writeStringBuffer, len, value);
8375
+ this._push(len === value.length && len < 40 ? writeStringBufferAscii : writeStringBuffer, len, value);
7817
8376
  return this;
7818
8377
  };
7819
8378
 
@@ -7827,7 +8386,7 @@ BufferWriter.prototype.string = function write_string_buffer(value) {
7827
8386
 
7828
8387
  BufferWriter._configure();
7829
8388
 
7830
- },{"35":35,"38":38}]},{},[16])
8389
+ },{"34":34,"41":41}]},{},[7])
7831
8390
 
7832
8391
  })();
7833
8392
  //# sourceMappingURL=protobuf.js.map