PageSourceSearch

https://xn--90afccar8afg8b5b.xn--p1ai/bitrix/js/pull/protobuf/protobuf.js?1626983971274055

js xn--90afccar8afg8b5b.xn--p1ai collected 2026-09-26 04:47:58 UTC 274,055 bytes, 8,712 lines download raw bytes

vendor: 11,893 bytes, lines 1-368
1/*!
2 * protobuf.js v6.8.6 (c) 2016, daniel wirtz
3 * compiled mon, 26 feb 2018 11:35:34 utc
4 * licensed under the bsd-3-clause license
5 * see: https://github.com/dcodeio/protobuf.js for details
6 *
7 * Modify list for integration with Bitrix Framework:
8 * - removed integration with RequireJS and AMD package builders;
9 */
10(function(global,undefined){"use strict";(function prelude(modules, cache, entries) {
11
12    // This is the prelude used to bundle protobuf.js for the browser. Wraps up the CommonJS
13    // sources through a conflict-free require shim and is again wrapped within an iife that
14    // provides a unified `global` and a minification-friendly `undefined` var plus a global
15    // "use strict" directive so that minification can remove the directives of each module.
16
17    function $require(name) {
18        var $module = cache[name];
19        if (!$module)
20            modules[name][0].call($module = cache[name] = { exports: {} }, $require, $module, $module.exports);
21        return $module.exports;
22    }
23
24    // Expose globally
25    var protobuf = global.protobuf = $require(entries[0]);
26
27    // Be nice to AMD
28    /*if (typeof define === "function" && define.amd)
29        define(["long"], function(Long) {
30            if (Long && Long.isLong) {
31                protobuf.util.Long = Long;
32                protobuf.configure();
33            }
34            return protobuf;
35        });*/
36
37    // Be nice to CommonJS
38    /*if (typeof module === "object" && module && module.exports)
39        module.exports = protobuf;*/
40
41})/* end of prelude */({1:[function(require,module,exports){
42"use strict";
43module.exports = asPromise;
44
45/**
46 * Callback as used by {@link util.asPromise}.
47 * @typedef asPromiseCallback
48 * @type {function}
49 * @param {Error|null} error Error, if any
50 * @param {...*} params Additional arguments
51 * @returns {undefined}
52 */
53
54/**
55 * Returns a promise from a node-style callback function.
56 * @memberof util
57 * @param {asPromiseCallback} fn Function to call
58 * @param {*} ctx Function context
59 * @param {...*} params Function arguments
60 * @returns {Promise<*>} Promisified function
61 */
62function asPromise(fn, ctx/*, varargs */) {
63    var params  = new Array(arguments.length - 1),
64        offset  = 0,
65        index   = 2,
66        pending = true;
67    while (index < arguments.length)
68        params[offset++] = arguments[index++];
69    return new Promise(function executor(resolve, reject) {
70        params[offset] = function callback(err/*, varargs */) {
71            if (pending) {
72                pending = false;
73                if (err)
74                    reject(err);
75                else {
76                    var params = new Array(arguments.length - 1),
77                        offset = 0;
78                    while (offset < params.length)
79                        params[offset++] = arguments[offset];
80                    resolve.apply(null, params);
81                }
82            }
83        };
84        try {
85            fn.apply(ctx || null, params);
86        } catch (err) {
87            if (pending) {
88                pending = false;
89                reject(err);
90            }
91        }
92    });
93}
94
95},{}],2:[function(require,module,exports){
96"use strict";
97
98/**
99 * A minimal base64 implementation for number arrays.
100 * @memberof util
101 * @namespace
102 */
103var base64 = exports;
104
105/**
106 * Calculates the byte length of a base64 encoded string.
107 * @param {string} string Base64 encoded string
108 * @returns {number} Byte length
109 */
110base64.length = function length(string) {
111    var p = string.length;
112    if (!p)
113        return 0;
114    var n = 0;
115    while (--p % 4 > 1 && string.charAt(p) === "=")
116        ++n;
117    return Math.ceil(string.length * 3) / 4 - n;
118};
119
120// Base64 encoding table
121var b64 = new Array(64);
122
123// Base64 decoding table
124var s64 = new Array(123);
125
126// 65..90, 97..122, 48..57, 43, 47
127for (var i = 0; i < 64;)
128    s64[b64[i] = i < 26 ? i + 65 : i < 52 ? i + 71 : i < 62 ? i - 4 : i - 59 | 43] = i++;
129
130/**
131 * Encodes a buffer to a base64 encoded string.
132 * @param {Uint8Array} buffer Source buffer
133 * @param {number} start Source start
134 * @param {number} end Source end
135 * @returns {string} Base64 encoded string
136 */
137base64.encode = function encode(buffer, start, end) {
138    var parts = null,
139        chunk = [];
140    var i = 0, // output index
141        j = 0, // goto index
142        t;     // temporary
143    while (start < end) {
144        var b = buffer[start++];
145        switch (j) {
146            case 0:
147                chunk[i++] = b64[b >> 2];
148                t = (b & 3) << 4;
149                j = 1;
150                break;
151            case 1:
152                chunk[i++] = b64[t | b >> 4];
153                t = (b & 15) << 2;
154                j = 2;
155                break;
156            case 2:
157                chunk[i++] = b64[t | b >> 6];
158                chunk[i++] = b64[b & 63];
159                j = 0;
160                break;
161        }
162        if (i > 8191) {
163            (parts || (parts = [])).push(String.fromCharCode.apply(String, chunk));
164            i = 0;
165        }
166    }
167    if (j) {
168        chunk[i++] = b64[t];
169        chunk[i++] = 61;
170        if (j === 1)
171            chunk[i++] = 61;
172    }
173    if (parts) {
174        if (i)
175            parts.push(String.fromCharCode.apply(String, chunk.slice(0, i)));
176        return parts.join("");
177    }
178    return String.fromCharCode.apply(String, chunk.slice(0, i));
179};
180
181var invalidEncoding = "invalid encoding";
182
183/**
184 * Decodes a base64 encoded string to a buffer.
185 * @param {string} string Source string
186 * @param {Uint8Array} buffer Destination buffer
187 * @param {number} offset Destination offset
188 * @returns {number} Number of bytes written
189 * @throws {Error} If encoding is invalid
190 */
191base64.decode = function decode(string, buffer, offset) {
192    var start = offset;
193    var j = 0, // goto index
194        t;     // temporary
195    for (var i = 0; i < string.length;) {
196        var c = string.charCodeAt(i++);
197        if (c === 61 && j > 1)
198            break;
199        if ((c = s64[c]) === undefined)
200            throw Error(invalidEncoding);
201        switch (j) {
202            case 0:
203                t = c;
204                j = 1;
205                break;
206            case 1:
207                buffer[offset++] = t << 2 | (c & 48) >> 4;
208                t = c;
209                j = 2;
210                break;
211            case 2:
212                buffer[offset++] = (t & 15) << 4 | (c & 60) >> 2;
213                t = c;
214                j = 3;
215                break;
216            case 3:
217                buffer[offset++] = (t & 3) << 6 | c;
218                j = 0;
219                break;
220        }
221    }
222    if (j === 1)
223        throw Error(invalidEncoding);
224    return offset - start;
225};
226
227/**
228 * Tests if the specified string appears to be base64 encoded.
229 * @param {string} string String to test
230 * @returns {boolean} `true` if probably base64 encoded, otherwise false
231 */
232base64.test = function test(string) {
233    return /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(string);
234};
235
236},{}],3:[function(require,module,exports){
237"use strict";
238module.exports = codegen;
239
240/**
241 * Begins generating a function.
242 * @memberof util
243 * @param {string[]} functionParams Function parameter names
244 * @param {string} [functionName] Function name if not anonymous
245 * @returns {Codegen} Appender that appends code to the function's body
246 */
247function codegen(functionParams, functionName) {
248
249    /* istanbul ignore if */
250    if (typeof functionParams === "string") {
251        functionName = functionParams;
252        functionParams = undefined;
253    }
254
255    var body = [];
256
257    /**
258     * Appends code to the function's body or finishes generation.
259     * @typedef Codegen
260     * @type {function}
261     * @param {string|Object.<string,*>} [formatStringOrScope] Format string or, to finish the function, an object of additional scope variables, if any
262     * @param {...*} [formatParams] Format parameters
263     * @returns {Codegen|Function} Itself or the generated function if finished
264     * @throws {Error} If format parameter counts do not match
265     */
266
267    function Codegen(formatStringOrScope) {
268        // note that explicit array handling below makes this ~50% faster
269
270        // finish the function
271        if (typeof formatStringOrScope !== "string") {
272            var source = toString();
273            if (codegen.verbose)
274                console.log("codegen: " + source); // eslint-disable-line no-console
275            source = "return " + source;
276            if (formatStringOrScope) {
277                var scopeKeys   = Object.keys(formatStringOrScope),
278                    scopeParams = new Array(scopeKeys.length + 1),
279                    scopeValues = new Array(scopeKeys.length),
280                    scopeOffset = 0;
281                while (scopeOffset < scopeKeys.length) {
282                    scopeParams[scopeOffset] = scopeKeys[scopeOffset];
283                    scopeValues[scopeOffset] = formatStringOrScope[scopeKeys[scopeOffset++]];
284                }
285                scopeParams[scopeOffset] = source;
286                return Function.apply(null, scopeParams).apply(null, scopeValues); // eslint-disable-line no-new-func
287            }
288            return Function(source)(); // eslint-disable-line no-new-func
289        }
290
291        // otherwise append to body
292        var formatParams = new Array(arguments.length - 1),
293            formatOffset = 0;
294        while (formatOffset < formatParams.length)
295            formatParams[formatOffset] = arguments[++formatOffset];
296        formatOffset = 0;
297        formatStringOrScope = formatStringOrScope.replace(/%([%dfijs])/g, function replace($0, $1) {
298            var value = formatParams[formatOffset++];
299            switch ($1) {
300                case "d": case "f": return String(Number(value));
301                case "i": return String(Math.floor(value));
302                case "j": return JSON.stringify(value);
303                case "s": return String(value);
304            }
305            return "%";
306        });
307        if (formatOffset !== formatParams.length)
308            throw Error("parameter count mismatch");
309        body.push(formatStringOrScope);
310        return Codegen;
311    }
312
313    function toString(functionNameOverride) {
314        return "function " + (functionNameOverride || functionName || "") + "(" + (functionParams && functionParams.join(",") || "") + "){\n  " + body.join("\n  ") + "\n}";
315    }
316
317    Codegen.toString = toString;
318    return Codegen;
319}
320
321/**
322 * Begins generating a function.
323 * @memberof util
324 * @function codegen
325 * @param {string} [functionName] Function name if not anonymous
326 * @returns {Codegen} Appender that appends code to the function's body
327 * @variation 2
328 */
329
330/**
331 * When set to `true`, codegen will log generated code to console. Useful for debugging.
332 * @name util.codegen.verbose
333 * @type {boolean}
334 */
335codegen.verbose = false;
336
337},{}],4:[function(require,module,exports){
338"use strict";
339module.exports = EventEmitter;
340
341/**
342 * Constructs a new event emitter instance.
343 * @classdesc A minimal event emitter.
344 * @memberof util
345 * @constructor
346 */
347function EventEmitter() {
348
349    /**
350     * Registered listeners.
351     * @type {Object.<string,*>}
352     * @private
353     */
354    this._listeners = {};
355}
356
357/**
358 * Registers an event listener.
359 * @param {string} evt Event name
360 * @param {function} fn Listener
361 * @param {*} [ctx] Listener context
362 * @returns {util.EventEmitter} `this`
363 */
364EventEmitter.prototype.on = function on(evt, fn, ctx) {
365    (this._listeners[evt] || (this._listeners[evt] = [])).push({
366        fn  : fn,
367        ctx : ctx || this
368    });
vendor: 5,262 bytes, lines 369-524
369    return this;
370};
371
372/**
373 * Removes an event listener or any matching listeners if arguments are omitted.
374 * @param {string} [evt] Event name. Removes all listeners if omitted.
375 * @param {function} [fn] Listener to remove. Removes all listeners of `evt` if omitted.
376 * @returns {util.EventEmitter} `this`
377 */
378EventEmitter.prototype.off = function off(evt, fn) {
379    if (evt === undefined)
380        this._listeners = {};
381    else {
382        if (fn === undefined)
383            this._listeners[evt] = [];
384        else {
385            var listeners = this._listeners[evt];
386            for (var i = 0; i < listeners.length;)
387                if (listeners[i].fn === fn)
388                    listeners.splice(i, 1);
389                else
390                    ++i;
391        }
392    }
393    return this;
394};
395
396/**
397 * Emits an event by calling its listeners with the specified arguments.
398 * @param {string} evt Event name
399 * @param {...*} args Arguments
400 * @returns {util.EventEmitter} `this`
401 */
402EventEmitter.prototype.emit = function emit(evt) {
403    var listeners = this._listeners[evt];
404    if (listeners) {
405        var args = [],
406            i = 1;
407        for (; i < arguments.length;)
408            args.push(arguments[i++]);
409        for (i = 0; i < listeners.length;)
410            listeners[i].fn.apply(listeners[i++].ctx, args);
411    }
412    return this;
413};
414
415},{}],5:[function(require,module,exports){
416"use strict";
417module.exports = fetch;
418
419var asPromise = require(1),
420    inquire   = require(7);
421
422var fs = inquire("fs");
423
424/**
425 * Node-style callback as used by {@link util.fetch}.
426 * @typedef FetchCallback
427 * @type {function}
428 * @param {?Error} error Error, if any, otherwise `null`
429 * @param {string} [contents] File contents, if there hasn't been an error
430 * @returns {undefined}
431 */
432
433/**
434 * Options as used by {@link util.fetch}.
435 * @typedef FetchOptions
436 * @type {Object}
437 * @property {boolean} [binary=false] Whether expecting a binary response
438 * @property {boolean} [xhr=false] If `true`, forces the use of XMLHttpRequest
439 */
440
441/**
442 * Fetches the contents of a file.
443 * @memberof util
444 * @param {string} filename File path or url
445 * @param {FetchOptions} options Fetch options
446 * @param {FetchCallback} callback Callback function
447 * @returns {undefined}
448 */
449function fetch(filename, options, callback) {
450    if (typeof options === "function") {
451        callback = options;
452        options = {};
453    } else if (!options)
454        options = {};
455
456    if (!callback)
457        return asPromise(fetch, this, filename, options); // eslint-disable-line no-invalid-this
458
459    // if a node-like filesystem is present, try it first but fall back to XHR if nothing is found.
460    if (!options.xhr && fs && fs.readFile)
461        return fs.readFile(filename, function fetchReadFileCallback(err, contents) {
462            return err && typeof XMLHttpRequest !== "undefined"
463                ? fetch.xhr(filename, options, callback)
464                : err
465                ? callback(err)
466                : callback(null, options.binary ? contents : contents.toString("utf8"));
467        });
468
469    // use the XHR version otherwise.
470    return fetch.xhr(filename, options, callback);
471}
472
473/**
474 * Fetches the contents of a file.
475 * @name util.fetch
476 * @function
477 * @param {string} path File path or url
478 * @param {FetchCallback} callback Callback function
479 * @returns {undefined}
480 * @variation 2
481 */
482
483/**
484 * Fetches the contents of a file.
485 * @name util.fetch
486 * @function
487 * @param {string} path File path or url
488 * @param {FetchOptions} [options] Fetch options
489 * @returns {Promise<string|Uint8Array>} Promise
490 * @variation 3
491 */
492
493/**/
494fetch.xhr = function fetch_xhr(filename, options, callback) {
495    var xhr = new XMLHttpRequest();
496    xhr.onreadystatechange /* works everywhere */ = function fetchOnReadyStateChange() {
497
498        if (xhr.readyState !== 4)
499            return undefined;
500
501        // local cors security errors return status 0 / empty string, too. afaik this cannot be
502        // reliably distinguished from an actually empty file for security reasons. feel free
503        // to send a pull request if you are aware of a solution.
504        if (xhr.status !== 0 && xhr.status !== 200)
505            return callback(Error("status " + xhr.status));
506
507        // if binary data is expected, make sure that some sort of array is returned, even if
508        // ArrayBuffers are not supported. the binary string fallback, however, is unsafe.
509        if (options.binary) {
510            var buffer = xhr.response;
511            if (!buffer) {
512                buffer = [];
513                for (var i = 0; i < xhr.responseText.length; ++i)
514                    buffer.push(xhr.responseText.charCodeAt(i) & 255);
515            }
516            return callback(null, typeof Uint8Array !== "undefined" ? new Uint8Array(buffer) : buffer);
517        }
518        return callback(null, xhr.responseText);
519    };
520
521    if (options.binary) {
522        // ref: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Sending_and_Receiving_Binary_Data#Receiving_binary_data_in_older_browsers
523        if ("overrideMimeType" in xhr)
524            xhr.overrideMimeType("text/plain;
vendor: 5,386 bytes, lines 524-694
524 charset=x-user-defined");
525        xhr.responseType = "arraybuffer";
526    }
527
528    xhr.open("GET", filename);
529    xhr.send();
530};
531
532},{"1":1,"7":7}],6:[function(require,module,exports){
533"use strict";
534
535module.exports = factory(factory);
536
537/**
538 * Reads / writes floats / doubles from / to buffers.
539 * @name util.float
540 * @namespace
541 */
542
543/**
544 * Writes a 32 bit float to a buffer using little endian byte order.
545 * @name util.float.writeFloatLE
546 * @function
547 * @param {number} val Value to write
548 * @param {Uint8Array} buf Target buffer
549 * @param {number} pos Target buffer offset
550 * @returns {undefined}
551 */
552
553/**
554 * Writes a 32 bit float to a buffer using big endian byte order.
555 * @name util.float.writeFloatBE
556 * @function
557 * @param {number} val Value to write
558 * @param {Uint8Array} buf Target buffer
559 * @param {number} pos Target buffer offset
560 * @returns {undefined}
561 */
562
563/**
564 * Reads a 32 bit float from a buffer using little endian byte order.
565 * @name util.float.readFloatLE
566 * @function
567 * @param {Uint8Array} buf Source buffer
568 * @param {number} pos Source buffer offset
569 * @returns {number} Value read
570 */
571
572/**
573 * Reads a 32 bit float from a buffer using big endian byte order.
574 * @name util.float.readFloatBE
575 * @function
576 * @param {Uint8Array} buf Source buffer
577 * @param {number} pos Source buffer offset
578 * @returns {number} Value read
579 */
580
581/**
582 * Writes a 64 bit double to a buffer using little endian byte order.
583 * @name util.float.writeDoubleLE
584 * @function
585 * @param {number} val Value to write
586 * @param {Uint8Array} buf Target buffer
587 * @param {number} pos Target buffer offset
588 * @returns {undefined}
589 */
590
591/**
592 * Writes a 64 bit double to a buffer using big endian byte order.
593 * @name util.float.writeDoubleBE
594 * @function
595 * @param {number} val Value to write
596 * @param {Uint8Array} buf Target buffer
597 * @param {number} pos Target buffer offset
598 * @returns {undefined}
599 */
600
601/**
602 * Reads a 64 bit double from a buffer using little endian byte order.
603 * @name util.float.readDoubleLE
604 * @function
605 * @param {Uint8Array} buf Source buffer
606 * @param {number} pos Source buffer offset
607 * @returns {number} Value read
608 */
609
610/**
611 * Reads a 64 bit double from a buffer using big endian byte order.
612 * @name util.float.readDoubleBE
613 * @function
614 * @param {Uint8Array} buf Source buffer
615 * @param {number} pos Source buffer offset
616 * @returns {number} Value read
617 */
618
619// Factory function for the purpose of node-based testing in modified global environments
620function factory(exports) {
621
622    // float: typed array
623    if (typeof Float32Array !== "undefined") (function() {
624
625        var f32 = new Float32Array([ -0 ]),
626            f8b = new Uint8Array(f32.buffer),
627            le  = f8b[3] === 128;
628
629        function writeFloat_f32_cpy(val, buf, pos) {
630            f32[0] = val;
631            buf[pos    ] = f8b[0];
632            buf[pos + 1] = f8b[1];
633            buf[pos + 2] = f8b[2];
634            buf[pos + 3] = f8b[3];
635        }
636
637        function writeFloat_f32_rev(val, buf, pos) {
638            f32[0] = val;
639            buf[pos    ] = f8b[3];
640            buf[pos + 1] = f8b[2];
641            buf[pos + 2] = f8b[1];
642            buf[pos + 3] = f8b[0];
643        }
644
645        /* istanbul ignore next */
646        exports.writeFloatLE = le ? writeFloat_f32_cpy : writeFloat_f32_rev;
647        /* istanbul ignore next */
648        exports.writeFloatBE = le ? writeFloat_f32_rev : writeFloat_f32_cpy;
649
650        function readFloat_f32_cpy(buf, pos) {
651            f8b[0] = buf[pos    ];
652            f8b[1] = buf[pos + 1];
653            f8b[2] = buf[pos + 2];
654            f8b[3] = buf[pos + 3];
655            return f32[0];
656        }
657
658        function readFloat_f32_rev(buf, pos) {
659            f8b[3] = buf[pos    ];
660            f8b[2] = buf[pos + 1];
661            f8b[1] = buf[pos + 2];
662            f8b[0] = buf[pos + 3];
663            return f32[0];
664        }
665
666        /* istanbul ignore next */
667        exports.readFloatLE = le ? readFloat_f32_cpy : readFloat_f32_rev;
668        /* istanbul ignore next */
669        exports.readFloatBE = le ? readFloat_f32_rev : readFloat_f32_cpy;
670
671    // float: ieee754
672    })(); else (function() {
673
674        function writeFloat_ieee754(writeUint, val, buf, pos) {
675            var sign = val < 0 ? 1 : 0;
676            if (sign)
677                val = -val;
678            if (val === 0)
679                writeUint(1 / val > 0 ? /* positive */ 0 : /* negative 0 */ 2147483648, buf, pos);
680            else if (isNaN(val))
681                writeUint(2143289344, buf, pos);
682            else if (val > 3.4028234663852886e+38) // +-Infinity
683                writeUint((sign << 31 | 2139095040) >>> 0, buf, pos);
684            else if (val < 1.1754943508222875e-38) // denormal
685                writeUint((sign << 31 | Math.round(val / 1.401298464324817e-45)) >>> 0, buf, pos);
686            else {
687                var exponent = Math.floor(Math.log(val) / Math.LN2),
688                    mantissa = Math.round(val * Math.pow(2, -exponent) * 8388608) & 8388607;
689                writeUint((sign << 31 | exponent + 127 << 23 | mantissa) >>> 0, buf, pos);
690            }
691        }
692
693        exports.writeFloatLE = writeFloat_ieee754.bind(null, writeUintLE);
694        exports.writeFloatBE = writeFloat_ieee754.bind(null, writeUintBE);
vendor: 8,937 bytes, lines 695-953
695
696        function readFloat_ieee754(readUint, buf, pos) {
697            var uint = readUint(buf, pos),
698                sign = (uint >> 31) * 2 + 1,
699                exponent = uint >>> 23 & 255,
700                mantissa = uint & 8388607;
701            return exponent === 255
702                ? mantissa
703                ? NaN
704                : sign * Infinity
705                : exponent === 0 // denormal
706                ? sign * 1.401298464324817e-45 * mantissa
707                : sign * Math.pow(2, exponent - 150) * (mantissa + 8388608);
708        }
709
710        exports.readFloatLE = readFloat_ieee754.bind(null, readUintLE);
711        exports.readFloatBE = readFloat_ieee754.bind(null, readUintBE);
712
713    })();
714
715    // double: typed array
716    if (typeof Float64Array !== "undefined") (function() {
717
718        var f64 = new Float64Array([-0]),
719            f8b = new Uint8Array(f64.buffer),
720            le  = f8b[7] === 128;
721
722        function writeDouble_f64_cpy(val, buf, pos) {
723            f64[0] = val;
724            buf[pos    ] = f8b[0];
725            buf[pos + 1] = f8b[1];
726            buf[pos + 2] = f8b[2];
727            buf[pos + 3] = f8b[3];
728            buf[pos + 4] = f8b[4];
729            buf[pos + 5] = f8b[5];
730            buf[pos + 6] = f8b[6];
731            buf[pos + 7] = f8b[7];
732        }
733
734        function writeDouble_f64_rev(val, buf, pos) {
735            f64[0] = val;
736            buf[pos    ] = f8b[7];
737            buf[pos + 1] = f8b[6];
738            buf[pos + 2] = f8b[5];
739            buf[pos + 3] = f8b[4];
740            buf[pos + 4] = f8b[3];
741            buf[pos + 5] = f8b[2];
742            buf[pos + 6] = f8b[1];
743            buf[pos + 7] = f8b[0];
744        }
745
746        /* istanbul ignore next */
747        exports.writeDoubleLE = le ? writeDouble_f64_cpy : writeDouble_f64_rev;
748        /* istanbul ignore next */
749        exports.writeDoubleBE = le ? writeDouble_f64_rev : writeDouble_f64_cpy;
750
751        function readDouble_f64_cpy(buf, pos) {
752            f8b[0] = buf[pos    ];
753            f8b[1] = buf[pos + 1];
754            f8b[2] = buf[pos + 2];
755            f8b[3] = buf[pos + 3];
756            f8b[4] = buf[pos + 4];
757            f8b[5] = buf[pos + 5];
758            f8b[6] = buf[pos + 6];
759            f8b[7] = buf[pos + 7];
760            return f64[0];
761        }
762
763        function readDouble_f64_rev(buf, pos) {
764            f8b[7] = buf[pos    ];
765            f8b[6] = buf[pos + 1];
766            f8b[5] = buf[pos + 2];
767            f8b[4] = buf[pos + 3];
768            f8b[3] = buf[pos + 4];
769            f8b[2] = buf[pos + 5];
770            f8b[1] = buf[pos + 6];
771            f8b[0] = buf[pos + 7];
772            return f64[0];
773        }
774
775        /* istanbul ignore next */
776        exports.readDoubleLE = le ? readDouble_f64_cpy : readDouble_f64_rev;
777        /* istanbul ignore next */
778        exports.readDoubleBE = le ? readDouble_f64_rev : readDouble_f64_cpy;
779
780    // double: ieee754
781    })(); else (function() {
782
783        function writeDouble_ieee754(writeUint, off0, off1, val, buf, pos) {
784            var sign = val < 0 ? 1 : 0;
785            if (sign)
786                val = -val;
787            if (val === 0) {
788                writeUint(0, buf, pos + off0);
789                writeUint(1 / val > 0 ? /* positive */ 0 : /* negative 0 */ 2147483648, buf, pos + off1);
790            } else if (isNaN(val)) {
791                writeUint(0, buf, pos + off0);
792                writeUint(2146959360, buf, pos + off1);
793            } else if (val > 1.7976931348623157e+308) { // +-Infinity
794                writeUint(0, buf, pos + off0);
795                writeUint((sign << 31 | 2146435072) >>> 0, buf, pos + off1);
796            } else {
797                var mantissa;
798                if (val < 2.2250738585072014e-308) { // denormal
799                    mantissa = val / 5e-324;
800                    writeUint(mantissa >>> 0, buf, pos + off0);
801                    writeUint((sign << 31 | mantissa / 4294967296) >>> 0, buf, pos + off1);
802                } else {
803                    var exponent = Math.floor(Math.log(val) / Math.LN2);
804                    if (exponent === 1024)
805                        exponent = 1023;
806                    mantissa = val * Math.pow(2, -exponent);
807                    writeUint(mantissa * 4503599627370496 >>> 0, buf, pos + off0);
808                    writeUint((sign << 31 | exponent + 1023 << 20 | mantissa * 1048576 & 1048575) >>> 0, buf, pos + off1);
809                }
810            }
811        }
812
813        exports.writeDoubleLE = writeDouble_ieee754.bind(null, writeUintLE, 0, 4);
814        exports.writeDoubleBE = writeDouble_ieee754.bind(null, writeUintBE, 4, 0);
815
816        function readDouble_ieee754(readUint, off0, off1, buf, pos) {
817            var lo = readUint(buf, pos + off0),
818                hi = readUint(buf, pos + off1);
819            var sign = (hi >> 31) * 2 + 1,
820                exponent = hi >>> 20 & 2047,
821                mantissa = 4294967296 * (hi & 1048575) + lo;
822            return exponent === 2047
823                ? mantissa
824                ? NaN
825                : sign * Infinity
826                : exponent === 0 // denormal
827                ? sign * 5e-324 * mantissa
828                : sign * Math.pow(2, exponent - 1075) * (mantissa + 4503599627370496);
829        }
830
831        exports.readDoubleLE = readDouble_ieee754.bind(null, readUintLE, 0, 4);
832        exports.readDoubleBE = readDouble_ieee754.bind(null, readUintBE, 4, 0);
833
834    })();
835
836    return exports;
837}
838
839// uint helpers
840
841function writeUintLE(val, buf, pos) {
842    buf[pos    ] =  val        & 255;
843    buf[pos + 1] =  val >>> 8  & 255;
844    buf[pos + 2] =  val >>> 16 & 255;
845    buf[pos + 3] =  val >>> 24;
846}
847
848function writeUintBE(val, buf, pos) {
849    buf[pos    ] =  val >>> 24;
850    buf[pos + 1] =  val >>> 16 & 255;
851    buf[pos + 2] =  val >>> 8  & 255;
852    buf[pos + 3] =  val        & 255;
853}
854
855function readUintLE(buf, pos) {
856    return (buf[pos    ]
857          | buf[pos + 1] << 8
858          | buf[pos + 2] << 16
859          | buf[pos + 3] << 24) >>> 0;
860}
861
862function readUintBE(buf, pos) {
863    return (buf[pos    ] << 24
864          | buf[pos + 1] << 16
865          | buf[pos + 2] << 8
866          | buf[pos + 3]) >>> 0;
867}
868
869},{}],7:[function(require,module,exports){
870"use strict";
871module.exports = inquire;
872
873/**
874 * Requires a module only if available.
875 * @memberof util
876 * @param {string} moduleName Module to require
877 * @returns {?Object} Required module if available and not empty, otherwise `null`
878 */
879function inquire(moduleName) {
880    try {
881        var mod = eval("quire".replace(/^/,"re"))(moduleName); // eslint-disable-line no-eval
882        if (mod && (mod.length || Object.keys(mod).length))
883            return mod;
884    } catch (e) {} // eslint-disable-line no-empty
885    return null;
886}
887
888},{}],8:[function(require,module,exports){
889"use strict";
890
891/**
892 * A minimal path module to resolve Unix, Windows and URL paths alike.
893 * @memberof util
894 * @namespace
895 */
896var path = exports;
897
898var isAbsolute =
899/**
900 * Tests if the specified path is absolute.
901 * @param {string} path Path to test
902 * @returns {boolean} `true` if path is absolute
903 */
904path.isAbsolute = function isAbsolute(path) {
905    return /^(?:\/|\w+:)/.test(path);
906};
907
908var normalize =
909/**
910 * Normalizes the specified path.
911 * @param {string} path Path to normalize
912 * @returns {string} Normalized path
913 */
914path.normalize = function normalize(path) {
915    path = path.replace(/\\/g, "/")
916               .replace(/\/{2,}/g, "/");
917    var parts    = path.split("/"),
918        absolute = isAbsolute(path),
919        prefix   = "";
920    if (absolute)
921        prefix = parts.shift() + "/";
922    for (var i = 0; i < parts.length;) {
923        if (parts[i] === "..") {
924            if (i > 0 && parts[i - 1] !== "..")
925                parts.splice(--i, 2);
926            else if (absolute)
927                parts.splice(i, 1);
928            else
929                ++i;
930        } else if (parts[i] === ".")
931            parts.splice(i, 1);
932        else
933            ++i;
934    }
935    return prefix + parts.join("/");
936};
937
938/**
939 * Resolves the specified include path against the specified origin path.
940 * @param {string} originPath Path to the origin file
941 * @param {string} includePath Include path relative to origin path
942 * @param {boolean} [alreadyNormalized=false] `true` if both paths are already known to be normalized
943 * @returns {string} Path to the include file
944 */
945path.resolve = function resolve(originPath, includePath, alreadyNormalized) {
946    if (!alreadyNormalized)
947        includePath = normalize(includePath);
948    if (isAbsolute(includePath))
949        return includePath;
950    if (!alreadyNormalized)
951        originPath = normalize(originPath);
952    return (originPath = originPath.replace(/(?:\/|^)[^/]+$/, "")).length ? normalize(originPath + "/" + includePath) : includePath;
953};
954
955},{}],9:[function(require,module,exports){
956"use strict";
957module.exports = pool;
958
959/**
960 * An allocator as used by {@link util.pool}.
961 * @typedef PoolAllocator
962 * @type {function}
963 * @param {number} size Buffer size
964 * @returns {Uint8Array} Buffer
965 */
966
967/**
968 * A slicer as used by {@link util.pool}.
969 * @typedef PoolSlicer
970 * @type {function}
971 * @param {number} start Start offset
972 * @param {number} end End offset
973 * @returns {Uint8Array} Buffer slice
974 * @this {Uint8Array}
975 */
976
977/**
978 * A general purpose buffer pool.
979 * @memberof util
980 * @function
981 * @param {PoolAllocator} alloc Allocator
982 * @param {PoolSlicer} slice Slicer
983 * @param {number} [size=8192] Slab size
984 * @returns {PoolAllocator} Pooled allocator
985 */
986function pool(alloc, slice, size) {
987    var SIZE   = size || 8192;
988    var MAX    = SIZE >>> 1;
989    var slab   = null;
990    var offset = SIZE;
991    return function pool_alloc(size) {
992        if (size < 1 || size > MAX)
993            return alloc(size);
994        if (offset + size > SIZE) {
995            slab = alloc(SIZE);
996            offset = 0;
997        }
998        var buf = slice.call(slab, offset, offset += size);
999        if (offset & 7) // align to 32 bit
1000            offset = (offset | 7) + 1;
1001        return buf;
1002    };
1003}
1004
1005},{}],10:[function(require,module,exports){
1006"use strict";
1007
1008/**
1009 * A minimal UTF8 implementation for number arrays.
1010 * @memberof util
1011 * @namespace
1012 */
1013var utf8 = exports;
1014
1015/**
1016 * Calculates the UTF8 byte length of a string.
1017 * @param {string} string String
1018 * @returns {number} Byte length
1019 */
1020utf8.length = function utf8_length(string) {
1021    var len = 0,
1022        c = 0;
1023    for (var i = 0; i < string.length; ++i) {
1024        c = string.charCodeAt(i);
1025        if (c < 128)
1026            len += 1;
1027        else if (c < 2048)
1028            len += 2;
1029        else if ((c & 0xFC00) === 0xD800 && (string.charCodeAt(i + 1) & 0xFC00) === 0xDC00) {
1030            ++i;
1031            len += 4;
1032        } else
1033            len += 3;
1034    }
1035    return len;
1036};
1037
1038/**
1039 * Reads UTF8 bytes as a string.
1040 * @param {Uint8Array} buffer Source buffer
1041 * @param {number} start Source start
1042 * @param {number} end Source end
1043 * @returns {string} String read
1044 */
1045utf8.read = function utf8_read(buffer, start, end) {
1046    var len = end - start;
1047    if (len < 1)
1048        return "";
1049    var parts = null,
1050        chunk = [],
1051        i = 0, // char offset
1052        t;     // temporary
1053    while (start < end) {
1054        t = buffer[start++];
1055        if (t < 128)
1056            chunk[i++] = t;
1057        else if (t > 191 && t < 224)
1058            chunk[i++] = (t & 31) << 6 | buffer[start++] & 63;
1059        else if (t > 239 && t < 365) {
1060            t = ((t & 7) << 18 | (buffer[start++] & 63) << 12 | (buffer[start++] & 63) << 6 | buffer[start++] & 63) - 0x10000;
1061            chunk[i++] = 0xD800 + (t >> 10);
1062            chunk[i++] = 0xDC00 + (t & 1023);
1063        } else
1064            chunk[i++] = (t & 15) << 12 | (buffer[start++] & 63) << 6 | buffer[start++] & 63;
1065        if (i > 8191) {
1066            (parts || (parts = [])).push(String.fromCharCode.apply(String, chunk));
1067            i = 0;
1068        }
1069    }
1070    if (parts) {
1071        if (i)
1072            parts.push(String.fromCharCode.apply(String, chunk.slice(0, i)));
1073        return parts.join("");
1074    }
1075    return String.fromCharCode.apply(String, chunk.slice(0, i));
1076};
1077
1078/**
1079 * Writes a string as UTF8 bytes.
1080 * @param {string} string Source string
1081 * @param {Uint8Array} buffer Destination buffer
1082 * @param {number} offset Destination offset
1083 * @returns {number} Bytes written
1084 */
1085utf8.write = function utf8_write(string, buffer, offset) {
1086    var start = offset,
1087        c1, // character 1
1088        c2; // character 2
1089    for (var i = 0; i < string.length; ++i) {
1090        c1 = string.charCodeAt(i);
1091        if (c1 < 128) {
1092            buffer[offset++] = c1;
1093        } else if (c1 < 2048) {
1094            buffer[offset++] = c1 >> 6       | 192;
1095            buffer[offset++] = c1       & 63 | 128;
1096        } else if ((c1 & 0xFC00) === 0xD800 && ((c2 = string.charCodeAt(i + 1)) & 0xFC00) === 0xDC00) {
1097            c1 = 0x10000 + ((c1 & 0x03FF) << 10) + (c2 & 0x03FF);
1098            ++i;
1099            buffer[offset++] = c1 >> 18      | 240;
1100            buffer[offset++] = c1 >> 12 & 63 | 128;
1101            buffer[offset++] = c1 >> 6  & 63 | 128;
1102            buffer[offset++] = c1       & 63 | 128;
1103        } else {
1104            buffer[offset++] = c1 >> 12      | 224;
1105            buffer[offset++] = c1 >> 6  & 63 | 128;
1106            buffer[offset++] = c1       & 63 | 128;
1107        }
1108    }
1109    return offset - start;
1110};
1111
1112},{}],11:[function(require,module,exports){
1113"use strict";
1114module.exports = common;
1115
1116var commonRe = /\/|\./;
1117
1118/**
1119 * Provides common type definitions.
1120 * Can also be used to provide additional google types or your own custom types.
1121 * @param {string} name Short name as in `google/protobuf/[name].proto` or full file name
1122 * @param {Object.<string,*>} json JSON definition within `google.protobuf` if a short name, otherwise the file's root definition
1123 * @returns {undefined}
1124 * @property {INamespace} google/protobuf/any.proto Any
1125 * @property {INamespace} google/protobuf/duration.proto Duration
1126 * @property {INamespace} google/protobuf/empty.proto Empty
1127 * @property {INamespace} google/protobuf/field_mask.proto FieldMask
1128 * @property {INamespace} google/protobuf/struct.proto Struct, Value, NullValue and ListValue
1129 * @property {INamespace} google/protobuf/timestamp.proto Timestamp
1130 * @property {INamespace} google/protobuf/wrappers.proto Wrappers
1131 * @example
1132 * // manually provides descriptor.proto (assumes google/protobuf/ namespace and .proto extension)
1133 * protobuf.common("descriptor", descriptorJson);
1134 *
1135 * // manually provides a custom definition (uses my.foo namespace)
1136 * protobuf.common("my/foo/bar.proto", myFooBarJson);
1137 */
1138function common(name, json) {
1139    if (!commonRe.test(name)) {
1140        name = "google/protobuf/" + name + ".proto";
1141        json = { nested: { google: { nested: { protobuf: { nested: json } } } } };
1142    }
1143    common[name] = json;
1144}
1145
vendor: 8,308 bytes, lines 1146-1515
1146// Not provided because of limited use (feel free to discuss or to provide yourself):
1147//
1148// google/protobuf/descriptor.proto
1149// google/protobuf/source_context.proto
1150// google/protobuf/type.proto
1151//
1152// Stripped and pre-parsed versions of these non-bundled files are instead available as part of
1153// the repository or package within the google/protobuf directory.
1154
1155common("any", {
1156
1157    /**
1158     * Properties of a google.protobuf.Any message.
1159     * @interface IAny
1160     * @type {Object}
1161     * @property {string} [typeUrl]
1162     * @property {Uint8Array} [bytes]
1163     * @memberof common
1164     */
1165    Any: {
1166        fields: {
1167            type_url: {
1168                type: "string",
1169                id: 1
1170            },
1171            value: {
1172                type: "bytes",
1173                id: 2
1174            }
1175        }
1176    }
1177});
1178
1179var timeType;
1180
1181common("duration", {
1182
1183    /**
1184     * Properties of a google.protobuf.Duration message.
1185     * @interface IDuration
1186     * @type {Object}
1187     * @property {number|Long} [seconds]
1188     * @property {number} [nanos]
1189     * @memberof common
1190     */
1191    Duration: timeType = {
1192        fields: {
1193            seconds: {
1194                type: "int64",
1195                id: 1
1196            },
1197            nanos: {
1198                type: "int32",
1199                id: 2
1200            }
1201        }
1202    }
1203});
1204
1205common("timestamp", {
1206
1207    /**
1208     * Properties of a google.protobuf.Timestamp message.
1209     * @interface ITimestamp
1210     * @type {Object}
1211     * @property {number|Long} [seconds]
1212     * @property {number} [nanos]
1213     * @memberof common
1214     */
1215    Timestamp: timeType
1216});
1217
1218common("empty", {
1219
1220    /**
1221     * Properties of a google.protobuf.Empty message.
1222     * @interface IEmpty
1223     * @memberof common
1224     */
1225    Empty: {
1226        fields: {}
1227    }
1228});
1229
1230common("struct", {
1231
1232    /**
1233     * Properties of a google.protobuf.Struct message.
1234     * @interface IStruct
1235     * @type {Object}
1236     * @property {Object.<string,IValue>} [fields]
1237     * @memberof common
1238     */
1239    Struct: {
1240        fields: {
1241            fields: {
1242                keyType: "string",
1243                type: "Value",
1244                id: 1
1245            }
1246        }
1247    },
1248
1249    /**
1250     * Properties of a google.protobuf.Value message.
1251     * @interface IValue
1252     * @type {Object}
1253     * @property {string} [kind]
1254     * @property {0} [nullValue]
1255     * @property {number} [numberValue]
1256     * @property {string} [stringValue]
1257     * @property {boolean} [boolValue]
1258     * @property {IStruct} [structValue]
1259     * @property {IListValue} [listValue]
1260     * @memberof common
1261     */
1262    Value: {
1263        oneofs: {
1264            kind: {
1265                oneof: [
1266                    "nullValue",
1267                    "numberValue",
1268                    "stringValue",
1269                    "boolValue",
1270                    "structValue",
1271                    "listValue"
1272                ]
1273            }
1274        },
1275        fields: {
1276            nullValue: {
1277                type: "NullValue",
1278                id: 1
1279            },
1280            numberValue: {
1281                type: "double",
1282                id: 2
1283            },
1284            stringValue: {
1285                type: "string",
1286                id: 3
1287            },
1288            boolValue: {
1289                type: "bool",
1290                id: 4
1291            },
1292            structValue: {
1293                type: "Struct",
1294                id: 5
1295            },
1296            listValue: {
1297                type: "ListValue",
1298                id: 6
1299            }
1300        }
1301    },
1302
1303    NullValue: {
1304        values: {
1305            NULL_VALUE: 0
1306        }
1307    },
1308
1309    /**
1310     * Properties of a google.protobuf.ListValue message.
1311     * @interface IListValue
1312     * @type {Object}
1313     * @property {Array.<IValue>} [values]
1314     * @memberof common
1315     */
1316    ListValue: {
1317        fields: {
1318            values: {
1319                rule: "repeated",
1320                type: "Value",
1321                id: 1
1322            }
1323        }
1324    }
1325});
1326
1327common("wrappers", {
1328
1329    /**
1330     * Properties of a google.protobuf.DoubleValue message.
1331     * @interface IDoubleValue
1332     * @type {Object}
1333     * @property {number} [value]
1334     * @memberof common
1335     */
1336    DoubleValue: {
1337        fields: {
1338            value: {
1339                type: "double",
1340                id: 1
1341            }
1342        }
1343    },
1344
1345    /**
1346     * Properties of a google.protobuf.FloatValue message.
1347     * @interface IFloatValue
1348     * @type {Object}
1349     * @property {number} [value]
1350     * @memberof common
1351     */
1352    FloatValue: {
1353        fields: {
1354            value: {
1355                type: "float",
1356                id: 1
1357            }
1358        }
1359    },
1360
1361    /**
1362     * Properties of a google.protobuf.Int64Value message.
1363     * @interface IInt64Value
1364     * @type {Object}
1365     * @property {number|Long} [value]
1366     * @memberof common
1367     */
1368    Int64Value: {
1369        fields: {
1370            value: {
1371                type: "int64",
1372                id: 1
1373            }
1374        }
1375    },
1376
1377    /**
1378     * Properties of a google.protobuf.UInt64Value message.
1379     * @interface IUInt64Value
1380     * @type {Object}
1381     * @property {number|Long} [value]
1382     * @memberof common
1383     */
1384    UInt64Value: {
1385        fields: {
1386            value: {
1387                type: "uint64",
1388                id: 1
1389            }
1390        }
1391    },
1392
1393    /**
1394     * Properties of a google.protobuf.Int32Value message.
1395     * @interface IInt32Value
1396     * @type {Object}
1397     * @property {number} [value]
1398     * @memberof common
1399     */
1400    Int32Value: {
1401        fields: {
1402            value: {
1403                type: "int32",
1404                id: 1
1405            }
1406        }
1407    },
1408
1409    /**
1410     * Properties of a google.protobuf.UInt32Value message.
1411     * @interface IUInt32Value
1412     * @type {Object}
1413     * @property {number} [value]
1414     * @memberof common
1415     */
1416    UInt32Value: {
1417        fields: {
1418            value: {
1419                type: "uint32",
1420                id: 1
1421            }
1422        }
1423    },
1424
1425    /**
1426     * Properties of a google.protobuf.BoolValue message.
1427     * @interface IBoolValue
1428     * @type {Object}
1429     * @property {boolean} [value]
1430     * @memberof common
1431     */
1432    BoolValue: {
1433        fields: {
1434            value: {
1435                type: "bool",
1436                id: 1
1437            }
1438        }
1439    },
1440
1441    /**
1442     * Properties of a google.protobuf.StringValue message.
1443     * @interface IStringValue
1444     * @type {Object}
1445     * @property {string} [value]
1446     * @memberof common
1447     */
1448    StringValue: {
1449        fields: {
1450            value: {
1451                type: "string",
1452                id: 1
1453            }
1454        }
1455    },
1456
1457    /**
1458     * Properties of a google.protobuf.BytesValue message.
1459     * @interface IBytesValue
1460     * @type {Object}
1461     * @property {Uint8Array} [value]
1462     * @memberof common
1463     */
1464    BytesValue: {
1465        fields: {
1466            value: {
1467                type: "bytes",
1468                id: 1
1469            }
1470        }
1471    }
1472});
1473
1474common("field_mask", {
1475
1476    /**
1477     * Properties of a google.protobuf.FieldMask message.
1478     * @interface IDoubleValue
1479     * @type {Object}
1480     * @property {number} [value]
1481     * @memberof common
1482     */
1483    FieldMask: {
1484        fields: {
1485            paths: {
1486                rule: "repeated",
1487                type: "string",
1488                id: 1
1489            }
1490        }
1491    }
1492});
1493
1494/**
1495 * Gets the root definition of the specified common proto file.
1496 *
1497 * Bundled definitions are:
1498 * - google/protobuf/any.proto
1499 * - google/protobuf/duration.proto
1500 * - google/protobuf/empty.proto
1501 * - google/protobuf/field_mask.proto
1502 * - google/protobuf/struct.proto
1503 * - google/protobuf/timestamp.proto
1504 * - google/protobuf/wrappers.proto
1505 *
1506 * @param {string} file Proto file name
1507 * @returns {INamespace|null} Root definition or `null` if not defined
1508 */
1509common.get = function get(file) {
1510    return common[file] || null;
1511};
1512
1513},{}],12:[function(require,module,exports){
1514"use strict";
1515/**
vendor: 12,680 bytes, lines 1516-1842
1516 * Runtime message from/to plain object converters.
1517 * @namespace
1518 */
1519var converter = exports;
1520
1521var Enum = require(15),
1522    util = require(37);
1523
1524/**
1525 * Generates a partial value fromObject conveter.
1526 * @param {Codegen} gen Codegen instance
1527 * @param {Field} field Reflected field
1528 * @param {number} fieldIndex Field index
1529 * @param {string} prop Property reference
1530 * @returns {Codegen} Codegen instance
1531 * @ignore
1532 */
1533function genValuePartial_fromObject(gen, field, fieldIndex, prop) {
1534    /* eslint-disable no-unexpected-multiline, block-scoped-var, no-redeclare */
1535    if (field.resolvedType) {
1536        if (field.resolvedType instanceof Enum) { gen
1537            ("switch(d%s){", prop);
1538            for (var values = field.resolvedType.values, keys = Object.keys(values), i = 0; i < keys.length; ++i) {
1539                if (field.repeated && values[keys[i]] === field.typeDefault) gen
1540                ("default:");
1541                gen
1542                ("case%j:", keys[i])
1543                ("case %i:", values[keys[i]])
1544                    ("m%s=%j", prop, values[keys[i]])
1545                    ("break");
1546            } gen
1547            ("}");
1548        } else gen
1549            ("if(typeof d%s!==\"object\")", prop)
1550                ("throw TypeError(%j)", field.fullName + ": object expected")
1551            ("m%s=types[%i].fromObject(d%s)", prop, fieldIndex, prop);
1552    } else {
1553        var isUnsigned = false;
1554        switch (field.type) {
1555            case "double":
1556            case "float": gen
1557                ("m%s=Number(d%s)", prop, prop); // also catches "NaN", "Infinity"
1558                break;
1559            case "uint32":
1560            case "fixed32": gen
1561                ("m%s=d%s>>>0", prop, prop);
1562                break;
1563            case "int32":
1564            case "sint32":
1565            case "sfixed32": gen
1566                ("m%s=d%s|0", prop, prop);
1567                break;
1568            case "uint64":
1569                isUnsigned = true;
1570                // eslint-disable-line no-fallthrough
1571            case "int64":
1572            case "sint64":
1573            case "fixed64":
1574            case "sfixed64": gen
1575                ("if(util.Long)")
1576                    ("(m%s=util.Long.fromValue(d%s)).unsigned=%j", prop, prop, isUnsigned)
1577                ("else if(typeof d%s===\"string\")", prop)
1578                    ("m%s=parseInt(d%s,10)", prop, prop)
1579                ("else if(typeof d%s===\"number\")", prop)
1580                    ("m%s=d%s", prop, prop)
1581                ("else if(typeof d%s===\"object\")", prop)
1582                    ("m%s=new util.LongBits(d%s.low>>>0,d%s.high>>>0).toNumber(%s)", prop, prop, prop, isUnsigned ? "true" : "");
1583                break;
1584            case "bytes": gen
1585                ("if(typeof d%s===\"string\")", prop)
1586                    ("util.base64.decode(d%s,m%s=util.newBuffer(util.base64.length(d%s)),0)", prop, prop, prop)
1587                ("else if(d%s.length)", prop)
1588                    ("m%s=d%s", prop, prop);
1589                break;
1590            case "string": gen
1591                ("m%s=String(d%s)", prop, prop);
1592                break;
1593            case "bool": gen
1594                ("m%s=Boolean(d%s)", prop, prop);
1595                break;
1596            /* default: gen
1597                ("m%s=d%s", prop, prop);
1598                break; */
1599        }
1600    }
1601    return gen;
1602    /* eslint-enable no-unexpected-multiline, block-scoped-var, no-redeclare */
1603}
1604
1605/**
1606 * Generates a plain object to runtime message converter specific to the specified message type.
1607 * @param {Type} mtype Message type
1608 * @returns {Codegen} Codegen instance
1609 */
1610converter.fromObject = function fromObject(mtype) {
1611    /* eslint-disable no-unexpected-multiline, block-scoped-var, no-redeclare */
1612    var fields = mtype.fieldsArray;
1613    var gen = util.codegen(["d"], mtype.name + "$fromObject")
1614    ("if(d instanceof this.ctor)")
1615        ("return d");
1616    if (!fields.length) return gen
1617    ("return new this.ctor");
1618    gen
1619    ("var m=new this.ctor");
1620    for (var i = 0; i < fields.length; ++i) {
1621        var field  = fields[i].resolve(),
1622            prop   = util.safeProp(field.name);
1623
1624        // Map fields
1625        if (field.map) { gen
1626    ("if(d%s){", prop)
1627        ("if(typeof d%s!==\"object\")", prop)
1628            ("throw TypeError(%j)", field.fullName + ": object expected")
1629        ("m%s={}", prop)
1630        ("for(var ks=Object.keys(d%s),i=0;i<ks.length;++i){", prop);
1631            genValuePartial_fromObject(gen, field, /* not sorted */ i, prop + "[ks[i]]")
1632        ("}")
1633    ("}");
1634
1635        // Repeated fields
1636        } else if (field.repeated) { gen
1637    ("if(d%s){", prop)
1638        ("if(!Array.isArray(d%s))", prop)
1639            ("throw TypeError(%j)", field.fullName + ": array expected")
1640        ("m%s=[]", prop)
1641        ("for(var i=0;i<d%s.length;++i){", prop);
1642            genValuePartial_fromObject(gen, field, /* not sorted */ i, prop + "[i]")
1643        ("}")
1644    ("}");
1645
1646        // Non-repeated fields
1647        } else {
1648            if (!(field.resolvedType instanceof Enum)) gen // no need to test for null/undefined if an enum (uses switch)
1649    ("if(d%s!=null){", prop); // !== undefined && !== null
1650        genValuePartial_fromObject(gen, field, /* not sorted */ i, prop);
1651            if (!(field.resolvedType instanceof Enum)) gen
1652    ("}");
1653        }
1654    } return gen
1655    ("return m");
1656    /* eslint-enable no-unexpected-multiline, block-scoped-var, no-redeclare */
1657};
1658
1659/**
1660 * Generates a partial value toObject converter.
1661 * @param {Codegen} gen Codegen instance
1662 * @param {Field} field Reflected field
1663 * @param {number} fieldIndex Field index
1664 * @param {string} prop Property reference
1665 * @returns {Codegen} Codegen instance
1666 * @ignore
1667 */
1668function genValuePartial_toObject(gen, field, fieldIndex, prop) {
1669    /* eslint-disable no-unexpected-multiline, block-scoped-var, no-redeclare */
1670    if (field.resolvedType) {
1671        if (field.resolvedType instanceof Enum) gen
1672            ("d%s=o.enums===String?types[%i].values[m%s]:m%s", prop, fieldIndex, prop, prop);
1673        else gen
1674            ("d%s=types[%i].toObject(m%s,o)", prop, fieldIndex, prop);
1675    } else {
1676        var isUnsigned = false;
1677        switch (field.type) {
1678            case "double":
1679            case "float": gen
1680            ("d%s=o.json&&!isFinite(m%s)?String(m%s):m%s", prop, prop, prop, prop);
1681                break;
1682            case "uint64":
1683                isUnsigned = true;
1684                // eslint-disable-line no-fallthrough
1685            case "int64":
1686            case "sint64":
1687            case "fixed64":
1688            case "sfixed64": gen
1689            ("if(typeof m%s===\"number\")", prop)
1690                ("d%s=o.longs===String?String(m%s):m%s", prop, prop, prop)
1691            ("else") // Long-like
1692                ("d%s=o.longs===String?util.Long.prototype.toString.call(m%s):o.longs===Number?new util.LongBits(m%s.low>>>0,m%s.high>>>0).toNumber(%s):m%s", prop, prop, prop, prop, isUnsigned ? "true": "", prop);
1693                break;
1694            case "bytes": gen
1695            ("d%s=o.bytes===String?util.base64.encode(m%s,0,m%s.length):o.bytes===Array?Array.prototype.slice.call(m%s):m%s", prop, prop, prop, prop, prop);
1696                break;
1697            default: gen
1698            ("d%s=m%s", prop, prop);
1699                break;
1700        }
1701    }
1702    return gen;
1703    /* eslint-enable no-unexpected-multiline, block-scoped-var, no-redeclare */
1704}
1705
1706/**
1707 * Generates a runtime message to plain object converter specific to the specified message type.
1708 * @param {Type} mtype Message type
1709 * @returns {Codegen} Codegen instance
1710 */
1711converter.toObject = function toObject(mtype) {
1712    /* eslint-disable no-unexpected-multiline, block-scoped-var, no-redeclare */
1713    var fields = mtype.fieldsArray.slice().sort(util.compareFieldsById);
1714    if (!fields.length)
1715        return util.codegen()("return {}");
1716    var gen = util.codegen(["m", "o"], mtype.name + "$toObject")
1717    ("if(!o)")
1718        ("o={}")
1719    ("var d={}");
1720
1721    var repeatedFields = [],
1722        mapFields = [],
1723        normalFields = [],
1724        i = 0;
1725    for (; i < fields.length; ++i)
1726        if (!fields[i].partOf)
1727            ( fields[i].resolve().repeated ? repeatedFields
1728            : fields[i].map ? mapFields
1729            : normalFields).push(fields[i]);
1730
1731    if (repeatedFields.length) { gen
1732    ("if(o.arrays||o.defaults){");
1733        for (i = 0; i < repeatedFields.length; ++i) gen
1734        ("d%s=[]", util.safeProp(repeatedFields[i].name));
1735        gen
1736    ("}");
1737    }
1738
1739    if (mapFields.length) { gen
1740    ("if(o.objects||o.defaults){");
1741        for (i = 0; i < mapFields.length; ++i) gen
1742        ("d%s={}", util.safeProp(mapFields[i].name));
1743        gen
1744    ("}");
1745    }
1746
1747    if (normalFields.length) { gen
1748    ("if(o.defaults){");
1749        for (i = 0; i < normalFields.length; ++i) {
1750            var field = normalFields[i],
1751                prop  = util.safeProp(field.name);
1752            if (field.resolvedType instanceof Enum) gen
1753        ("d%s=o.enums===String?%j:%j", prop, field.resolvedType.valuesById[field.typeDefault], field.typeDefault);
1754            else if (field.long) gen
1755        ("if(util.Long){")
1756            ("var n=new util.Long(%i,%i,%j)", field.typeDefault.low, field.typeDefault.high, field.typeDefault.unsigned)
1757            ("d%s=o.longs===String?n.toString():o.longs===Number?n.toNumber():n", prop)
1758        ("}else")
1759            ("d%s=o.longs===String?%j:%i", prop, field.typeDefault.toString(), field.typeDefault.toNumber());
1760            else if (field.bytes) gen
1761        ("d%s=o.bytes===String?%j:%s", prop, String.fromCharCode.apply(String, field.typeDefault), "[" + Array.prototype.slice.call(field.typeDefault).join(",") + "]");
1762            else gen
1763        ("d%s=%j", prop, field.typeDefault); // also messages (=null)
1764        } gen
1765    ("}");
1766    }
1767    var hasKs2 = false;
1768    for (i = 0; i < fields.length; ++i) {
1769        var field = fields[i],
1770            index = mtype._fieldsArray.indexOf(field),
1771            prop  = util.safeProp(field.name);
1772        if (field.map) {
1773            if (!hasKs2) { hasKs2 = true; gen
1774    ("var ks2");
1775            } gen
1776    ("if(m%s&&(ks2=Object.keys(m%s)).length){", prop, prop)
1777        ("d%s={}", prop)
1778        ("for(var j=0;j<ks2.length;++j){");
1779            genValuePartial_toObject(gen, field, /* sorted */ index, prop + "[ks2[j]]")
1780        ("}");
1781        } else if (field.repeated) { gen
1782    ("if(m%s&&m%s.length){", prop, prop)
1783        ("d%s=[]", prop)
1784        ("for(var j=0;j<m%s.length;++j){", prop);
1785            genValuePartial_toObject(gen, field, /* sorted */ index, prop + "[j]")
1786        ("}");
1787        } else { gen
1788    ("if(m%s!=null&&m.hasOwnProperty(%j)){", prop, field.name); // !== undefined && !== null
1789        genValuePartial_toObject(gen, field, /* sorted */ index, prop);
1790        if (field.partOf) gen
1791        ("if(o.oneofs)")
1792            ("d%s=%j", util.safeProp(field.partOf.name), field.name);
1793        }
1794        gen
1795    ("}");
1796    }
1797    return gen
1798    ("return d");
1799    /* eslint-enable no-unexpected-multiline, block-scoped-var, no-redeclare */
1800};
1801
1802},{"15":15,"37":37}],13:[function(require,module,exports){
1803"use strict";
1804module.exports = decoder;
1805
1806var Enum    = require(15),
1807    types   = require(36),
1808    util    = require(37);
1809
1810function missing(field) {
1811    return "missing required '" + field.name + "'";
1812}
1813
1814/**
1815 * Generates a decoder specific to the specified message type.
1816 * @param {Type} mtype Message type
1817 * @returns {Codegen} Codegen instance
1818 */
1819function decoder(mtype) {
1820    /* eslint-disable no-unexpected-multiline */
1821    var gen = util.codegen(["r", "l"], mtype.name + "$decode")
1822    ("if(!(r instanceof Reader))")
1823        ("r=Reader.create(r)")
1824    ("var c=l===undefined?r.len:r.pos+l,m=new this.ctor" + (mtype.fieldsArray.filter(function(field) { return field.map; }).length ? ",k" : ""))
1825    ("while(r.pos<c){")
1826        ("var t=r.uint32()");
1827    if (mtype.group) gen
1828        ("if((t&7)===4)")
1829            ("break");
1830    gen
1831        ("switch(t>>>3){");
1832
1833    var i = 0;
1834    for (; i < /* initializes */ mtype.fieldsArray.length; ++i) {
1835        var field = mtype._fieldsArray[i].resolve(),
1836            type  = field.resolvedType instanceof Enum ? "int32" : field.type,
1837            ref   = "m" + util.safeProp(field.name); gen
1838            ("case %i:", field.id);
1839
1840        // Map fields
1841        if (field.map) { gen
1842                ("r.skip().pos++") // assumes id 1 + key wireType
1843                ("if(%s===util.emptyObject)", ref)
1844                    ("%s={}", ref)
1845                ("k=r.%s()", field.keyType)
1846                ("r.pos++"); // assumes id 2 + value wireType
1847            if (types.long[field.keyType] !== undefined) {
1848                if (types.basic[type] === undefined) gen
1849                ("%s[typeof k===\"object\"?util.longToHash(k):k]=types[%i].decode(r,r.uint32())", ref, i); // can't be groups
1850                else gen
1851                ("%s[typeof k===\"object\"?util.longToHash(k):k]=r.%s()", ref, type);
1852            } else {
1853                if (types.basic[type] === undefined) gen
1854                ("%s[k]=types[%i].decode(r,r.uint32())", ref, i); // can't be groups
1855                else gen
1856                ("%s[k]=r.%s()", ref, type);
1857            }
1858
1859        // Repeated fields
1860        } else if (field.repeated) { gen
1861
1862                ("if(!(%s&&%s.length))", ref, ref)
1863                    ("%s=[]", ref);
1864
1865            // Packable (always check for forward and backward compatiblity)
1866            if (types.packed[type] !== undefined) gen
1867                ("if((t&7)===2){")
1868                    ("var c2=r.uint32()+r.pos")
1869                    ("while(r.pos<c2)")
1870                        ("%s.push(r.%s())", ref, type)
1871                ("}else");
1872
1873            // Non-packed
1874            if (types.basic[type] === undefined) gen(field.resolvedType.group
1875                    ? "%s.push(types[%i].decode(r))"
1876                    : "%s.push(types[%i].decode(r,r.uint32()))", ref, i);
1877            else gen
1878                    ("%s.push(r.%s())", ref, type);
1879
1880        // Non-repeated
1881        } else if (types.basic[type] === undefined) gen(field.resolvedType.group
1882                ? "%s=types[%i].decode(r)"
1883                : "%s=types[%i].decode(r,r.uint32())", ref, i);
1884        else gen
1885                ("%s=r.%s()", ref, type);
1886        gen
1887                ("break");
1888    // Unknown fields
1889    } gen
1890            ("default:")
1891                ("r.skipType(t&7)")
1892                ("break")
1893
1894        ("}")
1895    ("}");
1896
1897    // Field presence
1898    for (i = 0; i < mtype._fieldsArray.length; ++i) {
1899        var rfield = mtype._fieldsArray[i];
1900        if (rfield.required) gen
1901    ("if(!m.hasOwnProperty(%j))", rfield.name)
1902        ("throw util.ProtocolError(%j,{instance:m})", missing(rfield));
1903    }
1904
1905    return gen
1906    ("return m");
1907    /* eslint-enable no-unexpected-multiline */
1908}
1909
1910},{"15":15,"36":36,"37":37}],14:[function(require,module,exports){
1911"use strict";
1912module.exports = encoder;
1913
1914var Enum     = require(15),
1915    types    = require(36),
1916    util     = require(37);
1917
1918/**
1919 * Generates a partial message type encoder.
1920 * @param {Codegen} gen Codegen instance
1921 * @param {Field} field Reflected field
1922 * @param {number} fieldIndex Field index
1923 * @param {string} ref Variable reference
1924 * @returns {Codegen} Codegen instance
1925 * @ignore
1926 */
1927function genTypePartial(gen, field, fieldIndex, ref) {
1928    return field.resolvedType.group
1929        ? gen("types[%i].encode(%s,w.uint32(%i)).uint32(%i)", fieldIndex, ref, (field.id << 3 | 3) >>> 0, (field.id << 3 | 4) >>> 0)
1930        : gen("types[%i].encode(%s,w.uint32(%i).fork()).ldelim()", fieldIndex, ref, (field.id << 3 | 2) >>> 0);
1931}
1932
1933/**
1934 * Generates an encoder specific to the specified message type.
1935 * @param {Type} mtype Message type
1936 * @returns {Codegen} Codegen instance
1937 */
1938function encoder(mtype) {
1939    /* eslint-disable no-unexpected-multiline, block-scoped-var, no-redeclare */
1940    var gen = util.codegen(["m", "w"], mtype.name + "$encode")
1941    ("if(!w)")
1942        ("w=Writer.create()");
1943
1944    var i, ref;
1945
vendor: 4,137 bytes, lines 1946-2068
1946    // "when a message is serialized its known fields should be written sequentially by field number"
1947    var fields = /* initializes */ mtype.fieldsArray.slice().sort(util.compareFieldsById);
1948
1949    for (var i = 0; i < fields.length; ++i) {
1950        var field    = fields[i].resolve(),
1951            index    = mtype._fieldsArray.indexOf(field),
1952            type     = field.resolvedType instanceof Enum ? "int32" : field.type,
1953            wireType = types.basic[type];
1954            ref      = "m" + util.safeProp(field.name);
1955
1956        // Map fields
1957        if (field.map) {
1958            gen
1959    ("if(%s!=null&&m.hasOwnProperty(%j)){", ref, field.name) // !== undefined && !== null
1960        ("for(var ks=Object.keys(%s),i=0;i<ks.length;++i){", ref)
1961            ("w.uint32(%i).fork().uint32(%i).%s(ks[i])", (field.id << 3 | 2) >>> 0, 8 | types.mapKey[field.keyType], field.keyType);
1962            if (wireType === undefined) gen
1963            ("types[%i].encode(%s[ks[i]],w.uint32(18).fork()).ldelim().ldelim()", index, ref); // can't be groups
1964            else gen
1965            (".uint32(%i).%s(%s[ks[i]]).ldelim()", 16 | wireType, type, ref);
1966            gen
1967        ("}")
1968    ("}");
1969
1970            // Repeated fields
1971        } else if (field.repeated) { gen
1972    ("if(%s!=null&&%s.length){", ref, ref); // !== undefined && !== null
1973
1974            // Packed repeated
1975            if (field.packed && types.packed[type] !== undefined) { gen
1976
1977        ("w.uint32(%i).fork()", (field.id << 3 | 2) >>> 0)
1978        ("for(var i=0;i<%s.length;++i)", ref)
1979            ("w.%s(%s[i])", type, ref)
1980        ("w.ldelim()");
1981
1982            // Non-packed
1983            } else { gen
1984
1985        ("for(var i=0;i<%s.length;++i)", ref);
1986                if (wireType === undefined)
1987            genTypePartial(gen, field, index, ref + "[i]");
1988                else gen
1989            ("w.uint32(%i).%s(%s[i])", (field.id << 3 | wireType) >>> 0, type, ref);
1990
1991            } gen
1992    ("}");
1993
1994        // Non-repeated
1995        } else {
1996            if (field.optional) gen
1997    ("if(%s!=null&&m.hasOwnProperty(%j))", ref, field.name); // !== undefined && !== null
1998
1999            if (wireType === undefined)
2000        genTypePartial(gen, field, index, ref);
2001            else gen
2002        ("w.uint32(%i).%s(%s)", (field.id << 3 | wireType) >>> 0, type, ref);
2003
2004        }
2005    }
2006
2007    return gen
2008    ("return w");
2009    /* eslint-enable no-unexpected-multiline, block-scoped-var, no-redeclare */
2010}
2011},{"15":15,"36":36,"37":37}],15:[function(require,module,exports){
2012"use strict";
2013module.exports = Enum;
2014
2015// extends ReflectionObject
2016var ReflectionObject = require(24);
2017((Enum.prototype = Object.create(ReflectionObject.prototype)).constructor = Enum).className = "Enum";
2018
2019var Namespace = require(23),
2020    util = require(37);
2021
2022/**
2023 * Constructs a new enum instance.
2024 * @classdesc Reflected enum.
2025 * @extends ReflectionObject
2026 * @constructor
2027 * @param {string} name Unique name within its namespace
2028 * @param {Object.<string,number>} [values] Enum values as an object, by name
2029 * @param {Object.<string,*>} [options] Declared options
2030 * @param {string} [comment] The comment for this enum
2031 * @param {Object.<string,string>} [comments] The value comments for this enum
2032 */
2033function Enum(name, values, options, comment, comments) {
2034    ReflectionObject.call(this, name, options);
2035
2036    if (values && typeof values !== "object")
2037        throw TypeError("values must be an object");
2038
2039    /**
2040     * Enum values by id.
2041     * @type {Object.<number,string>}
2042     */
2043    this.valuesById = {};
2044
2045    /**
2046     * Enum values by name.
2047     * @type {Object.<string,number>}
2048     */
2049    this.values = Object.create(this.valuesById); // toJSON, marker
2050
2051    /**
2052     * Enum comment text.
2053     * @type {string|null}
2054     */
2055    this.comment = comment;
2056
2057    /**
2058     * Value comment texts, if any.
2059     * @type {Object.<string,string>}
2060     */
2061    this.comments = comments || {};
2062
2063    /**
2064     * Reserved ranges, if any.
2065     * @type {Array.<number[]|string>}
2066     */
2067    this.reserved = undefined; // toJSON
2068
2069    // Note that values inherit valuesById on their prototype which makes them a TypeScript-
2070    // compatible enum. This is used by pbts to write actual enum definitions that work for
2071    // static and reflection code alike instead of emitting generic object definitions.
2072
2073    if (values)
2074        for (var keys = Object.keys(values), i = 0; i < keys.length; ++i)
2075            if (typeof values[keys[i]] === "number") // use forward entries only
2076                this.valuesById[ this.values[keys[i]] = values[keys[i]] ] = keys[i];
2077}
2078
2079/**
2080 * Enum descriptor.
2081 * @interface IEnum
2082 * @property {Object.<string,number>} values Enum values
2083 * @property {Object.<string,*>} [options] Enum options
2084 */
2085
2086/**
2087 * Constructs an enum from an enum descriptor.
2088 * @param {string} name Enum name
2089 * @param {IEnum} json Enum descriptor
2090 * @returns {Enum} Created enum
2091 * @throws {TypeError} If arguments are invalid
2092 */
2093Enum.fromJSON = function fromJSON(name, json) {
2094    var enm = new Enum(name, json.values, json.options, json.comment, json.comments);
2095    enm.reserved = json.reserved;
2096    return enm;
2097};
2098
2099/**
2100 * Converts this enum to an enum descriptor.
2101 * @param {IToJSONOptions} [toJSONOptions] JSON conversion options
2102 * @returns {IEnum} Enum descriptor
2103 */
2104Enum.prototype.toJSON = function toJSON(toJSONOptions) {
2105    var keepComments = toJSONOptions ? Boolean(toJSONOptions.keepComments) : false;
2106    return util.toObject([
2107        "options"  , this.options,
2108        "values"   , this.values,
2109        "reserved" , this.reserved && this.reserved.length ? this.reserved : undefined,
2110        "comment"  , keepComments ? this.comment : undefined,
2111        "comments" , keepComments ? this.comments : undefined
2112    ]);
2113};
2114
2115/**
2116 * Adds a value to this enum.
2117 * @param {string} name Value name
2118 * @param {number} id Value id
2119 * @param {string} [comment] Comment, if any
2120 * @returns {Enum} `this`
2121 * @throws {TypeError} If arguments are invalid
2122 * @throws {Error} If there is already a value with this name or id
2123 */
2124Enum.prototype.add = function add(name, id, comment) {
2125    // utilized by the parser but not by .fromJSON
2126
2127    if (!util.isString(name))
2128        throw TypeError("name must be a string");
2129
2130    if (!util.isInteger(id))
2131        throw TypeError("id must be an integer");
2132
2133    if (this.values[name] !== undefined)
2134        throw Error("duplicate name '" + name + "' in " + this);
2135
2136    if (this.isReservedId(id))
2137        throw Error("id " + id + " is reserved in " + this);
2138
2139    if (this.isReservedName(name))
2140        throw Error("name '" + name + "' is reserved in " + this);
2141
2142    if (this.valuesById[id] !== undefined) {
2143        if (!(this.options && this.options.allow_alias))
2144            throw Error("duplicate id " + id + " in " + this);
2145        this.values[name] = id;
2146    } else
2147        this.valuesById[this.values[name] = id] = name;
2148
2149    this.comments[name] = comment || null;
2150    return this;
2151};
2152
2153/**
2154 * Removes a value from this enum
2155 * @param {string} name Value name
2156 * @returns {Enum} `this`
2157 * @throws {TypeError} If arguments are invalid
2158 * @throws {Error} If `name` is not a name of this enum
2159 */
2160Enum.prototype.remove = function remove(name) {
2161
2162    if (!util.isString(name))
2163        throw TypeError("name must be a string");
2164
2165    var val = this.values[name];
2166    if (val == null)
2167        throw Error("name '" + name + "' does not exist in " + this);
2168
2169    delete this.valuesById[val];
2170    delete this.values[name];
2171    delete this.comments[name];
2172
2173    return this;
2174};
2175
2176/**
2177 * Tests if the specified id is reserved.
2178 * @param {number} id Id to test
2179 * @returns {boolean} `true` if reserved, otherwise `false`
2180 */
2181Enum.prototype.isReservedId = function isReservedId(id) {
2182    return Namespace.isReservedId(this.reserved, id);
2183};
2184
2185/**
2186 * Tests if the specified name is reserved.
2187 * @param {string} name Name to test
2188 * @returns {boolean} `true` if reserved, otherwise `false`
2189 */
2190Enum.prototype.isReservedName = function isReservedName(name) {
2191    return Namespace.isReservedName(this.reserved, name);
2192};
2193
2194},{"23":23,"24":24,"37":37}],16:[function(require,module,exports){
2195"use strict";
2196module.exports = Field;
2197
2198// extends ReflectionObject
2199var ReflectionObject = require(24);
2200((Field.prototype = Object.create(ReflectionObject.prototype)).constructor = Field).className = "Field";
2201
2202var Enum  = require(15),
2203    types = require(36),
2204    util  = require(37);
2205
2206var Type; // cyclic
2207
2208var ruleRe = /^required|optional|repeated$/;
2209
2210/**
2211 * Constructs a new message field instance. Note that {@link MapField|map fields} have their own class.
2212 * @name Field
2213 * @classdesc Reflected message field.
2214 * @extends FieldBase
2215 * @constructor
2216 * @param {string} name Unique name within its namespace
2217 * @param {number} id Unique id within its namespace
2218 * @param {string} type Value type
2219 * @param {string|Object.<string,*>} [rule="optional"] Field rule
2220 * @param {string|Object.<string,*>} [extend] Extended type if different from parent
2221 * @param {Object.<string,*>} [options] Declared options
2222 */
2223
2224/**
2225 * Constructs a field from a field descriptor.
2226 * @param {string} name Field name
2227 * @param {IField} json Field descriptor
2228 * @returns {Field}
vendor: 4,090 bytes, lines 2228-2381
2228 Created field
2229 * @throws {TypeError} If arguments are invalid
2230 */
2231Field.fromJSON = function fromJSON(name, json) {
2232    return new Field(name, json.id, json.type, json.rule, json.extend, json.options, json.comment);
2233};
2234
2235/**
2236 * Not an actual constructor. Use {@link Field} instead.
2237 * @classdesc Base class of all reflected message fields. This is not an actual class but here for the sake of having consistent type definitions.
2238 * @exports FieldBase
2239 * @extends ReflectionObject
2240 * @constructor
2241 * @param {string} name Unique name within its namespace
2242 * @param {number} id Unique id within its namespace
2243 * @param {string} type Value type
2244 * @param {string|Object.<string,*>} [rule="optional"] Field rule
2245 * @param {string|Object.<string,*>} [extend] Extended type if different from parent
2246 * @param {Object.<string,*>} [options] Declared options
2247 * @param {string} [comment] Comment associated with this field
2248 */
2249function Field(name, id, type, rule, extend, options, comment) {
2250
2251    if (util.isObject(rule)) {
2252        comment = extend;
2253        options = rule;
2254        rule = extend = undefined;
2255    } else if (util.isObject(extend)) {
2256        comment = options;
2257        options = extend;
2258        extend = undefined;
2259    }
2260
2261    ReflectionObject.call(this, name, options);
2262
2263    if (!util.isInteger(id) || id < 0)
2264        throw TypeError("id must be a non-negative integer");
2265
2266    if (!util.isString(type))
2267        throw TypeError("type must be a string");
2268
2269    if (rule !== undefined && !ruleRe.test(rule = rule.toString().toLowerCase()))
2270        throw TypeError("rule must be a string rule");
2271
2272    if (extend !== undefined && !util.isString(extend))
2273        throw TypeError("extend must be a string");
2274
2275    /**
2276     * Field rule, if any.
2277     * @type {string|undefined}
2278     */
2279    this.rule = rule && rule !== "optional" ? rule : undefined; // toJSON
2280
2281    /**
2282     * Field type.
2283     * @type {string}
2284     */
2285    this.type = type; // toJSON
2286
2287    /**
2288     * Unique field id.
2289     * @type {number}
2290     */
2291    this.id = id; // toJSON, marker
2292
2293    /**
2294     * Extended type if different from parent.
2295     * @type {string|undefined}
2296     */
2297    this.extend = extend || undefined; // toJSON
2298
2299    /**
2300     * Whether this field is required.
2301     * @type {boolean}
2302     */
2303    this.required = rule === "required";
2304
2305    /**
2306     * Whether this field is optional.
2307     * @type {boolean}
2308     */
2309    this.optional = !this.required;
2310
2311    /**
2312     * Whether this field is repeated.
2313     * @type {boolean}
2314     */
2315    this.repeated = rule === "repeated";
2316
2317    /**
2318     * Whether this field is a map or not.
2319     * @type {boolean}
2320     */
2321    this.map = false;
2322
2323    /**
2324     * Message this field belongs to.
2325     * @type {Type|null}
2326     */
2327    this.message = null;
2328
2329    /**
2330     * OneOf this field belongs to, if any,
2331     * @type {OneOf|null}
2332     */
2333    this.partOf = null;
2334
2335    /**
2336     * The field type's default value.
2337     * @type {*}
2338     */
2339    this.typeDefault = null;
2340
2341    /**
2342     * The field's default value on prototypes.
2343     * @type {*}
2344     */
2345    this.defaultValue = null;
2346
2347    /**
2348     * Whether this field's value should be treated as a long.
2349     * @type {boolean}
2350     */
2351    this.long = util.Long ? types.long[type] !== undefined : /* istanbul ignore next */ false;
2352
2353    /**
2354     * Whether this field's value is a buffer.
2355     * @type {boolean}
2356     */
2357    this.bytes = type === "bytes";
2358
2359    /**
2360     * Resolved type if not a basic type.
2361     * @type {Type|Enum|null}
2362     */
2363    this.resolvedType = null;
2364
2365    /**
2366     * Sister-field within the extended type if a declaring extension field.
2367     * @type {Field|null}
2368     */
2369    this.extensionField = null;
2370
2371    /**
2372     * Sister-field within the declaring namespace if an extended field.
2373     * @type {Field|null}
2374     */
2375    this.declaringField = null;
2376
2377    /**
2378     * Internally remembers whether this field is packed.
2379     * @type {boolean|null}
2380     * @private
2381     */
2382    this._packed = null;
2383
2384    /**
2385     * Comment for this field.
2386     * @type {string|null}
2387     */
2388    this.comment = comment;
2389}
2390
2391/**
2392 * Determines whether this field is packed. Only relevant when repeated and working with proto2.
2393 * @name Field#packed
2394 * @type {boolean}
2395 * @readonly
2396 */
2397Object.defineProperty(Field.prototype, "packed", {
2398    get: function() {
2399        // defaults to packed=true if not explicity set to false
2400        if (this._packed === null)
2401            this._packed = this.getOption("packed") !== false;
2402        return this._packed;
2403    }
2404});
2405
2406/**
2407 * @override
2408 */
2409Field.prototype.setOption = function setOption(name, value, ifNotSet) {
2410    if (name === "packed") // clear cached before setting
2411        this._packed = null;
2412    return ReflectionObject.prototype.setOption.call(this, name, value, ifNotSet);
2413};
2414
2415/**
2416 * Field descriptor.
2417 * @interface IField
2418 * @property {string} [rule="optional"] Field rule
2419 * @property {string} type Field type
2420 * @property {number} id Field id
2421 * @property {Object.<string,*>} [options] Field options
2422 */
2423
2424/**
2425 * Extension field descriptor.
2426 * @interface IExtensionField
2427 * @extends IField
2428 * @property {string} extend Extended type
2429 */
2430
2431/**
2432 * Converts this field to a field descriptor.
2433 * @param {IToJSONOptions} [toJSONOptions] JSON conversion options
2434 * @returns {IField} Field descriptor
2435 */
2436Field.prototype.toJSON = function toJSON(toJSONOptions) {
2437    var keepComments = toJSONOptions ? Boolean(toJSONOptions.keepComments) : false;
2438    return util.toObject([
2439        "rule"    , this.rule !== "optional" && this.rule || undefined,
2440        "type"    , this.type,
2441        "id"      , this.id,
2442        "extend"  , this.extend,
2443        "options" , this.options,
2444        "comment" , keepComments ? this.comment : undefined
2445    ]);
2446};
2447
2448/**
2449 * Resolves this field's type references.
2450 * @returns {Field} `this`
2451 * @throws {Error} If any reference cannot be resolved
2452 */
2453Field.prototype.resolve = function resolve() {
2454
2455    if (this.resolved)
2456        return this;
2457
2458    if ((this.typeDefault = types.defaults[this.type]) === undefined) { // if not a basic type, resolve it
2459        this.resolvedType = (this.declaringField ? this.declaringField.parent : this.parent).lookupTypeOrEnum(this.type);
2460        if (this.resolvedType instanceof Type)
2461            this.typeDefault = null;
2462        else // instanceof Enum
2463            this.typeDefault = this.resolvedType.values[Object.keys(this.resolvedType.values)[0]]; // first defined
2464    }
2465
2466    // use explicitly set default value if present
2467    if (this.options && this.options["default"] != null) {
2468        this.typeDefault = this.options["default"];
2469        if (this.resolvedType instanceof Enum && typeof this.typeDefault === "string")
2470            this.typeDefault = this.resolvedType.values[this.typeDefault];
2471    }
2472
2473    // remove unnecessary options
2474    if (this.options) {
2475        if (this.options.packed === true || this.options.packed !== undefined && this.resolvedType && !(this.resolvedType instanceof Enum))
2476            delete this.options.packed;
2477        if (!Object.keys(this.options).length)
2478            this.options = undefined;
2479    }
2480
2481    // convert to internal data type if necesssary
2482    if (this.long) {
2483        this.typeDefault = util.Long.fromNumber(this.typeDefault, this.type.charAt(0) === "u");
2484
2485        /* istanbul ignore else */
2486        if (Object.freeze)
2487            Object.freeze(this.typeDefault); // long instances are meant to be immutable anyway (i.e. use small int cache that even requires it)
2488
2489    } else if (this.bytes && typeof this.typeDefault === "string") {
2490        var buf;
2491        if (util.base64.test(this.typeDefault))
2492            util.base64.decode(this.typeDefault, buf = util.newBuffer(util.base64.length(this.typeDefault)), 0);
2493        else
2494            util.utf8.write(this.typeDefault, buf = util.newBuffer(util.utf8.length(this.typeDefault)), 0);
2495        this.typeDefault = buf;
2496    }
2497
2498    // take special care of maps and repeated fields
2499    if (this.map)
2500        this.defaultValue = util.emptyObject;
2501    else if (this.repeated)
2502        this.defaultValue = util.emptyArray;
2503    else
2504        this.defaultValue = this.typeDefault;
2505
2506    // ensure proper value on prototype
2507    if (this.parent instanceof Type)
2508        this.parent.ctor.prototype[this.name] = this.defaultValue;
2509
2510    return ReflectionObject.prototype.resolve.call(this);
2511};
2512
2513/**
2514 * Decorator function as returned by {@link Field.d} and {@link MapField.d} (TypeScript).
2515 * @typedef FieldDecorator
2516 * @type {function}
2517 * @param {Object} prototype Target prototype
2518 * @param {string} fieldName Field name
2519 * @returns {undefined}
2520 */
2521
2522/**
2523 * Field decorator (TypeScript).
2524 * @name Field.d
2525 * @function
2526 * @param {number} fieldId Field id
2527 * @param {"double"|"float"|"int32"|"uint32"|"sint32"|"fixed32"|"sfixed32"|"int64"|"uint64"|"sint64"|"fixed64"|"sfixed64"|"string"|"bool"|"bytes"|Object} fieldType Field type
2528 * @param {"optional"|"required"|"repeated"} [fieldRule="optional"] Field rule
2529 * @param {T} [defaultValue] Default value
2530 * @returns {FieldDecorator} Decorator function
2531 * @template T extends number | number[] | Long | Long[] | string | string[] | boolean | boolean[] | Uint8Array | Uint8Array[] | Buffer | Buffer[]
2532 */
2533Field.d = function decorateField(fieldId, fieldType, fieldRule, defaultValue) {
2534
2535    // submessage: decorate the submessage and use its name as the type
2536    if (typeof fieldType === "function")
2537        fieldType = util.decorateType(fieldType).name;
2538
2539    // enum reference: create a reflected copy of the enum and keep reuseing it
2540    else if (fieldType && typeof fieldType === "object")
2541        fieldType = util.decorateEnum(fieldType).name;
2542
2543    return function fieldDecorator(prototype, fieldName) {
2544        util.decorateType(prototype.constructor)
2545            .add(new Field(fieldName, fieldId, fieldType, fieldRule, { "default": defaultValue }));
2546    };
2547};
vendor: 2,852 bytes, lines 2548-2629
2548
2549/**
2550 * Field decorator (TypeScript).
2551 * @name Field.d
2552 * @function
2553 * @param {number} fieldId Field id
2554 * @param {Constructor<T>|string} fieldType Field type
2555 * @param {"optional"|"required"|"repeated"} [fieldRule="optional"] Field rule
2556 * @returns {FieldDecorator} Decorator function
2557 * @template T extends Message<T>
2558 * @variation 2
2559 */
2560// like Field.d but without a default value
2561
2562Field._configure = function configure(Type_) {
2563    Type = Type_;
2564};
2565
2566},{"15":15,"24":24,"36":36,"37":37}],17:[function(require,module,exports){
2567"use strict";
2568var protobuf = module.exports = require(18);
2569
2570protobuf.build = "light";
2571
2572/**
2573 * A node-style callback as used by {@link load} and {@link Root#load}.
2574 * @typedef LoadCallback
2575 * @type {function}
2576 * @param {Error|null} error Error, if any, otherwise `null`
2577 * @param {Root} [root] Root, if there hasn't been an error
2578 * @returns {undefined}
2579 */
2580
2581/**
2582 * Loads one or multiple .proto or preprocessed .json files into a common root namespace and calls the callback.
2583 * @param {string|string[]} filename One or multiple files to load
2584 * @param {Root} root Root namespace, defaults to create a new one if omitted.
2585 * @param {LoadCallback} callback Callback function
2586 * @returns {undefined}
2587 * @see {@link Root#load}
2588 */
2589function load(filename, root, callback) {
2590    if (typeof root === "function") {
2591        callback = root;
2592        root = new protobuf.Root();
2593    } else if (!root)
2594        root = new protobuf.Root();
2595    return root.load(filename, callback);
2596}
2597
2598/**
2599 * Loads one or multiple .proto or preprocessed .json files into a common root namespace and calls the callback.
2600 * @name load
2601 * @function
2602 * @param {string|string[]} filename One or multiple files to load
2603 * @param {LoadCallback} callback Callback function
2604 * @returns {undefined}
2605 * @see {@link Root#load}
2606 * @variation 2
2607 */
2608// function load(filename:string, callback:LoadCallback):undefined
2609
2610/**
2611 * Loads one or multiple .proto or preprocessed .json files into a common root namespace and returns a promise.
2612 * @name load
2613 * @function
2614 * @param {string|string[]} filename One or multiple files to load
2615 * @param {Root} [root] Root namespace, defaults to create a new one if omitted.
2616 * @returns {Promise<Root>} Promise
2617 * @see {@link Root#load}
2618 * @variation 3
2619 */
2620// function load(filename:string, [root:Root]):Promise<Root>
2621
2622protobuf.load = load;
2623
2624/**
2625 * Synchronously loads one or multiple .proto or preprocessed .json files into a common root namespace (node only).
2626 * @param {string|string[]} filename One or multiple files to load
2627 * @param {Root} [root] Root namespace, defaults to create a new one if omitted.
2628 * @returns {Root} Root namespace
2629 * @throws {Error} If synchronous fetching is not supported (i.e. in browsers) or if a file's syntax is invali
vendor: 7,108 bytes, lines 2629-2850
2629d
2630 * @see {@link Root#loadSync}
2631 */
2632function loadSync(filename, root) {
2633    if (!root)
2634        root = new protobuf.Root();
2635    return root.loadSync(filename);
2636}
2637
2638protobuf.loadSync = loadSync;
2639
2640// Serialization
2641protobuf.encoder          = require(14);
2642protobuf.decoder          = require(13);
2643protobuf.verifier         = require(40);
2644protobuf.converter        = require(12);
2645
2646// Reflection
2647protobuf.ReflectionObject = require(24);
2648protobuf.Namespace        = require(23);
2649protobuf.Root             = require(29);
2650protobuf.Enum             = require(15);
2651protobuf.Type             = require(35);
2652protobuf.Field            = require(16);
2653protobuf.OneOf            = require(25);
2654protobuf.MapField         = require(20);
2655protobuf.Service          = require(33);
2656protobuf.Method           = require(22);
2657
2658// Runtime
2659protobuf.Message          = require(21);
2660protobuf.wrappers         = require(41);
2661
2662// Utility
2663protobuf.types            = require(36);
2664protobuf.util             = require(37);
2665
2666// Configure reflection
2667protobuf.ReflectionObject._configure(protobuf.Root);
2668protobuf.Namespace._configure(protobuf.Type, protobuf.Service);
2669protobuf.Root._configure(protobuf.Type);
2670protobuf.Field._configure(protobuf.Type);
2671
2672},{"12":12,"13":13,"14":14,"15":15,"16":16,"18":18,"20":20,"21":21,"22":22,"23":23,"24":24,"25":25,"29":29,"33":33,"35":35,"36":36,"37":37,"40":40,"41":41}],18:[function(require,module,exports){
2673"use strict";
2674var protobuf = exports;
2675
2676/**
2677 * Build type, one of `"full"`, `"light"` or `"minimal"`.
2678 * @name build
2679 * @type {string}
2680 * @const
2681 */
2682protobuf.build = "minimal";
2683
2684// Serialization
2685protobuf.Writer       = require(42);
2686protobuf.BufferWriter = require(43);
2687protobuf.Reader       = require(27);
2688protobuf.BufferReader = require(28);
2689
2690// Utility
2691protobuf.util         = require(39);
2692protobuf.rpc          = require(31);
2693protobuf.roots        = require(30);
2694protobuf.configure    = configure;
2695
2696/* istanbul ignore next */
2697/**
2698 * Reconfigures the library according to the environment.
2699 * @returns {undefined}
2700 */
2701function configure() {
2702    protobuf.Reader._configure(protobuf.BufferReader);
2703    protobuf.util._configure();
2704}
2705
2706// Configure serialization
2707protobuf.Writer._configure(protobuf.BufferWriter);
2708configure();
2709
2710},{"27":27,"28":28,"30":30,"31":31,"39":39,"42":42,"43":43}],19:[function(require,module,exports){
2711"use strict";
2712var protobuf = module.exports = require(17);
2713
2714protobuf.build = "full";
2715
2716// Parser
2717protobuf.tokenize         = require(34);
2718protobuf.parse            = require(26);
2719protobuf.common           = require(11);
2720
2721// Configure parser
2722protobuf.Root._configure(protobuf.Type, protobuf.parse, protobuf.common);
2723
2724},{"11":11,"17":17,"26":26,"34":34}],20:[function(require,module,exports){
2725"use strict";
2726module.exports = MapField;
2727
2728// extends Field
2729var Field = require(16);
2730((MapField.prototype = Object.create(Field.prototype)).constructor = MapField).className = "MapField";
2731
2732var types   = require(36),
2733    util    = require(37);
2734
2735/**
2736 * Constructs a new map field instance.
2737 * @classdesc Reflected map field.
2738 * @extends FieldBase
2739 * @constructor
2740 * @param {string} name Unique name within its namespace
2741 * @param {number} id Unique id within its namespace
2742 * @param {string} keyType Key type
2743 * @param {string} type Value type
2744 * @param {Object.<string,*>} [options] Declared options
2745 * @param {string} [comment] Comment associated with this field
2746 */
2747function MapField(name, id, keyType, type, options, comment) {
2748    Field.call(this, name, id, type, undefined, undefined, options, comment);
2749
2750    /* istanbul ignore if */
2751    if (!util.isString(keyType))
2752        throw TypeError("keyType must be a string");
2753
2754    /**
2755     * Key type.
2756     * @type {string}
2757     */
2758    this.keyType = keyType; // toJSON, marker
2759
2760    /**
2761     * Resolved key type if not a basic type.
2762     * @type {ReflectionObject|null}
2763     */
2764    this.resolvedKeyType = null;
2765
2766    // Overrides Field#map
2767    this.map = true;
2768}
2769
2770/**
2771 * Map field descriptor.
2772 * @interface IMapField
2773 * @extends {IField}
2774 * @property {string} keyType Key type
2775 */
2776
2777/**
2778 * Extension map field descriptor.
2779 * @interface IExtensionMapField
2780 * @extends IMapField
2781 * @property {string} extend Extended type
2782 */
2783
2784/**
2785 * Constructs a map field from a map field descriptor.
2786 * @param {string} name Field name
2787 * @param {IMapField} json Map field descriptor
2788 * @returns {MapField} Created map field
2789 * @throws {TypeError} If arguments are invalid
2790 */
2791MapField.fromJSON = function fromJSON(name, json) {
2792    return new MapField(name, json.id, json.keyType, json.type, json.options, json.comment);
2793};
2794
2795/**
2796 * Converts this map field to a map field descriptor.
2797 * @param {IToJSONOptions} [toJSONOptions] JSON conversion options
2798 * @returns {IMapField} Map field descriptor
2799 */
2800MapField.prototype.toJSON = function toJSON(toJSONOptions) {
2801    var keepComments = toJSONOptions ? Boolean(toJSONOptions.keepComments) : false;
2802    return util.toObject([
2803        "keyType" , this.keyType,
2804        "type"    , this.type,
2805        "id"      , this.id,
2806        "extend"  , this.extend,
2807        "options" , this.options,
2808        "comment" , keepComments ? this.comment : undefined
2809    ]);
2810};
2811
2812/**
2813 * @override
2814 */
2815MapField.prototype.resolve = function resolve() {
2816    if (this.resolved)
2817        return this;
2818
2819    // Besides a value type, map fields have a key type that may be "any scalar type except for floating point types and bytes"
2820    if (types.mapKey[this.keyType] === undefined)
2821        throw Error("invalid key type: " + this.keyType);
2822
2823    return Field.prototype.resolve.call(this);
2824};
2825
2826/**
2827 * Map field decorator (TypeScript).
2828 * @name MapField.d
2829 * @function
2830 * @param {number} fieldId Field id
2831 * @param {"int32"|"uint32"|"sint32"|"fixed32"|"sfixed32"|"int64"|"uint64"|"sint64"|"fixed64"|"sfixed64"|"bool"|"string"} fieldKeyType Field key type
2832 * @param {"double"|"float"|"int32"|"uint32"|"sint32"|"fixed32"|"sfixed32"|"int64"|"uint64"|"sint64"|"fixed64"|"sfixed64"|"bool"|"string"|"bytes"|Object|Constructor<{}>} fieldValueType Field value type
2833 * @returns {FieldDecorator} Decorator function
2834 * @template T extends { [key: string]: number | Long | string | boolean | Uint8Array | Buffer | number[] | Message<{}> }
2835 */
2836MapField.d = function decorateMapField(fieldId, fieldKeyType, fieldValueType) {
2837
2838    // submessage value: decorate the submessage and use its name as the type
2839    if (typeof fieldValueType === "function")
2840        fieldValueType = util.decorateType(fieldValueType).name;
2841
2842    // enum reference value: create a reflected copy of the enum and keep reuseing it
2843    else if (fieldValueType && typeof fieldValueType === "object")
2844        fieldValueType = util.decorateEnum(fieldValueType).name;
2845
2846    return function mapFieldDecorator(prototype, fieldName) {
2847        util.decorateType(prototype.constructor)
2848            .add(new MapField(fieldName, fieldId, fieldKeyType, fieldValueType));
2849    };
2850};
vendor: 19,371 bytes, lines 2851-3461
2851
2852},{"16":16,"36":36,"37":37}],21:[function(require,module,exports){
2853"use strict";
2854module.exports = Message;
2855
2856var util = require(39);
2857
2858/**
2859 * Constructs a new message instance.
2860 * @classdesc Abstract runtime message.
2861 * @constructor
2862 * @param {Properties<T>} [properties] Properties to set
2863 * @template T extends object
2864 */
2865function Message(properties) {
2866    // not used internally
2867    if (properties)
2868        for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
2869            this[keys[i]] = properties[keys[i]];
2870}
2871
2872/**
2873 * Reference to the reflected type.
2874 * @name Message.$type
2875 * @type {Type}
2876 * @readonly
2877 */
2878
2879/**
2880 * Reference to the reflected type.
2881 * @name Message#$type
2882 * @type {Type}
2883 * @readonly
2884 */
2885
2886/*eslint-disable valid-jsdoc*/
2887
2888/**
2889 * Creates a new message of this type using the specified properties.
2890 * @param {Object.<string,*>} [properties] Properties to set
2891 * @returns {Message<T>} Message instance
2892 * @template T extends Message<T>
2893 * @this Constructor<T>
2894 */
2895Message.create = function create(properties) {
2896    return this.$type.create(properties);
2897};
2898
2899/**
2900 * Encodes a message of this type.
2901 * @param {T|Object.<string,*>} message Message to encode
2902 * @param {Writer} [writer] Writer to use
2903 * @returns {Writer} Writer
2904 * @template T extends Message<T>
2905 * @this Constructor<T>
2906 */
2907Message.encode = function encode(message, writer) {
2908    return this.$type.encode(message, writer);
2909};
2910
2911/**
2912 * Encodes a message of this type preceeded by its length as a varint.
2913 * @param {T|Object.<string,*>} message Message to encode
2914 * @param {Writer} [writer] Writer to use
2915 * @returns {Writer} Writer
2916 * @template T extends Message<T>
2917 * @this Constructor<T>
2918 */
2919Message.encodeDelimited = function encodeDelimited(message, writer) {
2920    return this.$type.encodeDelimited(message, writer);
2921};
2922
2923/**
2924 * Decodes a message of this type.
2925 * @name Message.decode
2926 * @function
2927 * @param {Reader|Uint8Array} reader Reader or buffer to decode
2928 * @returns {T} Decoded message
2929 * @template T extends Message<T>
2930 * @this Constructor<T>
2931 */
2932Message.decode = function decode(reader) {
2933    return this.$type.decode(reader);
2934};
2935
2936/**
2937 * Decodes a message of this type preceeded by its length as a varint.
2938 * @name Message.decodeDelimited
2939 * @function
2940 * @param {Reader|Uint8Array} reader Reader or buffer to decode
2941 * @returns {T} Decoded message
2942 * @template T extends Message<T>
2943 * @this Constructor<T>
2944 */
2945Message.decodeDelimited = function decodeDelimited(reader) {
2946    return this.$type.decodeDelimited(reader);
2947};
2948
2949/**
2950 * Verifies a message of this type.
2951 * @name Message.verify
2952 * @function
2953 * @param {Object.<string,*>} message Plain object to verify
2954 * @returns {string|null} `null` if valid, otherwise the reason why it is not
2955 */
2956Message.verify = function verify(message) {
2957    return this.$type.verify(message);
2958};
2959
2960/**
2961 * Creates a new message of this type from a plain object. Also converts values to their respective internal types.
2962 * @param {Object.<string,*>} object Plain object
2963 * @returns {T} Message instance
2964 * @template T extends Message<T>
2965 * @this Constructor<T>
2966 */
2967Message.fromObject = function fromObject(object) {
2968    return this.$type.fromObject(object);
2969};
2970
2971/**
2972 * Creates a plain object from a message of this type. Also converts values to other types if specified.
2973 * @param {T} message Message instance
2974 * @param {IConversionOptions} [options] Conversion options
2975 * @returns {Object.<string,*>} Plain object
2976 * @template T extends Message<T>
2977 * @this Constructor<T>
2978 */
2979Message.toObject = function toObject(message, options) {
2980    return this.$type.toObject(message, options);
2981};
2982
2983/**
2984 * Converts this message to JSON.
2985 * @returns {Object.<string,*>} JSON object
2986 */
2987Message.prototype.toJSON = function toJSON() {
2988    return this.$type.toObject(this, util.toJSONOptions);
2989};
2990
2991/*eslint-enable valid-jsdoc*/
2992},{"39":39}],22:[function(require,module,exports){
2993"use strict";
2994module.exports = Method;
2995
2996// extends ReflectionObject
2997var ReflectionObject = require(24);
2998((Method.prototype = Object.create(ReflectionObject.prototype)).constructor = Method).className = "Method";
2999
3000var util = require(37);
3001
3002/**
3003 * Constructs a new service method instance.
3004 * @classdesc Reflected service method.
3005 * @extends ReflectionObject
3006 * @constructor
3007 * @param {string} name Method name
3008 * @param {string|undefined} type Method type, usually `"rpc"`
3009 * @param {string} requestType Request message type
3010 * @param {string} responseType Response message type
3011 * @param {boolean|Object.<string,*>} [requestStream] Whether the request is streamed
3012 * @param {boolean|Object.<string,*>} [responseStream] Whether the response is streamed
3013 * @param {Object.<string,*>} [options] Declared options
3014 * @param {string} [comment] The comment for this method
3015 */
3016function Method(name, type, requestType, responseType, requestStream, responseStream, options, comment) {
3017
3018    /* istanbul ignore next */
3019    if (util.isObject(requestStream)) {
3020        options = requestStream;
3021        requestStream = responseStream = undefined;
3022    } else if (util.isObject(responseStream)) {
3023        options = responseStream;
3024        responseStream = undefined;
3025    }
3026
3027    /* istanbul ignore if */
3028    if (!(type === undefined || util.isString(type)))
3029        throw TypeError("type must be a string");
3030
3031    /* istanbul ignore if */
3032    if (!util.isString(requestType))
3033        throw TypeError("requestType must be a string");
3034
3035    /* istanbul ignore if */
3036    if (!util.isString(responseType))
3037        throw TypeError("responseType must be a string");
3038
3039    ReflectionObject.call(this, name, options);
3040
3041    /**
3042     * Method type.
3043     * @type {string}
3044     */
3045    this.type = type || "rpc"; // toJSON
3046
3047    /**
3048     * Request type.
3049     * @type {string}
3050     */
3051    this.requestType = requestType; // toJSON, marker
3052
3053    /**
3054     * Whether requests are streamed or not.
3055     * @type {boolean|undefined}
3056     */
3057    this.requestStream = requestStream ? true : undefined; // toJSON
3058
3059    /**
3060     * Response type.
3061     * @type {string}
3062     */
3063    this.responseType = responseType; // toJSON
3064
3065    /**
3066     * Whether responses are streamed or not.
3067     * @type {boolean|undefined}
3068     */
3069    this.responseStream = responseStream ? true : undefined; // toJSON
3070
3071    /**
3072     * Resolved request type.
3073     * @type {Type|null}
3074     */
3075    this.resolvedRequestType = null;
3076
3077    /**
3078     * Resolved response type.
3079     * @type {Type|null}
3080     */
3081    this.resolvedResponseType = null;
3082
3083    /**
3084     * Comment for this method
3085     * @type {string|null}
3086     */
3087    this.comment = comment;
3088}
3089
3090/**
3091 * Method descriptor.
3092 * @interface IMethod
3093 * @property {string} [type="rpc"] Method type
3094 * @property {string} requestType Request type
3095 * @property {string} responseType Response type
3096 * @property {boolean} [requestStream=false] Whether requests are streamed
3097 * @property {boolean} [responseStream=false] Whether responses are streamed
3098 * @property {Object.<string,*>} [options] Method options
3099 */
3100
3101/**
3102 * Constructs a method from a method descriptor.
3103 * @param {string} name Method name
3104 * @param {IMethod} json Method descriptor
3105 * @returns {Method} Created method
3106 * @throws {TypeError} If arguments are invalid
3107 */
3108Method.fromJSON = function fromJSON(name, json) {
3109    return new Method(name, json.type, json.requestType, json.responseType, json.requestStream, json.responseStream, json.options, json.comment);
3110};
3111
3112/**
3113 * Converts this method to a method descriptor.
3114 * @param {IToJSONOptions} [toJSONOptions] JSON conversion options
3115 * @returns {IMethod} Method descriptor
3116 */
3117Method.prototype.toJSON = function toJSON(toJSONOptions) {
3118    var keepComments = toJSONOptions ? Boolean(toJSONOptions.keepComments) : false;
3119    return util.toObject([
3120        "type"           , this.type !== "rpc" && /* istanbul ignore next */ this.type || undefined,
3121        "requestType"    , this.requestType,
3122        "requestStream"  , this.requestStream,
3123        "responseType"   , this.responseType,
3124        "responseStream" , this.responseStream,
3125        "options"        , this.options,
3126        "comment"        , keepComments ? this.comment : undefined
3127    ]);
3128};
3129
3130/**
3131 * @override
3132 */
3133Method.prototype.resolve = function resolve() {
3134
3135    /* istanbul ignore if */
3136    if (this.resolved)
3137        return this;
3138
3139    this.resolvedRequestType = this.parent.lookupType(this.requestType);
3140    this.resolvedResponseType = this.parent.lookupType(this.responseType);
3141
3142    return ReflectionObject.prototype.resolve.call(this);
3143};
3144
3145},{"24":24,"37":37}],23:[function(require,module,exports){
3146"use strict";
3147module.exports = Namespace;
3148
3149// extends ReflectionObject
3150var ReflectionObject = require(24);
3151((Namespace.prototype = Object.create(ReflectionObject.prototype)).constructor = Namespace).className = "Namespace";
3152
3153var Enum     = require(15),
3154    Field    = require(16),
3155    util     = require(37);
3156
3157var Type,    // cyclic
3158    Service; // "
3159
3160/**
3161 * Constructs a new namespace instance.
3162 * @name Namespace
3163 * @classdesc Reflected namespace.
3164 * @extends NamespaceBase
3165 * @constructor
3166 * @param {string} name Namespace name
3167 * @param {Object.<string,*>} [options] Declared options
3168 */
3169
3170/**
3171 * Constructs a namespace from JSON.
3172 * @memberof Namespace
3173 * @function
3174 * @param {string} name Namespace name
3175 * @param {Object.<string,*>} json JSON object
3176 * @returns {Namespace} Created namespace
3177 * @throws {TypeError} If arguments are invalid
3178 */
3179Namespace.fromJSON = function fromJSON(name, json) {
3180    return new Namespace(name, json.options).addJSON(json.nested);
3181};
3182
3183/**
3184 * Converts an array of reflection objects to JSON.
3185 * @memberof Namespace
3186 * @param {ReflectionObject[]} array Object array
3187 * @param {IToJSONOptions} [toJSONOptions] JSON conversion options
3188 * @returns {Object.<string,*>|undefined} JSON object or `undefined` when array is empty
3189 */
3190function arrayToJSON(array, toJSONOptions) {
3191    if (!(array && array.length))
3192        return undefined;
3193    var obj = {};
3194    for (var i = 0; i < array.length; ++i)
3195        obj[array[i].name] = array[i].toJSON(toJSONOptions);
3196    return obj;
3197}
3198
3199Namespace.arrayToJSON = arrayToJSON;
3200
3201/**
3202 * Tests if the specified id is reserved.
3203 * @param {Array.<number[]|string>|undefined} reserved Array of reserved ranges and names
3204 * @param {number} id Id to test
3205 * @returns {boolean} `true` if reserved, otherwise `false`
3206 */
3207Namespace.isReservedId = function isReservedId(reserved, id) {
3208    if (reserved)
3209        for (var i = 0; i < reserved.length; ++i)
3210            if (typeof reserved[i] !== "string" && reserved[i][0] <= id && reserved[i][1] >= id)
3211                return true;
3212    return false;
3213};
3214
3215/**
3216 * Tests if the specified name is reserved.
3217 * @param {Array.<number[]|string>|undefined} reserved Array of reserved ranges and names
3218 * @param {string} name Name to test
3219 * @returns {boolean} `true` if reserved, otherwise `false`
3220 */
3221Namespace.isReservedName = function isReservedName(reserved, name) {
3222    if (reserved)
3223        for (var i = 0; i < reserved.length; ++i)
3224            if (reserved[i] === name)
3225                return true;
3226    return false;
3227};
3228
3229/**
3230 * Not an actual constructor. Use {@link Namespace} instead.
3231 * @classdesc Base class of all reflection objects containing nested objects. This is not an actual class but here for the sake of having consistent type definitions.
3232 * @exports NamespaceBase
3233 * @extends ReflectionObject
3234 * @abstract
3235 * @constructor
3236 * @param {string} name Namespace name
3237 * @param {Object.<string,*>} [options] Declared options
3238 * @see {@link Namespace}
3239 */
3240function Namespace(name, options) {
3241    ReflectionObject.call(this, name, options);
3242
3243    /**
3244     * Nested objects by name.
3245     * @type {Object.<string,ReflectionObject>|undefined}
3246     */
3247    this.nested = undefined; // toJSON
3248
3249    /**
3250     * Cached nested objects as an array.
3251     * @type {ReflectionObject[]|null}
3252     * @private
3253     */
3254    this._nestedArray = null;
3255}
3256
3257function clearCache(namespace) {
3258    namespace._nestedArray = null;
3259    return namespace;
3260}
3261
3262/**
3263 * Nested objects of this namespace as an array for iteration.
3264 * @name NamespaceBase#nestedArray
3265 * @type {ReflectionObject[]}
3266 * @readonly
3267 */
3268Object.defineProperty(Namespace.prototype, "nestedArray", {
3269    get: function() {
3270        return this._nestedArray || (this._nestedArray = util.toArray(this.nested));
3271    }
3272});
3273
3274/**
3275 * Namespace descriptor.
3276 * @interface INamespace
3277 * @property {Object.<string,*>} [options] Namespace options
3278 * @property {Object.<string,AnyNestedObject>} [nested] Nested object descriptors
3279 */
3280
3281/**
3282 * Any extension field descriptor.
3283 * @typedef AnyExtensionField
3284 * @type {IExtensionField|IExtensionMapField}
3285 */
3286
3287/**
3288 * Any nested object descriptor.
3289 * @typedef AnyNestedObject
3290 * @type {IEnum|IType|IService|AnyExtensionField|INamespace}
3291 */
3292// ^ BEWARE: VSCode hangs forever when using more than 5 types (that's why AnyExtensionField exists in the first place)
3293
3294/**
3295 * Converts this namespace to a namespace descriptor.
3296 * @param {IToJSONOptions} [toJSONOptions] JSON conversion options
3297 * @returns {INamespace} Namespace descriptor
3298 */
3299Namespace.prototype.toJSON = function toJSON(toJSONOptions) {
3300    return util.toObject([
3301        "options" , this.options,
3302        "nested"  , arrayToJSON(this.nestedArray, toJSONOptions)
3303    ]);
3304};
3305
3306/**
3307 * Adds nested objects to this namespace from nested object descriptors.
3308 * @param {Object.<string,AnyNestedObject>} nestedJson Any nested object descriptors
3309 * @returns {Namespace} `this`
3310 */
3311Namespace.prototype.addJSON = function addJSON(nestedJson) {
3312    var ns = this;
3313    /* istanbul ignore else */
3314    if (nestedJson) {
3315        for (var names = Object.keys(nestedJson), i = 0, nested; i < names.length; ++i) {
3316            nested = nestedJson[names[i]];
3317            ns.add( // most to least likely
3318                ( nested.fields !== undefined
3319                ? Type.fromJSON
3320                : nested.values !== undefined
3321                ? Enum.fromJSON
3322                : nested.methods !== undefined
3323                ? Service.fromJSON
3324                : nested.id !== undefined
3325                ? Field.fromJSON
3326                : Namespace.fromJSON )(names[i], nested)
3327            );
3328        }
3329    }
3330    return this;
3331};
3332
3333/**
3334 * Gets the nested object of the specified name.
3335 * @param {string} name Nested object name
3336 * @returns {ReflectionObject|null} The reflection object or `null` if it doesn't exist
3337 */
3338Namespace.prototype.get = function get(name) {
3339    return this.nested && this.nested[name]
3340        || null;
3341};
3342
3343/**
3344 * Gets the values of the nested {@link Enum|enum} of the specified name.
3345 * This methods differs from {@link Namespace#get|get} in that it returns an enum's values directly and throws instead of returning `null`.
3346 * @param {string} name Nested enum name
3347 * @returns {Object.<string,number>} Enum values
3348 * @throws {Error} If there is no such enum
3349 */
3350Namespace.prototype.getEnum = function getEnum(name) {
3351    if (this.nested && this.nested[name] instanceof Enum)
3352        return this.nested[name].values;
3353    throw Error("no such enum: " + name);
3354};
3355
3356/**
3357 * Adds a nested object to this namespace.
3358 * @param {ReflectionObject} object Nested object to add
3359 * @returns {Namespace} `this`
3360 * @throws {TypeError} If arguments are invalid
3361 * @throws {Error} If there is already a nested object with this name
3362 */
3363Namespace.prototype.add = function add(object) {
3364
3365    if (!(object instanceof Field && object.extend !== undefined || object instanceof Type || object instanceof Enum || object instanceof Service || object instanceof Namespace))
3366        throw TypeError("object must be a valid nested object");
3367
3368    if (!this.nested)
3369        this.nested = {};
3370    else {
3371        var prev = this.get(object.name);
3372        if (prev) {
3373            if (prev instanceof Namespace && object instanceof Namespace && !(prev instanceof Type || prev instanceof Service)) {
3374                // replace plain namespace but keep existing nested elements and options
3375                var nested = prev.nestedArray;
3376                for (var i = 0; i < nested.length; ++i)
3377                    object.add(nested[i]);
3378                this.remove(prev);
3379                if (!this.nested)
3380                    this.nested = {};
3381                object.setOptions(prev.options, true);
3382
3383            } else
3384                throw Error("duplicate name '" + object.name + "' in " + this);
3385        }
3386    }
3387    this.nested[object.name] = object;
3388    object.onAdd(this);
3389    return clearCache(this);
3390};
3391
3392/**
3393 * Removes a nested object from this namespace.
3394 * @param {ReflectionObject} object Nested object to remove
3395 * @returns {Namespace} `this`
3396 * @throws {TypeError} If arguments are invalid
3397 * @throws {Error} If `object` is not a member of this namespace
3398 */
3399Namespace.prototype.remove = function remove(object) {
3400
3401    if (!(object instanceof ReflectionObject))
3402        throw TypeError("object must be a ReflectionObject");
3403    if (object.parent !== this)
3404        throw Error(object + " is not a member of " + this);
3405
3406    delete this.nested[object.name];
3407    if (!Object.keys(this.nested).length)
3408        this.nested = undefined;
3409
3410    object.onRemove(this);
3411    return clearCache(this);
3412};
3413
3414/**
3415 * Defines additial namespaces within this one if not yet existing.
3416 * @param {string|string[]} path Path to create
3417 * @param {*} [json] Nested types to create from JSON
3418 * @returns {Namespace} Pointer to the last namespace created or `this` if path is empty
3419 */
3420Namespace.prototype.define = function define(path, json) {
3421
3422    if (util.isString(path))
3423        path = path.split(".");
3424    else if (!Array.isArray(path))
3425        throw TypeError("illegal path");
3426    if (path && path.length && path[0] === "")
3427        throw Error("path must be relative");
3428
3429    var ptr = this;
3430    while (path.length > 0) {
3431        var part = path.shift();
3432        if (ptr.nested && ptr.nested[part]) {
3433            ptr = ptr.nested[part];
3434            if (!(ptr instanceof Namespace))
3435                throw Error("path conflicts with non-namespace objects");
3436        } else
3437            ptr.add(ptr = new Namespace(part));
3438    }
3439    if (json)
3440        ptr.addJSON(json);
3441    return ptr;
3442};
3443
3444/**
3445 * Resolves this namespace's and all its nested objects' type references. Useful to validate a reflection tree, but comes at a cost.
3446 * @returns {Namespace} `this`
3447 */
3448Namespace.prototype.resolveAll = function resolveAll() {
3449    var nested = this.nestedArray, i = 0;
3450    while (i < nested.length)
3451        if (nested[i] instanceof Namespace)
3452            nested[i++].resolveAll();
3453        else
3454            nested[i++].resolve();
3455    return this.resolve();
3456};
3457
3458/**
3459 * Recursively looks up the reflection object matching the specified path in the scope of this namespace.
3460 * @param {string|string[]} path Path to look up
3461 * @param {*|Array.<*>}
3461 filterTypes Filter types, any combination of the constructors of `protobuf.Type`, `protobuf.Enum`, `protobuf.Service` etc.
3462 * @param {boolean} [parentAlreadyChecked=false] If known, whether the parent has already been checked
3463 * @returns {ReflectionObject|null} Looked up object or `null` if none could be found
3464 */
3465Namespace.prototype.lookup = function lookup(path, filterTypes, parentAlreadyChecked) {
3466
3467    /* istanbul ignore next */
3468    if (typeof filterTypes === "boolean") {
3469        parentAlreadyChecked = filterTypes;
3470        filterTypes = undefined;
3471    } else if (filterTypes && !Array.isArray(filterTypes))
3472        filterTypes = [ filterTypes ];
3473
3474    if (util.isString(path) && path.length) {
3475        if (path === ".")
3476            return this.root;
3477        path = path.split(".");
3478    } else if (!path.length)
3479        return this;
3480
3481    // Start at root if path is absolute
3482    if (path[0] === "")
3483        return this.root.lookup(path.slice(1), filterTypes);
3484
3485    // Test if the first part matches any nested object, and if so, traverse if path contains more
3486    var found = this.get(path[0]);
3487    if (found) {
3488        if (path.length === 1) {
3489            if (!filterTypes || filterTypes.indexOf(found.constructor) > -1)
3490                return found;
3491        } else if (found instanceof Namespace && (found = found.lookup(path.slice(1), filterTypes, true)))
3492            return found;
3493
3494    // Otherwise try each nested namespace
3495    } else
3496        for (var i = 0; i < this.nestedArray.length; ++i)
3497            if (this._nestedArray[i] instanceof Namespace && (found = this._nestedArray[i].lookup(path, filterTypes, true)))
3498                return found;
3499
3500    // If there hasn't been a match, try again at the parent
3501    if (this.parent === null || parentAlreadyChecked)
3502        return null;
3503    return this.parent.lookup(path, filterTypes);
3504};
3505
3506/**
3507 * Looks up the reflection object at the specified path, relative to this namespace.
3508 * @name NamespaceBase#lookup
3509 * @function
3510 * @param {string|string[]} path Path to look up
3511 * @param {boolean} [parentAlreadyChecked=false] Whether the parent has already been checked
3512 * @returns {ReflectionObject|null} Looked up object or `null` if none could be found
3513 * @variation 2
3514 */
3515// lookup(path: string, [parentAlreadyChecked: boolean])
3516
3517/**
3518 * Looks up the {@link Type|type} at the specified path, relative to this namespace.
3519 * Besides its signature, this methods differs from {@link Namespace#lookup|lookup} in that it throws instead of returning `null`.
3520 * @param {string|string[]} path Path to look up
3521 * @returns {Type} Looked up type
3522 * @throws {Error} If `path` does not point to a type
3523 */
3524Namespace.prototype.lookupType = function lookupType(path) {
3525    var found = this.lookup(path, [ Type ]);
3526    if (!found)
3527        throw Error("no such type: " + path);
3528    return found;
3529};
3530
3531/**
3532 * Looks up the values of the {@link Enum|enum} at the specified path, relative to this namespace.
3533 * Besides its signature, this methods differs from {@link Namespace#lookup|lookup} in that it throws instead of returning `null`.
3534 * @param {string|string[]} path Path to look up
3535 * @returns {Enum} Looked up enum
3536 * @throws {Error} If `path` does not point to an enum
3537 */
3538Namespace.prototype.lookupEnum = function lookupEnum(path) {
3539    var found = this.lookup(path, [ Enum ]);
3540    if (!found)
3541        throw Error("no such Enum '" + path + "' in " + this);
3542    return found;
3543};
3544
3545/**
3546 * Looks up the {@link Type|type} or {@link Enum|enum} at the specified path, relative to this namespace.
3547 * Besides its signature, this methods differs from {@link Namespace#lookup|lookup} in that it throws instead of returning `null`.
3548 * @param {string|string[]} path Path to look up
3549 * @returns {Type} Looked up type or enum
3550 * @throws {Error} If `path` does not point to a type or enum
3551 */
3552Namespace.prototype.lookupTypeOrEnum = function lookupTypeOrEnum(path) {
3553    var found = this.lookup(path, [ Type, Enum ]);
3554    if (!found)
3555        throw Error("no such Type or Enum '" + path + "' in " + this);
3556    return found;
3557};
3558
3559/**
3560 * Looks up the {@link Service|service} at the specified path, relative to this namespace.
3561 * Besides its signature, this methods differs from {@link Namespace#lookup|lookup} in that it throws instead of returning `null`.
3562 * @param {string|string[]} path Path to look up
3563 * @returns {Service} Looked up service
3564 * @throws {Error} If `path` does not point to a service
3565 */
3566Namespace.prototype.lookupService = function lookupService(path) {
3567    var found = this.lookup(path, [ Service ]);
vendor: 11,453 bytes, lines 3568-3982
3568    if (!found)
3569        throw Error("no such Service '" + path + "' in " + this);
3570    return found;
3571};
3572
3573Namespace._configure = function(Type_, Service_) {
3574    Type    = Type_;
3575    Service = Service_;
3576};
3577
3578},{"15":15,"16":16,"24":24,"37":37}],24:[function(require,module,exports){
3579"use strict";
3580module.exports = ReflectionObject;
3581
3582ReflectionObject.className = "ReflectionObject";
3583
3584var util = require(37);
3585
3586var Root; // cyclic
3587
3588/**
3589 * Constructs a new reflection object instance.
3590 * @classdesc Base class of all reflection objects.
3591 * @constructor
3592 * @param {string} name Object name
3593 * @param {Object.<string,*>} [options] Declared options
3594 * @abstract
3595 */
3596function ReflectionObject(name, options) {
3597
3598    if (!util.isString(name))
3599        throw TypeError("name must be a string");
3600
3601    if (options && !util.isObject(options))
3602        throw TypeError("options must be an object");
3603
3604    /**
3605     * Options.
3606     * @type {Object.<string,*>|undefined}
3607     */
3608    this.options = options; // toJSON
3609
3610    /**
3611     * Unique name within its namespace.
3612     * @type {string}
3613     */
3614    this.name = name;
3615
3616    /**
3617     * Parent namespace.
3618     * @type {Namespace|null}
3619     */
3620    this.parent = null;
3621
3622    /**
3623     * Whether already resolved or not.
3624     * @type {boolean}
3625     */
3626    this.resolved = false;
3627
3628    /**
3629     * Comment text, if any.
3630     * @type {string|null}
3631     */
3632    this.comment = null;
3633
3634    /**
3635     * Defining file name.
3636     * @type {string|null}
3637     */
3638    this.filename = null;
3639}
3640
3641Object.defineProperties(ReflectionObject.prototype, {
3642
3643    /**
3644     * Reference to the root namespace.
3645     * @name ReflectionObject#root
3646     * @type {Root}
3647     * @readonly
3648     */
3649    root: {
3650        get: function() {
3651            var ptr = this;
3652            while (ptr.parent !== null)
3653                ptr = ptr.parent;
3654            return ptr;
3655        }
3656    },
3657
3658    /**
3659     * Full name including leading dot.
3660     * @name ReflectionObject#fullName
3661     * @type {string}
3662     * @readonly
3663     */
3664    fullName: {
3665        get: function() {
3666            var path = [ this.name ],
3667                ptr = this.parent;
3668            while (ptr) {
3669                path.unshift(ptr.name);
3670                ptr = ptr.parent;
3671            }
3672            return path.join(".");
3673        }
3674    }
3675});
3676
3677/**
3678 * Converts this reflection object to its descriptor representation.
3679 * @returns {Object.<string,*>} Descriptor
3680 * @abstract
3681 */
3682ReflectionObject.prototype.toJSON = /* istanbul ignore next */ function toJSON() {
3683    throw Error(); // not implemented, shouldn't happen
3684};
3685
3686/**
3687 * Called when this object is added to a parent.
3688 * @param {ReflectionObject} parent Parent added to
3689 * @returns {undefined}
3690 */
3691ReflectionObject.prototype.onAdd = function onAdd(parent) {
3692    if (this.parent && this.parent !== parent)
3693        this.parent.remove(this);
3694    this.parent = parent;
3695    this.resolved = false;
3696    var root = parent.root;
3697    if (root instanceof Root)
3698        root._handleAdd(this);
3699};
3700
3701/**
3702 * Called when this object is removed from a parent.
3703 * @param {ReflectionObject} parent Parent removed from
3704 * @returns {undefined}
3705 */
3706ReflectionObject.prototype.onRemove = function onRemove(parent) {
3707    var root = parent.root;
3708    if (root instanceof Root)
3709        root._handleRemove(this);
3710    this.parent = null;
3711    this.resolved = false;
3712};
3713
3714/**
3715 * Resolves this objects type references.
3716 * @returns {ReflectionObject} `this`
3717 */
3718ReflectionObject.prototype.resolve = function resolve() {
3719    if (this.resolved)
3720        return this;
3721    if (this.root instanceof Root)
3722        this.resolved = true; // only if part of a root
3723    return this;
3724};
3725
3726/**
3727 * Gets an option value.
3728 * @param {string} name Option name
3729 * @returns {*} Option value or `undefined` if not set
3730 */
3731ReflectionObject.prototype.getOption = function getOption(name) {
3732    if (this.options)
3733        return this.options[name];
3734    return undefined;
3735};
3736
3737/**
3738 * Sets an option.
3739 * @param {string} name Option name
3740 * @param {*} value Option value
3741 * @param {boolean} [ifNotSet] Sets the option only if it isn't currently set
3742 * @returns {ReflectionObject} `this`
3743 */
3744ReflectionObject.prototype.setOption = function setOption(name, value, ifNotSet) {
3745    if (!ifNotSet || !this.options || this.options[name] === undefined)
3746        (this.options || (this.options = {}))[name] = value;
3747    return this;
3748};
3749
3750/**
3751 * Sets multiple options.
3752 * @param {Object.<string,*>} options Options to set
3753 * @param {boolean} [ifNotSet] Sets an option only if it isn't currently set
3754 * @returns {ReflectionObject} `this`
3755 */
3756ReflectionObject.prototype.setOptions = function setOptions(options, ifNotSet) {
3757    if (options)
3758        for (var keys = Object.keys(options), i = 0; i < keys.length; ++i)
3759            this.setOption(keys[i], options[keys[i]], ifNotSet);
3760    return this;
3761};
3762
3763/**
3764 * Converts this instance to its string representation.
3765 * @returns {string} Class name[, space, full name]
3766 */
3767ReflectionObject.prototype.toString = function toString() {
3768    var className = this.constructor.className,
3769        fullName  = this.fullName;
3770    if (fullName.length)
3771        return className + " " + fullName;
3772    return className;
3773};
3774
3775ReflectionObject._configure = function(Root_) {
3776    Root = Root_;
3777};
3778
3779},{"37":37}],25:[function(require,module,exports){
3780"use strict";
3781module.exports = OneOf;
3782
3783// extends ReflectionObject
3784var ReflectionObject = require(24);
3785((OneOf.prototype = Object.create(ReflectionObject.prototype)).constructor = OneOf).className = "OneOf";
3786
3787var Field = require(16),
3788    util  = require(37);
3789
3790/**
3791 * Constructs a new oneof instance.
3792 * @classdesc Reflected oneof.
3793 * @extends ReflectionObject
3794 * @constructor
3795 * @param {string} name Oneof name
3796 * @param {string[]|Object.<string,*>} [fieldNames] Field names
3797 * @param {Object.<string,*>} [options] Declared options
3798 * @param {string} [comment] Comment associated with this field
3799 */
3800function OneOf(name, fieldNames, options, comment) {
3801    if (!Array.isArray(fieldNames)) {
3802        options = fieldNames;
3803        fieldNames = undefined;
3804    }
3805    ReflectionObject.call(this, name, options);
3806
3807    /* istanbul ignore if */
3808    if (!(fieldNames === undefined || Array.isArray(fieldNames)))
3809        throw TypeError("fieldNames must be an Array");
3810
3811    /**
3812     * Field names that belong to this oneof.
3813     * @type {string[]}
3814     */
3815    this.oneof = fieldNames || []; // toJSON, marker
3816
3817    /**
3818     * Fields that belong to this oneof as an array for iteration.
3819     * @type {Field[]}
3820     * @readonly
3821     */
3822    this.fieldsArray = []; // declared readonly for conformance, possibly not yet added to parent
3823
3824    /**
3825     * Comment for this field.
3826     * @type {string|null}
3827     */
3828    this.comment = comment;
3829}
3830
3831/**
3832 * Oneof descriptor.
3833 * @interface IOneOf
3834 * @property {Array.<string>} oneof Oneof field names
3835 * @property {Object.<string,*>} [options] Oneof options
3836 */
3837
3838/**
3839 * Constructs a oneof from a oneof descriptor.
3840 * @param {string} name Oneof name
3841 * @param {IOneOf} json Oneof descriptor
3842 * @returns {OneOf} Created oneof
3843 * @throws {TypeError} If arguments are invalid
3844 */
3845OneOf.fromJSON = function fromJSON(name, json) {
3846    return new OneOf(name, json.oneof, json.options, json.comment);
3847};
3848
3849/**
3850 * Converts this oneof to a oneof descriptor.
3851 * @param {IToJSONOptions} [toJSONOptions] JSON conversion options
3852 * @returns {IOneOf} Oneof descriptor
3853 */
3854OneOf.prototype.toJSON = function toJSON(toJSONOptions) {
3855    var keepComments = toJSONOptions ? Boolean(toJSONOptions.keepComments) : false;
3856    return util.toObject([
3857        "options" , this.options,
3858        "oneof"   , this.oneof,
3859        "comment" , keepComments ? this.comment : undefined
3860    ]);
3861};
3862
3863/**
3864 * Adds the fields of the specified oneof to the parent if not already done so.
3865 * @param {OneOf} oneof The oneof
3866 * @returns {undefined}
3867 * @inner
3868 * @ignore
3869 */
3870function addFieldsToParent(oneof) {
3871    if (oneof.parent)
3872        for (var i = 0; i < oneof.fieldsArray.length; ++i)
3873            if (!oneof.fieldsArray[i].parent)
3874                oneof.parent.add(oneof.fieldsArray[i]);
3875}
3876
3877/**
3878 * Adds a field to this oneof and removes it from its current parent, if any.
3879 * @param {Field} field Field to add
3880 * @returns {OneOf} `this`
3881 */
3882OneOf.prototype.add = function add(field) {
3883
3884    /* istanbul ignore if */
3885    if (!(field instanceof Field))
3886        throw TypeError("field must be a Field");
3887
3888    if (field.parent && field.parent !== this.parent)
3889        field.parent.remove(field);
3890    this.oneof.push(field.name);
3891    this.fieldsArray.push(field);
3892    field.partOf = this; // field.parent remains null
3893    addFieldsToParent(this);
3894    return this;
3895};
3896
3897/**
3898 * Removes a field from this oneof and puts it back to the oneof's parent.
3899 * @param {Field} field Field to remove
3900 * @returns {OneOf} `this`
3901 */
3902OneOf.prototype.remove = function remove(field) {
3903
3904    /* istanbul ignore if */
3905    if (!(field instanceof Field))
3906        throw TypeError("field must be a Field");
3907
3908    var index = this.fieldsArray.indexOf(field);
3909
3910    /* istanbul ignore if */
3911    if (index < 0)
3912        throw Error(field + " is not a member of " + this);
3913
3914    this.fieldsArray.splice(index, 1);
3915    index = this.oneof.indexOf(field.name);
3916
3917    /* istanbul ignore else */
3918    if (index > -1) // theoretical
3919        this.oneof.splice(index, 1);
3920
3921    field.partOf = null;
3922    return this;
3923};
3924
3925/**
3926 * @override
3927 */
3928OneOf.prototype.onAdd = function onAdd(parent) {
3929    ReflectionObject.prototype.onAdd.call(this, parent);
3930    var self = this;
3931    // Collect present fields
3932    for (var i = 0; i < this.oneof.length; ++i) {
3933        var field = parent.get(this.oneof[i]);
3934        if (field && !field.partOf) {
3935            field.partOf = self;
3936            self.fieldsArray.push(field);
3937        }
3938    }
3939    // Add not yet present fields
3940    addFieldsToParent(this);
3941};
3942
3943/**
3944 * @override
3945 */
3946OneOf.prototype.onRemove = function onRemove(parent) {
3947    for (var i = 0, field; i < this.fieldsArray.length; ++i)
3948        if ((field = this.fieldsArray[i]).parent)
3949            field.parent.remove(field);
3950    ReflectionObject.prototype.onRemove.call(this, parent);
3951};
3952
3953/**
3954 * Decorator function as returned by {@link OneOf.d} (TypeScript).
3955 * @typedef OneOfDecorator
3956 * @type {function}
3957 * @param {Object} prototype Target prototype
3958 * @param {string} oneofName OneOf name
3959 * @returns {undefined}
3960 */
3961
3962/**
3963 * OneOf decorator (TypeScript).
3964 * @function
3965 * @param {...string} fieldNames Field names
3966 * @returns {OneOfDecorator} Decorator function
3967 * @template T extends string
3968 */
3969OneOf.d = function decorateOneOf() {
3970    var fieldNames = new Array(arguments.length),
3971        index = 0;
3972    while (index < arguments.length)
3973        fieldNames[index] = arguments[index++];
3974    return function oneOfDecorator(prototype, oneofName) {
3975        util.decorateType(prototype.constructor)
3976            .add(new OneOf(oneofName, fieldNames));
3977        Object.defineProperty(prototype, oneofName, {
3978            get: util.oneOfGetter(fieldNames),
3979            set: util.oneOfSetter(fieldNames)
3980        });
3981    };
3982};
vendor: 15,794 bytes, lines 3983-4506
3983
3984},{"16":16,"24":24,"37":37}],26:[function(require,module,exports){
3985"use strict";
3986module.exports = parse;
3987
3988parse.filename = null;
3989parse.defaults = { keepCase: false };
3990
3991var tokenize  = require(34),
3992    Root      = require(29),
3993    Type      = require(35),
3994    Field     = require(16),
3995    MapField  = require(20),
3996    OneOf     = require(25),
3997    Enum      = require(15),
3998    Service   = require(33),
3999    Method    = require(22),
4000    types     = require(36),
4001    util      = require(37);
4002
4003var base10Re    = /^[1-9][0-9]*$/,
4004    base10NegRe = /^-?[1-9][0-9]*$/,
4005    base16Re    = /^0[x][0-9a-fA-F]+$/,
4006    base16NegRe = /^-?0[x][0-9a-fA-F]+$/,
4007    base8Re     = /^0[0-7]+$/,
4008    base8NegRe  = /^-?0[0-7]+$/,
4009    numberRe    = /^(?![eE])[0-9]*(?:\.[0-9]*)?(?:[eE][+-]?[0-9]+)?$/,
4010    nameRe      = /^[a-zA-Z_][a-zA-Z_0-9]*$/,
4011    typeRefRe   = /^(?:\.?[a-zA-Z_][a-zA-Z_0-9]*)(?:\.[a-zA-Z_][a-zA-Z_0-9]*)*$/,
4012    fqTypeRefRe = /^(?:\.[a-zA-Z_][a-zA-Z_0-9]*)+$/;
4013
4014/**
4015 * Result object returned from {@link parse}.
4016 * @interface IParserResult
4017 * @property {string|undefined} package Package name, if declared
4018 * @property {string[]|undefined} imports Imports, if any
4019 * @property {string[]|undefined} weakImports Weak imports, if any
4020 * @property {string|undefined} syntax Syntax, if specified (either `"proto2"` or `"proto3"`)
4021 * @property {Root} root Populated root instance
4022 */
4023
4024/**
4025 * Options modifying the behavior of {@link parse}.
4026 * @interface IParseOptions
4027 * @property {boolean} [keepCase=false] Keeps field casing instead of converting to camel case
4028 * @property {boolean} [alternateCommentMode=false] Recognize double-slash comments in addition to doc-block comments.
4029 */
4030
4031/**
4032 * Options modifying the behavior of JSON serialization.
4033 * @interface IToJSONOptions
4034 * @property {boolean} [keepComments=false] Serializes comments.
4035 */
4036
4037/**
4038 * Parses the given .proto source and returns an object with the parsed contents.
4039 * @param {string} source Source contents
4040 * @param {Root} root Root to populate
4041 * @param {IParseOptions} [options] Parse options. Defaults to {@link parse.defaults} when omitted.
4042 * @returns {IParserResult} Parser result
4043 * @property {string} filename=null Currently processing file name for error reporting, if known
4044 * @property {IParseOptions} defaults Default {@link IParseOptions}
4045 */
4046function parse(source, root, options) {
4047    /* eslint-disable callback-return */
4048    if (!(root instanceof Root)) {
4049        options = root;
4050        root = new Root();
4051    }
4052    if (!options)
4053        options = parse.defaults;
4054
4055    var tn = tokenize(source, options.alternateCommentMode || false),
4056        next = tn.next,
4057        push = tn.push,
4058        peek = tn.peek,
4059        skip = tn.skip,
4060        cmnt = tn.cmnt;
4061
4062    var head = true,
4063        pkg,
4064        imports,
4065        weakImports,
4066        syntax,
4067        isProto3 = false;
4068
4069    var ptr = root;
4070
4071    var applyCase = options.keepCase ? function(name) { return name; } : util.camelCase;
4072
4073    /* istanbul ignore next */
4074    function illegal(token, name, insideTryCatch) {
4075        var filename = parse.filename;
4076        if (!insideTryCatch)
4077            parse.filename = null;
4078        return Error("illegal " + (name || "token") + " '" + token + "' (" + (filename ? filename + ", " : "") + "line " + tn.line + ")");
4079    }
4080
4081    function readString() {
4082        var values = [],
4083            token;
4084        do {
4085            /* istanbul ignore if */
4086            if ((token = next()) !== "\"" && token !== "'")
4087                throw illegal(token);
4088
4089            values.push(next());
4090            skip(token);
4091            token = peek();
4092        } while (token === "\"" || token === "'");
4093        return values.join("");
4094    }
4095
4096    function readValue(acceptTypeRef) {
4097        var token = next();
4098        switch (token) {
4099            case "'":
4100            case "\"":
4101                push(token);
4102                return readString();
4103            case "true": case "TRUE":
4104                return true;
4105            case "false": case "FALSE":
4106                return false;
4107        }
4108        try {
4109            return parseNumber(token, /* insideTryCatch */ true);
4110        } catch (e) {
4111
4112            /* istanbul ignore else */
4113            if (acceptTypeRef && typeRefRe.test(token))
4114                return token;
4115
4116            /* istanbul ignore next */
4117            throw illegal(token, "value");
4118        }
4119    }
4120
4121    function readRanges(target, acceptStrings) {
4122        var token, start;
4123        do {
4124            if (acceptStrings && ((token = peek()) === "\"" || token === "'"))
4125                target.push(readString());
4126            else
4127                target.push([ start = parseId(next()), skip("to", true) ? parseId(next()) : start ]);
4128        } while (skip(",", true));
4129        skip(";");
4130    }
4131
4132    function parseNumber(token, insideTryCatch) {
4133        var sign = 1;
4134        if (token.charAt(0) === "-") {
4135            sign = -1;
4136            token = token.substring(1);
4137        }
4138        switch (token) {
4139            case "inf": case "INF": case "Inf":
4140                return sign * Infinity;
4141            case "nan": case "NAN": case "Nan": case "NaN":
4142                return NaN;
4143            case "0":
4144                return 0;
4145        }
4146        if (base10Re.test(token))
4147            return sign * parseInt(token, 10);
4148        if (base16Re.test(token))
4149            return sign * parseInt(token, 16);
4150        if (base8Re.test(token))
4151            return sign * parseInt(token, 8);
4152
4153        /* istanbul ignore else */
4154        if (numberRe.test(token))
4155            return sign * parseFloat(token);
4156
4157        /* istanbul ignore next */
4158        throw illegal(token, "number", insideTryCatch);
4159    }
4160
4161    function parseId(token, acceptNegative) {
4162        switch (token) {
4163            case "max": case "MAX": case "Max":
4164                return 536870911;
4165            case "0":
4166                return 0;
4167        }
4168
4169        /* istanbul ignore if */
4170        if (!acceptNegative && token.charAt(0) === "-")
4171            throw illegal(token, "id");
4172
4173        if (base10NegRe.test(token))
4174            return parseInt(token, 10);
4175        if (base16NegRe.test(token))
4176            return parseInt(token, 16);
4177
4178        /* istanbul ignore else */
4179        if (base8NegRe.test(token))
4180            return parseInt(token, 8);
4181
4182        /* istanbul ignore next */
4183        throw illegal(token, "id");
4184    }
4185
4186    function parsePackage() {
4187
4188        /* istanbul ignore if */
4189        if (pkg !== undefined)
4190            throw illegal("package");
4191
4192        pkg = next();
4193
4194        /* istanbul ignore if */
4195        if (!typeRefRe.test(pkg))
4196            throw illegal(pkg, "name");
4197
4198        ptr = ptr.define(pkg);
4199        skip(";");
4200    }
4201
4202    function parseImport() {
4203        var token = peek();
4204        var whichImports;
4205        switch (token) {
4206            case "weak":
4207                whichImports = weakImports || (weakImports = []);
4208                next();
4209                break;
4210            case "public":
4211                next();
4212                // eslint-disable-line no-fallthrough
4213            default:
4214                whichImports = imports || (imports = []);
4215                break;
4216        }
4217        token = readString();
4218        skip(";");
4219        whichImports.push(token);
4220    }
4221
4222    function parseSyntax() {
4223        skip("=");
4224        syntax = readString();
4225        isProto3 = syntax === "proto3";
4226
4227        /* istanbul ignore if */
4228        if (!isProto3 && syntax !== "proto2")
4229            throw illegal(syntax, "syntax");
4230
4231        skip(";");
4232    }
4233
4234    function parseCommon(parent, token) {
4235        switch (token) {
4236
4237            case "option":
4238                parseOption(parent, token);
4239                skip(";");
4240                return true;
4241
4242            case "message":
4243                parseType(parent, token);
4244                return true;
4245
4246            case "enum":
4247                parseEnum(parent, token);
4248                return true;
4249
4250            case "service":
4251                parseService(parent, token);
4252                return true;
4253
4254            case "extend":
4255                parseExtension(parent, token);
4256                return true;
4257        }
4258        return false;
4259    }
4260
4261    function ifBlock(obj, fnIf, fnElse) {
4262        var trailingLine = tn.line;
4263        if (obj) {
4264            obj.comment = cmnt(); // try block-type comment
4265            obj.filename = parse.filename;
4266        }
4267        if (skip("{", true)) {
4268            var token;
4269            while ((token = next()) !== "}")
4270                fnIf(token);
4271            skip(";", true);
4272        } else {
4273            if (fnElse)
4274                fnElse();
4275            skip(";");
4276            if (obj && typeof obj.comment !== "string")
4277                obj.comment = cmnt(trailingLine); // try line-type comment if no block
4278        }
4279    }
4280
4281    function parseType(parent, token) {
4282
4283        /* istanbul ignore if */
4284        if (!nameRe.test(token = next()))
4285            throw illegal(token, "type name");
4286
4287        var type = new Type(token);
4288        ifBlock(type, function parseType_block(token) {
4289            if (parseCommon(type, token))
4290                return;
4291
4292            switch (token) {
4293
4294                case "map":
4295                    parseMapField(type, token);
4296                    break;
4297
4298                case "required":
4299                case "optional":
4300                case "repeated":
4301                    parseField(type, token);
4302                    break;
4303
4304                case "oneof":
4305                    parseOneOf(type, token);
4306                    break;
4307
4308                case "extensions":
4309                    readRanges(type.extensions || (type.extensions = []));
4310                    break;
4311
4312                case "reserved":
4313                    readRanges(type.reserved || (type.reserved = []), true);
4314                    break;
4315
4316                default:
4317                    /* istanbul ignore if */
4318                    if (!isProto3 || !typeRefRe.test(token))
4319                        throw illegal(token);
4320
4321                    push(token);
4322                    parseField(type, "optional");
4323                    break;
4324            }
4325        });
4326        parent.add(type);
4327    }
4328
4329    function parseField(parent, rule, extend) {
4330        var type = next();
4331        if (type === "group") {
4332            parseGroup(parent, rule);
4333            return;
4334        }
4335
4336        /* istanbul ignore if */
4337        if (!typeRefRe.test(type))
4338            throw illegal(type, "type");
4339
4340        var name = next();
4341
4342        /* istanbul ignore if */
4343        if (!nameRe.test(name))
4344            throw illegal(name, "name");
4345
4346        name = applyCase(name);
4347        skip("=");
4348
4349        var field = new Field(name, parseId(next()), type, rule, extend);
4350        ifBlock(field, function parseField_block(token) {
4351
4352            /* istanbul ignore else */
4353            if (token === "option") {
4354                parseOption(field, token);
4355                skip(";");
4356            } else
4357                throw illegal(token);
4358
4359        }, function parseField_line() {
4360            parseInlineOptions(field);
4361        });
4362        parent.add(field);
4363
4364        // JSON defaults to packed=true if not set so we have to set packed=false explicity when
4365        // parsing proto2 descriptors without the option, where applicable. This must be done for
4366        // all known packable types and anything that could be an enum (= is not a basic type).
4367        if (!isProto3 && field.repeated && (types.packed[type] !== undefined || types.basic[type] === undefined))
4368            field.setOption("packed", false, /* ifNotSet */ true);
4369    }
4370
4371    function parseGroup(parent, rule) {
4372        var name = next();
4373
4374        /* istanbul ignore if */
4375        if (!nameRe.test(name))
4376            throw illegal(name, "name");
4377
4378        var fieldName = util.lcFirst(name);
4379        if (name === fieldName)
4380            name = util.ucFirst(name);
4381        skip("=");
4382        var id = parseId(next());
4383        var type = new Type(name);
4384        type.group = true;
4385        var field = new Field(fieldName, id, name, rule);
4386        field.filename = parse.filename;
4387        ifBlock(type, function parseGroup_block(token) {
4388            switch (token) {
4389
4390                case "option":
4391                    parseOption(type, token);
4392                    skip(";");
4393                    break;
4394
4395                case "required":
4396                case "optional":
4397                case "repeated":
4398                    parseField(type, token);
4399                    break;
4400
4401                /* istanbul ignore next */
4402                default:
4403                    throw illegal(token); // there are no groups with proto3 semantics
4404            }
4405        });
4406        parent.add(type)
4407              .add(field);
4408    }
4409
4410    function parseMapField(parent) {
4411        skip("<");
4412        var keyType = next();
4413
4414        /* istanbul ignore if */
4415        if (types.mapKey[keyType] === undefined)
4416            throw illegal(keyType, "type");
4417
4418        skip(",");
4419        var valueType = next();
4420
4421        /* istanbul ignore if */
4422        if (!typeRefRe.test(valueType))
4423            throw illegal(valueType, "type");
4424
4425        skip(">");
4426        var name = next();
4427
4428        /* istanbul ignore if */
4429        if (!nameRe.test(name))
4430            throw illegal(name, "name");
4431
4432        skip("=");
4433        var field = new MapField(applyCase(name), parseId(next()), keyType, valueType);
4434        ifBlock(field, function parseMapField_block(token) {
4435
4436            /* istanbul ignore else */
4437            if (token === "option") {
4438                parseOption(field, token);
4439                skip(";");
4440            } else
4441                throw illegal(token);
4442
4443        }, function parseMapField_line() {
4444            parseInlineOptions(field);
4445        });
4446        parent.add(field);
4447    }
4448
4449    function parseOneOf(parent, token) {
4450
4451        /* istanbul ignore if */
4452        if (!nameRe.test(token = next()))
4453            throw illegal(token, "name");
4454
4455        var oneof = new OneOf(applyCase(token));
4456        ifBlock(oneof, function parseOneOf_block(token) {
4457            if (token === "option") {
4458                parseOption(oneof, token);
4459                skip(";");
4460            } else {
4461                push(token);
4462                parseField(oneof, "optional");
4463            }
4464        });
4465        parent.add(oneof);
4466    }
4467
4468    function parseEnum(parent, token) {
4469
4470        /* istanbul ignore if */
4471        if (!nameRe.test(token = next()))
4472            throw illegal(token, "name");
4473
4474        var enm = new Enum(token);
4475        ifBlock(enm, function parseEnum_block(token) {
4476          switch(token) {
4477            case "option":
4478              parseOption(enm, token);
4479              skip(";");
4480              break;
4481
4482            case "reserved":
4483              readRanges(enm.reserved || (enm.reserved = []), true);
4484              break;
4485
4486            default:
4487              parseEnumValue(enm, token);
4488          }
4489        });
4490        parent.add(enm);
4491    }
4492
4493    function parseEnumValue(parent, token) {
4494
4495        /* istanbul ignore if */
4496        if (!nameRe.test(token))
4497            throw illegal(token, "name");
4498
4499        skip("=");
4500        var value = parseId(next(), true),
4501            dummy = {};
4502        ifBlock(dummy, function parseEnumValue_block(token) {
4503
4504            /* istanbul ignore else */
4505            if (token === "option") {
4506                parseOption(dummy, token);
4506 // skip
4507                skip(";");
4508            } else
4509                throw illegal(token);
4510
4511        }, function parseEnumValue_line() {
4512            parseInlineOptions(dummy); // skip
4513        });
4514        parent.add(token, value, dummy.comment);
4515    }
4516
4517    function parseOption(parent, token) {
4518        var isCustom = skip("(", true);
4519
4520        /* istanbul ignore if */
4521        if (!typeRefRe.test(token = next()))
4522            throw illegal(token, "name");
4523
4524        var name = token;
4525        if (isCustom) {
4526            skip(")");
4527            name = "(" + name + ")";
4528            token = peek();
4529            if (fqTypeRefRe.test(token)) {
4530                name += token;
4531                next();
4532            }
4533        }
4534        skip("=");
4535        parseOptionValue(parent, name);
4536    }
4537
4538    function parseOptionValue(parent, name) {
4539        if (skip("{", true)) { // { a: "foo" b { c: "bar" } }
4540            do {
4541                /* istanbul ignore if */
4542                if (!nameRe.test(token = next()))
4543                    throw illegal(token, "name");
4544
4545                if (peek() === "{")
4546                    parseOptionValue(parent, name + "." + token);
4547                else {
4548                    skip(":");
4549                    if (peek() === "{")
4550                        parseOptionValue(parent, name + "." + token);
4551                    else
4552                        setOption(parent, name + "." + token, readValue(true));
4553                }
4554            } while (!skip("}", true));
4555        } else
4556            setOption(parent, name, readValue(true));
4557        // Does not enforce a delimiter to be universal
4558    }
4559
4560    function setOption(parent, name, value) {
4561        if (parent.setOption)
4562            parent.setOption(name, value);
4563    }
4564
4565    function parseInlineOptions(parent) {
4566        if (skip("[", true)) {
4567            do {
4568                parseOption(parent, "option");
4569            } while (skip(",", true));
4570            skip("]");
4571        }
4572        return parent;
4573    }
4574
4575    function parseService(parent, token) {
4576
4577        /* istanbul ignore if */
4578        if (!nameRe.test(token = next()))
4579            throw illegal(token, "service name");
4580
4581        var service = new Service(token);
4582        ifBlock(service, function parseService_block(token) {
4583            if (parseCommon(service, token))
4584                return;
4585
4586            /* istanbul ignore else */
4587            if (token === "rpc")
4588                parseMethod(service, token);
4589            else
4590                throw illegal(token);
4591        });
4592        parent.add(service);
4593    }
4594
4595    function parseMethod(parent, token) {
4596        var type = token;
4597
4598        /* istanbul ignore if */
4599        if (!nameRe.test(token = next()))
4600            throw illegal(token, "name");
4601
4602        var name = token,
4603            requestType, requestStream,
4604            responseType, responseStream;
4605
4606        skip("(");
4607        if (skip("stream", true))
4608            requestStream = true;
4609
4610        /* istanbul ignore if */
4611        if (!typeRefRe.test(token = next()))
4612            throw illegal(token);
4613
4614        requestType = token;
4615        skip(")"); skip("returns"); skip("(");
4616        if (skip("stream", true))
4617            responseStream = true;
4618
4619        /* istanbul ignore if */
4620        if (!typeRefRe.test(token = next()))
4621            throw illegal(token);
4622
4623        responseType = token;
4624        skip(")");
4625
4626        var method = new Method(name, type, requestType, responseType, requestStream, responseStream);
4627        ifBlock(method, function parseMethod_block(token) {
4628
4629            /* istanbul ignore else */
4630            if (token === "option") {
4631                parseOption(method, token);
4632                skip(";");
4633            } else
4634                throw illegal(token);
4635
4636        });
4637        parent.add(method);
4638    }
4639
4640    function parseExtension(parent, token) {
4641
4642        /* istanbul ignore if */
4643        if (!typeRefRe.test(token = next()))
4644            throw illegal(token, "reference");
4645
4646        var reference = token;
4647        ifBlock(null, function parseExtension_block(token) {
4648            switch (token) {
4649
4650                case "required":
4651                case "repeated":
4652                case "optional":
4653                    parseField(parent, token, reference);
4654                    break;
4655
4656                default:
4657                    /* istanbul ignore if */
4658                    if (!isProto3 || !typeRefRe.test(token))
4659                        throw illegal(token);
4660                    push(token);
4661                    parseField(parent, "optional", reference);
4662                    break;
4663            }
4664        });
4665    }
4666
4667    var token;
4668    while ((token = next()) !== null) {
4669        switch (token) {
4670
4671            case "package":
4672
4673                /* istanbul ignore if */
4674                if (!head)
4675                    throw illegal(token);
4676
4677                parsePackage();
4678                break;
4679
4680            case "import":
4681
4682                /* istanbul ignore if */
4683                if (!head)
4684                    throw illegal(token);
4685
4686                parseImport();
4687                break;
4688
4689            case "syntax":
4690
4691                /* istanbul ignore if */
4692                if (!head)
4693                    throw illegal(token);
4694
4695                parseSyntax();
4696                break;
4697
4698            case "option":
4699
4700                /* istanbul ignore if */
4701                if (!head)
4702                    throw illegal(token);
4703
4704                parseOption(ptr, token);
4705                skip(";");
4706                break;
4707
4708            default:
4709
4710                /* istanbul ignore else */
4711                if (parseCommon(ptr, token)) {
4712                    head = false;
4713                    continue;
4714                }
4715
4716                /* istanbul ignore next */
4717                throw illegal(token);
4718        }
4719    }
4720
4721    parse.filename = null;
4722    return {
4723        "package"     : pkg,
4724        "imports"     : imports,
4725         weakImports  : weakImports,
4726         syntax       : syntax,
4727         root         : root
4728    };
4729}
4730
4731/**
4732 * Parses the given .proto source and returns an object with the parsed contents.
4733 * @name parse
4734 * @function
4735 * @param {string} source Source contents
4736 * @param {IParseOptions} [options] Parse options. Defaults to {@link parse.defaults} when omitted.
4737 * @returns {IParserResult} Parser result
4738 * @property {string} filename=null Currently processing file name for error reporting, if known
4739 * @property {IParseOptions} defaults Default {@link IParseOptions}
4740 * @variation 2
4741 */
4742
4743},{"15":15,"16":16,"20":20,"22":22,"25":25,"29":29,"33":33,"34":34,"35":35,"36":36,"37":37}],27:[function(require,module,exports){
4744"use strict";
4745module.exports = Reader;
4746
4747var util      = require(39);
4748
4749var BufferReader; // cyclic
4750
4751var LongBits  = util.LongBits,
4752    utf8      = util.utf8;
4753
4754/* istanbul ignore next */
4755function indexOutOfRange(reader, writeLength) {
4756    return RangeError("index out of range: " + reader.pos + " + " + (writeLength || 1) + " > " + reader.len);
4757}
4758
4759/**
4760 * Constructs a new reader instance using the specified buffer.
4761 * @classdesc Wire format reader using `Uint8Array` if available, otherwise `Array`.
4762 * @constructor
4763 * @param {Uint8Array} buffer Buffer to read from
4764 */
4765function Reader(buffer) {
4766
4767    /**
4768     * Read buffer.
4769     * @type {Uint8Array}
4770     */
4771    this.buf = buffer;
4772
4773    /**
4774     * Read buffer position.
4775     * @type {number}
4776     */
4777    this.pos = 0;
4778
4779    /**
4780     * Read buffer length.
4781     * @type {number}
4782     */
4783    this.len = buffer.length;
4784}
4785
4786var create_array = typeof Uint8Array !== "undefined"
4787    ? function create_typed_array(buffer) {
4788        if (buffer instanceof Uint8Array || Array.isArray(buffer))
4789            return new Reader(buffer);
4790        throw Error("illegal buffer");
4791    }
4792    /* istanbul ignore next */
4793    : function create_array(buffer) {
4794        if (Array.isArray(buffer))
4795            return new Reader(buffer);
4796        throw Error("illegal buffer");
4797    };
4798
4799/**
4800 * Creates a new reader using the specified buffer.
4801 * @function
4802 * @param {Uint8Array|Buffer} buffer Buffer to read from
4803 * @returns {Reader|BufferReader} A {@link BufferReader} if `buffer` is a Buffer, otherwise a {@link Reader}
4804 * @throws {Error} If `buffer` is not a valid buffer
4805 */
4806Reader.create = util.Buffer
4807    ? function create_buffer_setup(buffer) {
4808        return (Reader.create = function create_buffer(buffer) {
4809            return util.Buffer.isBuffer(buffer)
4810                ? new BufferReader(buffer)
4811                /* istanbul ignore next */
4812                : create_array(buffer);
4813        })(buffer);
4814    }
4815    /* istanbul ignore next */
4816    : create_array;
4817
4818Reader.prototype._slice = util.Array.prototype.subarray || /* istanbul ignore next */ util.Array.prototype.slice;
4819
4820/**
4821 * Reads a varint as an unsigned 32 bit value.
4822 * @function
4823 * @returns {number} Value read
4824 */
4825Reader.prototype.uint32 = (function read_uint32_setup() {
4826    var value = 4294967295; // optimizer type-hint, tends to deopt otherwise (?!)
4827    return function read_uint32() {
4828        value = (         this.buf[this.pos] & 127       ) >>> 0; if (this.buf[this.pos++] < 128) return value;
4829        value = (value | (this.buf[this.pos] & 127) <<  7) >>> 0; if (this.buf[this.pos++] < 128) return value;
4830        value = (value | (this.buf[this.pos] & 127) << 14) >>> 0; if (this.buf[this.pos++] < 128) return value;
4831        value = (value | (this.buf[this.pos] & 127) << 21) >>> 0; if (this.buf[this.pos++] < 128) return value;
4832        value = (value | (this.buf[this.pos] &  15) << 28) >>> 0; if (this.buf[this.pos++] < 128) return value;
4833
4834        /* istanbul ignore if */
4835        if ((this.pos += 5) > this.len) {
4836            this.pos = this.len;
4837            throw indexOutOfRange(this, 10);
4838        }
4839        return value;
4840    };
4841})();
4842
4843/**
4844 * Reads a varint as a signed 32 bit value.
4845 * @returns {number} Value read
4846 */
4847Reader.prototype.int32 = function read_int32() {
4848    return this.uint32() | 0;
4849};
4850
4851/**
4852 * Reads a zig-zag encoded varint as a signed 32 bit value.
4853 * @returns {number} Value read
4854 */
4855Reader.prototype.sint32 = function read_sint32() {
4856    var value = this.uint32();
4857    return value >>> 1 ^ -(value & 1) | 0;
4858};
4859
4860/* eslint-disable no-invalid-this */
4861
4862function readLongVarint() {
4863    // tends to deopt with local vars for octet etc.
4864    var bits = new LongBits(0, 0);
4865    var i = 0;
4866    if (this.len - this.pos > 4) { // fast route (lo)
4867        for (; i < 4; ++i) {
4868            // 1st..4th
4869            bits.lo = (bits.lo | (this.buf[this.pos] & 127) << i * 7) >>> 0;
4870            if (this.buf[this.pos++] < 128)
4871                return bits;
4872        }
4873        // 5th
4874        bits.lo = (bits.lo | (this.buf[this.pos] & 127) << 28) >>> 0;
vendor: 4,991 bytes, lines 4875-5064
4875        bits.hi = (bits.hi | (this.buf[this.pos] & 127) >>  4) >>> 0;
4876        if (this.buf[this.pos++] < 128)
4877            return bits;
4878        i = 0;
4879    } else {
4880        for (; i < 3; ++i) {
4881            /* istanbul ignore if */
4882            if (this.pos >= this.len)
4883                throw indexOutOfRange(this);
4884            // 1st..3th
4885            bits.lo = (bits.lo | (this.buf[this.pos] & 127) << i * 7) >>> 0;
4886            if (this.buf[this.pos++] < 128)
4887                return bits;
4888        }
4889        // 4th
4890        bits.lo = (bits.lo | (this.buf[this.pos++] & 127) << i * 7) >>> 0;
4891        return bits;
4892    }
4893    if (this.len - this.pos > 4) { // fast route (hi)
4894        for (; i < 5; ++i) {
4895            // 6th..10th
4896            bits.hi = (bits.hi | (this.buf[this.pos] & 127) << i * 7 + 3) >>> 0;
4897            if (this.buf[this.pos++] < 128)
4898                return bits;
4899        }
4900    } else {
4901        for (; i < 5; ++i) {
4902            /* istanbul ignore if */
4903            if (this.pos >= this.len)
4904                throw indexOutOfRange(this);
4905            // 6th..10th
4906            bits.hi = (bits.hi | (this.buf[this.pos] & 127) << i * 7 + 3) >>> 0;
4907            if (this.buf[this.pos++] < 128)
4908                return bits;
4909        }
4910    }
4911    /* istanbul ignore next */
4912    throw Error("invalid varint encoding");
4913}
4914
4915/* eslint-enable no-invalid-this */
4916
4917/**
4918 * Reads a varint as a signed 64 bit value.
4919 * @name Reader#int64
4920 * @function
4921 * @returns {Long} Value read
4922 */
4923
4924/**
4925 * Reads a varint as an unsigned 64 bit value.
4926 * @name Reader#uint64
4927 * @function
4928 * @returns {Long} Value read
4929 */
4930
4931/**
4932 * Reads a zig-zag encoded varint as a signed 64 bit value.
4933 * @name Reader#sint64
4934 * @function
4935 * @returns {Long} Value read
4936 */
4937
4938/**
4939 * Reads a varint as a boolean.
4940 * @returns {boolean} Value read
4941 */
4942Reader.prototype.bool = function read_bool() {
4943    return this.uint32() !== 0;
4944};
4945
4946function readFixed32_end(buf, end) { // note that this uses `end`, not `pos`
4947    return (buf[end - 4]
4948          | buf[end - 3] << 8
4949          | buf[end - 2] << 16
4950          | buf[end - 1] << 24) >>> 0;
4951}
4952
4953/**
4954 * Reads fixed 32 bits as an unsigned 32 bit integer.
4955 * @returns {number} Value read
4956 */
4957Reader.prototype.fixed32 = function read_fixed32() {
4958
4959    /* istanbul ignore if */
4960    if (this.pos + 4 > this.len)
4961        throw indexOutOfRange(this, 4);
4962
4963    return readFixed32_end(this.buf, this.pos += 4);
4964};
4965
4966/**
4967 * Reads fixed 32 bits as a signed 32 bit integer.
4968 * @returns {number} Value read
4969 */
4970Reader.prototype.sfixed32 = function read_sfixed32() {
4971
4972    /* istanbul ignore if */
4973    if (this.pos + 4 > this.len)
4974        throw indexOutOfRange(this, 4);
4975
4976    return readFixed32_end(this.buf, this.pos += 4) | 0;
4977};
4978
4979/* eslint-disable no-invalid-this */
4980
4981function readFixed64(/* this: Reader */) {
4982
4983    /* istanbul ignore if */
4984    if (this.pos + 8 > this.len)
4985        throw indexOutOfRange(this, 8);
4986
4987    return new LongBits(readFixed32_end(this.buf, this.pos += 4), readFixed32_end(this.buf, this.pos += 4));
4988}
4989
4990/* eslint-enable no-invalid-this */
4991
4992/**
4993 * Reads fixed 64 bits.
4994 * @name Reader#fixed64
4995 * @function
4996 * @returns {Long} Value read
4997 */
4998
4999/**
5000 * Reads zig-zag encoded fixed 64 bits.
5001 * @name Reader#sfixed64
5002 * @function
5003 * @returns {Long} Value read
5004 */
5005
5006/**
5007 * Reads a float (32 bit) as a number.
5008 * @function
5009 * @returns {number} Value read
5010 */
5011Reader.prototype.float = function read_float() {
5012
5013    /* istanbul ignore if */
5014    if (this.pos + 4 > this.len)
5015        throw indexOutOfRange(this, 4);
5016
5017    var value = util.float.readFloatLE(this.buf, this.pos);
5018    this.pos += 4;
5019    return value;
5020};
5021
5022/**
5023 * Reads a double (64 bit float) as a number.
5024 * @function
5025 * @returns {number} Value read
5026 */
5027Reader.prototype.double = function read_double() {
5028
5029    /* istanbul ignore if */
5030    if (this.pos + 8 > this.len)
5031        throw indexOutOfRange(this, 4);
5032
5033    var value = util.float.readDoubleLE(this.buf, this.pos);
5034    this.pos += 8;
5035    return value;
5036};
5037
5038/**
5039 * Reads a sequence of bytes preceeded by its length as a varint.
5040 * @returns {Uint8Array} Value read
5041 */
5042Reader.prototype.bytes = function read_bytes() {
5043    var length = this.uint32(),
5044        start  = this.pos,
5045        end    = this.pos + length;
5046
5047    /* istanbul ignore if */
5048    if (end > this.len)
5049        throw indexOutOfRange(this, length);
5050
5051    this.pos += length;
5052    if (Array.isArray(this.buf)) // plain array
5053        return this.buf.slice(start, end);
5054    return start === end // fix for IE 10/Win8 and others' subarray returning array of size 1
5055        ? new this.buf.constructor(0)
5056        : this._slice.call(this.buf, start, end);
5057};
5058
5059/**
5060 * Reads a string preceeded by its byte length as a varint.
5061 * @returns {string} Value read
5062 */
5063Reader.prototype.string = function read_string() {
5064    var bytes = this.bytes();
5065    return utf8.read(bytes, 0, bytes.length);
5066};
5067
5068/**
5069 * Skips the specified number of bytes if specified, otherwise skips a varint.
5070 * @param {number} [length] Length if known, otherwise a varint is assumed
5071 * @returns {Reader} `this`
5072 */
5073Reader.prototype.skip = function skip(length) {
5074    if (typeof length === "number") {
5075        /* istanbul ignore if */
5076        if (this.pos + length > this.len)
5077            throw indexOutOfRange(this, length);
5078        this.pos += length;
5079    } else {
5080        do {
5081            /* istanbul ignore if */
5082            if (this.pos >= this.len)
5083                throw indexOutOfRange(this);
5084        } while (this.buf[this.pos++] & 128);
5085    }
5086    return this;
5087};
5088
5089/**
5090 * Skips the next element of the specified wire type.
5091 * @param {number} wireType Wire type received
5092 * @returns {Reader} `this`
5093 */
5094Reader.prototype.skipType = function(wireType) {
5095    switch (wireType) {
5096        case 0:
5097            this.skip();
5098            break;
5099        case 1:
5100            this.skip(8);
5101            break;
5102        case 2:
5103            this.skip(this.uint32());
5104            break;
5105        case 3:
5106            do { // eslint-disable-line no-constant-condition
5107                if ((wireType = this.uint32() & 7) === 4)
5108                    break;
5109                this.skipType(wireType);
5110            } while (true);
5111            break;
5112        case 5:
5113            this.skip(4);
5114            break;
5115
5116        /* istanbul ignore next */
5117        default:
5118            throw Error("invalid wire type " + wireType + " at offset " + this.pos);
5119    }
5120    return this;
5121};
5122
5123Reader._configure = function(BufferReader_) {
5124    BufferReader = BufferReader_;
5125
5126    var fn = util.Long ? "toLong" : /* istanbul ignore next */ "toNumber";
5127    util.merge(Reader.prototype, {
5128
5129        int64: function read_int64() {
5130            return readLongVarint.call(this)[fn](false);
5131        },
5132
5133        uint64: function read_uint64() {
5134            return readLongVarint.call(this)[fn](true);
5135        },
5136
5137        sint64: function read_sint64() {
5138            return readLongVarint.call(this).zzDecode()[fn](false);
5139        },
5140
5141        fixed64: function read_fixed64() {
5142            return readFixed64.call(this)[fn](true);
5143        },
5144
5145        sfixed64: function read_sfixed64() {
5146            return readFixed64.call(this)[fn](false);
5147        }
5148
5149    });
5150};
5151
5152},{"39":39}],28:[function(require,module,exports){
5153"use strict";
5154module.exports = BufferReader;
5155
5156// extends Reader
5157var Reader = require(27);
5158(BufferReader.prototype = Object.create(Reader.prototype)).constructor = BufferReader;
5159
5160var util = require(39);
5161
5162/**
5163 * Constructs a new buffer reader instance.
5164 * @classdesc Wire format reader using node buffers.
5165 * @extends Reader
5166 * @constructor
5167 * @param {Buffer} buffer Buffer to read from
5168 */
5169function BufferReader(buffer) {
5170    Reader.call(this, buffer);
5171
5172    /**
5173     * Read buffer.
5174     * @name BufferReader#buf
5175     * @type {Buffer}
5176     */
5177}
5178
5179/* istanbul ignore else */
5180if (util.Buffer)
5181    BufferReader.prototype._slice = util.Buffer.prototype.slice;
5182
5183/**
5184 * @override
5185 */
5186BufferReader.prototype.string = function read_string_buffer() {
5187    var len = this.uint32(); // modifies pos
5188    return this.buf.utf8Slice(this.pos, this.pos = Math.min(this.pos + len, this.len));
5189};
5190
5191/**
5192 * Reads a sequence of bytes preceeded by its length as a varint.
5193 * @name BufferReader#bytes
5194 * @function
5195 * @returns {Buffer} Value read
5196 */
5197
5198},{"27":27,"39":39}],29:[function(require,module,exports){
5199"use strict";
5200module.exports = Root;
5201
5202// extends Namespace
5203var Namespace = require(23);
5204((Root.prototype = Object.create(Namespace.prototype)).constructor = Root).className = "Root";
5205
5206var Field   = require(16),
5207    Enum    = require(15),
5208    OneOf   = require(25),
5209    util    = require(37);
5210
5211var Type,   // cyclic
5212    parse,  // might be excluded
5213    common; // "
5214
5215/**
5216 * Constructs a new root namespace instance.
5217 * @classdesc Root namespace wrapping all types, enums, services, sub-namespaces etc. that belong together.
5218 * @extends NamespaceBase
5219 * @constructor
5220 * @param {Object.<string,*>} [options] Top level options
5221 */
5222function Root(options) {
5223    Namespace.call(this, "", options);
5224
5225    /**
5226     * Deferred extension fields.
5227     * @type {Field[]}
5228     */
5229    this.deferred = [];
5230
5231    /**
5232     * Resolved file names of loaded files.
5233     * @type {string[]}
5234     */
5235    this.files = [];
5236}
5237
5238/**
5239 * Loads a namespace descriptor into a root namespace.
5240 * @param {INamespace} json Nameespace descriptor
5241 * @param {Root} [root] Root namespace, defaults to create a new one if omitted
5242 * @returns {Root} Root namespace
5243 */
5244Root.fromJSON = function fromJSON(json, root) {
5245    if (!root)
5246        root = new Root();
5247    if (json.options)
5248        root.setOptions(json.options);
5249    return root.addJSON(json.nested);
5250};
5251
5252/**
5253 * Resolves the path of an imported file, relative to the importing origin.
5254 * This method exists so you can override it with your own logic in case your imports are scattered over multiple directories.
5255 * @function
5256 * @param {string} origin The file name of the importing file
5257 * @param {string} target The file name being imported
5258 * @returns {string|null} Resolved path to `target` or `null` to skip the file
5259 */
5260Root.prototype.resolvePath = util.path.resolve;
5261
5262// A symbol-like function to safely signal synchronous loading
5263/* istanbul ignore next */
5264function SYNC() {} // eslint-disable-line no-empty-function
5265
5266/**
5267 * Loads one or multiple .proto or preprocessed .json files into this root namespace and calls the callback.
5268 * @param {string|string[]} filename Names of one or multiple files to load
5269 * @param {IParseOptions} options Parse options
5270 * @param {LoadCallback} callback Callback function
5271 * @returns {undefined}
5272 */
5273Root.prototype.load = function load(filename, options, callback) {
5274    if (typeof options === "function") {
5275        callback = options;
5276        options = undefined;
5277    }
5278    var self = this;
5279    if (!callback)
5280        return util.asPromise(load, self, filename, options);
5281
5282    var sync = callback === SYNC; // undocumented
5283
5284    // Finishes loading by calling the callback (exactly once)
5285    function finish(err, root) {
5286        /* istanbul ignore if */
5287        if (!callback)
5288            return;
5289        var cb = callback;
5290        callback = null;
5291        if (sync)
5292            throw err;
5293        cb(err, root);
5294    }
5295
5296    // Processes a single file
5297    function process(filename, source) {
5298        try {
5299            if (util.isString(source) && source.charAt(0) === "{")
5300                source = JSON.parse(source);
5301            if (!util.isString(source))
5302                self.setOptions(source.options).addJSON(source.nested);
5303            else {
5304                parse.filename = filename;
5305                var parsed = parse(source, self, options),
5306                    resolved,
5307                    i = 0;
5308                if (parsed.imports)
5309                    for (; i < parsed.imports.length; ++i)
5310                        if (resolved = self.resolvePath(filename, parsed.imports[i]))
5311                            fetch(resolved);
5312                if (parsed.weakImports)
5313                    for (i = 0; i < parsed.weakImports.length; ++i)
5314                        if (resolved = self.resolvePath(filename, parsed.weakImports[i]))
5315                            fetch(resolved, true);
5316            }
5317        } catch (err) {
5318            finish(err);
5319        }
5320        if (!sync && !queued)
5321            finish(null, self); // only once anyway
5322    }
5323
5324    // Fetches a single file
5325    function fetch(filename, weak) {
5326
5327        // Strip path if this file references a bundled definition
5328        var idx = filename.lastIndexOf("google/protobuf/");
5329        if (idx > -1) {
5330            var altname = filename.substring(idx);
5331            if (altname in common)
5332                filename = altname;
5333        }
5334
5335        // Skip if already loaded / attempted
5336        if (self.files.indexOf(filename) > -1)
5337            return;
5338        self.files.push(filename);
5339
5340        // Shortcut bundled definitions
5341        if (filename in common) {
5342            if (sync)
5343                process(filename, common[filename]);
5344            else {
5345                ++queued;
5346                setTimeout(function() {
5347                    --queued;
5348                    process(filename, common[filename]);
5349                });
5350            }
5351            return;
5352        }
5353
5354        // Otherwise fetch from disk or network
5355        if (sync) {
5356            var source;
5357            try {
5358                source = util.fs.readFileSync(filename).toString("utf8");
5359            } catch (err) {
5360                if (!weak)
5361                    finish(err);
5362                return;
5363            }
5364            process(filename, source);
5365        } else {
5366            ++queued;
5367            util.fetch(filename, function(err, source) {
5368                --queued;
5369                /* istanbul ignore if */
5370                if (!callback)
5371                    return; // terminated meanwhile
5372                if (err) {
5373                    /* istanbul ignore else */
5374                    if (!weak)
5375                        finish(err);
5376                    else if (!queued) // can't be covered reliably
5377                        finish(null, self);
5378                    return;
5379                }
5380                process(filename, source);
5381            });
5382        }
5383    }
5384    var queued = 0;
5385
5386    // Assembling the root namespace doesn't require working type
5387    // references anymore, so we can load everything in parallel
5388    if (util.isString(filename))
5389        filename = [ filename ];
5390    for (var i = 0, resolved; i < filename.length; ++i)
5391        if (resolved = self.resolvePath("", filename[i]))
5392            fetch(resolved);
5393
5394    if (sync)
5395        return self;
5396    if (!queued)
5397        finish(null, self);
5398    return undefined;
5399};
5400// function load(filename:string, options:IParseOptions, callback:LoadCallback):undefined
5401
5402/**
5403 * Loads one or multiple .proto or preprocessed .json files into this root namespace and calls the callback.
5404 * @function Root#load
5405 * @param {string|string[]} filename Names of one or multiple files to load
5406 * @param {LoadCallback} callback Callback function
5407 * @returns {undefined}
5408 * @variation 2
5409 */
5410// function load(filename:string, callback:LoadCallback):undefined
5411
5412/**
5413 * Loads one or multiple .proto or preprocessed .json files into this root namespace and returns a promise.
5414 * @function Root#load
5415 * @param {string|string[]} filename Names of one or multiple files to load
5416 * @param {IParseOptions} [options] Parse options. Defaults to {@link parse.defaults} when omitted.
5417 * @returns {Promise<Root>} Promise
5418 * @variation 3
5419 */
5420// function load(filename:string, [options:IParseOptions]):Promise<Root>
5421
5422/**
5423 * Synchronously loads one or multiple .proto or preprocessed .json files into this root namespace (node only).
5424 * @function Root#loadSync
5425 * @param {string|string[]} filename Names of one or multiple files to load
5426 * @param {IParseOptions} [options] Parse options. Defaults to {@link parse.defaults} when omitted.
5427 * @returns {Root} Root namespace
5428 * @throws {Error} If synchronous fetching is not supported (i.e. in browsers) or if a file's syntax is invali
vendor: 11,292 bytes, lines 5428-5746
5428d
5429 */
5430Root.prototype.loadSync = function loadSync(filename, options) {
5431    if (!util.isNode)
5432        throw Error("not supported");
5433    return this.load(filename, options, SYNC);
5434};
5435
5436/**
5437 * @override
5438 */
5439Root.prototype.resolveAll = function resolveAll() {
5440    if (this.deferred.length)
5441        throw Error("unresolvable extensions: " + this.deferred.map(function(field) {
5442            return "'extend " + field.extend + "' in " + field.parent.fullName;
5443        }).join(", "));
5444    return Namespace.prototype.resolveAll.call(this);
5445};
5446
5447// only uppercased (and thus conflict-free) children are exposed, see below
5448var exposeRe = /^[A-Z]/;
5449
5450/**
5451 * Handles a deferred declaring extension field by creating a sister field to represent it within its extended type.
5452 * @param {Root} root Root instance
5453 * @param {Field} field Declaring extension field witin the declaring type
5454 * @returns {boolean} `true` if successfully added to the extended type, `false` otherwise
5455 * @inner
5456 * @ignore
5457 */
5458function tryHandleExtension(root, field) {
5459    var extendedType = field.parent.lookup(field.extend);
5460    if (extendedType) {
5461        var sisterField = new Field(field.fullName, field.id, field.type, field.rule, undefined, field.options);
5462        sisterField.declaringField = field;
5463        field.extensionField = sisterField;
5464        extendedType.add(sisterField);
5465        return true;
5466    }
5467    return false;
5468}
5469
5470/**
5471 * Called when any object is added to this root or its sub-namespaces.
5472 * @param {ReflectionObject} object Object added
5473 * @returns {undefined}
5474 * @private
5475 */
5476Root.prototype._handleAdd = function _handleAdd(object) {
5477    if (object instanceof Field) {
5478
5479        if (/* an extension field (implies not part of a oneof) */ object.extend !== undefined && /* not already handled */ !object.extensionField)
5480            if (!tryHandleExtension(this, object))
5481                this.deferred.push(object);
5482
5483    } else if (object instanceof Enum) {
5484
5485        if (exposeRe.test(object.name))
5486            object.parent[object.name] = object.values; // expose enum values as property of its parent
5487
5488    } else if (!(object instanceof OneOf)) /* everything else is a namespace */ {
5489
5490        if (object instanceof Type) // Try to handle any deferred extensions
5491            for (var i = 0; i < this.deferred.length;)
5492                if (tryHandleExtension(this, this.deferred[i]))
5493                    this.deferred.splice(i, 1);
5494                else
5495                    ++i;
5496        for (var j = 0; j < /* initializes */ object.nestedArray.length; ++j) // recurse into the namespace
5497            this._handleAdd(object._nestedArray[j]);
5498        if (exposeRe.test(object.name))
5499            object.parent[object.name] = object; // expose namespace as property of its parent
5500    }
5501
5502    // The above also adds uppercased (and thus conflict-free) nested types, services and enums as
5503    // properties of namespaces just like static code does. This allows using a .d.ts generated for
5504    // a static module with reflection-based solutions where the condition is met.
5505};
5506
5507/**
5508 * Called when any object is removed from this root or its sub-namespaces.
5509 * @param {ReflectionObject} object Object removed
5510 * @returns {undefined}
5511 * @private
5512 */
5513Root.prototype._handleRemove = function _handleRemove(object) {
5514    if (object instanceof Field) {
5515
5516        if (/* an extension field */ object.extend !== undefined) {
5517            if (/* already handled */ object.extensionField) { // remove its sister field
5518                object.extensionField.parent.remove(object.extensionField);
5519                object.extensionField = null;
5520            } else { // cancel the extension
5521                var index = this.deferred.indexOf(object);
5522                /* istanbul ignore else */
5523                if (index > -1)
5524                    this.deferred.splice(index, 1);
5525            }
5526        }
5527
5528    } else if (object instanceof Enum) {
5529
5530        if (exposeRe.test(object.name))
5531            delete object.parent[object.name]; // unexpose enum values
5532
5533    } else if (object instanceof Namespace) {
5534
5535        for (var i = 0; i < /* initializes */ object.nestedArray.length; ++i) // recurse into the namespace
5536            this._handleRemove(object._nestedArray[i]);
5537
5538        if (exposeRe.test(object.name))
5539            delete object.parent[object.name]; // unexpose namespaces
5540
5541    }
5542};
5543
5544Root._configure = function(Type_, parse_, common_) {
5545    Type = Type_;
5546    parse = parse_;
5547    common = common_;
5548};
5549
5550},{"15":15,"16":16,"23":23,"25":25,"37":37}],30:[function(require,module,exports){
5551"use strict";
5552module.exports = {};
5553
5554/**
5555 * Named roots.
5556 * This is where pbjs stores generated structures (the option `-r, --root` specifies a name).
5557 * Can also be used manually to make roots available accross modules.
5558 * @name roots
5559 * @type {Object.<string,Root>}
5560 * @example
5561 * // pbjs -r myroot -o compiled.js ...
5562 *
5563 * // in another module:
5564 * require("./compiled.js");
5565 *
5566 * // in any subsequent module:
5567 * var root = protobuf.roots["myroot"];
5568 */
5569
5570},{}],31:[function(require,module,exports){
5571"use strict";
5572
5573/**
5574 * Streaming RPC helpers.
5575 * @namespace
5576 */
5577var rpc = exports;
5578
5579/**
5580 * RPC implementation passed to {@link Service#create} performing a service request on network level, i.e. by utilizing http requests or websockets.
5581 * @typedef RPCImpl
5582 * @type {function}
5583 * @param {Method|rpc.ServiceMethod<Message<{}>,Message<{}>>} method Reflected or static method being called
5584 * @param {Uint8Array} requestData Request data
5585 * @param {RPCImplCallback} callback Callback function
5586 * @returns {undefined}
5587 * @example
5588 * function rpcImpl(method, requestData, callback) {
5589 *     if (protobuf.util.lcFirst(method.name) !== "myMethod") // compatible with static code
5590 *         throw Error("no such method");
5591 *     asynchronouslyObtainAResponse(requestData, function(err, responseData) {
5592 *         callback(err, responseData);
5593 *     });
5594 * }
5595 */
5596
5597/**
5598 * Node-style callback as used by {@link RPCImpl}.
5599 * @typedef RPCImplCallback
5600 * @type {function}
5601 * @param {Error|null} error Error, if any, otherwise `null`
5602 * @param {Uint8Array|null} [response] Response data or `null` to signal end of stream, if there hasn't been an error
5603 * @returns {undefined}
5604 */
5605
5606rpc.Service = require(32);
5607
5608},{"32":32}],32:[function(require,module,exports){
5609"use strict";
5610module.exports = Service;
5611
5612var util = require(39);
5613
5614// Extends EventEmitter
5615(Service.prototype = Object.create(util.EventEmitter.prototype)).constructor = Service;
5616
5617/**
5618 * A service method callback as used by {@link rpc.ServiceMethod|ServiceMethod}.
5619 *
5620 * Differs from {@link RPCImplCallback} in that it is an actual callback of a service method which may not return `response = null`.
5621 * @typedef rpc.ServiceMethodCallback
5622 * @template TRes extends Message<TRes>
5623 * @type {function}
5624 * @param {Error|null} error Error, if any
5625 * @param {TRes} [response] Response message
5626 * @returns {undefined}
5627 */
5628
5629/**
5630 * A service method part of a {@link rpc.Service} as created by {@link Service.create}.
5631 * @typedef rpc.ServiceMethod
5632 * @template TReq extends Message<TReq>
5633 * @template TRes extends Message<TRes>
5634 * @type {function}
5635 * @param {TReq|Properties<TReq>} request Request message or plain object
5636 * @param {rpc.ServiceMethodCallback<TRes>} [callback] Node-style callback called with the error, if any, and the response message
5637 * @returns {Promise<Message<TRes>>} Promise if `callback` has been omitted, otherwise `undefined`
5638 */
5639
5640/**
5641 * Constructs a new RPC service instance.
5642 * @classdesc An RPC service as returned by {@link Service#create}.
5643 * @exports rpc.Service
5644 * @extends util.EventEmitter
5645 * @constructor
5646 * @param {RPCImpl} rpcImpl RPC implementation
5647 * @param {boolean} [requestDelimited=false] Whether requests are length-delimited
5648 * @param {boolean} [responseDelimited=false] Whether responses are length-delimited
5649 */
5650function Service(rpcImpl, requestDelimited, responseDelimited) {
5651
5652    if (typeof rpcImpl !== "function")
5653        throw TypeError("rpcImpl must be a function");
5654
5655    util.EventEmitter.call(this);
5656
5657    /**
5658     * RPC implementation. Becomes `null` once the service is ended.
5659     * @type {RPCImpl|null}
5660     */
5661    this.rpcImpl = rpcImpl;
5662
5663    /**
5664     * Whether requests are length-delimited.
5665     * @type {boolean}
5666     */
5667    this.requestDelimited = Boolean(requestDelimited);
5668
5669    /**
5670     * Whether responses are length-delimited.
5671     * @type {boolean}
5672     */
5673    this.responseDelimited = Boolean(responseDelimited);
5674}
5675
5676/**
5677 * Calls a service method through {@link rpc.Service#rpcImpl|rpcImpl}.
5678 * @param {Method|rpc.ServiceMethod<TReq,TRes>} method Reflected or static method
5679 * @param {Constructor<TReq>} requestCtor Request constructor
5680 * @param {Constructor<TRes>} responseCtor Response constructor
5681 * @param {TReq|Properties<TReq>} request Request message or plain object
5682 * @param {rpc.ServiceMethodCallback<TRes>} callback Service callback
5683 * @returns {undefined}
5684 * @template TReq extends Message<TReq>
5685 * @template TRes extends Message<TRes>
5686 */
5687Service.prototype.rpcCall = function rpcCall(method, requestCtor, responseCtor, request, callback) {
5688
5689    if (!request)
5690        throw TypeError("request must be specified");
5691
5692    var self = this;
5693    if (!callback)
5694        return util.asPromise(rpcCall, self, method, requestCtor, responseCtor, request);
5695
5696    if (!self.rpcImpl) {
5697        setTimeout(function() { callback(Error("already ended")); }, 0);
5698        return undefined;
5699    }
5700
5701    try {
5702        return self.rpcImpl(
5703            method,
5704            requestCtor[self.requestDelimited ? "encodeDelimited" : "encode"](request).finish(),
5705            function rpcCallback(err, response) {
5706
5707                if (err) {
5708                    self.emit("error", err, method);
5709                    return callback(err);
5710                }
5711
5712                if (response === null) {
5713                    self.end(/* endedByRPC */ true);
5714                    return undefined;
5715                }
5716
5717                if (!(response instanceof responseCtor)) {
5718                    try {
5719                        response = responseCtor[self.responseDelimited ? "decodeDelimited" : "decode"](response);
5720                    } catch (err) {
5721                        self.emit("error", err, method);
5722                        return callback(err);
5723                    }
5724                }
5725
5726                self.emit("data", response, method);
5727                return callback(null, response);
5728            }
5729        );
5730    } catch (err) {
5731        self.emit("error", err, method);
5732        setTimeout(function() { callback(err); }, 0);
5733        return undefined;
5734    }
5735};
5736
5737/**
5738 * Ends this service and emits the `end` event.
5739 * @param {boolean} [endedByRPC=false] Whether the service has been ended by the RPC implementation.
5740 * @returns {rpc.Service} `this`
5741 */
5742Service.prototype.end = function end(endedByRPC) {
5743    if (this.rpcImpl) {
5744        if (!endedByRPC) // signal end to rpcImpl
5745            this.rpcImpl(null, null, null);
5746        this.rpcImpl = null;
vendor: 5,908 bytes, lines 5747-5940
5747        this.emit("end").off();
5748    }
5749    return this;
5750};
5751
5752},{"39":39}],33:[function(require,module,exports){
5753"use strict";
5754module.exports = Service;
5755
5756// extends Namespace
5757var Namespace = require(23);
5758((Service.prototype = Object.create(Namespace.prototype)).constructor = Service).className = "Service";
5759
5760var Method = require(22),
5761    util   = require(37),
5762    rpc    = require(31);
5763
5764/**
5765 * Constructs a new service instance.
5766 * @classdesc Reflected service.
5767 * @extends NamespaceBase
5768 * @constructor
5769 * @param {string} name Service name
5770 * @param {Object.<string,*>} [options] Service options
5771 * @throws {TypeError} If arguments are invalid
5772 */
5773function Service(name, options) {
5774    Namespace.call(this, name, options);
5775
5776    /**
5777     * Service methods.
5778     * @type {Object.<string,Method>}
5779     */
5780    this.methods = {}; // toJSON, marker
5781
5782    /**
5783     * Cached methods as an array.
5784     * @type {Method[]|null}
5785     * @private
5786     */
5787    this._methodsArray = null;
5788}
5789
5790/**
5791 * Service descriptor.
5792 * @interface IService
5793 * @extends INamespace
5794 * @property {Object.<string,IMethod>} methods Method descriptors
5795 */
5796
5797/**
5798 * Constructs a service from a service descriptor.
5799 * @param {string} name Service name
5800 * @param {IService} json Service descriptor
5801 * @returns {Service} Created service
5802 * @throws {TypeError} If arguments are invalid
5803 */
5804Service.fromJSON = function fromJSON(name, json) {
5805    var service = new Service(name, json.options);
5806    /* istanbul ignore else */
5807    if (json.methods)
5808        for (var names = Object.keys(json.methods), i = 0; i < names.length; ++i)
5809            service.add(Method.fromJSON(names[i], json.methods[names[i]]));
5810    if (json.nested)
5811        service.addJSON(json.nested);
5812    service.comment = json.comment;
5813    return service;
5814};
5815
5816/**
5817 * Converts this service to a service descriptor.
5818 * @param {IToJSONOptions} [toJSONOptions] JSON conversion options
5819 * @returns {IService} Service descriptor
5820 */
5821Service.prototype.toJSON = function toJSON(toJSONOptions) {
5822    var inherited = Namespace.prototype.toJSON.call(this, toJSONOptions);
5823    var keepComments = toJSONOptions ? Boolean(toJSONOptions.keepComments) : false;
5824    return util.toObject([
5825        "options" , inherited && inherited.options || undefined,
5826        "methods" , Namespace.arrayToJSON(this.methodsArray, toJSONOptions) || /* istanbul ignore next */ {},
5827        "nested"  , inherited && inherited.nested || undefined,
5828        "comment" , keepComments ? this.comment : undefined
5829    ]);
5830};
5831
5832/**
5833 * Methods of this service as an array for iteration.
5834 * @name Service#methodsArray
5835 * @type {Method[]}
5836 * @readonly
5837 */
5838Object.defineProperty(Service.prototype, "methodsArray", {
5839    get: function() {
5840        return this._methodsArray || (this._methodsArray = util.toArray(this.methods));
5841    }
5842});
5843
5844function clearCache(service) {
5845    service._methodsArray = null;
5846    return service;
5847}
5848
5849/**
5850 * @override
5851 */
5852Service.prototype.get = function get(name) {
5853    return this.methods[name]
5854        || Namespace.prototype.get.call(this, name);
5855};
5856
5857/**
5858 * @override
5859 */
5860Service.prototype.resolveAll = function resolveAll() {
5861    var methods = this.methodsArray;
5862    for (var i = 0; i < methods.length; ++i)
5863        methods[i].resolve();
5864    return Namespace.prototype.resolve.call(this);
5865};
5866
5867/**
5868 * @override
5869 */
5870Service.prototype.add = function add(object) {
5871
5872    /* istanbul ignore if */
5873    if (this.get(object.name))
5874        throw Error("duplicate name '" + object.name + "' in " + this);
5875
5876    if (object instanceof Method) {
5877        this.methods[object.name] = object;
5878        object.parent = this;
5879        return clearCache(this);
5880    }
5881    return Namespace.prototype.add.call(this, object);
5882};
5883
5884/**
5885 * @override
5886 */
5887Service.prototype.remove = function remove(object) {
5888    if (object instanceof Method) {
5889
5890        /* istanbul ignore if */
5891        if (this.methods[object.name] !== object)
5892            throw Error(object + " is not a member of " + this);
5893
5894        delete this.methods[object.name];
5895        object.parent = null;
5896        return clearCache(this);
5897    }
5898    return Namespace.prototype.remove.call(this, object);
5899};
5900
5901/**
5902 * Creates a runtime service using the specified rpc implementation.
5903 * @param {RPCImpl} rpcImpl RPC implementation
5904 * @param {boolean} [requestDelimited=false] Whether requests are length-delimited
5905 * @param {boolean} [responseDelimited=false] Whether responses are length-delimited
5906 * @returns {rpc.Service} RPC service. Useful where requests and/or responses are streamed.
5907 */
5908Service.prototype.create = function create(rpcImpl, requestDelimited, responseDelimited) {
5909    var rpcService = new rpc.Service(rpcImpl, requestDelimited, responseDelimited);
5910    for (var i = 0, method; i < /* initializes */ this.methodsArray.length; ++i) {
5911        var methodName = util.lcFirst((method = this._methodsArray[i]).resolve().name).replace(/[^$\w_]/g, "");
5912        rpcService[methodName] = util.codegen(["r","c"], util.isReserved(methodName) ? methodName + "_" : methodName)("return this.rpcCall(m,q,s,r,c)")({
5913            m: method,
5914            q: method.resolvedRequestType.ctor,
5915            s: method.resolvedResponseType.ctor
5916        });
5917    }
5918    return rpcService;
5919};
5920
5921},{"22":22,"23":23,"31":31,"37":37}],34:[function(require,module,exports){
5922"use strict";
5923module.exports = tokenize;
5924
5925var delimRe        = /[\s{}=;:[\],'"()<>]/g,
5926    stringDoubleRe = /(?:"([^"\\]*(?:\\.[^"\\]*)*)")/g,
5927    stringSingleRe = /(?:'([^'\\]*(?:\\.[^'\\]*)*)')/g;
5928
5929var setCommentRe = /^ *[*/]+ */,
5930    setCommentAltRe = /^\s*\*?\/*/,
5931    setCommentSplitRe = /\n/g,
5932    whitespaceRe = /\s/,
5933    unescapeRe = /\\(.?)/g;
5934
5935var unescapeMap = {
5936    "0": "\0",
5937    "r": "\r",
5938    "n": "\n",
5939    "t": "\t"
5940};
5941
5942/**
5943 * Unescapes a string.
5944 * @param {string} str String to unescape
5945 * @returns {string} Unescaped string
5946 * @property {Object.<string,string>} map Special characters map
5947 * @memberof tokenize
5948 */
5949function unescape(str) {
5950    return str.replace(unescapeRe, function($0, $1) {
5951        switch ($1) {
5952            case "\\":
5953            case "":
5954                return $1;
5955            default:
5956                return unescapeMap[$1] || "";
5957        }
5958    });
5959}
5960
5961tokenize.unescape = unescape;
5962
5963/**
5964 * Gets the next token and advances.
5965 * @typedef TokenizerHandleNext
5966 * @type {function}
5967 * @returns {string|null} Next token or `null` on eof
5968 */
5969
5970/**
5971 * Peeks for the next token.
5972 * @typedef TokenizerHandlePeek
5973 * @type {function}
5974 * @returns {string|null} Next token or `null` on eof
5975 */
5976
5977/**
5978 * Pushes a token back to the stack.
5979 * @typedef TokenizerHandlePush
5980 * @type {function}
5981 * @param {string} token Token
5982 * @returns {undefined}
5983 */
5984
5985/**
5986 * Skips the next token.
5987 * @typedef TokenizerHandleSkip
5988 * @type {function}
5989 * @param {string} expected Expected token
5990 * @param {boolean} [optional=false] If optional
5991 * @returns {boolean} Whether the token matched
5992 * @throws {Error} If the token didn't match and is not optional
5993 */
5994
5995/**
5996 * Gets the comment on the previous line or, alternatively, the line comment on the specified line.
5997 * @typedef TokenizerHandleCmnt
5998 * @type {function}
5999 * @param {number} [line] Line number
6000 * @returns {string|null} Comment text or `null` if none
6001 */
6002
6003/**
6004 * Handle object returned from {@link tokenize}.
6005 * @interface ITokenizerHandle
6006 * @property {TokenizerHandleNext} next Gets the next token and advances (`null` on eof)
6007 * @property {TokenizerHandlePeek} peek Peeks for the next token (`null` on eof)
6008 * @property {TokenizerHandlePush} push Pushes a token back to the stack
6009 * @property {TokenizerHandleSkip} skip Skips a token, returns its presence and advances or, if non-optional and n
6009ot present, throws
6010 * @property {TokenizerHandleCmnt} cmnt Gets the comment on the previous line or the line comment on the specified line, if any
6011 * @property {number} line Current line number
6012 */
6013
6014/**
6015 * Tokenizes the given .proto source and returns an object with useful utility functions.
6016 * @param {string} source Source contents
6017 * @param {boolean} alternateCommentMode Whether we should activate alternate comment parsing mode.
6018 * @returns {ITokenizerHandle} Tokenizer handle
6019 */
6020function tokenize(source, alternateCommentMode) {
6021    /* eslint-disable callback-return */
6022    source = source.toString();
6023
6024    var offset = 0,
6025        length = source.length,
6026        line = 1,
6027        commentType = null,
6028        commentText = null,
6029        commentLine = 0,
6030        commentLineEmpty = false;
6031
6032    var stack = [];
6033
6034    var stringDelim = null;
6035
6036    /* istanbul ignore next */
6037    /**
6038     * Creates an error for illegal syntax.
6039     * @param {string} subject Subject
6040     * @returns {Error} Error created
6041     * @inner
6042     */
6043    function illegal(subject) {
6044        return Error("illegal " + subject + " (line " + line + ")");
6045    }
6046
6047    /**
6048     * Reads a string till its end.
6049     * @returns {string} String read
6050     * @inner
6051     */
6052    function readString() {
6053        var re = stringDelim === "'" ? stringSingleRe : stringDoubleRe;
6054        re.lastIndex = offset - 1;
6055        var match = re.exec(source);
6056        if (!match)
6057            throw illegal("string");
6058        offset = re.lastIndex;
6059        push(stringDelim);
6060        stringDelim = null;
6061        return unescape(match[1]);
6062    }
6063
6064    /**
6065     * Gets the character at `pos` within the source.
6066     * @param {number} pos Position
6067     * @returns {string} Character
6068     * @inner
6069     */
6070    function charAt(pos) {
6071        return source.charAt(pos);
6072    }
6073
6074    /**
6075     * Sets the current comment text.
6076     * @param {number} start Start offset
6077     * @param {number} end End offset
6078     * @returns {undefined}
6079     * @inner
6080     */
6081    function setComment(start, end) {
6082        commentType = source.charAt(start++);
6083        commentLine = line;
6084        commentLineEmpty = false;
6085        var lookback;
6086        if (alternateCommentMode) {
6087            lookback = 2;  // alternate comment parsing: "//" or "/*"
6088        } else {
6089            lookback = 3;  // "///" or "/**"
6090        }
6091        var commentOffset = start - lookback,
6092            c;
6093        do {
6094            if (--commentOffset < 0 ||
6095                    (c = source.charAt(commentOffset)) === "\n") {
6096                commentLineEmpty = true;
6097                break;
6098            }
6099        } while (c === " " || c === "\t");
6100        var lines = source
6101            .substring(start, end)
6102            .split(setCommentSplitRe);
6103        for (var i = 0; i < lines.length; ++i)
6104            lines[i] = lines[i]
6105                .replace(alternateCommentMode ? setCommentAltRe : setCommentRe, "")
6106                .trim();
6107        commentText = lines
6108            .join("\n")
6109            .trim();
6110    }
6111
6112    function isDoubleSlashCommentLine(startOffset) {
6113        var endOffset = findEndOfLine(startOffset);
6114
6115        // see if remaining line matches comment pattern
6116        var lineText = source.substring(startOffset, endOffset);
6117        // look for 1 or 2 slashes since startOffset would already point past
6118        // the first slash that started the comment.
6119        var isComment = /^\s*\/{1,2}/.test(lineText);
6120        return isComment;
6121    }
6122
6123    function findEndOfLine(cursor) {
6124        // find end of cursor's line
6125        var endOffset = cursor;
6126        while (endOffset < length && charAt(endOffset) !== "\n") {
6127            endOffset++;
6128        }
6129        return endOffset;
6130    }
6131
6132    /**
6133     * Obtains the next token.
6134     * @returns {string|null} Next token or `null` on eof
6135     * @inner
6136     */
6137    function next() {
6138        if (stack.length > 0)
6139            return stack.shift();
6140        if (stringDelim)
6141            return readString();
6142        var repeat,
6143            prev,
6144            curr,
6145            start,
6146            isDoc;
6147        do {
6148            if (offset === length)
6149                return null;
6150            repeat = false;
6151            while (whitespaceRe.test(curr = charAt(offset))) {
6152                if (curr === "\n")
6153                    ++line;
6154                if (++offset === length)
6155                    return null;
6156            }
6157
6158            if (charAt(offset) === "/") {
6159                if (++offset === length) {
6160                    throw illegal("comment");
6161                }
6162                if (charAt(offset) === "/") { // Line
6163                    if (!alternateCommentMode) {
6164                        // check for triple-slash comment
6165                        isDoc = charAt(start = offset + 1) === "/";
6166
6167                        while (charAt(++offset) !== "\n") {
6168                            if (offset === length) {
6169                                return null;
6170                            }
6171                        }
6172                        ++offset;
6173                        if (isDoc) {
6174                            setComment(start, offset - 1);
6175                        }
6176                        ++line;
6177                        repeat = true;
6178                    } else {
6179                        // check for double-slash comments, consolidating consecutive lines
6180                        start = offset;
6181                        isDoc = false;
6182                        if (isDoubleSlashCommentLine(offset)) {
6183                            isDoc = true;
6184                            do {
6185                                offset = findEndOfLine(offset);
6186                                if (offset === length) {
6187                                    break;
6188                                }
6189                                offset++;
6190                            } while (isDoubleSlashCommentLine(offset));
6191                        } else {
6192                            offset = Math.min(length, findEndOfLine(offset) + 1);
6193                        }
6194                        if (isDoc) {
6195                            setComment(start, offset);
6196                        }
6197                        line++;
6198                        repeat = true;
6199                    }
6200                } else if ((curr = charAt(offset)) === "*") { /* Block */
6201                    // check for /** (regular comment mode) or /* (alternate comment mode)
6202                    start = offset + 1;
6203                    isDoc = alternateCommentMode || charAt(start) === "*";
6204                    do {
6205                        if (curr === "\n") {
6206                            ++line;
6207                        }
6208                        if (++offset === length) {
6209                            throw illegal("comment");
6210                        }
6211                        prev = curr;
6212                        curr = charAt(offset);
6213                    } while (prev !== "*" || curr !== "/");
6214                    ++offset;
6215                    if (isDoc) {
6216                        setComment(start, offset - 2);
6217                    }
6218                    repeat = true;
6219                } else {
6220                    return "/";
6221                }
6222            }
6223        } while (repeat);
6224
6225        // offset !== length if we got here
6226
6227        var end = offset;
6228        delimRe.lastIndex = 0;
6229        var delim = delimRe.test(charAt(end++));
6230        if (!delim)
6231            while (end < length && !delimRe.test(charAt(end)))
6232                ++end;
6233        var token = source.substring(offset, offset = end);
6234        if (token === "\"" || token === "'")
6235            stringDelim = token;
6236        return token;
6237    }
6238
6239    /**
6240     * Pushes a token back to the stack.
6241     * @param {string} token Token
6242     * @returns {undefined}
6243     * @inner
6244     */
6245    function push(token) {
6246        stack.push(token);
6247    }
6248
6249    /**
6250     * Peeks for the next token.
6251     * @returns {string|null} Token or `null` on eof
6252     * @inner
6253     */
6254    function peek() {
6255        if (!stack.length) {
6256            var token = next();
6257            if (token === null)
6258                return null;
6259            push(token);
6260        }
6261        return stack[0];
6262    }
6263
6264    /**
6265     * Skips a token.
6266     * @param {string} expected Expected token
6267     * @param {boolean} [optional=false] Whether the token is optional
6268     * @returns {boolean} `true` when skipped, `false` if not
6269     * @throws {Error} When a required token is not present
6270     * @inner
6271     */
6272    function skip(expected, optional) {
6273        var actual = peek(),
6274            equals = actual === expected;
6275        if (equals) {
6276            next();
6277            return true;
6278        }
6279        if (!optional)
6280            throw illegal("token '" + actual + "', '" + expected + "' expected");
6281        return false;
6282    }
6283
6284    /**
6285     * Gets a comment.
6286     * @param {number} [trailingLine] Line number if looking for a trailing comment
6287     * @returns {string|null} Comment text
6288     * @inner
6289     */
6290    function cmnt(trailingLine) {
6291        var ret = null;
6292        if (trailingLine === undefined) {
6293            if (commentLine === line - 1 && (alternateCommentMode || commentType === "*" || commentLineEmpty)) {
6294                ret = commentText;
6295            }
6296        } else {
6297            /* istanbul ignore else */
6298            if (commentLine < trailingLine) {
6299                peek();
6300            }
6301            if (commentLine === trailingLine && !commentLineEmpty && (alternateCommentMode || commentType === "/")) {
6302                ret = commentText;
6303            }
6304        }
6305        return ret;
6306    }
6307
6308    return Object.defineProperty({
6309        next: next,
6310        peek: peek,
6311        push: push,
6312        skip: skip,
6313        cmnt: cmnt
6314    }, "line", {
6315        get: function() { return line; }
6316    });
6317    /* eslint-enable callback-return */
6318}
6319
6320},{}],35:[function(require,module,exports){
6321"use strict";
6322module.exports = Type;
6323
6324// extends Namespace
6325var Namespace = require(23);
6326((Type.prototype = Object.create(Namespace.prototype)).constructor = Type).className = "Type";
6327
6328var Enum      = require(15),
6329    OneOf     = require(25),
6330    Field     = require(16),
6331    MapField  = require(20),
6332    Service   = require(33),
6333    Message   = require(21),
6334    Reader    = require(27),
6335    Writer    = require(42),
6336    util      = require(37),
6337    encoder   = require(14),
6338    decoder   = require(13),
6339    verifier  = require(40),
6340    converter = require(12),
6341    wrappers  = require(41);
6342
6343/**
6344 * Constructs a new reflected message type instance.
6345 * @classdesc Reflected message type.
6346 * @extends NamespaceBase
6347 * @constructor
6348 * @param {string} name Message name
6349 * @param {Object.<string,*>} [options] Declared options
6350 */
6351function Type(name, options) {
6352    Namespace.call(this, name, options);
6353
6354    /**
6355     * Message fields.
6356     * @type {Object.<string,Field>}
6357     */
6358    this.fields = {};  // toJSON, marker
6359
6360    /**
6361     * Oneofs declared within this namespace, if any.
6362     * @type {Object.<string,OneOf>}
6363     */
6364    this.oneofs = undefined; // toJSON
6365
6366    /**
6367     * Extension ranges, if any.
6368     * @type {number[][]}
6369     */
6370    this.extensions = undefined; // toJSON
6371
6372    /**
6373     * Reserved ranges, if any.
6374     * @type {Array.<number[]|string>}
6375     */
6376    this.reserved = undefined; // toJSON
6377
6378    /*?
6379     * Whether this type is a legacy group.
6380     * @type {boolean|undefined}
6381     */
6382    this.group = undefined; // toJSON
6383
6384    /**
6385     * Cached fields by id.
6386     * @type {Object.<number,Field>|null}
6387     * @private
6388     */
6389    this._fieldsById = null;
6390
6391    /**
6392     * Cached fields as an array.
6393     * @type {Field[]|null}
6394     * @private
6395     */
6396    this._fieldsArray = null;
6397
6398    /**
6399     * Cached oneofs as an array.
6400     * @type {OneOf[]|null}
6401     * @private
6402     */
6403    this._oneofsArray = null;
6404
6405    /**
6406     * Cached constructor.
6407     * @type {Constructor<{}>}
6408     * @private
6409     */
6410    this._ctor = null;
6411}
6412
6413Object.defineProperties(Type.prototype, {
6414
6415    /**
6416     * Message fields by id.
6417     * @name Type#fieldsById
6418     * @type {Object.<number,Field>}
6419     * @readonly
6420     */
6421    fieldsById: {
6422        get: function() {
6423
6424            /* istanbul ignore if */
6425            if (this._fieldsById)
6426                return this._fieldsById;
6427
6428            this._fieldsById = {};
6429            for (var names = Object.keys(this.fields), i = 0; i < names.length; ++i) {
6430                var field = this.fields[names[i]],
6431                    id = field.id;
6432
6433                /* istanbul ignore if */
6434                if (this._fieldsById[id])
6435                    throw Error("duplicate id " + id + " in " + this);
6436
6437                this._fieldsById[id] = field;
6438            }
6439            return this._fieldsById;
6440        }
6441    },
6442
6443    /**
6444     * Fields of this message as an array for iteration.
6445     * @name Type#fieldsArray
6446     * @type {Field[]}
6447     * @readonly
6448     */
6449    fieldsArray: {
6450        get: function() {
6451            return this._fieldsArray || (this._fieldsArray = util.toArray(this.fields));
6452        }
6453    },
6454
6455    /**
6456     * Oneofs of this message as an array for iteration.
6457     * @name Type#oneofsArray
6458     * @type {OneOf[]}
6459     * @readonly
6460     */
6461    oneofsArray: {
6462        get: function() {
6463            return this._oneofsArray || (this._oneofsArray = util.toArray(this.oneofs));
6464        }
6465    },
6466
6467    /**
6468     * The registered constructor, if any registered, otherwise a generic constructor.
6469     * Assigning a function replaces the internal constructor. If the function does not extend {@link Message} yet, its prototype will be setup accordingly and static methods will be populated. If it already extends {@link Message}, it will just replace the internal constructor.
6470     * @name Type#ctor
6471     * @type {Constructor<{}>}
6472     */
6473    ctor: {
6474        get: function() {
6475            return this._ctor || (this.ctor = Type.generateConstructor(this)());
6476        },
6477        set: function(ctor) {
6478
6479            // Ensure proper prototype
6480            var prototype = ctor.prototype;
6481            if (!(prototype instanceof Message)) {
6482                (ctor.prototype = new Message()).constructor = ctor;
6483                util.merge(ctor.prototype, prototype);
6484            }
6485
6486            // Classes and messages reference their reflected type
6487            ctor.$type = ctor.prototype.$type = this;
6488
6489            // Mix in static methods
6490            util.merge(ctor, Message, true);
6491
6492            this._ctor = ctor;
6493
6494            // Messages have non-enumerable default values on their prototype
6495            var i = 0;
6496            for (; i < /* initializes */ this.fieldsArray.length; ++i)
6497                this._fieldsArray[i].resolve(); // ensures a proper value
6498
6499            // Messages have non-enumerable getters and setters for each virtual oneof field
6500            var ctorProperties = {};
6501            for (i = 0; i < /* initializes */ this.oneofsArray.length; ++i)
6502                ctorProperties[this._oneofsArray[i].resolve().name] = {
6503                    get: util.oneOfGetter(this._oneofsArray[i].oneof),
6504                    set: util.oneOfSetter(this._oneofsArray[i].oneof)
6505                };
6506            if (i)
6507                Object.defineProperties(ctor.prototype, ctorProperties);
6508        }
6509    }
6510});
6511
6512/**
6513 * Generates a constructor function for the specified type.
6514 * @param {Type} mtype Message type
6515 * @returns {Codegen} Codegen instance
6516 */
6517Type.generateConstructor = function generateConstructor(mtype) {
6518    /* eslint-disable no-unexpected-multiline */
6519    var gen = util.codegen(["p"], mtype.name);
6520    // explicitly initialize mutable object/array fields so that these aren't just inherited from the prototype
6521    for (var i = 0, field; i < mtype.fieldsArray.length; ++i)
6522        if ((field = mtype._fieldsArray[i]).map) gen
6523            ("this%s={}", util.safeProp(field.name));
6524        else if (field.repeated) gen
6525            ("this%s=[]", util.safeProp(field.name));
6526    return gen
6527    ("if(p)for(var ks=Object.keys(p),i=0;i<ks.length;++i)if(p[ks[i]]!=null)") // omit undefined or null
6528        ("this[ks[i]]=p[ks[i]]");
6529    /* eslint-enable no-unexpected-multiline */
6530};
6531
6532function clearCache(type) {
6533    type._fieldsById = type._fieldsArray = type._oneofsArray = null;
6534    delete type.encode;
6535    delete type.decode;
6536    delete type.verify;
6537    return type;
6538}
6539
6540/**
6541 * Message type descriptor.
6542 * @interface IType
6543 * @extends INamespace
6544 * @property {Object.<string,IOneOf>} [oneofs] Oneof descriptors
6545 * @property {Object.<string,IField>} fields Field descriptors
6546 * @property {number[][]} [extensions] Extension ranges
6547 * @property {number[][]} [reserved] Reserved ranges
6548 * @property {boolean} [group=false] Whether a legacy group or not
6549 */
6550
6551/**
6552 * Creates a message type from a message type descriptor.
6553 * @param {string} name Message name
6554 * @param {IType} json Message type descriptor
6555 * @returns {Type} Created message type
6556 */
6557Type.fromJSON = function fromJSON(name, json) {
6558    var type = new Type(name, json.options);
6559    type.extensions = json.extensions;
6560    type.reserved = json.reserved;
6561    var names = Object.keys(json.fields),
6562        i = 0;
6563    for (; i < names.length; ++i)
6564        type.add(
6565            ( typeof json.fields[names[i]].keyType !== "undefined"
6566            ? MapField.fromJSON
6567            : Field.fromJSON )(names[i], json.fields[names[i]])
6568        );
6569    if (json.oneofs)
6570        for (names = Object.keys(json.oneofs), i = 0; i < names.length; ++i)
6571            type.add(OneOf.fromJSON(names[i], json.oneofs[names[i]]));
6572    if (json.nested)
6573        for (names = Object.keys(json.nested), i = 0; i < names.length; ++i) {
6574            var nested = json.nested[names[i]];
6575            type.add( // most to least likely
6576                ( nested.id !== undefined
6577                ? Field.fromJSON
6578                : nested.fields !== undefined
6579                ? Type.fromJSON
6580                : nested.values !== undefined
6581                ? Enum.fromJSON
6582                : nested.methods !== undefined
6583                ? Service.fromJSON
6584                : Namespace.fromJSON )(names[i], nested)
6585            );
6586        }
6587    if (json.extensions && json.extensions.length)
6588        type.extensions = json.extensions;
6589    if (json.reserved && json.reserved.length)
6590        type.reserved = json.reserved;
6591    if (json.group)
6592        type.group = true;
6593    if (json.comment)
6594        type.comment = json.comment;
6595    return type;
6596};
6597
6598/**
6599 * Converts this message type to a message type descriptor.
6600 * @param {IToJSONOptions} [toJSONOptions] JSON conversion options
6601 * @returns {IType} Message type descriptor
6602 */
6603Type.prototype.toJSON = function toJSON(toJSONOptions) {
6604    var inherited = Namespace.prototype.toJSON.call(this, toJSONOptions);
6605    var keepComments = toJSONOptions ? Boolean(toJSONOptions.keepComments) : false;
6606    return util.toObject([
6607        "options"    , inherited && inherited.options || undefined,
6608        "oneofs"     , Namespace.arrayToJSON(this.oneofsArray, toJSONOptions),
6609        "fields"     , Namespace.arrayToJSON(this.fieldsArray.filter(function(obj) { return !obj.declaringField; }), toJSONOptions) || {},
6610        "extensions" , this.extensions && this.extensions.length ? this.extensions : undefined,
6611        "reserved"   , this.reserved && this.reserved.length ? this.reserved : undefined,
6612        "group"      , this.group || undefined,
6613        "nested"     , inherited && inherited.nested || undefined,
6614        "comment"    , keepComments ? this.comment : undefined
6615    ]);
6616};
6617
6618/**
6619 * @override
6620 */
6621Type.prototype.resolveAll = function resolveAll() {
6622    var fields = this.fieldsArray, i = 0;
6623    while (i < fields.length)
6624        fields[i++].resolve();
6625    var oneofs = this.oneofsArray; i = 0;
6626    while (i < oneofs.length)
6627        oneofs[i++].resolve();
6628    return Namespace.prototype.resolveAll.call(this);
6629};
6630
6631/**
6632 * @override
6633 */
6634Type.prototype.get = function get(name) {
6635    return this.fields[name]
6636        || this.oneofs && this.oneofs[name]
6637        || this.nested && this.nested[name]
6638        || null;
6639};
6640
6641/**
6642 * Adds a nested object to this type.
6643 * @param {ReflectionObject} object Nested object to add
6644 * @returns {Type} `this`
6645 * @throws {TypeError} If arguments are invalid
6646 * @throws {Error} If there is already a nested object with this name or, if a field, when there is already a field with this id
6647 */
6648Type.prototype.add = function add(object) {
6649
6650    if (this.get(object.name))
6651        throw Error("duplicate name '" + object.name + "' in " + this);
6652
6653    if (object instanceof Field && object.extend === undefined) {
6654        // NOTE: Extension fields aren't actual fields on the declaring type, but nested objects.
6655        // The root object takes care of adding distinct sister-fields to the respective extended
6656        // type instead.
6657
6658        // avoids calling the getter if not absolutely necessary because it's called quite frequently
6659        if (this._fieldsById ? /* istanbul ignore next */ this._fieldsById[object.id] : this.fieldsById[object.id])
6660            throw Error("duplicate id " + object.id + " in " + this);
6661        if (this.isReservedId(object.id))
6662            throw Error("id " + object.id + " is reserved in " + this);
6663        if (this.isReservedName(object.name))
6664            throw Error("name '" + object.name + "' is reserved in " + this);
6665
6666        if (object.parent)
6667            object.parent.remove(object);
6668        this.fields[object.name] = object;
6669        object.message = this;
6670        object.onAdd(this);
6671        return clearCache(this);
6672    }
6673    if (object instanceof OneOf) {
6674        if (!this.oneofs)
6675            this.oneofs = {};
6676        this.oneofs[object.name] = object;
6677        object.onAdd(this);
6678        return clearCache(this);
6679    }
6680    return Namespace.prototype.add.call(this, object);
6681};
6682
6683/**
6684 * Removes a nested object from this type.
6685 * @param {ReflectionObject} object Nested object to remove
6686 * @returns {Type} `this`
6687 * @throws {TypeError} If arguments are invalid
6688 * @throws {Error} If `object` is not a member of this type
6689 */
6690Type.prototype.remove = function remove(object) {
6691    if (object instanceof Field && object.extend === undefined) {
6692        // See Type#add for the reason why extension fields are excluded here.
6693
6694        /* istanbul ignore if */
6695        if (!this.fields || this.fields[object.name] !== object)
6696            throw Error(object + " is not a member of " + this);
6697
6698        delete this.fields[object.name];
6699        object.parent = null;
6700        object.onRemove(this);
6701        return clearCache(this);
6702    }
6703    if (object instanceof OneOf) {
6704
6705        /* istanbul ignore if */
6706        if (!this.oneofs || this.oneofs[object.name] !== object)
6707            throw Error(object + " is not a member of " + this);
6708
6709        delete this.oneofs[object.name];
6710        object.parent = null;
6711        object.onRemove(this);
6712        return clearCache(this);
6713    }
6714    return Namespace.prototype.remove.call(this, object);
6715};
6716
6717/**
6718 * Tests if the specified id is reserved.
6719 * @param {number} id Id to test
6720 * @returns {boolean} `true` if reserved, otherwise `false`
6721 */
6722Type.prototype.isReservedId = function isReservedId(id) {
6723    return Namespace.isReservedId(this.reserved, id);
6724};
6725
6726/**
6727 * Tests if the specified name is reserved.
6728 * @param {string} name Name to test
6729 * @returns {boolean} `true` if reserved, otherwise `false`
6730 */
6731Type.prototype.isReservedName = function isReservedName(name) {
6732    return Namespace.isReservedName(this.reserved, name);
6733};
6734
6735/**
6736 * Creates a new message of this type using the specified properties.
6737 * @param {Object.<string,*>} [properties] Properties to set
6738 * @returns {Message<{}>} Message instance
6739 */
6740Type.prototype.create = function create(properties) {
6741    return new this.ctor(properties);
6742};
6743
6744/**
6745 * Sets up {@link Type#encode|encode}, {@link Type#decode|decode} and {@link Type#verify|verify}.
6746 * @returns {Type} `this`
6747 */
6748Type.prototype.setup = function setup() {
6749    // Sets up everything at once so that the prototype chain does not have to be re-evaluated
6750    // multiple times (V8, soft-deopt prototype-check).
6751
6752    var fullName = this.fullName,
6753        types    = [];
6754    for (var i = 0; i < /* initializes */ this.fieldsArray.length; ++i)
6755        types.push(this._fieldsArray[i].resolve().resolvedType);
6756
6757    // Replace setup methods with type-specific generated functions
6758    this.encode = encoder(this)({
6759        Writer : Writer,
6760        types  : types,
6761        util   : util
6762    });
vendor: 5,935 bytes, lines 6763-6909
6763    this.decode = decoder(this)({
6764        Reader : Reader,
6765        types  : types,
6766        util   : util
6767    });
6768    this.verify = verifier(this)({
6769        types : types,
6770        util  : util
6771    });
6772    this.fromObject = converter.fromObject(this)({
6773        types : types,
6774        util  : util
6775    });
6776    this.toObject = converter.toObject(this)({
6777        types : types,
6778        util  : util
6779    });
6780
6781    // Inject custom wrappers for common types
6782    var wrapper = wrappers[fullName];
6783    if (wrapper) {
6784        var originalThis = Object.create(this);
6785        // if (wrapper.fromObject) {
6786            originalThis.fromObject = this.fromObject;
6787            this.fromObject = wrapper.fromObject.bind(originalThis);
6788        // }
6789        // if (wrapper.toObject) {
6790            originalThis.toObject = this.toObject;
6791            this.toObject = wrapper.toObject.bind(originalThis);
6792        // }
6793    }
6794
6795    return this;
6796};
6797
6798/**
6799 * Encodes a message of this type. Does not implicitly {@link Type#verify|verify} messages.
6800 * @param {Message<{}>|Object.<string,*>} message Message instance or plain object
6801 * @param {Writer} [writer] Writer to encode to
6802 * @returns {Writer} writer
6803 */
6804Type.prototype.encode = function encode_setup(message, writer) {
6805    return this.setup().encode(message, writer); // overrides this method
6806};
6807
6808/**
6809 * Encodes a message of this type preceeded by its byte length as a varint. Does not implicitly {@link Type#verify|verify} messages.
6810 * @param {Message<{}>|Object.<string,*>} message Message instance or plain object
6811 * @param {Writer} [writer] Writer to encode to
6812 * @returns {Writer} writer
6813 */
6814Type.prototype.encodeDelimited = function encodeDelimited(message, writer) {
6815    return this.encode(message, writer && writer.len ? writer.fork() : writer).ldelim();
6816};
6817
6818/**
6819 * Decodes a message of this type.
6820 * @param {Reader|Uint8Array} reader Reader or buffer to decode from
6821 * @param {number} [length] Length of the message, if known beforehand
6822 * @returns {Message<{}>} Decoded message
6823 * @throws {Error} If the payload is not a reader or valid buffer
6824 * @throws {util.ProtocolError<{}>} If required fields are missing
6825 */
6826Type.prototype.decode = function decode_setup(reader, length) {
6827    return this.setup().decode(reader, length); // overrides this method
6828};
6829
6830/**
6831 * Decodes a message of this type preceeded by its byte length as a varint.
6832 * @param {Reader|Uint8Array} reader Reader or buffer to decode from
6833 * @returns {Message<{}>} Decoded message
6834 * @throws {Error} If the payload is not a reader or valid buffer
6835 * @throws {util.ProtocolError} If required fields are missing
6836 */
6837Type.prototype.decodeDelimited = function decodeDelimited(reader) {
6838    if (!(reader instanceof Reader))
6839        reader = Reader.create(reader);
6840    return this.decode(reader, reader.uint32());
6841};
6842
6843/**
6844 * Verifies that field values are valid and that required fields are present.
6845 * @param {Object.<string,*>} message Plain object to verify
6846 * @returns {null|string} `null` if valid, otherwise the reason why it is not
6847 */
6848Type.prototype.verify = function verify_setup(message) {
6849    return this.setup().verify(message); // overrides this method
6850};
6851
6852/**
6853 * Creates a new message of this type from a plain object. Also converts values to their respective internal types.
6854 * @param {Object.<string,*>} object Plain object to convert
6855 * @returns {Message<{}>} Message instance
6856 */
6857Type.prototype.fromObject = function fromObject(object) {
6858    return this.setup().fromObject(object);
6859};
6860
6861/**
6862 * Conversion options as used by {@link Type#toObject} and {@link Message.toObject}.
6863 * @interface IConversionOptions
6864 * @property {Function} [longs] Long conversion type.
6865 * Valid values are `String` and `Number` (the global types).
6866 * Defaults to copy the present value, which is a possibly unsafe number without and a {@link Long} with a long library.
6867 * @property {Function} [enums] Enum value conversion type.
6868 * Only valid value is `String` (the global type).
6869 * Defaults to copy the present value, which is the numeric id.
6870 * @property {Function} [bytes] Bytes value conversion type.
6871 * Valid values are `Array` and (a base64 encoded) `String` (the global types).
6872 * Defaults to copy the present value, which usually is a Buffer under node and an Uint8Array in the browser.
6873 * @property {boolean} [defaults=false] Also sets default values on the resulting object
6874 * @property {boolean} [arrays=false] Sets empty arrays for missing repeated fields even if `defaults=false`
6875 * @property {boolean} [objects=false] Sets empty objects for missing map fields even if `defaults=false`
6876 * @property {boolean} [oneofs=false] Includes virtual oneof properties set to the present field's name, if any
6877 * @property {boolean} [json=false] Performs additional JSON compatibility conversions, i.e. NaN and Infinity to strings
6878 */
6879
6880/**
6881 * Creates a plain object from a message of this type. Also converts values to other types if specified.
6882 * @param {Message<{}>} message Message instance
6883 * @param {IConversionOptions} [options] Conversion options
6884 * @returns {Object.<string,*>} Plain object
6885 */
6886Type.prototype.toObject = function toObject(message, options) {
6887    return this.setup().toObject(message, options);
6888};
6889
6890/**
6891 * Decorator function as returned by {@link Type.d} (TypeScript).
6892 * @typedef TypeDecorator
6893 * @type {function}
6894 * @param {Constructor<T>} target Target constructor
6895 * @returns {undefined}
6896 * @template T extends Message<T>
6897 */
6898
6899/**
6900 * Type decorator (TypeScript).
6901 * @param {string} [typeName] Type name, defaults to the constructor's name
6902 * @returns {TypeDecorator<T>} Decorator function
6903 * @template T extends Message<T>
6904 */
6905Type.d = function decorateType(typeName) {
6906    return function typeDecorator(target) {
6907        util.decorateType(target, typeName);
6908    };
6909};
vendor: 13,526 bytes, lines 6910-7380
6910
6911},{"12":12,"13":13,"14":14,"15":15,"16":16,"20":20,"21":21,"23":23,"25":25,"27":27,"33":33,"37":37,"40":40,"41":41,"42":42}],36:[function(require,module,exports){
6912"use strict";
6913
6914/**
6915 * Common type constants.
6916 * @namespace
6917 */
6918var types = exports;
6919
6920var util = require(37);
6921
6922var s = [
6923    "double",   // 0
6924    "float",    // 1
6925    "int32",    // 2
6926    "uint32",   // 3
6927    "sint32",   // 4
6928    "fixed32",  // 5
6929    "sfixed32", // 6
6930    "int64",    // 7
6931    "uint64",   // 8
6932    "sint64",   // 9
6933    "fixed64",  // 10
6934    "sfixed64", // 11
6935    "bool",     // 12
6936    "string",   // 13
6937    "bytes"     // 14
6938];
6939
6940function bake(values, offset) {
6941    var i = 0, o = {};
6942    offset |= 0;
6943    while (i < values.length) o[s[i + offset]] = values[i++];
6944    return o;
6945}
6946
6947/**
6948 * Basic type wire types.
6949 * @type {Object.<string,number>}
6950 * @const
6951 * @property {number} double=1 Fixed64 wire type
6952 * @property {number} float=5 Fixed32 wire type
6953 * @property {number} int32=0 Varint wire type
6954 * @property {number} uint32=0 Varint wire type
6955 * @property {number} sint32=0 Varint wire type
6956 * @property {number} fixed32=5 Fixed32 wire type
6957 * @property {number} sfixed32=5 Fixed32 wire type
6958 * @property {number} int64=0 Varint wire type
6959 * @property {number} uint64=0 Varint wire type
6960 * @property {number} sint64=0 Varint wire type
6961 * @property {number} fixed64=1 Fixed64 wire type
6962 * @property {number} sfixed64=1 Fixed64 wire type
6963 * @property {number} bool=0 Varint wire type
6964 * @property {number} string=2 Ldelim wire type
6965 * @property {number} bytes=2 Ldelim wire type
6966 */
6967types.basic = bake([
6968    /* double   */ 1,
6969    /* float    */ 5,
6970    /* int32    */ 0,
6971    /* uint32   */ 0,
6972    /* sint32   */ 0,
6973    /* fixed32  */ 5,
6974    /* sfixed32 */ 5,
6975    /* int64    */ 0,
6976    /* uint64   */ 0,
6977    /* sint64   */ 0,
6978    /* fixed64  */ 1,
6979    /* sfixed64 */ 1,
6980    /* bool     */ 0,
6981    /* string   */ 2,
6982    /* bytes    */ 2
6983]);
6984
6985/**
6986 * Basic type defaults.
6987 * @type {Object.<string,*>}
6988 * @const
6989 * @property {number} double=0 Double default
6990 * @property {number} float=0 Float default
6991 * @property {number} int32=0 Int32 default
6992 * @property {number} uint32=0 Uint32 default
6993 * @property {number} sint32=0 Sint32 default
6994 * @property {number} fixed32=0 Fixed32 default
6995 * @property {number} sfixed32=0 Sfixed32 default
6996 * @property {number} int64=0 Int64 default
6997 * @property {number} uint64=0 Uint64 default
6998 * @property {number} sint64=0 Sint32 default
6999 * @property {number} fixed64=0 Fixed64 default
7000 * @property {number} sfixed64=0 Sfixed64 default
7001 * @property {boolean} bool=false Bool default
7002 * @property {string} string="" String default
7003 * @property {Array.<number>} bytes=Array(0) Bytes default
7004 * @property {null} message=null Message default
7005 */
7006types.defaults = bake([
7007    /* double   */ 0,
7008    /* float    */ 0,
7009    /* int32    */ 0,
7010    /* uint32   */ 0,
7011    /* sint32   */ 0,
7012    /* fixed32  */ 0,
7013    /* sfixed32 */ 0,
7014    /* int64    */ 0,
7015    /* uint64   */ 0,
7016    /* sint64   */ 0,
7017    /* fixed64  */ 0,
7018    /* sfixed64 */ 0,
7019    /* bool     */ false,
7020    /* string   */ "",
7021    /* bytes    */ util.emptyArray,
7022    /* message  */ null
7023]);
7024
7025/**
7026 * Basic long type wire types.
7027 * @type {Object.<string,number>}
7028 * @const
7029 * @property {number} int64=0 Varint wire type
7030 * @property {number} uint64=0 Varint wire type
7031 * @property {number} sint64=0 Varint wire type
7032 * @property {number} fixed64=1 Fixed64 wire type
7033 * @property {number} sfixed64=1 Fixed64 wire type
7034 */
7035types.long = bake([
7036    /* int64    */ 0,
7037    /* uint64   */ 0,
7038    /* sint64   */ 0,
7039    /* fixed64  */ 1,
7040    /* sfixed64 */ 1
7041], 7);
7042
7043/**
7044 * Allowed types for map keys with their associated wire type.
7045 * @type {Object.<string,number>}
7046 * @const
7047 * @property {number} int32=0 Varint wire type
7048 * @property {number} uint32=0 Varint wire type
7049 * @property {number} sint32=0 Varint wire type
7050 * @property {number} fixed32=5 Fixed32 wire type
7051 * @property {number} sfixed32=5 Fixed32 wire type
7052 * @property {number} int64=0 Varint wire type
7053 * @property {number} uint64=0 Varint wire type
7054 * @property {number} sint64=0 Varint wire type
7055 * @property {number} fixed64=1 Fixed64 wire type
7056 * @property {number} sfixed64=1 Fixed64 wire type
7057 * @property {number} bool=0 Varint wire type
7058 * @property {number} string=2 Ldelim wire type
7059 */
7060types.mapKey = bake([
7061    /* int32    */ 0,
7062    /* uint32   */ 0,
7063    /* sint32   */ 0,
7064    /* fixed32  */ 5,
7065    /* sfixed32 */ 5,
7066    /* int64    */ 0,
7067    /* uint64   */ 0,
7068    /* sint64   */ 0,
7069    /* fixed64  */ 1,
7070    /* sfixed64 */ 1,
7071    /* bool     */ 0,
7072    /* string   */ 2
7073], 2);
7074
7075/**
7076 * Allowed types for packed repeated fields with their associated wire type.
7077 * @type {Object.<string,number>}
7078 * @const
7079 * @property {number} double=1 Fixed64 wire type
7080 * @property {number} float=5 Fixed32 wire type
7081 * @property {number} int32=0 Varint wire type
7082 * @property {number} uint32=0 Varint wire type
7083 * @property {number} sint32=0 Varint wire type
7084 * @property {number} fixed32=5 Fixed32 wire type
7085 * @property {number} sfixed32=5 Fixed32 wire type
7086 * @property {number} int64=0 Varint wire type
7087 * @property {number} uint64=0 Varint wire type
7088 * @property {number} sint64=0 Varint wire type
7089 * @property {number} fixed64=1 Fixed64 wire type
7090 * @property {number} sfixed64=1 Fixed64 wire type
7091 * @property {number} bool=0 Varint wire type
7092 */
7093types.packed = bake([
7094    /* double   */ 1,
7095    /* float    */ 5,
7096    /* int32    */ 0,
7097    /* uint32   */ 0,
7098    /* sint32   */ 0,
7099    /* fixed32  */ 5,
7100    /* sfixed32 */ 5,
7101    /* int64    */ 0,
7102    /* uint64   */ 0,
7103    /* sint64   */ 0,
7104    /* fixed64  */ 1,
7105    /* sfixed64 */ 1,
7106    /* bool     */ 0
7107]);
7108
7109},{"37":37}],37:[function(require,module,exports){
7110"use strict";
7111
7112/**
7113 * Various utility functions.
7114 * @namespace
7115 */
7116var util = module.exports = require(39);
7117
7118var roots = require(30);
7119
7120var Type, // cyclic
7121    Enum;
7122
7123util.codegen = require(3);
7124util.fetch   = require(5);
7125util.path    = require(8);
7126
7127/**
7128 * Node's fs module if available.
7129 * @type {Object.<string,*>}
7130 */
7131util.fs = util.inquire("fs");
7132
7133/**
7134 * Converts an object's values to an array.
7135 * @param {Object.<string,*>} object Object to convert
7136 * @returns {Array.<*>} Converted array
7137 */
7138util.toArray = function toArray(object) {
7139    if (object) {
7140        var keys  = Object.keys(object),
7141            array = new Array(keys.length),
7142            index = 0;
7143        while (index < keys.length)
7144            array[index] = object[keys[index++]];
7145        return array;
7146    }
7147    return [];
7148};
7149
7150/**
7151 * Converts an array of keys immediately followed by their respective value to an object, omitting undefined values.
7152 * @param {Array.<*>} array Array to convert
7153 * @returns {Object.<string,*>} Converted object
7154 */
7155util.toObject = function toObject(array) {
7156    var object = {},
7157        index  = 0;
7158    while (index < array.length) {
7159        var key = array[index++],
7160            val = array[index++];
7161        if (val !== undefined)
7162            object[key] = val;
7163    }
7164    return object;
7165};
7166
7167var safePropBackslashRe = /\\/g,
7168    safePropQuoteRe     = /"/g;
7169
7170/**
7171 * Tests whether the specified name is a reserved word in JS.
7172 * @param {string} name Name to test
7173 * @returns {boolean} `true` if reserved, otherwise `false`
7174 */
7175util.isReserved = function isReserved(name) {
7176    return /^(?:do|if|in|for|let|new|try|var|case|else|enum|eval|false|null|this|true|void|with|break|catch|class|const|super|throw|while|yield|delete|export|import|public|return|static|switch|typeof|default|extends|finally|package|private|continue|debugger|function|arguments|interface|protected|implements|instanceof)$/.test(name);
7177};
7178
7179/**
7180 * Returns a safe property accessor for the specified property name.
7181 * @param {string} prop Property name
7182 * @returns {string} Safe accessor
7183 */
7184util.safeProp = function safeProp(prop) {
7185    if (!/^[$\w_]+$/.test(prop) || util.isReserved(prop))
7186        return "[\"" + prop.replace(safePropBackslashRe, "\\\\").replace(safePropQuoteRe, "\\\"") + "\"]";
7187    return "." + prop;
7188};
7189
7190/**
7191 * Converts the first character of a string to upper case.
7192 * @param {string} str String to convert
7193 * @returns {string} Converted string
7194 */
7195util.ucFirst = function ucFirst(str) {
7196    return str.charAt(0).toUpperCase() + str.substring(1);
7197};
7198
7199var camelCaseRe = /_([a-z])/g;
7200
7201/**
7202 * Converts a string to camel case.
7203 * @param {string} str String to convert
7204 * @returns {string} Converted string
7205 */
7206util.camelCase = function camelCase(str) {
7207    return str.substring(0, 1)
7208         + str.substring(1)
7209               .replace(camelCaseRe, function($0, $1) { return $1.toUpperCase(); });
7210};
7211
7212/**
7213 * Compares reflected fields by id.
7214 * @param {Field} a First field
7215 * @param {Field} b Second field
7216 * @returns {number} Comparison value
7217 */
7218util.compareFieldsById = function compareFieldsById(a, b) {
7219    return a.id - b.id;
7220};
7221
7222/**
7223 * Decorator helper for types (TypeScript).
7224 * @param {Constructor<T>} ctor Constructor function
7225 * @param {string} [typeName] Type name, defaults to the constructor's name
7226 * @returns {Type} Reflected type
7227 * @template T extends Message<T>
7228 * @property {Root} root Decorators root
7229 */
7230util.decorateType = function decorateType(ctor, typeName) {
7231
7232    /* istanbul ignore if */
7233    if (ctor.$type) {
7234        if (typeName && ctor.$type.name !== typeName) {
7235            util.decorateRoot.remove(ctor.$type);
7236            ctor.$type.name = typeName;
7237            util.decorateRoot.add(ctor.$type);
7238        }
7239        return ctor.$type;
7240    }
7241
7242    /* istanbul ignore next */
7243    if (!Type)
7244        Type = require(35);
7245
7246    var type = new Type(typeName || ctor.name);
7247    util.decorateRoot.add(type);
7248    type.ctor = ctor; // sets up .encode, .decode etc.
7249    Object.defineProperty(ctor, "$type", { value: type, enumerable: false });
7250    Object.defineProperty(ctor.prototype, "$type", { value: type, enumerable: false });
7251    return type;
7252};
7253
7254var decorateEnumIndex = 0;
7255
7256/**
7257 * Decorator helper for enums (TypeScript).
7258 * @param {Object} object Enum object
7259 * @returns {Enum} Reflected enum
7260 */
7261util.decorateEnum = function decorateEnum(object) {
7262
7263    /* istanbul ignore if */
7264    if (object.$type)
7265        return object.$type;
7266
7267    /* istanbul ignore next */
7268    if (!Enum)
7269        Enum = require(15);
7270
7271    var enm = new Enum("Enum" + decorateEnumIndex++, object);
7272    util.decorateRoot.add(enm);
7273    Object.defineProperty(object, "$type", { value: enm, enumerable: false });
7274    return enm;
7275};
7276
7277/**
7278 * Decorator root (TypeScript).
7279 * @name util.decorateRoot
7280 * @type {Root}
7281 * @readonly
7282 */
7283Object.defineProperty(util, "decorateRoot", {
7284    get: function() {
7285        return roots["decorated"] || (roots["decorated"] = new (require(29))());
7286    }
7287});
7288
7289},{"15":15,"29":29,"3":3,"30":30,"35":35,"39":39,"5":5,"8":8}],38:[function(require,module,exports){
7290"use strict";
7291module.exports = LongBits;
7292
7293var util = require(39);
7294
7295/**
7296 * Constructs new long bits.
7297 * @classdesc Helper class for working with the low and high bits of a 64 bit value.
7298 * @memberof util
7299 * @constructor
7300 * @param {number} lo Low 32 bits, unsigned
7301 * @param {number} hi High 32 bits, unsigned
7302 */
7303function LongBits(lo, hi) {
7304
7305    // note that the casts below are theoretically unnecessary as of today, but older statically
7306    // generated converter code might still call the ctor with signed 32bits. kept for compat.
7307
7308    /**
7309     * Low bits.
7310     * @type {number}
7311     */
7312    this.lo = lo >>> 0;
7313
7314    /**
7315     * High bits.
7316     * @type {number}
7317     */
7318    this.hi = hi >>> 0;
7319}
7320
7321/**
7322 * Zero bits.
7323 * @memberof util.LongBits
7324 * @type {util.LongBits}
7325 */
7326var zero = LongBits.zero = new LongBits(0, 0);
7327
7328zero.toNumber = function() { return 0; };
7329zero.zzEncode = zero.zzDecode = function() { return this; };
7330zero.length = function() { return 1; };
7331
7332/**
7333 * Zero hash.
7334 * @memberof util.LongBits
7335 * @type {string}
7336 */
7337var zeroHash = LongBits.zeroHash = "\0\0\0\0\0\0\0\0";
7338
7339/**
7340 * Constructs new long bits from the specified number.
7341 * @param {number} value Value
7342 * @returns {util.LongBits} Instance
7343 */
7344LongBits.fromNumber = function fromNumber(value) {
7345    if (value === 0)
7346        return zero;
7347    var sign = value < 0;
7348    if (sign)
7349        value = -value;
7350    var lo = value >>> 0,
7351        hi = (value - lo) / 4294967296 >>> 0;
7352    if (sign) {
7353        hi = ~hi >>> 0;
7354        lo = ~lo >>> 0;
7355        if (++lo > 4294967295) {
7356            lo = 0;
7357            if (++hi > 4294967295)
7358                hi = 0;
7359        }
7360    }
7361    return new LongBits(lo, hi);
7362};
7363
7364/**
7365 * Constructs new long bits from a number, long or string.
7366 * @param {Long|number|string} value Value
7367 * @returns {util.LongBits} Instance
7368 */
7369LongBits.from = function from(value) {
7370    if (typeof value === "number")
7371        return LongBits.fromNumber(value);
7372    if (util.isString(value)) {
7373        /* istanbul ignore else */
7374        if (util.Long)
7375            value = util.Long.fromString(value);
7376        else
7377            return LongBits.fromNumber(parseInt(value, 10));
7378    }
7379    return value.low || value.high ? new LongBits(value.low >>> 0, value.high >>> 0) : zero;
7380};
vendor: 8,329 bytes, lines 7381-7654
7381
7382/**
7383 * Converts this long bits to a possibly unsafe JavaScript number.
7384 * @param {boolean} [unsigned=false] Whether unsigned or not
7385 * @returns {number} Possibly unsafe number
7386 */
7387LongBits.prototype.toNumber = function toNumber(unsigned) {
7388    if (!unsigned && this.hi >>> 31) {
7389        var lo = ~this.lo + 1 >>> 0,
7390            hi = ~this.hi     >>> 0;
7391        if (!lo)
7392            hi = hi + 1 >>> 0;
7393        return -(lo + hi * 4294967296);
7394    }
7395    return this.lo + this.hi * 4294967296;
7396};
7397
7398/**
7399 * Converts this long bits to a long.
7400 * @param {boolean} [unsigned=false] Whether unsigned or not
7401 * @returns {Long} Long
7402 */
7403LongBits.prototype.toLong = function toLong(unsigned) {
7404    return util.Long
7405        ? new util.Long(this.lo | 0, this.hi | 0, Boolean(unsigned))
7406        /* istanbul ignore next */
7407        : { low: this.lo | 0, high: this.hi | 0, unsigned: Boolean(unsigned) };
7408};
7409
7410var charCodeAt = String.prototype.charCodeAt;
7411
7412/**
7413 * Constructs new long bits from the specified 8 characters long hash.
7414 * @param {string} hash Hash
7415 * @returns {util.LongBits} Bits
7416 */
7417LongBits.fromHash = function fromHash(hash) {
7418    if (hash === zeroHash)
7419        return zero;
7420    return new LongBits(
7421        ( charCodeAt.call(hash, 0)
7422        | charCodeAt.call(hash, 1) << 8
7423        | charCodeAt.call(hash, 2) << 16
7424        | charCodeAt.call(hash, 3) << 24) >>> 0
7425    ,
7426        ( charCodeAt.call(hash, 4)
7427        | charCodeAt.call(hash, 5) << 8
7428        | charCodeAt.call(hash, 6) << 16
7429        | charCodeAt.call(hash, 7) << 24) >>> 0
7430    );
7431};
7432
7433/**
7434 * Converts this long bits to a 8 characters long hash.
7435 * @returns {string} Hash
7436 */
7437LongBits.prototype.toHash = function toHash() {
7438    return String.fromCharCode(
7439        this.lo        & 255,
7440        this.lo >>> 8  & 255,
7441        this.lo >>> 16 & 255,
7442        this.lo >>> 24      ,
7443        this.hi        & 255,
7444        this.hi >>> 8  & 255,
7445        this.hi >>> 16 & 255,
7446        this.hi >>> 24
7447    );
7448};
7449
7450/**
7451 * Zig-zag encodes this long bits.
7452 * @returns {util.LongBits} `this`
7453 */
7454LongBits.prototype.zzEncode = function zzEncode() {
7455    var mask =   this.hi >> 31;
7456    this.hi  = ((this.hi << 1 | this.lo >>> 31) ^ mask) >>> 0;
7457    this.lo  = ( this.lo << 1                   ^ mask) >>> 0;
7458    return this;
7459};
7460
7461/**
7462 * Zig-zag decodes this long bits.
7463 * @returns {util.LongBits} `this`
7464 */
7465LongBits.prototype.zzDecode = function zzDecode() {
7466    var mask = -(this.lo & 1);
7467    this.lo  = ((this.lo >>> 1 | this.hi << 31) ^ mask) >>> 0;
7468    this.hi  = ( this.hi >>> 1                  ^ mask) >>> 0;
7469    return this;
7470};
7471
7472/**
7473 * Calculates the length of this longbits when encoded as a varint.
7474 * @returns {number} Length
7475 */
7476LongBits.prototype.length = function length() {
7477    var part0 =  this.lo,
7478        part1 = (this.lo >>> 28 | this.hi << 4) >>> 0,
7479        part2 =  this.hi >>> 24;
7480    return part2 === 0
7481         ? part1 === 0
7482           ? part0 < 16384
7483             ? part0 < 128 ? 1 : 2
7484             : part0 < 2097152 ? 3 : 4
7485           : part1 < 16384
7486             ? part1 < 128 ? 5 : 6
7487             : part1 < 2097152 ? 7 : 8
7488         : part2 < 128 ? 9 : 10;
7489};
7490
7491},{"39":39}],39:[function(require,module,exports){
7492"use strict";
7493var util = exports;
7494
7495// used to return a Promise where callback is omitted
7496util.asPromise = require(1);
7497
7498// converts to / from base64 encoded strings
7499util.base64 = require(2);
7500
7501// base class of rpc.Service
7502util.EventEmitter = require(4);
7503
7504// float handling accross browsers
7505util.float = require(6);
7506
7507// requires modules optionally and hides the call from bundlers
7508util.inquire = require(7);
7509
7510// converts to / from utf8 encoded strings
7511util.utf8 = require(10);
7512
7513// provides a node-like buffer pool in the browser
7514util.pool = require(9);
7515
7516// utility to work with the low and high bits of a 64 bit value
7517util.LongBits = require(38);
7518
7519/**
7520 * An immuable empty array.
7521 * @memberof util
7522 * @type {Array.<*>}
7523 * @const
7524 */
7525util.emptyArray = Object.freeze ? Object.freeze([]) : /* istanbul ignore next */ []; // used on prototypes
7526
7527/**
7528 * An immutable empty object.
7529 * @type {Object}
7530 * @const
7531 */
7532util.emptyObject = Object.freeze ? Object.freeze({}) : /* istanbul ignore next */ {}; // used on prototypes
7533
7534/**
7535 * Whether running within node or not.
7536 * @memberof util
7537 * @type {boolean}
7538 * @const
7539 */
7540util.isNode = Boolean(global.process && global.process.versions && global.process.versions.node);
7541
7542/**
7543 * Tests if the specified value is an integer.
7544 * @function
7545 * @param {*} value Value to test
7546 * @returns {boolean} `true` if the value is an integer
7547 */
7548util.isInteger = Number.isInteger || /* istanbul ignore next */ function isInteger(value) {
7549    return typeof value === "number" && isFinite(value) && Math.floor(value) === value;
7550};
7551
7552/**
7553 * Tests if the specified value is a string.
7554 * @param {*} value Value to test
7555 * @returns {boolean} `true` if the value is a string
7556 */
7557util.isString = function isString(value) {
7558    return typeof value === "string" || value instanceof String;
7559};
7560
7561/**
7562 * Tests if the specified value is a non-null object.
7563 * @param {*} value Value to test
7564 * @returns {boolean} `true` if the value is a non-null object
7565 */
7566util.isObject = function isObject(value) {
7567    return value && typeof value === "object";
7568};
7569
7570/**
7571 * Checks if a property on a message is considered to be present.
7572 * This is an alias of {@link util.isSet}.
7573 * @function
7574 * @param {Object} obj Plain object or message instance
7575 * @param {string} prop Property name
7576 * @returns {boolean} `true` if considered to be present, otherwise `false`
7577 */
7578util.isset =
7579
7580/**
7581 * Checks if a property on a message is considered to be present.
7582 * @param {Object} obj Plain object or message instance
7583 * @param {string} prop Property name
7584 * @returns {boolean} `true` if considered to be present, otherwise `false`
7585 */
7586util.isSet = function isSet(obj, prop) {
7587    var value = obj[prop];
7588    if (value != null && obj.hasOwnProperty(prop)) // eslint-disable-line eqeqeq, no-prototype-builtins
7589        return typeof value !== "object" || (Array.isArray(value) ? value.length : Object.keys(value).length) > 0;
7590    return false;
7591};
7592
7593/**
7594 * Any compatible Buffer instance.
7595 * This is a minimal stand-alone definition of a Buffer instance. The actual type is that exported by node's typings.
7596 * @interface Buffer
7597 * @extends Uint8Array
7598 */
7599
7600/**
7601 * Node's Buffer class if available.
7602 * @type {Constructor<Buffer>}
7603 */
7604util.Buffer = (function() {
7605    try {
7606        var Buffer = util.inquire("buffer").Buffer;
7607        // refuse to use non-node buffers if not explicitly assigned (perf reasons):
7608        return Buffer.prototype.utf8Write ? Buffer : /* istanbul ignore next */ null;
7609    } catch (e) {
7610        /* istanbul ignore next */
7611        return null;
7612    }
7613})();
7614
7615// Internal alias of or polyfull for Buffer.from.
7616util._Buffer_from = null;
7617
7618// Internal alias of or polyfill for Buffer.allocUnsafe.
7619util._Buffer_allocUnsafe = null;
7620
7621/**
7622 * Creates a new buffer of whatever type supported by the environment.
7623 * @param {number|number[]} [sizeOrArray=0] Buffer size or number array
7624 * @returns {Uint8Array|Buffer} Buffer
7625 */
7626util.newBuffer = function newBuffer(sizeOrArray) {
7627    /* istanbul ignore next */
7628    return typeof sizeOrArray === "number"
7629        ? util.Buffer
7630            ? util._Buffer_allocUnsafe(sizeOrArray)
7631            : new util.Array(sizeOrArray)
7632        : util.Buffer
7633            ? util._Buffer_from(sizeOrArray)
7634            : typeof Uint8Array === "undefined"
7635                ? sizeOrArray
7636                : new Uint8Array(sizeOrArray);
7637};
7638
7639/**
7640 * Array implementation used in the browser. `Uint8Array` if supported, otherwise `Array`.
7641 * @type {Constructor<Uint8Array>}
7642 */
7643util.Array = typeof Uint8Array !== "undefined" ? Uint8Array /* istanbul ignore next */ : Array;
7644
7645/**
7646 * Any compatible Long instance.
7647 * This is a minimal stand-alone definition of a Long instance. The actual type is that exported by long.js.
7648 * @interface Long
7649 * @property {number} low Low bits
7650 * @property {number} high High bits
7651 * @property {boolean} unsigned Whether unsigned or not
7652 */
7653
7654/**
7655 * Long.js's Long class if available.
7656 * @type {Constructor<Long>}
7657 */
7658util.Long = /* istanbul ignore next */ global.dcodeIO && /* istanbul ignore next */ global.dcodeIO.Long || util.inquire("long");
7659
7660/**
7661 * Regular expression used to verify 2 bit (`bool`) map keys.
7662 * @type {RegExp}
7663 * @const
7664 */
7665util.key2Re = /^true|false|0|1$/;
7666
7667/**
7668 * Regular expression used to verify 32 bit (`int32` etc.) map keys.
7669 * @type {RegExp}
7670 * @const
7671 */
7672util.key32Re = /^-?(?:0|[1-9][0-9]*)$/;
7673
7674/**
7675 * Regular expression used to verify 64 bit (`int64` etc.) map keys.
7676 * @type {RegExp}
7677 * @const
7678 */
7679util.key64Re = /^(?:[\\x00-\\xff]{8}|-?(?:0|[1-9][0-9]*))$/;
7680
7681/**
7682 * Converts a number or long to an 8 characters long hash string.
7683 * @param {Long|number} value Value to convert
7684 * @returns {string} Hash
7685 */
7686util.longToHash = function longToHash(value) {
7687    return value
7688        ? util.LongBits.from(value).toHash()
7689        : util.LongBits.zeroHash;
7690};
7691
7692/**
7693 * Converts an 8 characters long hash string to a long or number.
7694 * @param {string} hash Hash
7695 * @param {boolean} [unsigned=false] Whether unsigned or not
7696 * @returns {Long|number} Original value
7697 */
7698util.longFromHash = function longFromHash(hash, unsigned) {
7699    var bits = util.LongBits.fromHash(hash);
7700    if (util.Long)
7701        return util.Long.fromBits(bits.lo, bits.hi, unsigned);
7702    return bits.toNumber(Boolean(unsigned));
7703};
7704
7705/**
7706 * Merges the properties of the source object into the destination object.
7707 * @memberof util
7708 * @param {Object.<string,*>} dst Destination object
7709 * @param {Object.<string,*>} src Source object
7710 * @param {boolean} [ifNotSet=false] Merges only if the key is not already set
7711 * @returns {Object.<string,*>} Destination object
7712 */
7713function merge(dst, src, ifNotSet) { // used by converters
7714    for (var keys = Object.keys(src), i = 0; i < keys.length; ++i)
7715        if (dst[keys[i]] === undefined || !ifNotSet)
7716            dst[keys[i]] = src[keys[i]];
7717    return dst;
7718}
7719
7720util.merge = merge;
7721
7722/**
7723 * Converts the first character of a string to lower case.
7724 * @param {string} str String to convert
7725 * @returns {string} Converted string
7726 */
7727util.lcFirst = function lcFirst(str) {
7728    return str.charAt(0).toLowerCase() + str.substring(1);
7729};
7730
7731/**
7732 * Creates a custom error constructor.
7733 * @memberof util
7734 * @param {string} name Error name
7735 * @returns {Constructor<Error>} Custom error constructor
7736 */
7737function newError(name) {
7738
7739    function CustomError(message, properties) {
7740
7741        if (!(this instanceof CustomError))
7742            return new CustomError(message, properties);
7743
7744        // Error.call(this, message);
7745        // ^ just returns a new error instance because the ctor can be called as a function
7746
7747        Object.defineProperty(this, "message", { get: function() { return message; } });
7748
7749        /* istanbul ignore next */
7750        if (Error.captureStackTrace) // node
7751            Error.captureStackTrace(this, CustomError);
7752        else
7753            Object.defineProperty(this, "stack", { value: (new Error()).stack || "" });
7754
7755        if (properties)
7756            merge(this, properties);
7757    }
7758
7759    (CustomError.prototype = Object.create(Error.prototype)).constructor = CustomError;
7760
7761    Object.defineProperty(CustomError.prototype, "name", { get: function() { return name; } });
7762
7763    CustomError.prototype.toString = function toString() {
7764        return this.name + ": " + this.message;
7765    };
7766
7767    return CustomError;
7768}
7769
7770util.newError = newError;
7771
7772/**
7773 * Constructs a new protocol error.
7774 * @classdesc Error subclass indicating a protocol specifc error.
7775 * @memberof util
7776 * @extends Error
7777 * @template T extends Message<T>
7778 * @constructor
7779 * @param {string} message Error message
7780 * @param {Object.<string,*>} [properties] Additional properties
7781 * @example
7782 * try {
7783 *     MyMessage.decode(someBuffer); // throws if required fields are missing
7784 * } catch (e) {
7785 *     if (e instanceof ProtocolError && e.instance)
7786 *         console.log("decoded so far: " + JSON.stringify(e.instance));
7787 * }
7788 */
7789util.ProtocolError = newError("ProtocolError");
7790
7791/**
7792 * So far decoded message instance.
7793 * @name util.ProtocolError#instance
7794 * @type {Message<T>}
7795 */
7796
7797/**
7798 * A OneOf getter as returned by {@link util.oneOfGetter}.
7799 * @typedef OneOfGetter
7800 * @type {function}
7801 * @returns {string|undefined} Set field name, if any
7802 */
7803
7804/**
7805 * Builds a getter for a oneof's present field name.
7806 * @param {string[]} fieldNames Field names
7807 * @returns {OneOfGetter} Unbound getter
7808 */
7809util.oneOfGetter = function getOneOf(fieldNames) {
7810    var fieldMap = {};
7811    for (var i = 0; i < fieldNames.length; ++i)
7812        fieldMap[fieldNames[i]] = 1;
7813
7814    /**
7815     * @returns {string|undefined} Set field name, if any
7816     * @this Object
7817     * @ignore
7818     */
7819    return function() { // eslint-disable-line consistent-return
7820        for (var keys = Object.keys(this), i = keys.length - 1; i > -1; --i)
7821            if (fieldMap[keys[i]] === 1 && this[keys[i]] !== undefined && this[keys[i]] !== null)
7822                return keys[i];
7823    };
7824};
vendor: 8,734 bytes, lines 7825-8088
7825
7826/**
7827 * A OneOf setter as returned by {@link util.oneOfSetter}.
7828 * @typedef OneOfSetter
7829 * @type {function}
7830 * @param {string|undefined} value Field name
7831 * @returns {undefined}
7832 */
7833
7834/**
7835 * Builds a setter for a oneof's present field name.
7836 * @param {string[]} fieldNames Field names
7837 * @returns {OneOfSetter} Unbound setter
7838 */
7839util.oneOfSetter = function setOneOf(fieldNames) {
7840
7841    /**
7842     * @param {string} name Field name
7843     * @returns {undefined}
7844     * @this Object
7845     * @ignore
7846     */
7847    return function(name) {
7848        for (var i = 0; i < fieldNames.length; ++i)
7849            if (fieldNames[i] !== name)
7850                delete this[fieldNames[i]];
7851    };
7852};
7853
7854/**
7855 * Default conversion options used for {@link Message#toJSON} implementations.
7856 *
7857 * These options are close to proto3's JSON mapping with the exception that internal types like Any are handled just like messages. More precisely:
7858 *
7859 * - Longs become strings
7860 * - Enums become string keys
7861 * - Bytes become base64 encoded strings
7862 * - (Sub-)Messages become plain objects
7863 * - Maps become plain objects with all string keys
7864 * - Repeated fields become arrays
7865 * - NaN and Infinity for float and double fields become strings
7866 *
7867 * @type {IConversionOptions}
7868 * @see https://developers.google.com/protocol-buffers/docs/proto3?hl=en#json
7869 */
7870util.toJSONOptions = {
7871    longs: String,
7872    enums: String,
7873    bytes: String,
7874    json: true
7875};
7876
7877util._configure = function() {
7878    var Buffer = util.Buffer;
7879    /* istanbul ignore if */
7880    if (!Buffer) {
7881        util._Buffer_from = util._Buffer_allocUnsafe = null;
7882        return;
7883    }
7884    // because node 4.x buffers are incompatible & immutable
7885    // see: https://github.com/dcodeIO/protobuf.js/pull/665
7886    util._Buffer_from = Buffer.from !== Uint8Array.from && Buffer.from ||
7887        /* istanbul ignore next */
7888        function Buffer_from(value, encoding) {
7889            return new Buffer(value, encoding);
7890        };
7891    util._Buffer_allocUnsafe = Buffer.allocUnsafe ||
7892        /* istanbul ignore next */
7893        function Buffer_allocUnsafe(size) {
7894            return new Buffer(size);
7895        };
7896};
7897
7898},{"1":1,"10":10,"2":2,"38":38,"4":4,"6":6,"7":7,"9":9}],40:[function(require,module,exports){
7899"use strict";
7900module.exports = verifier;
7901
7902var Enum      = require(15),
7903    util      = require(37);
7904
7905function invalid(field, expected) {
7906    return field.name + ": " + expected + (field.repeated && expected !== "array" ? "[]" : field.map && expected !== "object" ? "{k:"+field.keyType+"}" : "") + " expected";
7907}
7908
7909/**
7910 * Generates a partial value verifier.
7911 * @param {Codegen} gen Codegen instance
7912 * @param {Field} field Reflected field
7913 * @param {number} fieldIndex Field index
7914 * @param {string} ref Variable reference
7915 * @returns {Codegen} Codegen instance
7916 * @ignore
7917 */
7918function genVerifyValue(gen, field, fieldIndex, ref) {
7919    /* eslint-disable no-unexpected-multiline */
7920    if (field.resolvedType) {
7921        if (field.resolvedType instanceof Enum) { gen
7922            ("switch(%s){", ref)
7923                ("default:")
7924                    ("return%j", invalid(field, "enum value"));
7925            for (var keys = Object.keys(field.resolvedType.values), j = 0; j < keys.length; ++j) gen
7926                ("case %i:", field.resolvedType.values[keys[j]]);
7927            gen
7928                    ("break")
7929            ("}");
7930        } else {
7931            gen
7932            ("{")
7933                ("var e=types[%i].verify(%s);", fieldIndex, ref)
7934                ("if(e)")
7935                    ("return%j+e", field.name + ".")
7936            ("}");
7937        }
7938    } else {
7939        switch (field.type) {
7940            case "int32":
7941            case "uint32":
7942            case "sint32":
7943            case "fixed32":
7944            case "sfixed32": gen
7945                ("if(!util.isInteger(%s))", ref)
7946                    ("return%j", invalid(field, "integer"));
7947                break;
7948            case "int64":
7949            case "uint64":
7950            case "sint64":
7951            case "fixed64":
7952            case "sfixed64": gen
7953                ("if(!util.isInteger(%s)&&!(%s&&util.isInteger(%s.low)&&util.isInteger(%s.high)))", ref, ref, ref, ref)
7954                    ("return%j", invalid(field, "integer|Long"));
7955                break;
7956            case "float":
7957            case "double": gen
7958                ("if(typeof %s!==\"number\")", ref)
7959                    ("return%j", invalid(field, "number"));
7960                break;
7961            case "bool": gen
7962                ("if(typeof %s!==\"boolean\")", ref)
7963                    ("return%j", invalid(field, "boolean"));
7964                break;
7965            case "string": gen
7966                ("if(!util.isString(%s))", ref)
7967                    ("return%j", invalid(field, "string"));
7968                break;
7969            case "bytes": gen
7970                ("if(!(%s&&typeof %s.length===\"number\"||util.isString(%s)))", ref, ref, ref)
7971                    ("return%j", invalid(field, "buffer"));
7972                break;
7973        }
7974    }
7975    return gen;
7976    /* eslint-enable no-unexpected-multiline */
7977}
7978
7979/**
7980 * Generates a partial key verifier.
7981 * @param {Codegen} gen Codegen instance
7982 * @param {Field} field Reflected field
7983 * @param {string} ref Variable reference
7984 * @returns {Codegen} Codegen instance
7985 * @ignore
7986 */
7987function genVerifyKey(gen, field, ref) {
7988    /* eslint-disable no-unexpected-multiline */
7989    switch (field.keyType) {
7990        case "int32":
7991        case "uint32":
7992        case "sint32":
7993        case "fixed32":
7994        case "sfixed32": gen
7995            ("if(!util.key32Re.test(%s))", ref)
7996                ("return%j", invalid(field, "integer key"));
7997            break;
7998        case "int64":
7999        case "uint64":
8000        case "sint64":
8001        case "fixed64":
8002        case "sfixed64": gen
8003            ("if(!util.key64Re.test(%s))", ref) // see comment above: x is ok, d is not
8004                ("return%j", invalid(field, "integer|Long key"));
8005            break;
8006        case "bool": gen
8007            ("if(!util.key2Re.test(%s))", ref)
8008                ("return%j", invalid(field, "boolean key"));
8009            break;
8010    }
8011    return gen;
8012    /* eslint-enable no-unexpected-multiline */
8013}
8014
8015/**
8016 * Generates a verifier specific to the specified message type.
8017 * @param {Type} mtype Message type
8018 * @returns {Codegen} Codegen instance
8019 */
8020function verifier(mtype) {
8021    /* eslint-disable no-unexpected-multiline */
8022
8023    var gen = util.codegen(["m"], mtype.name + "$verify")
8024    ("if(typeof m!==\"object\"||m===null)")
8025        ("return%j", "object expected");
8026    var oneofs = mtype.oneofsArray,
8027        seenFirstField = {};
8028    if (oneofs.length) gen
8029    ("var p={}");
8030
8031    for (var i = 0; i < /* initializes */ mtype.fieldsArray.length; ++i) {
8032        var field = mtype._fieldsArray[i].resolve(),
8033            ref   = "m" + util.safeProp(field.name);
8034
8035        if (field.optional) gen
8036        ("if(%s!=null&&m.hasOwnProperty(%j)){", ref, field.name); // !== undefined && !== null
8037
8038        // map fields
8039        if (field.map) { gen
8040            ("if(!util.isObject(%s))", ref)
8041                ("return%j", invalid(field, "object"))
8042            ("var k=Object.keys(%s)", ref)
8043            ("for(var i=0;i<k.length;++i){");
8044                genVerifyKey(gen, field, "k[i]");
8045                genVerifyValue(gen, field, i, ref + "[k[i]]")
8046            ("}");
8047
8048        // repeated fields
8049        } else if (field.repeated) { gen
8050            ("if(!Array.isArray(%s))", ref)
8051                ("return%j", invalid(field, "array"))
8052            ("for(var i=0;i<%s.length;++i){", ref);
8053                genVerifyValue(gen, field, i, ref + "[i]")
8054            ("}");
8055
8056        // required or present fields
8057        } else {
8058            if (field.partOf) {
8059                var oneofProp = util.safeProp(field.partOf.name);
8060                if (seenFirstField[field.partOf.name] === 1) gen
8061            ("if(p%s===1)", oneofProp)
8062                ("return%j", field.partOf.name + ": multiple values");
8063                seenFirstField[field.partOf.name] = 1;
8064                gen
8065            ("p%s=1", oneofProp);
8066            }
8067            genVerifyValue(gen, field, i, ref);
8068        }
8069        if (field.optional) gen
8070        ("}");
8071    }
8072    return gen
8073    ("return null");
8074    /* eslint-enable no-unexpected-multiline */
8075}
8076},{"15":15,"37":37}],41:[function(require,module,exports){
8077"use strict";
8078
8079/**
8080 * Wrappers for common types.
8081 * @type {Object.<string,IWrapper>}
8082 * @const
8083 */
8084var wrappers = exports;
8085
8086var Message = require(21);
8087
8088/**
8089 * From object converter part of an {@link IWrapper}.
8090 * @typedef WrapperFromObjectConverter
8091 * @type {function}
8092 * @param {Object.<string,*>} object Plain object
8093 * @returns {Message<{}>} Message instance
8094 * @this Type
8095 */
8096
8097/**
8098 * To object converter part of an {@link IWrapper}.
8099 * @typedef WrapperToObjectConverter
8100 * @type {function}
8101 * @param {Message<{}>} message Message instance
8102 * @param {IConversionOptions} [options] Conversion options
8103 * @returns {Object.<string,*>} Plain object
8104 * @this Type
8105 */
8106
8107/**
8108 * Common type wrapper part of {@link wrappers}.
8109 * @interface IWrapper
8110 * @property {WrapperFromObjectConverter} [fromObject] From object converter
8111 * @property {WrapperToObjectConverter} [toObject] To object converter
8112 */
8113
8114// Custom wrapper for Any
8115wrappers[".google.protobuf.Any"] = {
8116
8117    fromObject: function(object) {
8118
8119        // unwrap value type if mapped
8120        if (object && object["@type"]) {
8121            var type = this.lookup(object["@type"]);
8122            /* istanbul ignore else */
8123            if (type) {
8124                // type_url does not accept leading "."
8125                var type_url = object["@type"].charAt(0) === "." ?
8126                    object["@type"].substr(1) : object["@type"];
8127                // type_url prefix is optional, but path seperator is required
8128                return this.create({
8129                    type_url: "/" + type_url,
8130                    value: type.encode(type.fromObject(object)).finish()
8131                });
8132            }
8133        }
8134
8135        return this.fromObject(object);
8136    },
8137
8138    toObject: function(message, options) {
8139
8140        // decode value if requested and unmapped
8141        if (options && options.json && message.type_url && message.value) {
8142            // Only use fully qualified type name after the last '/'
8143            var name = message.type_url.substring(message.type_url.lastIndexOf("/") + 1);
8144            var type = this.lookup(name);
8145            /* istanbul ignore else */
8146            if (type)
8147                message = type.decode(message.value);
8148        }
8149
8150        // wrap value if unmapped
8151        if (!(message instanceof this.ctor) && message instanceof Message) {
8152            var object = message.$type.toObject(message, options);
8153            object["@type"] = message.$type.fullName;
8154            return object;
8155        }
8156
8157        return this.toObject(message, options);
8158    }
8159};
8160
8161},{"21":21}],42:[function(require,module,exports){
8162"use strict";
8163module.exports = Writer;
8164
8165var util      = require(39);
8166
8167var BufferWriter; // cyclic
8168
8169var LongBits  = util.LongBits,
8170    base64    = util.base64,
8171    utf8      = util.utf8;
8172
8173/**
8174 * Constructs a new writer operation instance.
8175 * @classdesc Scheduled writer operation.
8176 * @constructor
8177 * @param {function(*, Uint8Array, number)} fn Function to call
8178 * @param {number} len Value byte length
8179 * @param {*} val Value to write
8180 * @ignore
8181 */
8182function Op(fn, len, val) {
8183
8184    /**
8185     * Function to call.
8186     * @type {function(Uint8Array, number, *)}
8187     */
8188    this.fn = fn;
8189
8190    /**
8191     * Value byte length.
8192     * @type {number}
8193     */
8194    this.len = len;
8195
8196    /**
8197     * Next operation.
8198     * @type {Writer.Op|undefined}
8199     */
8200    this.next = undefined;
8201
8202    /**
8203     * Value to write.
8204     * @type {*}
8205     */
8206    this.val = val; // type varies
8207}
8208
8209/* istanbul ignore next */
8210function noop() {} // eslint-disable-line no-empty-function
8211
8212/**
8213 * Constructs a new writer state instance.
8214 * @classdesc Copied writer state.
8215 * @memberof Writer
8216 * @constructor
8217 * @param {Writer} writer Writer to copy state from
8218 * @ignore
8219 */
8220function State(writer) {
8221
8222    /**
8223     * Current head.
8224     * @type {Writer.Op}
8225     */
8226    this.head = writer.head;
8227
8228    /**
8229     * Current tail.
8230     * @type {Writer.Op}
8231     */
8232    this.tail = writer.tail;
8233
8234    /**
8235     * Current buffer length.
8236     * @type {number}
8237     */
8238    this.len = writer.len;
8239
8240    /**
8241     * Next state.
8242     * @type {State|null}
8243     */
8244    this.next = writer.states;
8245}
8246
8247/**
8248 * Constructs a new writer instance.
8249 * @classdesc Wire format writer using `Uint8Array` if available, otherwise `Array`.
8250 * @constructor
8251 */
8252function Writer() {
8253
8254    /**
8255     * Current length.
8256     * @type {number}
8257     */
8258    this.len = 0;
8259
8260    /**
8261     * Operations head.
8262     * @type {Object}
8263     */
8264    this.head = new Op(noop, 0, 0);
8265
8266    /**
8267     * Operations tail
8268     * @type {Object}
8269     */
8270    this.tail = this.head;
8271
8272    /**
8273     * Linked forked states.
8274     * @type {Object|null}
8275     */
8276    this.states = null;
8277
8278    // When a value is written, the writer calculates its byte length and puts it into a linked
8279    // list of operations to perform when finish() is called. This both allows us to allocate
8280    // buffers of the exact required size and reduces the amount of work we have to do compared
8281    // to first calculating over objects and then encoding over objects. In our case, the encoding
8282    // part is just a linked list walk calling operations with already prepared values.
8283}
8284
8285/**
8286 * Creates a new writer.
8287 * @function
8288 * @returns {BufferWriter|Writer} A {@link BufferWriter} when Buffers are supported, otherwise a {@link Writer}
8289 */
8290Writer.create = util.Buffer
8291    ? function create_buffer_setup() {
8292        return (Writer.create = function create_buffer() {
8293            return new BufferWriter();
8294        })();
8295    }
8296    /* istanbul ignore next */
8297    : function create_array() {
8298        return new Writer();
8299    };
8300
8301/**
8302 * Allocates a buffer of the specified size.
8303 * @param {number} size Buffer size
8304 * @returns {Uint8Array} Buffer
8305 */
8306Writer.alloc = function alloc(size) {
8307    return new util.Array(size);
8308};
8309
8310// Use Uint8Array buffer pool in the browser, just like node does with buffers
8311/* istanbul ignore else */
8312if (util.Array !== Array)
8313    Writer.alloc = util.pool(Writer.alloc, util.Array.prototype.subarray);
8314
8315/**
8316 * Pushes a new operation to the queue.
8317 * @param {function(Uint8Array, number, *)} fn Function to call
8318 * @param {number} len Value byte length
8319 * @param {number} val Value to write
8320 * @returns {Writer} `this`
8321 * @private
8322 */
8323Writer.prototype._push = function push(fn, len, val) {
8324    this.tail = this.tail.next = new Op(fn, len, val);
8325    this.len += len;
8326    return this;
8327};
vendor: 7,002 bytes, lines 8328-8565
8328
8329function writeByte(val, buf, pos) {
8330    buf[pos] = val & 255;
8331}
8332
8333function writeVarint32(val, buf, pos) {
8334    while (val > 127) {
8335        buf[pos++] = val & 127 | 128;
8336        val >>>= 7;
8337    }
8338    buf[pos] = val;
8339}
8340
8341/**
8342 * Constructs a new varint writer operation instance.
8343 * @classdesc Scheduled varint writer operation.
8344 * @extends Op
8345 * @constructor
8346 * @param {number} len Value byte length
8347 * @param {number} val Value to write
8348 * @ignore
8349 */
8350function VarintOp(len, val) {
8351    this.len = len;
8352    this.next = undefined;
8353    this.val = val;
8354}
8355
8356VarintOp.prototype = Object.create(Op.prototype);
8357VarintOp.prototype.fn = writeVarint32;
8358
8359/**
8360 * Writes an unsigned 32 bit value as a varint.
8361 * @param {number} value Value to write
8362 * @returns {Writer} `this`
8363 */
8364Writer.prototype.uint32 = function write_uint32(value) {
8365    // here, the call to this.push has been inlined and a varint specific Op subclass is used.
8366    // uint32 is by far the most frequently used operation and benefits significantly from this.
8367    this.len += (this.tail = this.tail.next = new VarintOp(
8368        (value = value >>> 0)
8369                < 128       ? 1
8370        : value < 16384     ? 2
8371        : value < 2097152   ? 3
8372        : value < 268435456 ? 4
8373        :                     5,
8374    value)).len;
8375    return this;
8376};
8377
8378/**
8379 * Writes a signed 32 bit value as a varint.
8380 * @function
8381 * @param {number} value Value to write
8382 * @returns {Writer} `this`
8383 */
8384Writer.prototype.int32 = function write_int32(value) {
8385    return value < 0
8386        ? this._push(writeVarint64, 10, LongBits.fromNumber(value)) // 10 bytes per spec
8387        : this.uint32(value);
8388};
8389
8390/**
8391 * Writes a 32 bit value as a varint, zig-zag encoded.
8392 * @param {number} value Value to write
8393 * @returns {Writer} `this`
8394 */
8395Writer.prototype.sint32 = function write_sint32(value) {
8396    return this.uint32((value << 1 ^ value >> 31) >>> 0);
8397};
8398
8399function writeVarint64(val, buf, pos) {
8400    while (val.hi) {
8401        buf[pos++] = val.lo & 127 | 128;
8402        val.lo = (val.lo >>> 7 | val.hi << 25) >>> 0;
8403        val.hi >>>= 7;
8404    }
8405    while (val.lo > 127) {
8406        buf[pos++] = val.lo & 127 | 128;
8407        val.lo = val.lo >>> 7;
8408    }
8409    buf[pos++] = val.lo;
8410}
8411
8412/**
8413 * Writes an unsigned 64 bit value as a varint.
8414 * @param {Long|number|string} value Value to write
8415 * @returns {Writer} `this`
8416 * @throws {TypeError} If `value` is a string and no long library is present.
8417 */
8418Writer.prototype.uint64 = function write_uint64(value) {
8419    var bits = LongBits.from(value);
8420    return this._push(writeVarint64, bits.length(), bits);
8421};
8422
8423/**
8424 * Writes a signed 64 bit value as a varint.
8425 * @function
8426 * @param {Long|number|string} value Value to write
8427 * @returns {Writer} `this`
8428 * @throws {TypeError} If `value` is a string and no long library is present.
8429 */
8430Writer.prototype.int64 = Writer.prototype.uint64;
8431
8432/**
8433 * Writes a signed 64 bit value as a varint, zig-zag encoded.
8434 * @param {Long|number|string} value Value to write
8435 * @returns {Writer} `this`
8436 * @throws {TypeError} If `value` is a string and no long library is present.
8437 */
8438Writer.prototype.sint64 = function write_sint64(value) {
8439    var bits = LongBits.from(value).zzEncode();
8440    return this._push(writeVarint64, bits.length(), bits);
8441};
8442
8443/**
8444 * Writes a boolish value as a varint.
8445 * @param {boolean} value Value to write
8446 * @returns {Writer} `this`
8447 */
8448Writer.prototype.bool = function write_bool(value) {
8449    return this._push(writeByte, 1, value ? 1 : 0);
8450};
8451
8452function writeFixed32(val, buf, pos) {
8453    buf[pos    ] =  val         & 255;
8454    buf[pos + 1] =  val >>> 8   & 255;
8455    buf[pos + 2] =  val >>> 16  & 255;
8456    buf[pos + 3] =  val >>> 24;
8457}
8458
8459/**
8460 * Writes an unsigned 32 bit value as fixed 32 bits.
8461 * @param {number} value Value to write
8462 * @returns {Writer} `this`
8463 */
8464Writer.prototype.fixed32 = function write_fixed32(value) {
8465    return this._push(writeFixed32, 4, value >>> 0);
8466};
8467
8468/**
8469 * Writes a signed 32 bit value as fixed 32 bits.
8470 * @function
8471 * @param {number} value Value to write
8472 * @returns {Writer} `this`
8473 */
8474Writer.prototype.sfixed32 = Writer.prototype.fixed32;
8475
8476/**
8477 * Writes an unsigned 64 bit value as fixed 64 bits.
8478 * @param {Long|number|string} value Value to write
8479 * @returns {Writer} `this`
8480 * @throws {TypeError} If `value` is a string and no long library is present.
8481 */
8482Writer.prototype.fixed64 = function write_fixed64(value) {
8483    var bits = LongBits.from(value);
8484    return this._push(writeFixed32, 4, bits.lo)._push(writeFixed32, 4, bits.hi);
8485};
8486
8487/**
8488 * Writes a signed 64 bit value as fixed 64 bits.
8489 * @function
8490 * @param {Long|number|string} value Value to write
8491 * @returns {Writer} `this`
8492 * @throws {TypeError} If `value` is a string and no long library is present.
8493 */
8494Writer.prototype.sfixed64 = Writer.prototype.fixed64;
8495
8496/**
8497 * Writes a float (32 bit).
8498 * @function
8499 * @param {number} value Value to write
8500 * @returns {Writer} `this`
8501 */
8502Writer.prototype.float = function write_float(value) {
8503    return this._push(util.float.writeFloatLE, 4, value);
8504};
8505
8506/**
8507 * Writes a double (64 bit float).
8508 * @function
8509 * @param {number} value Value to write
8510 * @returns {Writer} `this`
8511 */
8512Writer.prototype.double = function write_double(value) {
8513    return this._push(util.float.writeDoubleLE, 8, value);
8514};
8515
8516var writeBytes = util.Array.prototype.set
8517    ? function writeBytes_set(val, buf, pos) {
8518        buf.set(val, pos); // also works for plain array values
8519    }
8520    /* istanbul ignore next */
8521    : function writeBytes_for(val, buf, pos) {
8522        for (var i = 0; i < val.length; ++i)
8523            buf[pos + i] = val[i];
8524    };
8525
8526/**
8527 * Writes a sequence of bytes.
8528 * @param {Uint8Array|string} value Buffer or base64 encoded string to write
8529 * @returns {Writer} `this`
8530 */
8531Writer.prototype.bytes = function write_bytes(value) {
8532    var len = value.length >>> 0;
8533    if (!len)
8534        return this._push(writeByte, 1, 0);
8535    if (util.isString(value)) {
8536        var buf = Writer.alloc(len = base64.length(value));
8537        base64.decode(value, buf, 0);
8538        value = buf;
8539    }
8540    return this.uint32(len)._push(writeBytes, len, value);
8541};
8542
8543/**
8544 * Writes a string.
8545 * @param {string} value Value to write
8546 * @returns {Writer} `this`
8547 */
8548Writer.prototype.string = function write_string(value) {
8549    var len = utf8.length(value);
8550    return len
8551        ? this.uint32(len)._push(utf8.write, len, value)
8552        : this._push(writeByte, 1, 0);
8553};
8554
8555/**
8556 * Forks this writer's state by pushing it to a stack.
8557 * Calling {@link Writer#reset|reset} or {@link Writer#ldelim|ldelim} resets the writer to the previous state.
8558 * @returns {Writer} `this`
8559 */
8560Writer.prototype.fork = function fork() {
8561    this.states = new State(this);
8562    this.head = this.tail = new Op(noop, 0, 0);
8563    this.len = 0;
8564    return this;
8565};
8566
8567/**
8568 * Resets this instance to the last state.
8569 * @returns {Writer} `this`
8570 */
8571Writer.prototype.reset = function reset() {
8572    if (this.states) {
8573        this.head   = this.states.head;
8574        this.tail   = this.states.tail;
8575        this.len    = this.states.len;
8576        this.states = this.states.next;
8577    } else {
8578        this.head = this.tail = new Op(noop, 0, 0);
8579        this.len  = 0;
8580    }
8581    return this;
8582};
8583
8584/**
8585 * Resets to the last state and appends the fork state's current write length as a varint followed by its operations.
8586 * @returns {Writer} `this`
8587 */
8588Writer.prototype.ldelim = function ldelim() {
8589    var head = this.head,
8590        tail = this.tail,
8591        len  = this.len;
8592    this.reset().uint32(len);
8593    if (len) {
8594        this.tail.next = head.next; // skip noop
8595        this.tail = tail;
8596        this.len += len;
8597    }
8598    return this;
8599};
8600
8601/**
8602 * Finishes the write operation.
8603 * @returns {Uint8Array} Finished buffer
8604 */
8605Writer.prototype.finish = function finish() {
8606    var head = this.head.next, // skip noop
8607        buf  = this.constructor.alloc(this.len),
8608        pos  = 0;
8609    while (head) {
8610        head.fn(head.val, buf, pos);
8611        pos += head.len;
8612        head = head.next;
8613    }
8614    // this.head = this.tail = null;
8615    return buf;
8616};
8617
8618Writer._configure = function(BufferWriter_) {
8619    BufferWriter = BufferWriter_;
8620};
8621
8622},{"39":39}],43:[function(require,module,exports){
8623"use strict";
8624module.exports = BufferWriter;
8625
8626// extends Writer
8627var Writer = require(42);
8628(BufferWriter.prototype = Object.create(Writer.prototype)).constructor = BufferWriter;
8629
8630var util = require(39);
8631
8632var Buffer = util.Buffer;
8633
8634/**
8635 * Constructs a new buffer writer instance.
8636 * @classdesc Wire format writer using node buffers.
8637 * @extends Writer
8638 * @constructor
8639 */
8640function BufferWriter() {
8641    Writer.call(this);
8642}
8643
8644/**
8645 * Allocates a buffer of the specified size.
8646 * @param {number} size Buffer size
8647 * @returns {Buffer} Buffer
8648 */
8649BufferWriter.alloc = function alloc_buffer(size) {
8650    return (BufferWriter.alloc = util._Buffer_allocUnsafe)(size);
8651};
8652
8653var writeBytesBuffer = Buffer && Buffer.prototype instanceof Uint8Array && Buffer.prototype.set.name === "set"
8654    ? function writeBytesBuffer_set(val, buf, pos) {
8655        buf.set(val, pos); // faster than copy (requires node >= 4 where Buffers extend Uint8Array and set is properly inherited)
8656                           // also works for plain array values
8657    }
8658    /* istanbul ignore next */
8659    : function writeBytesBuffer_copy(val, buf, pos) {
8660        if (val.copy) // Buffer values
8661            val.copy(buf, pos, 0, val.length);
8662        else for (var i = 0; i < val.length;) // plain array values
8663            buf[pos++] = val[i++];
8664    };
8665
8666/**
8667 * @override
8668 */
8669BufferWriter.prototype.bytes = function write_bytes_buffer(value) {
8670    if (util.isString(value))
8671        value = util._Buffer_from(value, "base64");
8672    var len = value.length >>> 0;
8673    this.uint32(len);
8674    if (len)
8675        this._push(writeBytesBuffer, len, value);
8676    return this;
8677};
8678
8679function writeStringBuffer(val, buf, pos) {
8680    if (val.length < 40) // plain js is faster for short strings (probably due to redundant assertions)
8681        util.utf8.write(val, buf, pos);
8682    else
8683        buf.utf8Write(val, pos);
8684}
8685
8686/**
8687 * @override
8688 */
8689BufferWriter.prototype.string = function write_string_buffer(value) {
8690    var len = Buffer.byteLength(value);
8691    this.uint32(len);
8692    if (len)
8693        this._push(writeStringBuffer, len, value);
8694    return this;
8695};
8696
8697
8698/**
8699 * Finishes the write operation.
8700 * @name BufferWriter#finish
8701 * @function
8702 * @returns {Buffer} Finished buffer
8703 */
8704
8705},{"39":39,"42":42}]},{},[19])
8706
8707})(
8708	typeof window==="object" && window
8709	|| typeof self==="object" && self
8710	|| this
8711);
8712

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.