@azure/web-pubsub-client-protobuf 1.0.0-beta.1 → 1.0.0-beta.2

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