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