@azure/web-pubsub-client-protobuf 1.0.0-alpha.20230828.1 → 1.0.0-alpha.20230926.3

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.
package/dist/index.js CHANGED
@@ -2,16 +2,2694 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- // minimal library entry point.
6
- module.exports = require("./src/index-minimal");
5
+ var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
6
+
7
+ var indexMinimal = {};
8
+
9
+ var minimal$1 = {};
10
+
11
+ var aspromise = asPromise;
12
+
13
+ /**
14
+ * Callback as used by {@link util.asPromise}.
15
+ * @typedef asPromiseCallback
16
+ * @type {function}
17
+ * @param {Error|null} error Error, if any
18
+ * @param {...*} params Additional arguments
19
+ * @returns {undefined}
20
+ */
21
+
22
+ /**
23
+ * Returns a promise from a node-style callback function.
24
+ * @memberof util
25
+ * @param {asPromiseCallback} fn Function to call
26
+ * @param {*} ctx Function context
27
+ * @param {...*} params Function arguments
28
+ * @returns {Promise<*>} Promisified function
29
+ */
30
+ function asPromise(fn, ctx/*, varargs */) {
31
+ var params = new Array(arguments.length - 1),
32
+ offset = 0,
33
+ index = 2,
34
+ pending = true;
35
+ while (index < arguments.length)
36
+ params[offset++] = arguments[index++];
37
+ return new Promise(function executor(resolve, reject) {
38
+ params[offset] = function callback(err/*, varargs */) {
39
+ if (pending) {
40
+ pending = false;
41
+ if (err)
42
+ reject(err);
43
+ else {
44
+ var params = new Array(arguments.length - 1),
45
+ offset = 0;
46
+ while (offset < params.length)
47
+ params[offset++] = arguments[offset];
48
+ resolve.apply(null, params);
49
+ }
50
+ }
51
+ };
52
+ try {
53
+ fn.apply(ctx || null, params);
54
+ } catch (err) {
55
+ if (pending) {
56
+ pending = false;
57
+ reject(err);
58
+ }
59
+ }
60
+ });
61
+ }
62
+
63
+ var base64$1 = {};
64
+
65
+ (function (exports) {
66
+
67
+ /**
68
+ * A minimal base64 implementation for number arrays.
69
+ * @memberof util
70
+ * @namespace
71
+ */
72
+ var base64 = exports;
73
+
74
+ /**
75
+ * Calculates the byte length of a base64 encoded string.
76
+ * @param {string} string Base64 encoded string
77
+ * @returns {number} Byte length
78
+ */
79
+ base64.length = function length(string) {
80
+ var p = string.length;
81
+ if (!p)
82
+ return 0;
83
+ var n = 0;
84
+ while (--p % 4 > 1 && string.charAt(p) === "=")
85
+ ++n;
86
+ return Math.ceil(string.length * 3) / 4 - n;
87
+ };
88
+
89
+ // Base64 encoding table
90
+ var b64 = new Array(64);
91
+
92
+ // Base64 decoding table
93
+ var s64 = new Array(123);
94
+
95
+ // 65..90, 97..122, 48..57, 43, 47
96
+ for (var i = 0; i < 64;)
97
+ s64[b64[i] = i < 26 ? i + 65 : i < 52 ? i + 71 : i < 62 ? i - 4 : i - 59 | 43] = i++;
98
+
99
+ /**
100
+ * Encodes a buffer to a base64 encoded string.
101
+ * @param {Uint8Array} buffer Source buffer
102
+ * @param {number} start Source start
103
+ * @param {number} end Source end
104
+ * @returns {string} Base64 encoded string
105
+ */
106
+ base64.encode = function encode(buffer, start, end) {
107
+ var parts = null,
108
+ chunk = [];
109
+ var i = 0, // output index
110
+ j = 0, // goto index
111
+ t; // temporary
112
+ while (start < end) {
113
+ var b = buffer[start++];
114
+ switch (j) {
115
+ case 0:
116
+ chunk[i++] = b64[b >> 2];
117
+ t = (b & 3) << 4;
118
+ j = 1;
119
+ break;
120
+ case 1:
121
+ chunk[i++] = b64[t | b >> 4];
122
+ t = (b & 15) << 2;
123
+ j = 2;
124
+ break;
125
+ case 2:
126
+ chunk[i++] = b64[t | b >> 6];
127
+ chunk[i++] = b64[b & 63];
128
+ j = 0;
129
+ break;
130
+ }
131
+ if (i > 8191) {
132
+ (parts || (parts = [])).push(String.fromCharCode.apply(String, chunk));
133
+ i = 0;
134
+ }
135
+ }
136
+ if (j) {
137
+ chunk[i++] = b64[t];
138
+ chunk[i++] = 61;
139
+ if (j === 1)
140
+ chunk[i++] = 61;
141
+ }
142
+ if (parts) {
143
+ if (i)
144
+ parts.push(String.fromCharCode.apply(String, chunk.slice(0, i)));
145
+ return parts.join("");
146
+ }
147
+ return String.fromCharCode.apply(String, chunk.slice(0, i));
148
+ };
149
+
150
+ var invalidEncoding = "invalid encoding";
151
+
152
+ /**
153
+ * Decodes a base64 encoded string to a buffer.
154
+ * @param {string} string Source string
155
+ * @param {Uint8Array} buffer Destination buffer
156
+ * @param {number} offset Destination offset
157
+ * @returns {number} Number of bytes written
158
+ * @throws {Error} If encoding is invalid
159
+ */
160
+ base64.decode = function decode(string, buffer, offset) {
161
+ var start = offset;
162
+ var j = 0, // goto index
163
+ t; // temporary
164
+ for (var i = 0; i < string.length;) {
165
+ var c = string.charCodeAt(i++);
166
+ if (c === 61 && j > 1)
167
+ break;
168
+ if ((c = s64[c]) === undefined)
169
+ throw Error(invalidEncoding);
170
+ switch (j) {
171
+ case 0:
172
+ t = c;
173
+ j = 1;
174
+ break;
175
+ case 1:
176
+ buffer[offset++] = t << 2 | (c & 48) >> 4;
177
+ t = c;
178
+ j = 2;
179
+ break;
180
+ case 2:
181
+ buffer[offset++] = (t & 15) << 4 | (c & 60) >> 2;
182
+ t = c;
183
+ j = 3;
184
+ break;
185
+ case 3:
186
+ buffer[offset++] = (t & 3) << 6 | c;
187
+ j = 0;
188
+ break;
189
+ }
190
+ }
191
+ if (j === 1)
192
+ throw Error(invalidEncoding);
193
+ return offset - start;
194
+ };
195
+
196
+ /**
197
+ * Tests if the specified string appears to be base64 encoded.
198
+ * @param {string} string String to test
199
+ * @returns {boolean} `true` if probably base64 encoded, otherwise false
200
+ */
201
+ base64.test = function test(string) {
202
+ return /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(string);
203
+ };
204
+ } (base64$1));
205
+
206
+ var eventemitter = EventEmitter;
207
+
208
+ /**
209
+ * Constructs a new event emitter instance.
210
+ * @classdesc A minimal event emitter.
211
+ * @memberof util
212
+ * @constructor
213
+ */
214
+ function EventEmitter() {
215
+
216
+ /**
217
+ * Registered listeners.
218
+ * @type {Object.<string,*>}
219
+ * @private
220
+ */
221
+ this._listeners = {};
222
+ }
223
+
224
+ /**
225
+ * Registers an event listener.
226
+ * @param {string} evt Event name
227
+ * @param {function} fn Listener
228
+ * @param {*} [ctx] Listener context
229
+ * @returns {util.EventEmitter} `this`
230
+ */
231
+ EventEmitter.prototype.on = function on(evt, fn, ctx) {
232
+ (this._listeners[evt] || (this._listeners[evt] = [])).push({
233
+ fn : fn,
234
+ ctx : ctx || this
235
+ });
236
+ return this;
237
+ };
238
+
239
+ /**
240
+ * Removes an event listener or any matching listeners if arguments are omitted.
241
+ * @param {string} [evt] Event name. Removes all listeners if omitted.
242
+ * @param {function} [fn] Listener to remove. Removes all listeners of `evt` if omitted.
243
+ * @returns {util.EventEmitter} `this`
244
+ */
245
+ EventEmitter.prototype.off = function off(evt, fn) {
246
+ if (evt === undefined)
247
+ this._listeners = {};
248
+ else {
249
+ if (fn === undefined)
250
+ this._listeners[evt] = [];
251
+ else {
252
+ var listeners = this._listeners[evt];
253
+ for (var i = 0; i < listeners.length;)
254
+ if (listeners[i].fn === fn)
255
+ listeners.splice(i, 1);
256
+ else
257
+ ++i;
258
+ }
259
+ }
260
+ return this;
261
+ };
262
+
263
+ /**
264
+ * Emits an event by calling its listeners with the specified arguments.
265
+ * @param {string} evt Event name
266
+ * @param {...*} args Arguments
267
+ * @returns {util.EventEmitter} `this`
268
+ */
269
+ EventEmitter.prototype.emit = function emit(evt) {
270
+ var listeners = this._listeners[evt];
271
+ if (listeners) {
272
+ var args = [],
273
+ i = 1;
274
+ for (; i < arguments.length;)
275
+ args.push(arguments[i++]);
276
+ for (i = 0; i < listeners.length;)
277
+ listeners[i].fn.apply(listeners[i++].ctx, args);
278
+ }
279
+ return this;
280
+ };
281
+
282
+ var float = factory(factory);
283
+
284
+ /**
285
+ * Reads / writes floats / doubles from / to buffers.
286
+ * @name util.float
287
+ * @namespace
288
+ */
289
+
290
+ /**
291
+ * Writes a 32 bit float to a buffer using little endian byte order.
292
+ * @name util.float.writeFloatLE
293
+ * @function
294
+ * @param {number} val Value to write
295
+ * @param {Uint8Array} buf Target buffer
296
+ * @param {number} pos Target buffer offset
297
+ * @returns {undefined}
298
+ */
299
+
300
+ /**
301
+ * Writes a 32 bit float to a buffer using big endian byte order.
302
+ * @name util.float.writeFloatBE
303
+ * @function
304
+ * @param {number} val Value to write
305
+ * @param {Uint8Array} buf Target buffer
306
+ * @param {number} pos Target buffer offset
307
+ * @returns {undefined}
308
+ */
309
+
310
+ /**
311
+ * Reads a 32 bit float from a buffer using little endian byte order.
312
+ * @name util.float.readFloatLE
313
+ * @function
314
+ * @param {Uint8Array} buf Source buffer
315
+ * @param {number} pos Source buffer offset
316
+ * @returns {number} Value read
317
+ */
318
+
319
+ /**
320
+ * Reads a 32 bit float from a buffer using big endian byte order.
321
+ * @name util.float.readFloatBE
322
+ * @function
323
+ * @param {Uint8Array} buf Source buffer
324
+ * @param {number} pos Source buffer offset
325
+ * @returns {number} Value read
326
+ */
327
+
328
+ /**
329
+ * Writes a 64 bit double to a buffer using little endian byte order.
330
+ * @name util.float.writeDoubleLE
331
+ * @function
332
+ * @param {number} val Value to write
333
+ * @param {Uint8Array} buf Target buffer
334
+ * @param {number} pos Target buffer offset
335
+ * @returns {undefined}
336
+ */
337
+
338
+ /**
339
+ * Writes a 64 bit double to a buffer using big endian byte order.
340
+ * @name util.float.writeDoubleBE
341
+ * @function
342
+ * @param {number} val Value to write
343
+ * @param {Uint8Array} buf Target buffer
344
+ * @param {number} pos Target buffer offset
345
+ * @returns {undefined}
346
+ */
347
+
348
+ /**
349
+ * Reads a 64 bit double from a buffer using little endian byte order.
350
+ * @name util.float.readDoubleLE
351
+ * @function
352
+ * @param {Uint8Array} buf Source buffer
353
+ * @param {number} pos Source buffer offset
354
+ * @returns {number} Value read
355
+ */
356
+
357
+ /**
358
+ * Reads a 64 bit double from a buffer using big endian byte order.
359
+ * @name util.float.readDoubleBE
360
+ * @function
361
+ * @param {Uint8Array} buf Source buffer
362
+ * @param {number} pos Source buffer offset
363
+ * @returns {number} Value read
364
+ */
365
+
366
+ // Factory function for the purpose of node-based testing in modified global environments
367
+ function factory(exports) {
368
+
369
+ // float: typed array
370
+ if (typeof Float32Array !== "undefined") (function() {
371
+
372
+ var f32 = new Float32Array([ -0 ]),
373
+ f8b = new Uint8Array(f32.buffer),
374
+ le = f8b[3] === 128;
375
+
376
+ function writeFloat_f32_cpy(val, buf, pos) {
377
+ f32[0] = val;
378
+ buf[pos ] = f8b[0];
379
+ buf[pos + 1] = f8b[1];
380
+ buf[pos + 2] = f8b[2];
381
+ buf[pos + 3] = f8b[3];
382
+ }
383
+
384
+ function writeFloat_f32_rev(val, buf, pos) {
385
+ f32[0] = val;
386
+ buf[pos ] = f8b[3];
387
+ buf[pos + 1] = f8b[2];
388
+ buf[pos + 2] = f8b[1];
389
+ buf[pos + 3] = f8b[0];
390
+ }
391
+
392
+ /* istanbul ignore next */
393
+ exports.writeFloatLE = le ? writeFloat_f32_cpy : writeFloat_f32_rev;
394
+ /* istanbul ignore next */
395
+ exports.writeFloatBE = le ? writeFloat_f32_rev : writeFloat_f32_cpy;
396
+
397
+ function readFloat_f32_cpy(buf, pos) {
398
+ f8b[0] = buf[pos ];
399
+ f8b[1] = buf[pos + 1];
400
+ f8b[2] = buf[pos + 2];
401
+ f8b[3] = buf[pos + 3];
402
+ return f32[0];
403
+ }
404
+
405
+ function readFloat_f32_rev(buf, pos) {
406
+ f8b[3] = buf[pos ];
407
+ f8b[2] = buf[pos + 1];
408
+ f8b[1] = buf[pos + 2];
409
+ f8b[0] = buf[pos + 3];
410
+ return f32[0];
411
+ }
412
+
413
+ /* istanbul ignore next */
414
+ exports.readFloatLE = le ? readFloat_f32_cpy : readFloat_f32_rev;
415
+ /* istanbul ignore next */
416
+ exports.readFloatBE = le ? readFloat_f32_rev : readFloat_f32_cpy;
417
+
418
+ // float: ieee754
419
+ })(); else (function() {
420
+
421
+ function writeFloat_ieee754(writeUint, val, buf, pos) {
422
+ var sign = val < 0 ? 1 : 0;
423
+ if (sign)
424
+ val = -val;
425
+ if (val === 0)
426
+ writeUint(1 / val > 0 ? /* positive */ 0 : /* negative 0 */ 2147483648, buf, pos);
427
+ else if (isNaN(val))
428
+ writeUint(2143289344, buf, pos);
429
+ else if (val > 3.4028234663852886e+38) // +-Infinity
430
+ writeUint((sign << 31 | 2139095040) >>> 0, buf, pos);
431
+ else if (val < 1.1754943508222875e-38) // denormal
432
+ writeUint((sign << 31 | Math.round(val / 1.401298464324817e-45)) >>> 0, buf, pos);
433
+ else {
434
+ var exponent = Math.floor(Math.log(val) / Math.LN2),
435
+ mantissa = Math.round(val * Math.pow(2, -exponent) * 8388608) & 8388607;
436
+ writeUint((sign << 31 | exponent + 127 << 23 | mantissa) >>> 0, buf, pos);
437
+ }
438
+ }
439
+
440
+ exports.writeFloatLE = writeFloat_ieee754.bind(null, writeUintLE);
441
+ exports.writeFloatBE = writeFloat_ieee754.bind(null, writeUintBE);
442
+
443
+ function readFloat_ieee754(readUint, buf, pos) {
444
+ var uint = readUint(buf, pos),
445
+ sign = (uint >> 31) * 2 + 1,
446
+ exponent = uint >>> 23 & 255,
447
+ mantissa = uint & 8388607;
448
+ return exponent === 255
449
+ ? mantissa
450
+ ? NaN
451
+ : sign * Infinity
452
+ : exponent === 0 // denormal
453
+ ? sign * 1.401298464324817e-45 * mantissa
454
+ : sign * Math.pow(2, exponent - 150) * (mantissa + 8388608);
455
+ }
456
+
457
+ exports.readFloatLE = readFloat_ieee754.bind(null, readUintLE);
458
+ exports.readFloatBE = readFloat_ieee754.bind(null, readUintBE);
459
+
460
+ })();
461
+
462
+ // double: typed array
463
+ if (typeof Float64Array !== "undefined") (function() {
464
+
465
+ var f64 = new Float64Array([-0]),
466
+ f8b = new Uint8Array(f64.buffer),
467
+ le = f8b[7] === 128;
468
+
469
+ function writeDouble_f64_cpy(val, buf, pos) {
470
+ f64[0] = val;
471
+ buf[pos ] = f8b[0];
472
+ buf[pos + 1] = f8b[1];
473
+ buf[pos + 2] = f8b[2];
474
+ buf[pos + 3] = f8b[3];
475
+ buf[pos + 4] = f8b[4];
476
+ buf[pos + 5] = f8b[5];
477
+ buf[pos + 6] = f8b[6];
478
+ buf[pos + 7] = f8b[7];
479
+ }
480
+
481
+ function writeDouble_f64_rev(val, buf, pos) {
482
+ f64[0] = val;
483
+ buf[pos ] = f8b[7];
484
+ buf[pos + 1] = f8b[6];
485
+ buf[pos + 2] = f8b[5];
486
+ buf[pos + 3] = f8b[4];
487
+ buf[pos + 4] = f8b[3];
488
+ buf[pos + 5] = f8b[2];
489
+ buf[pos + 6] = f8b[1];
490
+ buf[pos + 7] = f8b[0];
491
+ }
492
+
493
+ /* istanbul ignore next */
494
+ exports.writeDoubleLE = le ? writeDouble_f64_cpy : writeDouble_f64_rev;
495
+ /* istanbul ignore next */
496
+ exports.writeDoubleBE = le ? writeDouble_f64_rev : writeDouble_f64_cpy;
497
+
498
+ function readDouble_f64_cpy(buf, pos) {
499
+ f8b[0] = buf[pos ];
500
+ f8b[1] = buf[pos + 1];
501
+ f8b[2] = buf[pos + 2];
502
+ f8b[3] = buf[pos + 3];
503
+ f8b[4] = buf[pos + 4];
504
+ f8b[5] = buf[pos + 5];
505
+ f8b[6] = buf[pos + 6];
506
+ f8b[7] = buf[pos + 7];
507
+ return f64[0];
508
+ }
509
+
510
+ function readDouble_f64_rev(buf, pos) {
511
+ f8b[7] = buf[pos ];
512
+ f8b[6] = buf[pos + 1];
513
+ f8b[5] = buf[pos + 2];
514
+ f8b[4] = buf[pos + 3];
515
+ f8b[3] = buf[pos + 4];
516
+ f8b[2] = buf[pos + 5];
517
+ f8b[1] = buf[pos + 6];
518
+ f8b[0] = buf[pos + 7];
519
+ return f64[0];
520
+ }
521
+
522
+ /* istanbul ignore next */
523
+ exports.readDoubleLE = le ? readDouble_f64_cpy : readDouble_f64_rev;
524
+ /* istanbul ignore next */
525
+ exports.readDoubleBE = le ? readDouble_f64_rev : readDouble_f64_cpy;
526
+
527
+ // double: ieee754
528
+ })(); else (function() {
529
+
530
+ function writeDouble_ieee754(writeUint, off0, off1, val, buf, pos) {
531
+ var sign = val < 0 ? 1 : 0;
532
+ if (sign)
533
+ val = -val;
534
+ if (val === 0) {
535
+ writeUint(0, buf, pos + off0);
536
+ writeUint(1 / val > 0 ? /* positive */ 0 : /* negative 0 */ 2147483648, buf, pos + off1);
537
+ } else if (isNaN(val)) {
538
+ writeUint(0, buf, pos + off0);
539
+ writeUint(2146959360, buf, pos + off1);
540
+ } else if (val > 1.7976931348623157e+308) { // +-Infinity
541
+ writeUint(0, buf, pos + off0);
542
+ writeUint((sign << 31 | 2146435072) >>> 0, buf, pos + off1);
543
+ } else {
544
+ var mantissa;
545
+ if (val < 2.2250738585072014e-308) { // denormal
546
+ mantissa = val / 5e-324;
547
+ writeUint(mantissa >>> 0, buf, pos + off0);
548
+ writeUint((sign << 31 | mantissa / 4294967296) >>> 0, buf, pos + off1);
549
+ } else {
550
+ var exponent = Math.floor(Math.log(val) / Math.LN2);
551
+ if (exponent === 1024)
552
+ exponent = 1023;
553
+ mantissa = val * Math.pow(2, -exponent);
554
+ writeUint(mantissa * 4503599627370496 >>> 0, buf, pos + off0);
555
+ writeUint((sign << 31 | exponent + 1023 << 20 | mantissa * 1048576 & 1048575) >>> 0, buf, pos + off1);
556
+ }
557
+ }
558
+ }
559
+
560
+ exports.writeDoubleLE = writeDouble_ieee754.bind(null, writeUintLE, 0, 4);
561
+ exports.writeDoubleBE = writeDouble_ieee754.bind(null, writeUintBE, 4, 0);
562
+
563
+ function readDouble_ieee754(readUint, off0, off1, buf, pos) {
564
+ var lo = readUint(buf, pos + off0),
565
+ hi = readUint(buf, pos + off1);
566
+ var sign = (hi >> 31) * 2 + 1,
567
+ exponent = hi >>> 20 & 2047,
568
+ mantissa = 4294967296 * (hi & 1048575) + lo;
569
+ return exponent === 2047
570
+ ? mantissa
571
+ ? NaN
572
+ : sign * Infinity
573
+ : exponent === 0 // denormal
574
+ ? sign * 5e-324 * mantissa
575
+ : sign * Math.pow(2, exponent - 1075) * (mantissa + 4503599627370496);
576
+ }
577
+
578
+ exports.readDoubleLE = readDouble_ieee754.bind(null, readUintLE, 0, 4);
579
+ exports.readDoubleBE = readDouble_ieee754.bind(null, readUintBE, 4, 0);
580
+
581
+ })();
582
+
583
+ return exports;
584
+ }
585
+
586
+ // uint helpers
587
+
588
+ function writeUintLE(val, buf, pos) {
589
+ buf[pos ] = val & 255;
590
+ buf[pos + 1] = val >>> 8 & 255;
591
+ buf[pos + 2] = val >>> 16 & 255;
592
+ buf[pos + 3] = val >>> 24;
593
+ }
594
+
595
+ function writeUintBE(val, buf, pos) {
596
+ buf[pos ] = val >>> 24;
597
+ buf[pos + 1] = val >>> 16 & 255;
598
+ buf[pos + 2] = val >>> 8 & 255;
599
+ buf[pos + 3] = val & 255;
600
+ }
601
+
602
+ function readUintLE(buf, pos) {
603
+ return (buf[pos ]
604
+ | buf[pos + 1] << 8
605
+ | buf[pos + 2] << 16
606
+ | buf[pos + 3] << 24) >>> 0;
607
+ }
608
+
609
+ function readUintBE(buf, pos) {
610
+ return (buf[pos ] << 24
611
+ | buf[pos + 1] << 16
612
+ | buf[pos + 2] << 8
613
+ | buf[pos + 3]) >>> 0;
614
+ }
615
+
616
+ var inquire_1 = inquire;
617
+
618
+ /**
619
+ * Requires a module only if available.
620
+ * @memberof util
621
+ * @param {string} moduleName Module to require
622
+ * @returns {?Object} Required module if available and not empty, otherwise `null`
623
+ */
624
+ function inquire(moduleName) {
625
+ try {
626
+ var mod = eval("quire".replace(/^/,"re"))(moduleName); // eslint-disable-line no-eval
627
+ if (mod && (mod.length || Object.keys(mod).length))
628
+ return mod;
629
+ } catch (e) {} // eslint-disable-line no-empty
630
+ return null;
631
+ }
632
+
633
+ var utf8$2 = {};
634
+
635
+ (function (exports) {
636
+
637
+ /**
638
+ * A minimal UTF8 implementation for number arrays.
639
+ * @memberof util
640
+ * @namespace
641
+ */
642
+ var utf8 = exports;
643
+
644
+ /**
645
+ * Calculates the UTF8 byte length of a string.
646
+ * @param {string} string String
647
+ * @returns {number} Byte length
648
+ */
649
+ utf8.length = function utf8_length(string) {
650
+ var len = 0,
651
+ c = 0;
652
+ for (var i = 0; i < string.length; ++i) {
653
+ c = string.charCodeAt(i);
654
+ if (c < 128)
655
+ len += 1;
656
+ else if (c < 2048)
657
+ len += 2;
658
+ else if ((c & 0xFC00) === 0xD800 && (string.charCodeAt(i + 1) & 0xFC00) === 0xDC00) {
659
+ ++i;
660
+ len += 4;
661
+ } else
662
+ len += 3;
663
+ }
664
+ return len;
665
+ };
666
+
667
+ /**
668
+ * Reads UTF8 bytes as a string.
669
+ * @param {Uint8Array} buffer Source buffer
670
+ * @param {number} start Source start
671
+ * @param {number} end Source end
672
+ * @returns {string} String read
673
+ */
674
+ utf8.read = function utf8_read(buffer, start, end) {
675
+ var len = end - start;
676
+ if (len < 1)
677
+ return "";
678
+ var parts = null,
679
+ chunk = [],
680
+ i = 0, // char offset
681
+ t; // temporary
682
+ while (start < end) {
683
+ t = buffer[start++];
684
+ if (t < 128)
685
+ chunk[i++] = t;
686
+ else if (t > 191 && t < 224)
687
+ chunk[i++] = (t & 31) << 6 | buffer[start++] & 63;
688
+ else if (t > 239 && t < 365) {
689
+ t = ((t & 7) << 18 | (buffer[start++] & 63) << 12 | (buffer[start++] & 63) << 6 | buffer[start++] & 63) - 0x10000;
690
+ chunk[i++] = 0xD800 + (t >> 10);
691
+ chunk[i++] = 0xDC00 + (t & 1023);
692
+ } else
693
+ chunk[i++] = (t & 15) << 12 | (buffer[start++] & 63) << 6 | buffer[start++] & 63;
694
+ if (i > 8191) {
695
+ (parts || (parts = [])).push(String.fromCharCode.apply(String, chunk));
696
+ i = 0;
697
+ }
698
+ }
699
+ if (parts) {
700
+ if (i)
701
+ parts.push(String.fromCharCode.apply(String, chunk.slice(0, i)));
702
+ return parts.join("");
703
+ }
704
+ return String.fromCharCode.apply(String, chunk.slice(0, i));
705
+ };
706
+
707
+ /**
708
+ * Writes a string as UTF8 bytes.
709
+ * @param {string} string Source string
710
+ * @param {Uint8Array} buffer Destination buffer
711
+ * @param {number} offset Destination offset
712
+ * @returns {number} Bytes written
713
+ */
714
+ utf8.write = function utf8_write(string, buffer, offset) {
715
+ var start = offset,
716
+ c1, // character 1
717
+ c2; // character 2
718
+ for (var i = 0; i < string.length; ++i) {
719
+ c1 = string.charCodeAt(i);
720
+ if (c1 < 128) {
721
+ buffer[offset++] = c1;
722
+ } else if (c1 < 2048) {
723
+ buffer[offset++] = c1 >> 6 | 192;
724
+ buffer[offset++] = c1 & 63 | 128;
725
+ } else if ((c1 & 0xFC00) === 0xD800 && ((c2 = string.charCodeAt(i + 1)) & 0xFC00) === 0xDC00) {
726
+ c1 = 0x10000 + ((c1 & 0x03FF) << 10) + (c2 & 0x03FF);
727
+ ++i;
728
+ buffer[offset++] = c1 >> 18 | 240;
729
+ buffer[offset++] = c1 >> 12 & 63 | 128;
730
+ buffer[offset++] = c1 >> 6 & 63 | 128;
731
+ buffer[offset++] = c1 & 63 | 128;
732
+ } else {
733
+ buffer[offset++] = c1 >> 12 | 224;
734
+ buffer[offset++] = c1 >> 6 & 63 | 128;
735
+ buffer[offset++] = c1 & 63 | 128;
736
+ }
737
+ }
738
+ return offset - start;
739
+ };
740
+ } (utf8$2));
741
+
742
+ var pool_1 = pool;
743
+
744
+ /**
745
+ * An allocator as used by {@link util.pool}.
746
+ * @typedef PoolAllocator
747
+ * @type {function}
748
+ * @param {number} size Buffer size
749
+ * @returns {Uint8Array} Buffer
750
+ */
751
+
752
+ /**
753
+ * A slicer as used by {@link util.pool}.
754
+ * @typedef PoolSlicer
755
+ * @type {function}
756
+ * @param {number} start Start offset
757
+ * @param {number} end End offset
758
+ * @returns {Uint8Array} Buffer slice
759
+ * @this {Uint8Array}
760
+ */
761
+
762
+ /**
763
+ * A general purpose buffer pool.
764
+ * @memberof util
765
+ * @function
766
+ * @param {PoolAllocator} alloc Allocator
767
+ * @param {PoolSlicer} slice Slicer
768
+ * @param {number} [size=8192] Slab size
769
+ * @returns {PoolAllocator} Pooled allocator
770
+ */
771
+ function pool(alloc, slice, size) {
772
+ var SIZE = size || 8192;
773
+ var MAX = SIZE >>> 1;
774
+ var slab = null;
775
+ var offset = SIZE;
776
+ return function pool_alloc(size) {
777
+ if (size < 1 || size > MAX)
778
+ return alloc(size);
779
+ if (offset + size > SIZE) {
780
+ slab = alloc(SIZE);
781
+ offset = 0;
782
+ }
783
+ var buf = slice.call(slab, offset, offset += size);
784
+ if (offset & 7) // align to 32 bit
785
+ offset = (offset | 7) + 1;
786
+ return buf;
787
+ };
788
+ }
789
+
790
+ var longbits;
791
+ var hasRequiredLongbits;
792
+
793
+ function requireLongbits () {
794
+ if (hasRequiredLongbits) return longbits;
795
+ hasRequiredLongbits = 1;
796
+ longbits = LongBits;
797
+
798
+ var util = requireMinimal();
799
+
800
+ /**
801
+ * Constructs new long bits.
802
+ * @classdesc Helper class for working with the low and high bits of a 64 bit value.
803
+ * @memberof util
804
+ * @constructor
805
+ * @param {number} lo Low 32 bits, unsigned
806
+ * @param {number} hi High 32 bits, unsigned
807
+ */
808
+ function LongBits(lo, hi) {
809
+
810
+ // note that the casts below are theoretically unnecessary as of today, but older statically
811
+ // generated converter code might still call the ctor with signed 32bits. kept for compat.
812
+
813
+ /**
814
+ * Low bits.
815
+ * @type {number}
816
+ */
817
+ this.lo = lo >>> 0;
818
+
819
+ /**
820
+ * High bits.
821
+ * @type {number}
822
+ */
823
+ this.hi = hi >>> 0;
824
+ }
825
+
826
+ /**
827
+ * Zero bits.
828
+ * @memberof util.LongBits
829
+ * @type {util.LongBits}
830
+ */
831
+ var zero = LongBits.zero = new LongBits(0, 0);
832
+
833
+ zero.toNumber = function() { return 0; };
834
+ zero.zzEncode = zero.zzDecode = function() { return this; };
835
+ zero.length = function() { return 1; };
836
+
837
+ /**
838
+ * Zero hash.
839
+ * @memberof util.LongBits
840
+ * @type {string}
841
+ */
842
+ var zeroHash = LongBits.zeroHash = "\0\0\0\0\0\0\0\0";
843
+
844
+ /**
845
+ * Constructs new long bits from the specified number.
846
+ * @param {number} value Value
847
+ * @returns {util.LongBits} Instance
848
+ */
849
+ LongBits.fromNumber = function fromNumber(value) {
850
+ if (value === 0)
851
+ return zero;
852
+ var sign = value < 0;
853
+ if (sign)
854
+ value = -value;
855
+ var lo = value >>> 0,
856
+ hi = (value - lo) / 4294967296 >>> 0;
857
+ if (sign) {
858
+ hi = ~hi >>> 0;
859
+ lo = ~lo >>> 0;
860
+ if (++lo > 4294967295) {
861
+ lo = 0;
862
+ if (++hi > 4294967295)
863
+ hi = 0;
864
+ }
865
+ }
866
+ return new LongBits(lo, hi);
867
+ };
868
+
869
+ /**
870
+ * Constructs new long bits from a number, long or string.
871
+ * @param {Long|number|string} value Value
872
+ * @returns {util.LongBits} Instance
873
+ */
874
+ LongBits.from = function from(value) {
875
+ if (typeof value === "number")
876
+ return LongBits.fromNumber(value);
877
+ if (util.isString(value)) {
878
+ /* istanbul ignore else */
879
+ if (util.Long)
880
+ value = util.Long.fromString(value);
881
+ else
882
+ return LongBits.fromNumber(parseInt(value, 10));
883
+ }
884
+ return value.low || value.high ? new LongBits(value.low >>> 0, value.high >>> 0) : zero;
885
+ };
886
+
887
+ /**
888
+ * Converts this long bits to a possibly unsafe JavaScript number.
889
+ * @param {boolean} [unsigned=false] Whether unsigned or not
890
+ * @returns {number} Possibly unsafe number
891
+ */
892
+ LongBits.prototype.toNumber = function toNumber(unsigned) {
893
+ if (!unsigned && this.hi >>> 31) {
894
+ var lo = ~this.lo + 1 >>> 0,
895
+ hi = ~this.hi >>> 0;
896
+ if (!lo)
897
+ hi = hi + 1 >>> 0;
898
+ return -(lo + hi * 4294967296);
899
+ }
900
+ return this.lo + this.hi * 4294967296;
901
+ };
902
+
903
+ /**
904
+ * Converts this long bits to a long.
905
+ * @param {boolean} [unsigned=false] Whether unsigned or not
906
+ * @returns {Long} Long
907
+ */
908
+ LongBits.prototype.toLong = function toLong(unsigned) {
909
+ return util.Long
910
+ ? new util.Long(this.lo | 0, this.hi | 0, Boolean(unsigned))
911
+ /* istanbul ignore next */
912
+ : { low: this.lo | 0, high: this.hi | 0, unsigned: Boolean(unsigned) };
913
+ };
914
+
915
+ var charCodeAt = String.prototype.charCodeAt;
916
+
917
+ /**
918
+ * Constructs new long bits from the specified 8 characters long hash.
919
+ * @param {string} hash Hash
920
+ * @returns {util.LongBits} Bits
921
+ */
922
+ LongBits.fromHash = function fromHash(hash) {
923
+ if (hash === zeroHash)
924
+ return zero;
925
+ return new LongBits(
926
+ ( charCodeAt.call(hash, 0)
927
+ | charCodeAt.call(hash, 1) << 8
928
+ | charCodeAt.call(hash, 2) << 16
929
+ | charCodeAt.call(hash, 3) << 24) >>> 0
930
+ ,
931
+ ( charCodeAt.call(hash, 4)
932
+ | charCodeAt.call(hash, 5) << 8
933
+ | charCodeAt.call(hash, 6) << 16
934
+ | charCodeAt.call(hash, 7) << 24) >>> 0
935
+ );
936
+ };
937
+
938
+ /**
939
+ * Converts this long bits to a 8 characters long hash.
940
+ * @returns {string} Hash
941
+ */
942
+ LongBits.prototype.toHash = function toHash() {
943
+ return String.fromCharCode(
944
+ this.lo & 255,
945
+ this.lo >>> 8 & 255,
946
+ this.lo >>> 16 & 255,
947
+ this.lo >>> 24 ,
948
+ this.hi & 255,
949
+ this.hi >>> 8 & 255,
950
+ this.hi >>> 16 & 255,
951
+ this.hi >>> 24
952
+ );
953
+ };
954
+
955
+ /**
956
+ * Zig-zag encodes this long bits.
957
+ * @returns {util.LongBits} `this`
958
+ */
959
+ LongBits.prototype.zzEncode = function zzEncode() {
960
+ var mask = this.hi >> 31;
961
+ this.hi = ((this.hi << 1 | this.lo >>> 31) ^ mask) >>> 0;
962
+ this.lo = ( this.lo << 1 ^ mask) >>> 0;
963
+ return this;
964
+ };
965
+
966
+ /**
967
+ * Zig-zag decodes this long bits.
968
+ * @returns {util.LongBits} `this`
969
+ */
970
+ LongBits.prototype.zzDecode = function zzDecode() {
971
+ var mask = -(this.lo & 1);
972
+ this.lo = ((this.lo >>> 1 | this.hi << 31) ^ mask) >>> 0;
973
+ this.hi = ( this.hi >>> 1 ^ mask) >>> 0;
974
+ return this;
975
+ };
976
+
977
+ /**
978
+ * Calculates the length of this longbits when encoded as a varint.
979
+ * @returns {number} Length
980
+ */
981
+ LongBits.prototype.length = function length() {
982
+ var part0 = this.lo,
983
+ part1 = (this.lo >>> 28 | this.hi << 4) >>> 0,
984
+ part2 = this.hi >>> 24;
985
+ return part2 === 0
986
+ ? part1 === 0
987
+ ? part0 < 16384
988
+ ? part0 < 128 ? 1 : 2
989
+ : part0 < 2097152 ? 3 : 4
990
+ : part1 < 16384
991
+ ? part1 < 128 ? 5 : 6
992
+ : part1 < 2097152 ? 7 : 8
993
+ : part2 < 128 ? 9 : 10;
994
+ };
995
+ return longbits;
996
+ }
997
+
998
+ var hasRequiredMinimal;
999
+
1000
+ function requireMinimal () {
1001
+ if (hasRequiredMinimal) return minimal$1;
1002
+ hasRequiredMinimal = 1;
1003
+ (function (exports) {
1004
+ var util = exports;
1005
+
1006
+ // used to return a Promise where callback is omitted
1007
+ util.asPromise = aspromise;
1008
+
1009
+ // converts to / from base64 encoded strings
1010
+ util.base64 = base64$1;
1011
+
1012
+ // base class of rpc.Service
1013
+ util.EventEmitter = eventemitter;
1014
+
1015
+ // float handling accross browsers
1016
+ util.float = float;
1017
+
1018
+ // requires modules optionally and hides the call from bundlers
1019
+ util.inquire = inquire_1;
1020
+
1021
+ // converts to / from utf8 encoded strings
1022
+ util.utf8 = utf8$2;
1023
+
1024
+ // provides a node-like buffer pool in the browser
1025
+ util.pool = pool_1;
1026
+
1027
+ // utility to work with the low and high bits of a 64 bit value
1028
+ util.LongBits = requireLongbits();
1029
+
1030
+ /**
1031
+ * Whether running within node or not.
1032
+ * @memberof util
1033
+ * @type {boolean}
1034
+ */
1035
+ util.isNode = Boolean(typeof commonjsGlobal !== "undefined"
1036
+ && commonjsGlobal
1037
+ && commonjsGlobal.process
1038
+ && commonjsGlobal.process.versions
1039
+ && commonjsGlobal.process.versions.node);
1040
+
1041
+ /**
1042
+ * Global object reference.
1043
+ * @memberof util
1044
+ * @type {Object}
1045
+ */
1046
+ util.global = util.isNode && commonjsGlobal
1047
+ || typeof window !== "undefined" && window
1048
+ || typeof self !== "undefined" && self
1049
+ || commonjsGlobal; // eslint-disable-line no-invalid-this
1050
+
1051
+ /**
1052
+ * An immuable empty array.
1053
+ * @memberof util
1054
+ * @type {Array.<*>}
1055
+ * @const
1056
+ */
1057
+ util.emptyArray = Object.freeze ? Object.freeze([]) : /* istanbul ignore next */ []; // used on prototypes
1058
+
1059
+ /**
1060
+ * An immutable empty object.
1061
+ * @type {Object}
1062
+ * @const
1063
+ */
1064
+ util.emptyObject = Object.freeze ? Object.freeze({}) : /* istanbul ignore next */ {}; // used on prototypes
1065
+
1066
+ /**
1067
+ * Tests if the specified value is an integer.
1068
+ * @function
1069
+ * @param {*} value Value to test
1070
+ * @returns {boolean} `true` if the value is an integer
1071
+ */
1072
+ util.isInteger = Number.isInteger || /* istanbul ignore next */ function isInteger(value) {
1073
+ return typeof value === "number" && isFinite(value) && Math.floor(value) === value;
1074
+ };
1075
+
1076
+ /**
1077
+ * Tests if the specified value is a string.
1078
+ * @param {*} value Value to test
1079
+ * @returns {boolean} `true` if the value is a string
1080
+ */
1081
+ util.isString = function isString(value) {
1082
+ return typeof value === "string" || value instanceof String;
1083
+ };
1084
+
1085
+ /**
1086
+ * Tests if the specified value is a non-null object.
1087
+ * @param {*} value Value to test
1088
+ * @returns {boolean} `true` if the value is a non-null object
1089
+ */
1090
+ util.isObject = function isObject(value) {
1091
+ return value && typeof value === "object";
1092
+ };
1093
+
1094
+ /**
1095
+ * Checks if a property on a message is considered to be present.
1096
+ * This is an alias of {@link util.isSet}.
1097
+ * @function
1098
+ * @param {Object} obj Plain object or message instance
1099
+ * @param {string} prop Property name
1100
+ * @returns {boolean} `true` if considered to be present, otherwise `false`
1101
+ */
1102
+ util.isset =
1103
+
1104
+ /**
1105
+ * Checks if a property on a message is considered to be present.
1106
+ * @param {Object} obj Plain object or message instance
1107
+ * @param {string} prop Property name
1108
+ * @returns {boolean} `true` if considered to be present, otherwise `false`
1109
+ */
1110
+ util.isSet = function isSet(obj, prop) {
1111
+ var value = obj[prop];
1112
+ if (value != null && obj.hasOwnProperty(prop)) // eslint-disable-line eqeqeq, no-prototype-builtins
1113
+ return typeof value !== "object" || (Array.isArray(value) ? value.length : Object.keys(value).length) > 0;
1114
+ return false;
1115
+ };
1116
+
1117
+ /**
1118
+ * Any compatible Buffer instance.
1119
+ * This is a minimal stand-alone definition of a Buffer instance. The actual type is that exported by node's typings.
1120
+ * @interface Buffer
1121
+ * @extends Uint8Array
1122
+ */
1123
+
1124
+ /**
1125
+ * Node's Buffer class if available.
1126
+ * @type {Constructor<Buffer>}
1127
+ */
1128
+ util.Buffer = (function() {
1129
+ try {
1130
+ var Buffer = util.inquire("buffer").Buffer;
1131
+ // refuse to use non-node buffers if not explicitly assigned (perf reasons):
1132
+ return Buffer.prototype.utf8Write ? Buffer : /* istanbul ignore next */ null;
1133
+ } catch (e) {
1134
+ /* istanbul ignore next */
1135
+ return null;
1136
+ }
1137
+ })();
1138
+
1139
+ // Internal alias of or polyfull for Buffer.from.
1140
+ util._Buffer_from = null;
1141
+
1142
+ // Internal alias of or polyfill for Buffer.allocUnsafe.
1143
+ util._Buffer_allocUnsafe = null;
1144
+
1145
+ /**
1146
+ * Creates a new buffer of whatever type supported by the environment.
1147
+ * @param {number|number[]} [sizeOrArray=0] Buffer size or number array
1148
+ * @returns {Uint8Array|Buffer} Buffer
1149
+ */
1150
+ util.newBuffer = function newBuffer(sizeOrArray) {
1151
+ /* istanbul ignore next */
1152
+ return typeof sizeOrArray === "number"
1153
+ ? util.Buffer
1154
+ ? util._Buffer_allocUnsafe(sizeOrArray)
1155
+ : new util.Array(sizeOrArray)
1156
+ : util.Buffer
1157
+ ? util._Buffer_from(sizeOrArray)
1158
+ : typeof Uint8Array === "undefined"
1159
+ ? sizeOrArray
1160
+ : new Uint8Array(sizeOrArray);
1161
+ };
1162
+
1163
+ /**
1164
+ * Array implementation used in the browser. `Uint8Array` if supported, otherwise `Array`.
1165
+ * @type {Constructor<Uint8Array>}
1166
+ */
1167
+ util.Array = typeof Uint8Array !== "undefined" ? Uint8Array /* istanbul ignore next */ : Array;
1168
+
1169
+ /**
1170
+ * Any compatible Long instance.
1171
+ * This is a minimal stand-alone definition of a Long instance. The actual type is that exported by long.js.
1172
+ * @interface Long
1173
+ * @property {number} low Low bits
1174
+ * @property {number} high High bits
1175
+ * @property {boolean} unsigned Whether unsigned or not
1176
+ */
1177
+
1178
+ /**
1179
+ * Long.js's Long class if available.
1180
+ * @type {Constructor<Long>}
1181
+ */
1182
+ util.Long = /* istanbul ignore next */ util.global.dcodeIO && /* istanbul ignore next */ util.global.dcodeIO.Long
1183
+ || /* istanbul ignore next */ util.global.Long
1184
+ || util.inquire("long");
1185
+
1186
+ /**
1187
+ * Regular expression used to verify 2 bit (`bool`) map keys.
1188
+ * @type {RegExp}
1189
+ * @const
1190
+ */
1191
+ util.key2Re = /^true|false|0|1$/;
1192
+
1193
+ /**
1194
+ * Regular expression used to verify 32 bit (`int32` etc.) map keys.
1195
+ * @type {RegExp}
1196
+ * @const
1197
+ */
1198
+ util.key32Re = /^-?(?:0|[1-9][0-9]*)$/;
1199
+
1200
+ /**
1201
+ * Regular expression used to verify 64 bit (`int64` etc.) map keys.
1202
+ * @type {RegExp}
1203
+ * @const
1204
+ */
1205
+ util.key64Re = /^(?:[\\x00-\\xff]{8}|-?(?:0|[1-9][0-9]*))$/;
1206
+
1207
+ /**
1208
+ * Converts a number or long to an 8 characters long hash string.
1209
+ * @param {Long|number} value Value to convert
1210
+ * @returns {string} Hash
1211
+ */
1212
+ util.longToHash = function longToHash(value) {
1213
+ return value
1214
+ ? util.LongBits.from(value).toHash()
1215
+ : util.LongBits.zeroHash;
1216
+ };
1217
+
1218
+ /**
1219
+ * Converts an 8 characters long hash string to a long or number.
1220
+ * @param {string} hash Hash
1221
+ * @param {boolean} [unsigned=false] Whether unsigned or not
1222
+ * @returns {Long|number} Original value
1223
+ */
1224
+ util.longFromHash = function longFromHash(hash, unsigned) {
1225
+ var bits = util.LongBits.fromHash(hash);
1226
+ if (util.Long)
1227
+ return util.Long.fromBits(bits.lo, bits.hi, unsigned);
1228
+ return bits.toNumber(Boolean(unsigned));
1229
+ };
1230
+
1231
+ /**
1232
+ * Merges the properties of the source object into the destination object.
1233
+ * @memberof util
1234
+ * @param {Object.<string,*>} dst Destination object
1235
+ * @param {Object.<string,*>} src Source object
1236
+ * @param {boolean} [ifNotSet=false] Merges only if the key is not already set
1237
+ * @returns {Object.<string,*>} Destination object
1238
+ */
1239
+ function merge(dst, src, ifNotSet) { // used by converters
1240
+ for (var keys = Object.keys(src), i = 0; i < keys.length; ++i)
1241
+ if (dst[keys[i]] === undefined || !ifNotSet)
1242
+ dst[keys[i]] = src[keys[i]];
1243
+ return dst;
1244
+ }
1245
+
1246
+ util.merge = merge;
1247
+
1248
+ /**
1249
+ * Converts the first character of a string to lower case.
1250
+ * @param {string} str String to convert
1251
+ * @returns {string} Converted string
1252
+ */
1253
+ util.lcFirst = function lcFirst(str) {
1254
+ return str.charAt(0).toLowerCase() + str.substring(1);
1255
+ };
1256
+
1257
+ /**
1258
+ * Creates a custom error constructor.
1259
+ * @memberof util
1260
+ * @param {string} name Error name
1261
+ * @returns {Constructor<Error>} Custom error constructor
1262
+ */
1263
+ function newError(name) {
1264
+
1265
+ function CustomError(message, properties) {
1266
+
1267
+ if (!(this instanceof CustomError))
1268
+ return new CustomError(message, properties);
1269
+
1270
+ // Error.call(this, message);
1271
+ // ^ just returns a new error instance because the ctor can be called as a function
1272
+
1273
+ Object.defineProperty(this, "message", { get: function() { return message; } });
1274
+
1275
+ /* istanbul ignore next */
1276
+ if (Error.captureStackTrace) // node
1277
+ Error.captureStackTrace(this, CustomError);
1278
+ else
1279
+ Object.defineProperty(this, "stack", { value: new Error().stack || "" });
1280
+
1281
+ if (properties)
1282
+ merge(this, properties);
1283
+ }
1284
+
1285
+ CustomError.prototype = Object.create(Error.prototype, {
1286
+ constructor: {
1287
+ value: CustomError,
1288
+ writable: true,
1289
+ enumerable: false,
1290
+ configurable: true,
1291
+ },
1292
+ name: {
1293
+ get: function get() { return name; },
1294
+ set: undefined,
1295
+ enumerable: false,
1296
+ // configurable: false would accurately preserve the behavior of
1297
+ // the original, but I'm guessing that was not intentional.
1298
+ // For an actual error subclass, this property would
1299
+ // be configurable.
1300
+ configurable: true,
1301
+ },
1302
+ toString: {
1303
+ value: function value() { return this.name + ": " + this.message; },
1304
+ writable: true,
1305
+ enumerable: false,
1306
+ configurable: true,
1307
+ },
1308
+ });
1309
+
1310
+ return CustomError;
1311
+ }
1312
+
1313
+ util.newError = newError;
1314
+
1315
+ /**
1316
+ * Constructs a new protocol error.
1317
+ * @classdesc Error subclass indicating a protocol specifc error.
1318
+ * @memberof util
1319
+ * @extends Error
1320
+ * @template T extends Message<T>
1321
+ * @constructor
1322
+ * @param {string} message Error message
1323
+ * @param {Object.<string,*>} [properties] Additional properties
1324
+ * @example
1325
+ * try {
1326
+ * MyMessage.decode(someBuffer); // throws if required fields are missing
1327
+ * } catch (e) {
1328
+ * if (e instanceof ProtocolError && e.instance)
1329
+ * console.log("decoded so far: " + JSON.stringify(e.instance));
1330
+ * }
1331
+ */
1332
+ util.ProtocolError = newError("ProtocolError");
1333
+
1334
+ /**
1335
+ * So far decoded message instance.
1336
+ * @name util.ProtocolError#instance
1337
+ * @type {Message<T>}
1338
+ */
1339
+
1340
+ /**
1341
+ * A OneOf getter as returned by {@link util.oneOfGetter}.
1342
+ * @typedef OneOfGetter
1343
+ * @type {function}
1344
+ * @returns {string|undefined} Set field name, if any
1345
+ */
1346
+
1347
+ /**
1348
+ * Builds a getter for a oneof's present field name.
1349
+ * @param {string[]} fieldNames Field names
1350
+ * @returns {OneOfGetter} Unbound getter
1351
+ */
1352
+ util.oneOfGetter = function getOneOf(fieldNames) {
1353
+ var fieldMap = {};
1354
+ for (var i = 0; i < fieldNames.length; ++i)
1355
+ fieldMap[fieldNames[i]] = 1;
1356
+
1357
+ /**
1358
+ * @returns {string|undefined} Set field name, if any
1359
+ * @this Object
1360
+ * @ignore
1361
+ */
1362
+ return function() { // eslint-disable-line consistent-return
1363
+ for (var keys = Object.keys(this), i = keys.length - 1; i > -1; --i)
1364
+ if (fieldMap[keys[i]] === 1 && this[keys[i]] !== undefined && this[keys[i]] !== null)
1365
+ return keys[i];
1366
+ };
1367
+ };
1368
+
1369
+ /**
1370
+ * A OneOf setter as returned by {@link util.oneOfSetter}.
1371
+ * @typedef OneOfSetter
1372
+ * @type {function}
1373
+ * @param {string|undefined} value Field name
1374
+ * @returns {undefined}
1375
+ */
1376
+
1377
+ /**
1378
+ * Builds a setter for a oneof's present field name.
1379
+ * @param {string[]} fieldNames Field names
1380
+ * @returns {OneOfSetter} Unbound setter
1381
+ */
1382
+ util.oneOfSetter = function setOneOf(fieldNames) {
1383
+
1384
+ /**
1385
+ * @param {string} name Field name
1386
+ * @returns {undefined}
1387
+ * @this Object
1388
+ * @ignore
1389
+ */
1390
+ return function(name) {
1391
+ for (var i = 0; i < fieldNames.length; ++i)
1392
+ if (fieldNames[i] !== name)
1393
+ delete this[fieldNames[i]];
1394
+ };
1395
+ };
1396
+
1397
+ /**
1398
+ * Default conversion options used for {@link Message#toJSON} implementations.
1399
+ *
1400
+ * These options are close to proto3's JSON mapping with the exception that internal types like Any are handled just like messages. More precisely:
1401
+ *
1402
+ * - Longs become strings
1403
+ * - Enums become string keys
1404
+ * - Bytes become base64 encoded strings
1405
+ * - (Sub-)Messages become plain objects
1406
+ * - Maps become plain objects with all string keys
1407
+ * - Repeated fields become arrays
1408
+ * - NaN and Infinity for float and double fields become strings
1409
+ *
1410
+ * @type {IConversionOptions}
1411
+ * @see https://developers.google.com/protocol-buffers/docs/proto3?hl=en#json
1412
+ */
1413
+ util.toJSONOptions = {
1414
+ longs: String,
1415
+ enums: String,
1416
+ bytes: String,
1417
+ json: true
1418
+ };
1419
+
1420
+ // Sets up buffer utility according to the environment (called in index-minimal)
1421
+ util._configure = function() {
1422
+ var Buffer = util.Buffer;
1423
+ /* istanbul ignore if */
1424
+ if (!Buffer) {
1425
+ util._Buffer_from = util._Buffer_allocUnsafe = null;
1426
+ return;
1427
+ }
1428
+ // because node 4.x buffers are incompatible & immutable
1429
+ // see: https://github.com/dcodeIO/protobuf.js/pull/665
1430
+ util._Buffer_from = Buffer.from !== Uint8Array.from && Buffer.from ||
1431
+ /* istanbul ignore next */
1432
+ function Buffer_from(value, encoding) {
1433
+ return new Buffer(value, encoding);
1434
+ };
1435
+ util._Buffer_allocUnsafe = Buffer.allocUnsafe ||
1436
+ /* istanbul ignore next */
1437
+ function Buffer_allocUnsafe(size) {
1438
+ return new Buffer(size);
1439
+ };
1440
+ };
1441
+ } (minimal$1));
1442
+ return minimal$1;
1443
+ }
1444
+
1445
+ var writer = Writer$1;
1446
+
1447
+ var util$4 = requireMinimal();
1448
+
1449
+ var BufferWriter$1; // cyclic
1450
+
1451
+ var LongBits$1 = util$4.LongBits,
1452
+ base64 = util$4.base64,
1453
+ utf8$1 = util$4.utf8;
1454
+
1455
+ /**
1456
+ * Constructs a new writer operation instance.
1457
+ * @classdesc Scheduled writer operation.
1458
+ * @constructor
1459
+ * @param {function(*, Uint8Array, number)} fn Function to call
1460
+ * @param {number} len Value byte length
1461
+ * @param {*} val Value to write
1462
+ * @ignore
1463
+ */
1464
+ function Op(fn, len, val) {
1465
+
1466
+ /**
1467
+ * Function to call.
1468
+ * @type {function(Uint8Array, number, *)}
1469
+ */
1470
+ this.fn = fn;
1471
+
1472
+ /**
1473
+ * Value byte length.
1474
+ * @type {number}
1475
+ */
1476
+ this.len = len;
1477
+
1478
+ /**
1479
+ * Next operation.
1480
+ * @type {Writer.Op|undefined}
1481
+ */
1482
+ this.next = undefined;
1483
+
1484
+ /**
1485
+ * Value to write.
1486
+ * @type {*}
1487
+ */
1488
+ this.val = val; // type varies
1489
+ }
1490
+
1491
+ /* istanbul ignore next */
1492
+ function noop() {} // eslint-disable-line no-empty-function
1493
+
1494
+ /**
1495
+ * Constructs a new writer state instance.
1496
+ * @classdesc Copied writer state.
1497
+ * @memberof Writer
1498
+ * @constructor
1499
+ * @param {Writer} writer Writer to copy state from
1500
+ * @ignore
1501
+ */
1502
+ function State(writer) {
1503
+
1504
+ /**
1505
+ * Current head.
1506
+ * @type {Writer.Op}
1507
+ */
1508
+ this.head = writer.head;
1509
+
1510
+ /**
1511
+ * Current tail.
1512
+ * @type {Writer.Op}
1513
+ */
1514
+ this.tail = writer.tail;
1515
+
1516
+ /**
1517
+ * Current buffer length.
1518
+ * @type {number}
1519
+ */
1520
+ this.len = writer.len;
1521
+
1522
+ /**
1523
+ * Next state.
1524
+ * @type {State|null}
1525
+ */
1526
+ this.next = writer.states;
1527
+ }
1528
+
1529
+ /**
1530
+ * Constructs a new writer instance.
1531
+ * @classdesc Wire format writer using `Uint8Array` if available, otherwise `Array`.
1532
+ * @constructor
1533
+ */
1534
+ function Writer$1() {
1535
+
1536
+ /**
1537
+ * Current length.
1538
+ * @type {number}
1539
+ */
1540
+ this.len = 0;
1541
+
1542
+ /**
1543
+ * Operations head.
1544
+ * @type {Object}
1545
+ */
1546
+ this.head = new Op(noop, 0, 0);
1547
+
1548
+ /**
1549
+ * Operations tail
1550
+ * @type {Object}
1551
+ */
1552
+ this.tail = this.head;
1553
+
1554
+ /**
1555
+ * Linked forked states.
1556
+ * @type {Object|null}
1557
+ */
1558
+ this.states = null;
1559
+
1560
+ // When a value is written, the writer calculates its byte length and puts it into a linked
1561
+ // list of operations to perform when finish() is called. This both allows us to allocate
1562
+ // buffers of the exact required size and reduces the amount of work we have to do compared
1563
+ // to first calculating over objects and then encoding over objects. In our case, the encoding
1564
+ // part is just a linked list walk calling operations with already prepared values.
1565
+ }
1566
+
1567
+ var create$1 = function create() {
1568
+ return util$4.Buffer
1569
+ ? function create_buffer_setup() {
1570
+ return (Writer$1.create = function create_buffer() {
1571
+ return new BufferWriter$1();
1572
+ })();
1573
+ }
1574
+ /* istanbul ignore next */
1575
+ : function create_array() {
1576
+ return new Writer$1();
1577
+ };
1578
+ };
1579
+
1580
+ /**
1581
+ * Creates a new writer.
1582
+ * @function
1583
+ * @returns {BufferWriter|Writer} A {@link BufferWriter} when Buffers are supported, otherwise a {@link Writer}
1584
+ */
1585
+ Writer$1.create = create$1();
1586
+
1587
+ /**
1588
+ * Allocates a buffer of the specified size.
1589
+ * @param {number} size Buffer size
1590
+ * @returns {Uint8Array} Buffer
1591
+ */
1592
+ Writer$1.alloc = function alloc(size) {
1593
+ return new util$4.Array(size);
1594
+ };
1595
+
1596
+ // Use Uint8Array buffer pool in the browser, just like node does with buffers
1597
+ /* istanbul ignore else */
1598
+ if (util$4.Array !== Array)
1599
+ Writer$1.alloc = util$4.pool(Writer$1.alloc, util$4.Array.prototype.subarray);
1600
+
1601
+ /**
1602
+ * Pushes a new operation to the queue.
1603
+ * @param {function(Uint8Array, number, *)} fn Function to call
1604
+ * @param {number} len Value byte length
1605
+ * @param {number} val Value to write
1606
+ * @returns {Writer} `this`
1607
+ * @private
1608
+ */
1609
+ Writer$1.prototype._push = function push(fn, len, val) {
1610
+ this.tail = this.tail.next = new Op(fn, len, val);
1611
+ this.len += len;
1612
+ return this;
1613
+ };
1614
+
1615
+ function writeByte(val, buf, pos) {
1616
+ buf[pos] = val & 255;
1617
+ }
1618
+
1619
+ function writeVarint32(val, buf, pos) {
1620
+ while (val > 127) {
1621
+ buf[pos++] = val & 127 | 128;
1622
+ val >>>= 7;
1623
+ }
1624
+ buf[pos] = val;
1625
+ }
1626
+
1627
+ /**
1628
+ * Constructs a new varint writer operation instance.
1629
+ * @classdesc Scheduled varint writer operation.
1630
+ * @extends Op
1631
+ * @constructor
1632
+ * @param {number} len Value byte length
1633
+ * @param {number} val Value to write
1634
+ * @ignore
1635
+ */
1636
+ function VarintOp(len, val) {
1637
+ this.len = len;
1638
+ this.next = undefined;
1639
+ this.val = val;
1640
+ }
1641
+
1642
+ VarintOp.prototype = Object.create(Op.prototype);
1643
+ VarintOp.prototype.fn = writeVarint32;
1644
+
1645
+ /**
1646
+ * Writes an unsigned 32 bit value as a varint.
1647
+ * @param {number} value Value to write
1648
+ * @returns {Writer} `this`
1649
+ */
1650
+ Writer$1.prototype.uint32 = function write_uint32(value) {
1651
+ // here, the call to this.push has been inlined and a varint specific Op subclass is used.
1652
+ // uint32 is by far the most frequently used operation and benefits significantly from this.
1653
+ this.len += (this.tail = this.tail.next = new VarintOp(
1654
+ (value = value >>> 0)
1655
+ < 128 ? 1
1656
+ : value < 16384 ? 2
1657
+ : value < 2097152 ? 3
1658
+ : value < 268435456 ? 4
1659
+ : 5,
1660
+ value)).len;
1661
+ return this;
1662
+ };
1663
+
1664
+ /**
1665
+ * Writes a signed 32 bit value as a varint.
1666
+ * @function
1667
+ * @param {number} value Value to write
1668
+ * @returns {Writer} `this`
1669
+ */
1670
+ Writer$1.prototype.int32 = function write_int32(value) {
1671
+ return value < 0
1672
+ ? this._push(writeVarint64, 10, LongBits$1.fromNumber(value)) // 10 bytes per spec
1673
+ : this.uint32(value);
1674
+ };
1675
+
1676
+ /**
1677
+ * Writes a 32 bit value as a varint, zig-zag encoded.
1678
+ * @param {number} value Value to write
1679
+ * @returns {Writer} `this`
1680
+ */
1681
+ Writer$1.prototype.sint32 = function write_sint32(value) {
1682
+ return this.uint32((value << 1 ^ value >> 31) >>> 0);
1683
+ };
1684
+
1685
+ function writeVarint64(val, buf, pos) {
1686
+ while (val.hi) {
1687
+ buf[pos++] = val.lo & 127 | 128;
1688
+ val.lo = (val.lo >>> 7 | val.hi << 25) >>> 0;
1689
+ val.hi >>>= 7;
1690
+ }
1691
+ while (val.lo > 127) {
1692
+ buf[pos++] = val.lo & 127 | 128;
1693
+ val.lo = val.lo >>> 7;
1694
+ }
1695
+ buf[pos++] = val.lo;
1696
+ }
1697
+
1698
+ /**
1699
+ * Writes an unsigned 64 bit value as a varint.
1700
+ * @param {Long|number|string} value Value to write
1701
+ * @returns {Writer} `this`
1702
+ * @throws {TypeError} If `value` is a string and no long library is present.
1703
+ */
1704
+ Writer$1.prototype.uint64 = function write_uint64(value) {
1705
+ var bits = LongBits$1.from(value);
1706
+ return this._push(writeVarint64, bits.length(), bits);
1707
+ };
1708
+
1709
+ /**
1710
+ * Writes a signed 64 bit value as a varint.
1711
+ * @function
1712
+ * @param {Long|number|string} value Value to write
1713
+ * @returns {Writer} `this`
1714
+ * @throws {TypeError} If `value` is a string and no long library is present.
1715
+ */
1716
+ Writer$1.prototype.int64 = Writer$1.prototype.uint64;
1717
+
1718
+ /**
1719
+ * Writes a signed 64 bit value as a varint, zig-zag encoded.
1720
+ * @param {Long|number|string} value Value to write
1721
+ * @returns {Writer} `this`
1722
+ * @throws {TypeError} If `value` is a string and no long library is present.
1723
+ */
1724
+ Writer$1.prototype.sint64 = function write_sint64(value) {
1725
+ var bits = LongBits$1.from(value).zzEncode();
1726
+ return this._push(writeVarint64, bits.length(), bits);
1727
+ };
1728
+
1729
+ /**
1730
+ * Writes a boolish value as a varint.
1731
+ * @param {boolean} value Value to write
1732
+ * @returns {Writer} `this`
1733
+ */
1734
+ Writer$1.prototype.bool = function write_bool(value) {
1735
+ return this._push(writeByte, 1, value ? 1 : 0);
1736
+ };
1737
+
1738
+ function writeFixed32(val, buf, pos) {
1739
+ buf[pos ] = val & 255;
1740
+ buf[pos + 1] = val >>> 8 & 255;
1741
+ buf[pos + 2] = val >>> 16 & 255;
1742
+ buf[pos + 3] = val >>> 24;
1743
+ }
1744
+
1745
+ /**
1746
+ * Writes an unsigned 32 bit value as fixed 32 bits.
1747
+ * @param {number} value Value to write
1748
+ * @returns {Writer} `this`
1749
+ */
1750
+ Writer$1.prototype.fixed32 = function write_fixed32(value) {
1751
+ return this._push(writeFixed32, 4, value >>> 0);
1752
+ };
1753
+
1754
+ /**
1755
+ * Writes a signed 32 bit value as fixed 32 bits.
1756
+ * @function
1757
+ * @param {number} value Value to write
1758
+ * @returns {Writer} `this`
1759
+ */
1760
+ Writer$1.prototype.sfixed32 = Writer$1.prototype.fixed32;
1761
+
1762
+ /**
1763
+ * Writes an unsigned 64 bit value as fixed 64 bits.
1764
+ * @param {Long|number|string} value Value to write
1765
+ * @returns {Writer} `this`
1766
+ * @throws {TypeError} If `value` is a string and no long library is present.
1767
+ */
1768
+ Writer$1.prototype.fixed64 = function write_fixed64(value) {
1769
+ var bits = LongBits$1.from(value);
1770
+ return this._push(writeFixed32, 4, bits.lo)._push(writeFixed32, 4, bits.hi);
1771
+ };
1772
+
1773
+ /**
1774
+ * Writes a signed 64 bit value as fixed 64 bits.
1775
+ * @function
1776
+ * @param {Long|number|string} value Value to write
1777
+ * @returns {Writer} `this`
1778
+ * @throws {TypeError} If `value` is a string and no long library is present.
1779
+ */
1780
+ Writer$1.prototype.sfixed64 = Writer$1.prototype.fixed64;
1781
+
1782
+ /**
1783
+ * Writes a float (32 bit).
1784
+ * @function
1785
+ * @param {number} value Value to write
1786
+ * @returns {Writer} `this`
1787
+ */
1788
+ Writer$1.prototype.float = function write_float(value) {
1789
+ return this._push(util$4.float.writeFloatLE, 4, value);
1790
+ };
1791
+
1792
+ /**
1793
+ * Writes a double (64 bit float).
1794
+ * @function
1795
+ * @param {number} value Value to write
1796
+ * @returns {Writer} `this`
1797
+ */
1798
+ Writer$1.prototype.double = function write_double(value) {
1799
+ return this._push(util$4.float.writeDoubleLE, 8, value);
1800
+ };
1801
+
1802
+ var writeBytes = util$4.Array.prototype.set
1803
+ ? function writeBytes_set(val, buf, pos) {
1804
+ buf.set(val, pos); // also works for plain array values
1805
+ }
1806
+ /* istanbul ignore next */
1807
+ : function writeBytes_for(val, buf, pos) {
1808
+ for (var i = 0; i < val.length; ++i)
1809
+ buf[pos + i] = val[i];
1810
+ };
1811
+
1812
+ /**
1813
+ * Writes a sequence of bytes.
1814
+ * @param {Uint8Array|string} value Buffer or base64 encoded string to write
1815
+ * @returns {Writer} `this`
1816
+ */
1817
+ Writer$1.prototype.bytes = function write_bytes(value) {
1818
+ var len = value.length >>> 0;
1819
+ if (!len)
1820
+ return this._push(writeByte, 1, 0);
1821
+ if (util$4.isString(value)) {
1822
+ var buf = Writer$1.alloc(len = base64.length(value));
1823
+ base64.decode(value, buf, 0);
1824
+ value = buf;
1825
+ }
1826
+ return this.uint32(len)._push(writeBytes, len, value);
1827
+ };
1828
+
1829
+ /**
1830
+ * Writes a string.
1831
+ * @param {string} value Value to write
1832
+ * @returns {Writer} `this`
1833
+ */
1834
+ Writer$1.prototype.string = function write_string(value) {
1835
+ var len = utf8$1.length(value);
1836
+ return len
1837
+ ? this.uint32(len)._push(utf8$1.write, len, value)
1838
+ : this._push(writeByte, 1, 0);
1839
+ };
1840
+
1841
+ /**
1842
+ * Forks this writer's state by pushing it to a stack.
1843
+ * Calling {@link Writer#reset|reset} or {@link Writer#ldelim|ldelim} resets the writer to the previous state.
1844
+ * @returns {Writer} `this`
1845
+ */
1846
+ Writer$1.prototype.fork = function fork() {
1847
+ this.states = new State(this);
1848
+ this.head = this.tail = new Op(noop, 0, 0);
1849
+ this.len = 0;
1850
+ return this;
1851
+ };
1852
+
1853
+ /**
1854
+ * Resets this instance to the last state.
1855
+ * @returns {Writer} `this`
1856
+ */
1857
+ Writer$1.prototype.reset = function reset() {
1858
+ if (this.states) {
1859
+ this.head = this.states.head;
1860
+ this.tail = this.states.tail;
1861
+ this.len = this.states.len;
1862
+ this.states = this.states.next;
1863
+ } else {
1864
+ this.head = this.tail = new Op(noop, 0, 0);
1865
+ this.len = 0;
1866
+ }
1867
+ return this;
1868
+ };
1869
+
1870
+ /**
1871
+ * Resets to the last state and appends the fork state's current write length as a varint followed by its operations.
1872
+ * @returns {Writer} `this`
1873
+ */
1874
+ Writer$1.prototype.ldelim = function ldelim() {
1875
+ var head = this.head,
1876
+ tail = this.tail,
1877
+ len = this.len;
1878
+ this.reset().uint32(len);
1879
+ if (len) {
1880
+ this.tail.next = head.next; // skip noop
1881
+ this.tail = tail;
1882
+ this.len += len;
1883
+ }
1884
+ return this;
1885
+ };
1886
+
1887
+ /**
1888
+ * Finishes the write operation.
1889
+ * @returns {Uint8Array} Finished buffer
1890
+ */
1891
+ Writer$1.prototype.finish = function finish() {
1892
+ var head = this.head.next, // skip noop
1893
+ buf = this.constructor.alloc(this.len),
1894
+ pos = 0;
1895
+ while (head) {
1896
+ head.fn(head.val, buf, pos);
1897
+ pos += head.len;
1898
+ head = head.next;
1899
+ }
1900
+ // this.head = this.tail = null;
1901
+ return buf;
1902
+ };
1903
+
1904
+ Writer$1._configure = function(BufferWriter_) {
1905
+ BufferWriter$1 = BufferWriter_;
1906
+ Writer$1.create = create$1();
1907
+ BufferWriter$1._configure();
1908
+ };
1909
+
1910
+ var writer_buffer = BufferWriter;
1911
+
1912
+ // extends Writer
1913
+ var Writer = writer;
1914
+ (BufferWriter.prototype = Object.create(Writer.prototype)).constructor = BufferWriter;
1915
+
1916
+ var util$3 = requireMinimal();
1917
+
1918
+ /**
1919
+ * Constructs a new buffer writer instance.
1920
+ * @classdesc Wire format writer using node buffers.
1921
+ * @extends Writer
1922
+ * @constructor
1923
+ */
1924
+ function BufferWriter() {
1925
+ Writer.call(this);
1926
+ }
1927
+
1928
+ BufferWriter._configure = function () {
1929
+ /**
1930
+ * Allocates a buffer of the specified size.
1931
+ * @function
1932
+ * @param {number} size Buffer size
1933
+ * @returns {Buffer} Buffer
1934
+ */
1935
+ BufferWriter.alloc = util$3._Buffer_allocUnsafe;
1936
+
1937
+ BufferWriter.writeBytesBuffer = util$3.Buffer && util$3.Buffer.prototype instanceof Uint8Array && util$3.Buffer.prototype.set.name === "set"
1938
+ ? function writeBytesBuffer_set(val, buf, pos) {
1939
+ buf.set(val, pos); // faster than copy (requires node >= 4 where Buffers extend Uint8Array and set is properly inherited)
1940
+ // also works for plain array values
1941
+ }
1942
+ /* istanbul ignore next */
1943
+ : function writeBytesBuffer_copy(val, buf, pos) {
1944
+ if (val.copy) // Buffer values
1945
+ val.copy(buf, pos, 0, val.length);
1946
+ else for (var i = 0; i < val.length;) // plain array values
1947
+ buf[pos++] = val[i++];
1948
+ };
1949
+ };
1950
+
1951
+
1952
+ /**
1953
+ * @override
1954
+ */
1955
+ BufferWriter.prototype.bytes = function write_bytes_buffer(value) {
1956
+ if (util$3.isString(value))
1957
+ value = util$3._Buffer_from(value, "base64");
1958
+ var len = value.length >>> 0;
1959
+ this.uint32(len);
1960
+ if (len)
1961
+ this._push(BufferWriter.writeBytesBuffer, len, value);
1962
+ return this;
1963
+ };
1964
+
1965
+ function writeStringBuffer(val, buf, pos) {
1966
+ if (val.length < 40) // plain js is faster for short strings (probably due to redundant assertions)
1967
+ util$3.utf8.write(val, buf, pos);
1968
+ else if (buf.utf8Write)
1969
+ buf.utf8Write(val, pos);
1970
+ else
1971
+ buf.write(val, pos);
1972
+ }
1973
+
1974
+ /**
1975
+ * @override
1976
+ */
1977
+ BufferWriter.prototype.string = function write_string_buffer(value) {
1978
+ var len = util$3.Buffer.byteLength(value);
1979
+ this.uint32(len);
1980
+ if (len)
1981
+ this._push(writeStringBuffer, len, value);
1982
+ return this;
1983
+ };
1984
+
1985
+
1986
+ /**
1987
+ * Finishes the write operation.
1988
+ * @name BufferWriter#finish
1989
+ * @function
1990
+ * @returns {Buffer} Finished buffer
1991
+ */
1992
+
1993
+ BufferWriter._configure();
1994
+
1995
+ var reader = Reader$1;
1996
+
1997
+ var util$2 = requireMinimal();
1998
+
1999
+ var BufferReader$1; // cyclic
2000
+
2001
+ var LongBits = util$2.LongBits,
2002
+ utf8 = util$2.utf8;
2003
+
2004
+ /* istanbul ignore next */
2005
+ function indexOutOfRange(reader, writeLength) {
2006
+ return RangeError("index out of range: " + reader.pos + " + " + (writeLength || 1) + " > " + reader.len);
2007
+ }
2008
+
2009
+ /**
2010
+ * Constructs a new reader instance using the specified buffer.
2011
+ * @classdesc Wire format reader using `Uint8Array` if available, otherwise `Array`.
2012
+ * @constructor
2013
+ * @param {Uint8Array} buffer Buffer to read from
2014
+ */
2015
+ function Reader$1(buffer) {
2016
+
2017
+ /**
2018
+ * Read buffer.
2019
+ * @type {Uint8Array}
2020
+ */
2021
+ this.buf = buffer;
2022
+
2023
+ /**
2024
+ * Read buffer position.
2025
+ * @type {number}
2026
+ */
2027
+ this.pos = 0;
2028
+
2029
+ /**
2030
+ * Read buffer length.
2031
+ * @type {number}
2032
+ */
2033
+ this.len = buffer.length;
2034
+ }
2035
+
2036
+ var create_array = typeof Uint8Array !== "undefined"
2037
+ ? function create_typed_array(buffer) {
2038
+ if (buffer instanceof Uint8Array || Array.isArray(buffer))
2039
+ return new Reader$1(buffer);
2040
+ throw Error("illegal buffer");
2041
+ }
2042
+ /* istanbul ignore next */
2043
+ : function create_array(buffer) {
2044
+ if (Array.isArray(buffer))
2045
+ return new Reader$1(buffer);
2046
+ throw Error("illegal buffer");
2047
+ };
2048
+
2049
+ var create = function create() {
2050
+ return util$2.Buffer
2051
+ ? function create_buffer_setup(buffer) {
2052
+ return (Reader$1.create = function create_buffer(buffer) {
2053
+ return util$2.Buffer.isBuffer(buffer)
2054
+ ? new BufferReader$1(buffer)
2055
+ /* istanbul ignore next */
2056
+ : create_array(buffer);
2057
+ })(buffer);
2058
+ }
2059
+ /* istanbul ignore next */
2060
+ : create_array;
2061
+ };
2062
+
2063
+ /**
2064
+ * Creates a new reader using the specified buffer.
2065
+ * @function
2066
+ * @param {Uint8Array|Buffer} buffer Buffer to read from
2067
+ * @returns {Reader|BufferReader} A {@link BufferReader} if `buffer` is a Buffer, otherwise a {@link Reader}
2068
+ * @throws {Error} If `buffer` is not a valid buffer
2069
+ */
2070
+ Reader$1.create = create();
2071
+
2072
+ Reader$1.prototype._slice = util$2.Array.prototype.subarray || /* istanbul ignore next */ util$2.Array.prototype.slice;
2073
+
2074
+ /**
2075
+ * Reads a varint as an unsigned 32 bit value.
2076
+ * @function
2077
+ * @returns {number} Value read
2078
+ */
2079
+ Reader$1.prototype.uint32 = (function read_uint32_setup() {
2080
+ var value = 4294967295; // optimizer type-hint, tends to deopt otherwise (?!)
2081
+ return function read_uint32() {
2082
+ value = ( this.buf[this.pos] & 127 ) >>> 0; if (this.buf[this.pos++] < 128) return value;
2083
+ value = (value | (this.buf[this.pos] & 127) << 7) >>> 0; if (this.buf[this.pos++] < 128) return value;
2084
+ value = (value | (this.buf[this.pos] & 127) << 14) >>> 0; if (this.buf[this.pos++] < 128) return value;
2085
+ value = (value | (this.buf[this.pos] & 127) << 21) >>> 0; if (this.buf[this.pos++] < 128) return value;
2086
+ value = (value | (this.buf[this.pos] & 15) << 28) >>> 0; if (this.buf[this.pos++] < 128) return value;
2087
+
2088
+ /* istanbul ignore if */
2089
+ if ((this.pos += 5) > this.len) {
2090
+ this.pos = this.len;
2091
+ throw indexOutOfRange(this, 10);
2092
+ }
2093
+ return value;
2094
+ };
2095
+ })();
2096
+
2097
+ /**
2098
+ * Reads a varint as a signed 32 bit value.
2099
+ * @returns {number} Value read
2100
+ */
2101
+ Reader$1.prototype.int32 = function read_int32() {
2102
+ return this.uint32() | 0;
2103
+ };
2104
+
2105
+ /**
2106
+ * Reads a zig-zag encoded varint as a signed 32 bit value.
2107
+ * @returns {number} Value read
2108
+ */
2109
+ Reader$1.prototype.sint32 = function read_sint32() {
2110
+ var value = this.uint32();
2111
+ return value >>> 1 ^ -(value & 1) | 0;
2112
+ };
2113
+
2114
+ /* eslint-disable no-invalid-this */
2115
+
2116
+ function readLongVarint() {
2117
+ // tends to deopt with local vars for octet etc.
2118
+ var bits = new LongBits(0, 0);
2119
+ var i = 0;
2120
+ if (this.len - this.pos > 4) { // fast route (lo)
2121
+ for (; i < 4; ++i) {
2122
+ // 1st..4th
2123
+ bits.lo = (bits.lo | (this.buf[this.pos] & 127) << i * 7) >>> 0;
2124
+ if (this.buf[this.pos++] < 128)
2125
+ return bits;
2126
+ }
2127
+ // 5th
2128
+ bits.lo = (bits.lo | (this.buf[this.pos] & 127) << 28) >>> 0;
2129
+ bits.hi = (bits.hi | (this.buf[this.pos] & 127) >> 4) >>> 0;
2130
+ if (this.buf[this.pos++] < 128)
2131
+ return bits;
2132
+ i = 0;
2133
+ } else {
2134
+ for (; i < 3; ++i) {
2135
+ /* istanbul ignore if */
2136
+ if (this.pos >= this.len)
2137
+ throw indexOutOfRange(this);
2138
+ // 1st..3th
2139
+ bits.lo = (bits.lo | (this.buf[this.pos] & 127) << i * 7) >>> 0;
2140
+ if (this.buf[this.pos++] < 128)
2141
+ return bits;
2142
+ }
2143
+ // 4th
2144
+ bits.lo = (bits.lo | (this.buf[this.pos++] & 127) << i * 7) >>> 0;
2145
+ return bits;
2146
+ }
2147
+ if (this.len - this.pos > 4) { // fast route (hi)
2148
+ for (; i < 5; ++i) {
2149
+ // 6th..10th
2150
+ bits.hi = (bits.hi | (this.buf[this.pos] & 127) << i * 7 + 3) >>> 0;
2151
+ if (this.buf[this.pos++] < 128)
2152
+ return bits;
2153
+ }
2154
+ } else {
2155
+ for (; i < 5; ++i) {
2156
+ /* istanbul ignore if */
2157
+ if (this.pos >= this.len)
2158
+ throw indexOutOfRange(this);
2159
+ // 6th..10th
2160
+ bits.hi = (bits.hi | (this.buf[this.pos] & 127) << i * 7 + 3) >>> 0;
2161
+ if (this.buf[this.pos++] < 128)
2162
+ return bits;
2163
+ }
2164
+ }
2165
+ /* istanbul ignore next */
2166
+ throw Error("invalid varint encoding");
2167
+ }
2168
+
2169
+ /* eslint-enable no-invalid-this */
2170
+
2171
+ /**
2172
+ * Reads a varint as a signed 64 bit value.
2173
+ * @name Reader#int64
2174
+ * @function
2175
+ * @returns {Long} Value read
2176
+ */
2177
+
2178
+ /**
2179
+ * Reads a varint as an unsigned 64 bit value.
2180
+ * @name Reader#uint64
2181
+ * @function
2182
+ * @returns {Long} Value read
2183
+ */
2184
+
2185
+ /**
2186
+ * Reads a zig-zag encoded varint as a signed 64 bit value.
2187
+ * @name Reader#sint64
2188
+ * @function
2189
+ * @returns {Long} Value read
2190
+ */
2191
+
2192
+ /**
2193
+ * Reads a varint as a boolean.
2194
+ * @returns {boolean} Value read
2195
+ */
2196
+ Reader$1.prototype.bool = function read_bool() {
2197
+ return this.uint32() !== 0;
2198
+ };
2199
+
2200
+ function readFixed32_end(buf, end) { // note that this uses `end`, not `pos`
2201
+ return (buf[end - 4]
2202
+ | buf[end - 3] << 8
2203
+ | buf[end - 2] << 16
2204
+ | buf[end - 1] << 24) >>> 0;
2205
+ }
2206
+
2207
+ /**
2208
+ * Reads fixed 32 bits as an unsigned 32 bit integer.
2209
+ * @returns {number} Value read
2210
+ */
2211
+ Reader$1.prototype.fixed32 = function read_fixed32() {
2212
+
2213
+ /* istanbul ignore if */
2214
+ if (this.pos + 4 > this.len)
2215
+ throw indexOutOfRange(this, 4);
2216
+
2217
+ return readFixed32_end(this.buf, this.pos += 4);
2218
+ };
2219
+
2220
+ /**
2221
+ * Reads fixed 32 bits as a signed 32 bit integer.
2222
+ * @returns {number} Value read
2223
+ */
2224
+ Reader$1.prototype.sfixed32 = function read_sfixed32() {
2225
+
2226
+ /* istanbul ignore if */
2227
+ if (this.pos + 4 > this.len)
2228
+ throw indexOutOfRange(this, 4);
2229
+
2230
+ return readFixed32_end(this.buf, this.pos += 4) | 0;
2231
+ };
2232
+
2233
+ /* eslint-disable no-invalid-this */
2234
+
2235
+ function readFixed64(/* this: Reader */) {
2236
+
2237
+ /* istanbul ignore if */
2238
+ if (this.pos + 8 > this.len)
2239
+ throw indexOutOfRange(this, 8);
2240
+
2241
+ return new LongBits(readFixed32_end(this.buf, this.pos += 4), readFixed32_end(this.buf, this.pos += 4));
2242
+ }
2243
+
2244
+ /* eslint-enable no-invalid-this */
2245
+
2246
+ /**
2247
+ * Reads fixed 64 bits.
2248
+ * @name Reader#fixed64
2249
+ * @function
2250
+ * @returns {Long} Value read
2251
+ */
2252
+
2253
+ /**
2254
+ * Reads zig-zag encoded fixed 64 bits.
2255
+ * @name Reader#sfixed64
2256
+ * @function
2257
+ * @returns {Long} Value read
2258
+ */
2259
+
2260
+ /**
2261
+ * Reads a float (32 bit) as a number.
2262
+ * @function
2263
+ * @returns {number} Value read
2264
+ */
2265
+ Reader$1.prototype.float = function read_float() {
2266
+
2267
+ /* istanbul ignore if */
2268
+ if (this.pos + 4 > this.len)
2269
+ throw indexOutOfRange(this, 4);
2270
+
2271
+ var value = util$2.float.readFloatLE(this.buf, this.pos);
2272
+ this.pos += 4;
2273
+ return value;
2274
+ };
2275
+
2276
+ /**
2277
+ * Reads a double (64 bit float) as a number.
2278
+ * @function
2279
+ * @returns {number} Value read
2280
+ */
2281
+ Reader$1.prototype.double = function read_double() {
2282
+
2283
+ /* istanbul ignore if */
2284
+ if (this.pos + 8 > this.len)
2285
+ throw indexOutOfRange(this, 4);
2286
+
2287
+ var value = util$2.float.readDoubleLE(this.buf, this.pos);
2288
+ this.pos += 8;
2289
+ return value;
2290
+ };
2291
+
2292
+ /**
2293
+ * Reads a sequence of bytes preceeded by its length as a varint.
2294
+ * @returns {Uint8Array} Value read
2295
+ */
2296
+ Reader$1.prototype.bytes = function read_bytes() {
2297
+ var length = this.uint32(),
2298
+ start = this.pos,
2299
+ end = this.pos + length;
2300
+
2301
+ /* istanbul ignore if */
2302
+ if (end > this.len)
2303
+ throw indexOutOfRange(this, length);
2304
+
2305
+ this.pos += length;
2306
+ if (Array.isArray(this.buf)) // plain array
2307
+ return this.buf.slice(start, end);
2308
+
2309
+ if (start === end) { // fix for IE 10/Win8 and others' subarray returning array of size 1
2310
+ var nativeBuffer = util$2.Buffer;
2311
+ return nativeBuffer
2312
+ ? nativeBuffer.alloc(0)
2313
+ : new this.buf.constructor(0);
2314
+ }
2315
+ return this._slice.call(this.buf, start, end);
2316
+ };
2317
+
2318
+ /**
2319
+ * Reads a string preceeded by its byte length as a varint.
2320
+ * @returns {string} Value read
2321
+ */
2322
+ Reader$1.prototype.string = function read_string() {
2323
+ var bytes = this.bytes();
2324
+ return utf8.read(bytes, 0, bytes.length);
2325
+ };
2326
+
2327
+ /**
2328
+ * Skips the specified number of bytes if specified, otherwise skips a varint.
2329
+ * @param {number} [length] Length if known, otherwise a varint is assumed
2330
+ * @returns {Reader} `this`
2331
+ */
2332
+ Reader$1.prototype.skip = function skip(length) {
2333
+ if (typeof length === "number") {
2334
+ /* istanbul ignore if */
2335
+ if (this.pos + length > this.len)
2336
+ throw indexOutOfRange(this, length);
2337
+ this.pos += length;
2338
+ } else {
2339
+ do {
2340
+ /* istanbul ignore if */
2341
+ if (this.pos >= this.len)
2342
+ throw indexOutOfRange(this);
2343
+ } while (this.buf[this.pos++] & 128);
2344
+ }
2345
+ return this;
2346
+ };
2347
+
2348
+ /**
2349
+ * Skips the next element of the specified wire type.
2350
+ * @param {number} wireType Wire type received
2351
+ * @returns {Reader} `this`
2352
+ */
2353
+ Reader$1.prototype.skipType = function(wireType) {
2354
+ switch (wireType) {
2355
+ case 0:
2356
+ this.skip();
2357
+ break;
2358
+ case 1:
2359
+ this.skip(8);
2360
+ break;
2361
+ case 2:
2362
+ this.skip(this.uint32());
2363
+ break;
2364
+ case 3:
2365
+ while ((wireType = this.uint32() & 7) !== 4) {
2366
+ this.skipType(wireType);
2367
+ }
2368
+ break;
2369
+ case 5:
2370
+ this.skip(4);
2371
+ break;
2372
+
2373
+ /* istanbul ignore next */
2374
+ default:
2375
+ throw Error("invalid wire type " + wireType + " at offset " + this.pos);
2376
+ }
2377
+ return this;
2378
+ };
2379
+
2380
+ Reader$1._configure = function(BufferReader_) {
2381
+ BufferReader$1 = BufferReader_;
2382
+ Reader$1.create = create();
2383
+ BufferReader$1._configure();
2384
+
2385
+ var fn = util$2.Long ? "toLong" : /* istanbul ignore next */ "toNumber";
2386
+ util$2.merge(Reader$1.prototype, {
2387
+
2388
+ int64: function read_int64() {
2389
+ return readLongVarint.call(this)[fn](false);
2390
+ },
2391
+
2392
+ uint64: function read_uint64() {
2393
+ return readLongVarint.call(this)[fn](true);
2394
+ },
2395
+
2396
+ sint64: function read_sint64() {
2397
+ return readLongVarint.call(this).zzDecode()[fn](false);
2398
+ },
2399
+
2400
+ fixed64: function read_fixed64() {
2401
+ return readFixed64.call(this)[fn](true);
2402
+ },
2403
+
2404
+ sfixed64: function read_sfixed64() {
2405
+ return readFixed64.call(this)[fn](false);
2406
+ }
2407
+
2408
+ });
2409
+ };
2410
+
2411
+ var reader_buffer = BufferReader;
2412
+
2413
+ // extends Reader
2414
+ var Reader = reader;
2415
+ (BufferReader.prototype = Object.create(Reader.prototype)).constructor = BufferReader;
2416
+
2417
+ var util$1 = requireMinimal();
2418
+
2419
+ /**
2420
+ * Constructs a new buffer reader instance.
2421
+ * @classdesc Wire format reader using node buffers.
2422
+ * @extends Reader
2423
+ * @constructor
2424
+ * @param {Buffer} buffer Buffer to read from
2425
+ */
2426
+ function BufferReader(buffer) {
2427
+ Reader.call(this, buffer);
2428
+
2429
+ /**
2430
+ * Read buffer.
2431
+ * @name BufferReader#buf
2432
+ * @type {Buffer}
2433
+ */
2434
+ }
2435
+
2436
+ BufferReader._configure = function () {
2437
+ /* istanbul ignore else */
2438
+ if (util$1.Buffer)
2439
+ BufferReader.prototype._slice = util$1.Buffer.prototype.slice;
2440
+ };
2441
+
2442
+
2443
+ /**
2444
+ * @override
2445
+ */
2446
+ BufferReader.prototype.string = function read_string_buffer() {
2447
+ var len = this.uint32(); // modifies pos
2448
+ return this.buf.utf8Slice
2449
+ ? this.buf.utf8Slice(this.pos, this.pos = Math.min(this.pos + len, this.len))
2450
+ : this.buf.toString("utf-8", this.pos, this.pos = Math.min(this.pos + len, this.len));
2451
+ };
2452
+
2453
+ /**
2454
+ * Reads a sequence of bytes preceeded by its length as a varint.
2455
+ * @name BufferReader#bytes
2456
+ * @function
2457
+ * @returns {Buffer} Value read
2458
+ */
2459
+
2460
+ BufferReader._configure();
2461
+
2462
+ var rpc = {};
2463
+
2464
+ var service = Service;
2465
+
2466
+ var util = requireMinimal();
2467
+
2468
+ // Extends EventEmitter
2469
+ (Service.prototype = Object.create(util.EventEmitter.prototype)).constructor = Service;
2470
+
2471
+ /**
2472
+ * A service method callback as used by {@link rpc.ServiceMethod|ServiceMethod}.
2473
+ *
2474
+ * Differs from {@link RPCImplCallback} in that it is an actual callback of a service method which may not return `response = null`.
2475
+ * @typedef rpc.ServiceMethodCallback
2476
+ * @template TRes extends Message<TRes>
2477
+ * @type {function}
2478
+ * @param {Error|null} error Error, if any
2479
+ * @param {TRes} [response] Response message
2480
+ * @returns {undefined}
2481
+ */
2482
+
2483
+ /**
2484
+ * A service method part of a {@link rpc.Service} as created by {@link Service.create}.
2485
+ * @typedef rpc.ServiceMethod
2486
+ * @template TReq extends Message<TReq>
2487
+ * @template TRes extends Message<TRes>
2488
+ * @type {function}
2489
+ * @param {TReq|Properties<TReq>} request Request message or plain object
2490
+ * @param {rpc.ServiceMethodCallback<TRes>} [callback] Node-style callback called with the error, if any, and the response message
2491
+ * @returns {Promise<Message<TRes>>} Promise if `callback` has been omitted, otherwise `undefined`
2492
+ */
2493
+
2494
+ /**
2495
+ * Constructs a new RPC service instance.
2496
+ * @classdesc An RPC service as returned by {@link Service#create}.
2497
+ * @exports rpc.Service
2498
+ * @extends util.EventEmitter
2499
+ * @constructor
2500
+ * @param {RPCImpl} rpcImpl RPC implementation
2501
+ * @param {boolean} [requestDelimited=false] Whether requests are length-delimited
2502
+ * @param {boolean} [responseDelimited=false] Whether responses are length-delimited
2503
+ */
2504
+ function Service(rpcImpl, requestDelimited, responseDelimited) {
2505
+
2506
+ if (typeof rpcImpl !== "function")
2507
+ throw TypeError("rpcImpl must be a function");
2508
+
2509
+ util.EventEmitter.call(this);
2510
+
2511
+ /**
2512
+ * RPC implementation. Becomes `null` once the service is ended.
2513
+ * @type {RPCImpl|null}
2514
+ */
2515
+ this.rpcImpl = rpcImpl;
2516
+
2517
+ /**
2518
+ * Whether requests are length-delimited.
2519
+ * @type {boolean}
2520
+ */
2521
+ this.requestDelimited = Boolean(requestDelimited);
2522
+
2523
+ /**
2524
+ * Whether responses are length-delimited.
2525
+ * @type {boolean}
2526
+ */
2527
+ this.responseDelimited = Boolean(responseDelimited);
2528
+ }
2529
+
2530
+ /**
2531
+ * Calls a service method through {@link rpc.Service#rpcImpl|rpcImpl}.
2532
+ * @param {Method|rpc.ServiceMethod<TReq,TRes>} method Reflected or static method
2533
+ * @param {Constructor<TReq>} requestCtor Request constructor
2534
+ * @param {Constructor<TRes>} responseCtor Response constructor
2535
+ * @param {TReq|Properties<TReq>} request Request message or plain object
2536
+ * @param {rpc.ServiceMethodCallback<TRes>} callback Service callback
2537
+ * @returns {undefined}
2538
+ * @template TReq extends Message<TReq>
2539
+ * @template TRes extends Message<TRes>
2540
+ */
2541
+ Service.prototype.rpcCall = function rpcCall(method, requestCtor, responseCtor, request, callback) {
2542
+
2543
+ if (!request)
2544
+ throw TypeError("request must be specified");
2545
+
2546
+ var self = this;
2547
+ if (!callback)
2548
+ return util.asPromise(rpcCall, self, method, requestCtor, responseCtor, request);
2549
+
2550
+ if (!self.rpcImpl) {
2551
+ setTimeout(function() { callback(Error("already ended")); }, 0);
2552
+ return undefined;
2553
+ }
2554
+
2555
+ try {
2556
+ return self.rpcImpl(
2557
+ method,
2558
+ requestCtor[self.requestDelimited ? "encodeDelimited" : "encode"](request).finish(),
2559
+ function rpcCallback(err, response) {
2560
+
2561
+ if (err) {
2562
+ self.emit("error", err, method);
2563
+ return callback(err);
2564
+ }
2565
+
2566
+ if (response === null) {
2567
+ self.end(/* endedByRPC */ true);
2568
+ return undefined;
2569
+ }
2570
+
2571
+ if (!(response instanceof responseCtor)) {
2572
+ try {
2573
+ response = responseCtor[self.responseDelimited ? "decodeDelimited" : "decode"](response);
2574
+ } catch (err) {
2575
+ self.emit("error", err, method);
2576
+ return callback(err);
2577
+ }
2578
+ }
2579
+
2580
+ self.emit("data", response, method);
2581
+ return callback(null, response);
2582
+ }
2583
+ );
2584
+ } catch (err) {
2585
+ self.emit("error", err, method);
2586
+ setTimeout(function() { callback(err); }, 0);
2587
+ return undefined;
2588
+ }
2589
+ };
2590
+
2591
+ /**
2592
+ * Ends this service and emits the `end` event.
2593
+ * @param {boolean} [endedByRPC=false] Whether the service has been ended by the RPC implementation.
2594
+ * @returns {rpc.Service} `this`
2595
+ */
2596
+ Service.prototype.end = function end(endedByRPC) {
2597
+ if (this.rpcImpl) {
2598
+ if (!endedByRPC) // signal end to rpcImpl
2599
+ this.rpcImpl(null, null, null);
2600
+ this.rpcImpl = null;
2601
+ this.emit("end").off();
2602
+ }
2603
+ return this;
2604
+ };
2605
+
2606
+ (function (exports) {
2607
+
2608
+ /**
2609
+ * Streaming RPC helpers.
2610
+ * @namespace
2611
+ */
2612
+ var rpc = exports;
2613
+
2614
+ /**
2615
+ * RPC implementation passed to {@link Service#create} performing a service request on network level, i.e. by utilizing http requests or websockets.
2616
+ * @typedef RPCImpl
2617
+ * @type {function}
2618
+ * @param {Method|rpc.ServiceMethod<Message<{}>,Message<{}>>} method Reflected or static method being called
2619
+ * @param {Uint8Array} requestData Request data
2620
+ * @param {RPCImplCallback} callback Callback function
2621
+ * @returns {undefined}
2622
+ * @example
2623
+ * function rpcImpl(method, requestData, callback) {
2624
+ * if (protobuf.util.lcFirst(method.name) !== "myMethod") // compatible with static code
2625
+ * throw Error("no such method");
2626
+ * asynchronouslyObtainAResponse(requestData, function(err, responseData) {
2627
+ * callback(err, responseData);
2628
+ * });
2629
+ * }
2630
+ */
2631
+
2632
+ /**
2633
+ * Node-style callback as used by {@link RPCImpl}.
2634
+ * @typedef RPCImplCallback
2635
+ * @type {function}
2636
+ * @param {Error|null} error Error, if any, otherwise `null`
2637
+ * @param {Uint8Array|null} [response] Response data or `null` to signal end of stream, if there hasn't been an error
2638
+ * @returns {undefined}
2639
+ */
2640
+
2641
+ rpc.Service = service;
2642
+ } (rpc));
2643
+
2644
+ var roots = {};
2645
+
2646
+ (function (exports) {
2647
+ var protobuf = exports;
2648
+
2649
+ /**
2650
+ * Build type, one of `"full"`, `"light"` or `"minimal"`.
2651
+ * @name build
2652
+ * @type {string}
2653
+ * @const
2654
+ */
2655
+ protobuf.build = "minimal";
2656
+
2657
+ // Serialization
2658
+ protobuf.Writer = writer;
2659
+ protobuf.BufferWriter = writer_buffer;
2660
+ protobuf.Reader = reader;
2661
+ protobuf.BufferReader = reader_buffer;
2662
+
2663
+ // Utility
2664
+ protobuf.util = requireMinimal();
2665
+ protobuf.rpc = rpc;
2666
+ protobuf.roots = roots;
2667
+ protobuf.configure = configure;
2668
+
2669
+ /* istanbul ignore next */
2670
+ /**
2671
+ * Reconfigures the library according to the environment.
2672
+ * @returns {undefined}
2673
+ */
2674
+ function configure() {
2675
+ protobuf.util._configure();
2676
+ protobuf.Writer._configure(protobuf.BufferWriter);
2677
+ protobuf.Reader._configure(protobuf.BufferReader);
2678
+ }
2679
+
2680
+ // Set up buffer utility according to the environment
2681
+ configure();
2682
+ } (indexMinimal));
2683
+
2684
+ var minimal = indexMinimal;
7
2685
 
8
2686
  /*eslint-disable block-scoped-var, id-length, no-control-regex, no-magic-numbers, no-prototype-builtins, no-redeclare, no-shadow, no-var, sort-vars*/
9
2687
 
10
2688
  // Common aliases
11
- const $Reader = undefined, $Writer = undefined, $util = undefined;
2689
+ const $Reader = minimal.Reader, $Writer = minimal.Writer, $util = minimal.util;
12
2690
 
13
2691
  // Exported root namespace
14
- const $root = undefined || (undefined = {});
2692
+ const $root = minimal.roots["default"] || (minimal.roots["default"] = {});
15
2693
 
16
2694
  const UpstreamMessage = $root.UpstreamMessage = (() => {
17
2695
 
@@ -359,7 +3037,7 @@ const UpstreamMessage = $root.UpstreamMessage = (() => {
359
3037
  * @returns {Object.<string,*>} JSON object
360
3038
  */
361
3039
  UpstreamMessage.prototype.toJSON = function toJSON() {
362
- return this.constructor.toObject(this, undefined);
3040
+ return this.constructor.toObject(this, minimal.util.toJSONOptions);
363
3041
  };
364
3042
 
365
3043
  /**
@@ -675,7 +3353,7 @@ const UpstreamMessage = $root.UpstreamMessage = (() => {
675
3353
  * @returns {Object.<string,*>} JSON object
676
3354
  */
677
3355
  SendToGroupMessage.prototype.toJSON = function toJSON() {
678
- return this.constructor.toObject(this, undefined);
3356
+ return this.constructor.toObject(this, minimal.util.toJSONOptions);
679
3357
  };
680
3358
 
681
3359
  /**
@@ -957,7 +3635,7 @@ const UpstreamMessage = $root.UpstreamMessage = (() => {
957
3635
  * @returns {Object.<string,*>} JSON object
958
3636
  */
959
3637
  EventMessage.prototype.toJSON = function toJSON() {
960
- return this.constructor.toObject(this, undefined);
3638
+ return this.constructor.toObject(this, minimal.util.toJSONOptions);
961
3639
  };
962
3640
 
963
3641
  /**
@@ -1210,7 +3888,7 @@ const UpstreamMessage = $root.UpstreamMessage = (() => {
1210
3888
  * @returns {Object.<string,*>} JSON object
1211
3889
  */
1212
3890
  JoinGroupMessage.prototype.toJSON = function toJSON() {
1213
- return this.constructor.toObject(this, undefined);
3891
+ return this.constructor.toObject(this, minimal.util.toJSONOptions);
1214
3892
  };
1215
3893
 
1216
3894
  /**
@@ -1463,7 +4141,7 @@ const UpstreamMessage = $root.UpstreamMessage = (() => {
1463
4141
  * @returns {Object.<string,*>} JSON object
1464
4142
  */
1465
4143
  LeaveGroupMessage.prototype.toJSON = function toJSON() {
1466
- return this.constructor.toObject(this, undefined);
4144
+ return this.constructor.toObject(this, minimal.util.toJSONOptions);
1467
4145
  };
1468
4146
 
1469
4147
  /**
@@ -1680,7 +4358,7 @@ const UpstreamMessage = $root.UpstreamMessage = (() => {
1680
4358
  * @returns {Object.<string,*>} JSON object
1681
4359
  */
1682
4360
  SequenceAckMessage.prototype.toJSON = function toJSON() {
1683
- return this.constructor.toObject(this, undefined);
4361
+ return this.constructor.toObject(this, minimal.util.toJSONOptions);
1684
4362
  };
1685
4363
 
1686
4364
  /**
@@ -1980,7 +4658,7 @@ const DownstreamMessage = $root.DownstreamMessage = (() => {
1980
4658
  * @returns {Object.<string,*>} JSON object
1981
4659
  */
1982
4660
  DownstreamMessage.prototype.toJSON = function toJSON() {
1983
- return this.constructor.toObject(this, undefined);
4661
+ return this.constructor.toObject(this, minimal.util.toJSONOptions);
1984
4662
  };
1985
4663
 
1986
4664
  /**
@@ -2264,7 +4942,7 @@ const DownstreamMessage = $root.DownstreamMessage = (() => {
2264
4942
  * @returns {Object.<string,*>} JSON object
2265
4943
  */
2266
4944
  AckMessage.prototype.toJSON = function toJSON() {
2267
- return this.constructor.toObject(this, undefined);
4945
+ return this.constructor.toObject(this, minimal.util.toJSONOptions);
2268
4946
  };
2269
4947
 
2270
4948
  /**
@@ -2488,7 +5166,7 @@ const DownstreamMessage = $root.DownstreamMessage = (() => {
2488
5166
  * @returns {Object.<string,*>} JSON object
2489
5167
  */
2490
5168
  ErrorMessage.prototype.toJSON = function toJSON() {
2491
- return this.constructor.toObject(this, undefined);
5169
+ return this.constructor.toObject(this, minimal.util.toJSONOptions);
2492
5170
  };
2493
5171
 
2494
5172
  /**
@@ -2810,7 +5488,7 @@ const DownstreamMessage = $root.DownstreamMessage = (() => {
2810
5488
  * @returns {Object.<string,*>} JSON object
2811
5489
  */
2812
5490
  DataMessage.prototype.toJSON = function toJSON() {
2813
- return this.constructor.toObject(this, undefined);
5491
+ return this.constructor.toObject(this, minimal.util.toJSONOptions);
2814
5492
  };
2815
5493
 
2816
5494
  /**
@@ -3072,7 +5750,7 @@ const DownstreamMessage = $root.DownstreamMessage = (() => {
3072
5750
  * @returns {Object.<string,*>} JSON object
3073
5751
  */
3074
5752
  SystemMessage.prototype.toJSON = function toJSON() {
3075
- return this.constructor.toObject(this, undefined);
5753
+ return this.constructor.toObject(this, minimal.util.toJSONOptions);
3076
5754
  };
3077
5755
 
3078
5756
  /**
@@ -3319,7 +5997,7 @@ const DownstreamMessage = $root.DownstreamMessage = (() => {
3319
5997
  * @returns {Object.<string,*>} JSON object
3320
5998
  */
3321
5999
  ConnectedMessage.prototype.toJSON = function toJSON() {
3322
- return this.constructor.toObject(this, undefined);
6000
+ return this.constructor.toObject(this, minimal.util.toJSONOptions);
3323
6001
  };
3324
6002
 
3325
6003
  /**
@@ -3522,7 +6200,7 @@ const DownstreamMessage = $root.DownstreamMessage = (() => {
3522
6200
  * @returns {Object.<string,*>} JSON object
3523
6201
  */
3524
6202
  DisconnectedMessage.prototype.toJSON = function toJSON() {
3525
- return this.constructor.toObject(this, undefined);
6203
+ return this.constructor.toObject(this, minimal.util.toJSONOptions);
3526
6204
  };
3527
6205
 
3528
6206
  /**
@@ -3845,7 +6523,7 @@ const MessageData = $root.MessageData = (() => {
3845
6523
  * @returns {Object.<string,*>} JSON object
3846
6524
  */
3847
6525
  MessageData.prototype.toJSON = function toJSON() {
3848
- return this.constructor.toObject(this, undefined);
6526
+ return this.constructor.toObject(this, minimal.util.toJSONOptions);
3849
6527
  };
3850
6528
 
3851
6529
  /**
@@ -4099,7 +6777,7 @@ const google = $root.google = (() => {
4099
6777
  * @returns {Object.<string,*>} JSON object
4100
6778
  */
4101
6779
  Any.prototype.toJSON = function toJSON() {
4102
- return this.constructor.toObject(this, undefined);
6780
+ return this.constructor.toObject(this, minimal.util.toJSONOptions);
4103
6781
  };
4104
6782
 
4105
6783
  /**