@depup/apollo__protobufjs 1.2.7-depup.0

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