UNPKG

shadow-function

Version:

ioing lib - shadow Function, worker Function

1,541 lines (1,410 loc) 243 kB
/*! * protobuf.js v6.7.0 (c) 2016, Daniel Wirtz * Compiled Sun, 12 Mar 2017 21:09:56 UTC * Licensed under the BSD-3-Clause License * see: https://github.com/dcodeIO/protobuf.js for details */ (function(global,undefined){"use strict";(function prelude(modules, cache, entries) { // This is the prelude used to bundle protobuf.js for the browser. Wraps up the CommonJS // sources through a conflict-free require shim and is again wrapped within an iife that // provides a unified `global` and a minification-friendly `undefined` var plus a global // "use strict" directive so that minification can remove the directives of each module. function $require(name) { var $module = cache[name]; if (!$module) modules[name][0].call($module = cache[name] = { exports: {} }, $require, $module, $module.exports); return $module.exports; } // Expose globally var protobuf = global.protobuf = $require(entries[0]); // Be nice to AMD if (typeof define === "function" && define.amd) define(["long"], function(Long) { protobuf.util.Long = Long; protobuf.configure(); return protobuf; }); // Be nice to CommonJS if (typeof module === "object" && module && module.exports) module.exports = protobuf; })/* end of prelude */({1:[function(require,module,exports){ "use strict"; module.exports = asPromise; /** * Returns a promise from a node-style callback function. * @memberof util * @param {function(?Error, ...*)} fn Function to call * @param {*} ctx Function context * @param {...*} params Function arguments * @returns {Promise<*>} Promisified function */ function asPromise(fn, ctx/*, varargs */) { var params = []; for (var i = 2; i < arguments.length;) params.push(arguments[i++]); var pending = true; return new Promise(function asPromiseExecutor(resolve, reject) { params.push(function asPromiseCallback(err/*, varargs */) { if (pending) { pending = false; if (err) reject(err); else { var args = []; for (var i = 1; i < arguments.length;) args.push(arguments[i++]); resolve.apply(null, args); } } }); try { fn.apply(ctx || this, params); // eslint-disable-line no-invalid-this } catch (err) { if (pending) { pending = false; reject(err); } } }); } },{}],2:[function(require,module,exports){ "use strict"; /** * A minimal base64 implementation for number arrays. * @memberof util * @namespace */ var base64 = exports; /** * Calculates the byte length of a base64 encoded string. * @param {string} string Base64 encoded string * @returns {number} Byte length */ base64.length = function length(string) { var p = string.length; if (!p) return 0; var n = 0; while (--p % 4 > 1 && string.charAt(p) === "=") ++n; return Math.ceil(string.length * 3) / 4 - n; }; // Base64 encoding table var b64 = new Array(64); // Base64 decoding table var s64 = new Array(123); // 65..90, 97..122, 48..57, 43, 47 for (var i = 0; i < 64;) s64[b64[i] = i < 26 ? i + 65 : i < 52 ? i + 71 : i < 62 ? i - 4 : i - 59 | 43] = i++; /** * Encodes a buffer to a base64 encoded string. * @param {Uint8Array} buffer Source buffer * @param {number} start Source start * @param {number} end Source end * @returns {string} Base64 encoded string */ base64.encode = function encode(buffer, start, end) { var string = []; // alt: new Array(Math.ceil((end - start) / 3) * 4); var i = 0, // output index j = 0, // goto index t; // temporary while (start < end) { var b = buffer[start++]; switch (j) { case 0: string[i++] = b64[b >> 2]; t = (b & 3) << 4; j = 1; break; case 1: string[i++] = b64[t | b >> 4]; t = (b & 15) << 2; j = 2; break; case 2: string[i++] = b64[t | b >> 6]; string[i++] = b64[b & 63]; j = 0; break; } } if (j) { string[i++] = b64[t]; string[i ] = 61; if (j === 1) string[i + 1] = 61; } return String.fromCharCode.apply(String, string); }; var invalidEncoding = "invalid encoding"; /** * Decodes a base64 encoded string to a buffer. * @param {string} string Source string * @param {Uint8Array} buffer Destination buffer * @param {number} offset Destination offset * @returns {number} Number of bytes written * @throws {Error} If encoding is invalid */ base64.decode = function decode(string, buffer, offset) { var start = offset; var j = 0, // goto index t; // temporary for (var i = 0; i < string.length;) { var c = string.charCodeAt(i++); if (c === 61 && j > 1) break; if ((c = s64[c]) === undefined) throw Error(invalidEncoding); switch (j) { case 0: t = c; j = 1; break; case 1: buffer[offset++] = t << 2 | (c & 48) >> 4; t = c; j = 2; break; case 2: buffer[offset++] = (t & 15) << 4 | (c & 60) >> 2; t = c; j = 3; break; case 3: buffer[offset++] = (t & 3) << 6 | c; j = 0; break; } } if (j === 1) throw Error(invalidEncoding); return offset - start; }; /** * Tests if the specified string appears to be base64 encoded. * @param {string} string String to test * @returns {boolean} `true` if probably base64 encoded, otherwise false */ base64.test = function test(string) { return /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(string); }; },{}],3:[function(require,module,exports){ "use strict"; module.exports = codegen; var blockOpenRe = /[{[]$/, blockCloseRe = /^[}\]]/, casingRe = /:$/, branchRe = /^\s*(?:if|}?else if|while|for)\b|\b(?:else)\s*$/, breakRe = /\b(?:break|continue)(?: \w+)?;?$|^\s*return\b/; /** * A closure for generating functions programmatically. * @memberof util * @namespace * @function * @param {...string} params Function parameter names * @returns {Codegen} Codegen instance * @property {boolean} supported Whether code generation is supported by the environment. * @property {boolean} verbose=false When set to true, codegen will log generated code to console. Useful for debugging. * @property {function(string, ...*):string} sprintf Underlying sprintf implementation */ function codegen() { var params = [], src = [], indent = 1, inCase = false; for (var i = 0; i < arguments.length;) params.push(arguments[i++]); /** * A codegen instance as returned by {@link codegen}, that also is a sprintf-like appender function. * @typedef Codegen * @type {function} * @param {string} format Format string * @param {...*} args Replacements * @returns {Codegen} Itself * @property {function(string=):string} str Stringifies the so far generated function source. * @property {function(string=, Object=):function} eof Ends generation and builds the function whilst applying a scope. */ /**/ function gen() { var args = [], i = 0; for (; i < arguments.length;) args.push(arguments[i++]); var line = sprintf.apply(null, args); var level = indent; if (src.length) { var prev = src[src.length - 1]; // block open or one time branch if (blockOpenRe.test(prev)) level = ++indent; // keep else if (branchRe.test(prev)) ++level; // once // casing if (casingRe.test(prev) && !casingRe.test(line)) { level = ++indent; inCase = true; } else if (inCase && breakRe.test(prev)) { level = --indent; inCase = false; } // block close if (blockCloseRe.test(line)) level = --indent; } for (i = 0; i < level; ++i) line = "\t" + line; src.push(line); return gen; } /** * Stringifies the so far generated function source. * @param {string} [name] Function name, defaults to generate an anonymous function * @returns {string} Function source using tabs for indentation * @inner */ function str(name) { return "function" + (name ? " " + name.replace(/[^\w_$]/g, "_") : "") + "(" + params.join(",") + ") {\n" + src.join("\n") + "\n}"; } gen.str = str; /** * Ends generation and builds the function whilst applying a scope. * @param {string} [name] Function name, defaults to generate an anonymous function * @param {Object.<string,*>} [scope] Function scope * @returns {function} The generated function, with scope applied if specified * @inner */ function eof(name, scope) { if (typeof name === "object") { scope = name; name = undefined; } var source = gen.str(name); if (codegen.verbose) console.log("--- codegen ---\n" + source.replace(/^/mg, "> ").replace(/\t/g, " ")); // eslint-disable-line no-console var keys = Object.keys(scope || (scope = {})); return Function.apply(null, keys.concat("return " + source)).apply(null, keys.map(function(key) { return scope[key]; })); // eslint-disable-line no-new-func // ^ Creates a wrapper function with the scoped variable names as its parameters, // calls it with the respective scoped variable values ^ // and returns our brand-new properly scoped function. // // This works because "Invoking the Function constructor as a function (without using the // new operator) has the same effect as invoking it as a constructor." // https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Function } gen.eof = eof; return gen; } function sprintf(format) { var args = [], i = 1; for (; i < arguments.length;) args.push(arguments[i++]); i = 0; format = format.replace(/%([dfjs])/g, function($0, $1) { switch ($1) { case "d": return Math.floor(args[i++]); case "f": return Number(args[i++]); case "j": return JSON.stringify(args[i++]); default: return args[i++]; } }); if (i !== args.length) throw Error("argument count mismatch"); return format; } codegen.sprintf = sprintf; codegen.supported = false; try { codegen.supported = codegen("a","b")("return a-b").eof()(2,1) === 1; } catch (e) {} // eslint-disable-line no-empty codegen.verbose = false; },{}],4:[function(require,module,exports){ "use strict"; module.exports = EventEmitter; /** * Constructs a new event emitter instance. * @classdesc A minimal event emitter. * @memberof util * @constructor */ function EventEmitter() { /** * Registered listeners. * @type {Object.<string,*>} * @private */ this._listeners = {}; } /** * Registers an event listener. * @param {string} evt Event name * @param {function} fn Listener * @param {*} [ctx] Listener context * @returns {util.EventEmitter} `this` */ EventEmitter.prototype.on = function on(evt, fn, ctx) { (this._listeners[evt] || (this._listeners[evt] = [])).push({ fn : fn, ctx : ctx || this }); return this; }; /** * Removes an event listener or any matching listeners if arguments are omitted. * @param {string} [evt] Event name. Removes all listeners if omitted. * @param {function} [fn] Listener to remove. Removes all listeners of `evt` if omitted. * @returns {util.EventEmitter} `this` */ EventEmitter.prototype.off = function off(evt, fn) { if (evt === undefined) this._listeners = {}; else { if (fn === undefined) this._listeners[evt] = []; else { var listeners = this._listeners[evt]; for (var i = 0; i < listeners.length;) if (listeners[i].fn === fn) listeners.splice(i, 1); else ++i; } } return this; }; /** * Emits an event by calling its listeners with the specified arguments. * @param {string} evt Event name * @param {...*} args Arguments * @returns {util.EventEmitter} `this` */ EventEmitter.prototype.emit = function emit(evt) { var listeners = this._listeners[evt]; if (listeners) { var args = [], i = 1; for (; i < arguments.length;) args.push(arguments[i++]); for (i = 0; i < listeners.length;) listeners[i].fn.apply(listeners[i++].ctx, args); } return this; }; },{}],5:[function(require,module,exports){ "use strict"; module.exports = fetch; var asPromise = require(1), inquire = require(6); var fs = inquire("fs"); /** * Node-style callback as used by {@link util.fetch}. * @typedef FetchCallback * @type {function} * @param {?Error} error Error, if any, otherwise `null` * @param {string} [contents] File contents, if there hasn't been an error * @returns {undefined} */ /** * Options as used by {@link util.fetch}. * @typedef FetchOptions * @type {Object} * @property {boolean} [binary=false] Whether expecting a binary response * @property {boolean} [xhr=false] If `true`, forces the use of XMLHttpRequest */ /** * Fetches the contents of a file. * @memberof util * @param {string} filename File path or url * @param {FetchOptions} options Fetch options * @param {FetchCallback} callback Callback function * @returns {undefined} */ function fetch(filename, options, callback) { if (typeof options === "function") { callback = options; options = {}; } else if (!options) options = {}; if (!callback) return asPromise(fetch, this, filename, options); // eslint-disable-line no-invalid-this // if a node-like filesystem is present, try it first but fall back to XHR if nothing is found. if (!options.xhr && fs && fs.readFile) return fs.readFile(filename, function fetchReadFileCallback(err, contents) { return err && typeof XMLHttpRequest !== "undefined" ? fetch.xhr(filename, options, callback) : err ? callback(err) : callback(null, options.binary ? contents : contents.toString("utf8")); }); // use the XHR version otherwise. return fetch.xhr(filename, options, callback); } /** * Fetches the contents of a file. * @name util.fetch * @function * @param {string} path File path or url * @param {FetchCallback} callback Callback function * @returns {undefined} * @variation 2 */ /** * Fetches the contents of a file. * @name util.fetch * @function * @param {string} path File path or url * @param {FetchOptions} [options] Fetch options * @returns {Promise<string|Uint8Array>} Promise * @variation 3 */ /**/ fetch.xhr = function fetch_xhr(filename, options, callback) { var xhr = new XMLHttpRequest(); xhr.onreadystatechange /* works everywhere */ = function fetchOnReadyStateChange() { if (xhr.readyState !== 4) return undefined; // local cors security errors return status 0 / empty string, too. afaik this cannot be // reliably distinguished from an actually empty file for security reasons. feel free // to send a pull request if you are aware of a solution. if (xhr.status !== 0 && xhr.status !== 200) return callback(Error("status " + xhr.status)); // if binary data is expected, make sure that some sort of array is returned, even if // ArrayBuffers are not supported. the binary string fallback, however, is unsafe. if (options.binary) { var buffer = xhr.response; if (!buffer) { buffer = []; for (var i = 0; i < xhr.responseText.length; ++i) buffer.push(xhr.responseText.charCodeAt(i) & 255); } return callback(null, typeof Uint8Array !== "undefined" ? new Uint8Array(buffer) : buffer); } return callback(null, xhr.responseText); }; if (options.binary) { // ref: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Sending_and_Receiving_Binary_Data#Receiving_binary_data_in_older_browsers if ("overrideMimeType" in xhr) xhr.overrideMimeType("text/plain; charset=x-user-defined"); xhr.responseType = "arraybuffer"; } xhr.open("GET", filename); xhr.send(); }; },{"1":1,"6":6}],6:[function(require,module,exports){ "use strict"; module.exports = inquire; /** * Requires a module only if available. * @memberof util * @param {string} moduleName Module to require * @returns {?Object} Required module if available and not empty, otherwise `null` */ function inquire(moduleName) { try { var mod = eval("quire".replace(/^/,"re"))(moduleName); // eslint-disable-line no-eval if (mod && (mod.length || Object.keys(mod).length)) return mod; } catch (e) {} // eslint-disable-line no-empty return null; } },{}],7:[function(require,module,exports){ "use strict"; /** * A minimal path module to resolve Unix, Windows and URL paths alike. * @memberof util * @namespace */ var path = exports; var isAbsolute = /** * Tests if the specified path is absolute. * @param {string} path Path to test * @returns {boolean} `true` if path is absolute */ path.isAbsolute = function isAbsolute(path) { return /^(?:\/|\w+:)/.test(path); }; var normalize = /** * Normalizes the specified path. * @param {string} path Path to normalize * @returns {string} Normalized path */ path.normalize = function normalize(path) { path = path.replace(/\\/g, "/") .replace(/\/{2,}/g, "/"); var parts = path.split("/"), absolute = isAbsolute(path), prefix = ""; if (absolute) prefix = parts.shift() + "/"; for (var i = 0; i < parts.length;) { if (parts[i] === "..") { if (i > 0 && parts[i - 1] !== "..") parts.splice(--i, 2); else if (absolute) parts.splice(i, 1); else ++i; } else if (parts[i] === ".") parts.splice(i, 1); else ++i; } return prefix + parts.join("/"); }; /** * Resolves the specified include path against the specified origin path. * @param {string} originPath Path to the origin file * @param {string} includePath Include path relative to origin path * @param {boolean} [alreadyNormalized=false] `true` if both paths are already known to be normalized * @returns {string} Path to the include file */ path.resolve = function resolve(originPath, includePath, alreadyNormalized) { if (!alreadyNormalized) includePath = normalize(includePath); if (isAbsolute(includePath)) return includePath; if (!alreadyNormalized) originPath = normalize(originPath); return (originPath = originPath.replace(/(?:\/|^)[^/]+$/, "")).length ? normalize(originPath + "/" + includePath) : includePath; }; },{}],8:[function(require,module,exports){ "use strict"; module.exports = pool; /** * An allocator as used by {@link util.pool}. * @typedef PoolAllocator * @type {function} * @param {number} size Buffer size * @returns {Uint8Array} Buffer */ /** * A slicer as used by {@link util.pool}. * @typedef PoolSlicer * @type {function} * @param {number} start Start offset * @param {number} end End offset * @returns {Uint8Array} Buffer slice * @this {Uint8Array} */ /** * A general purpose buffer pool. * @memberof util * @function * @param {PoolAllocator} alloc Allocator * @param {PoolSlicer} slice Slicer * @param {number} [size=8192] Slab size * @returns {PoolAllocator} Pooled allocator */ function pool(alloc, slice, size) { var SIZE = size || 8192; var MAX = SIZE >>> 1; var slab = null; var offset = SIZE; return function pool_alloc(size) { if (size < 1 || size > MAX) return alloc(size); if (offset + size > SIZE) { slab = alloc(SIZE); offset = 0; } var buf = slice.call(slab, offset, offset += size); if (offset & 7) // align to 32 bit offset = (offset | 7) + 1; return buf; }; } },{}],9:[function(require,module,exports){ "use strict"; /** * A minimal UTF8 implementation for number arrays. * @memberof util * @namespace */ var utf8 = exports; /** * Calculates the UTF8 byte length of a string. * @param {string} string String * @returns {number} Byte length */ utf8.length = function utf8_length(string) { var len = 0, c = 0; for (var i = 0; i < string.length; ++i) { c = string.charCodeAt(i); if (c < 128) len += 1; else if (c < 2048) len += 2; else if ((c & 0xFC00) === 0xD800 && (string.charCodeAt(i + 1) & 0xFC00) === 0xDC00) { ++i; len += 4; } else len += 3; } return len; }; /** * Reads UTF8 bytes as a string. * @param {Uint8Array} buffer Source buffer * @param {number} start Source start * @param {number} end Source end * @returns {string} String read */ utf8.read = function utf8_read(buffer, start, end) { var len = end - start; if (len < 1) return ""; var parts = null, chunk = [], i = 0, // char offset t; // temporary while (start < end) { t = buffer[start++]; if (t < 128) chunk[i++] = t; else if (t > 191 && t < 224) chunk[i++] = (t & 31) << 6 | buffer[start++] & 63; else if (t > 239 && t < 365) { t = ((t & 7) << 18 | (buffer[start++] & 63) << 12 | (buffer[start++] & 63) << 6 | buffer[start++] & 63) - 0x10000; chunk[i++] = 0xD800 + (t >> 10); chunk[i++] = 0xDC00 + (t & 1023); } else chunk[i++] = (t & 15) << 12 | (buffer[start++] & 63) << 6 | buffer[start++] & 63; if (i > 8191) { (parts || (parts = [])).push(String.fromCharCode.apply(String, chunk)); i = 0; } } if (parts) { if (i) parts.push(String.fromCharCode.apply(String, chunk.slice(0, i))); return parts.join(""); } return String.fromCharCode.apply(String, chunk.slice(0, i)); }; /** * Writes a string as UTF8 bytes. * @param {string} string Source string * @param {Uint8Array} buffer Destination buffer * @param {number} offset Destination offset * @returns {number} Bytes written */ utf8.write = function utf8_write(string, buffer, offset) { var start = offset, c1, // character 1 c2; // character 2 for (var i = 0; i < string.length; ++i) { c1 = string.charCodeAt(i); if (c1 < 128) { buffer[offset++] = c1; } else if (c1 < 2048) { buffer[offset++] = c1 >> 6 | 192; buffer[offset++] = c1 & 63 | 128; } else if ((c1 & 0xFC00) === 0xD800 && ((c2 = string.charCodeAt(i + 1)) & 0xFC00) === 0xDC00) { c1 = 0x10000 + ((c1 & 0x03FF) << 10) + (c2 & 0x03FF); ++i; buffer[offset++] = c1 >> 18 | 240; buffer[offset++] = c1 >> 12 & 63 | 128; buffer[offset++] = c1 >> 6 & 63 | 128; buffer[offset++] = c1 & 63 | 128; } else { buffer[offset++] = c1 >> 12 | 224; buffer[offset++] = c1 >> 6 & 63 | 128; buffer[offset++] = c1 & 63 | 128; } } return offset - start; }; },{}],10:[function(require,module,exports){ "use strict"; module.exports = Class; var Message = require(21), util = require(36); var Type; // cyclic /** * Constructs a new message prototype for the specified reflected type and sets up its constructor. * @classdesc Runtime class providing the tools to create your own custom classes. * @constructor * @param {Type} type Reflected message type * @param {*} [ctor] Custom constructor to set up, defaults to create a generic one if omitted * @returns {Message} Message prototype */ function Class(type, ctor) { if (!Type) Type = require(34); if (!(type instanceof Type)) throw TypeError("type must be a Type"); if (ctor) { if (typeof ctor !== "function") throw TypeError("ctor must be a function"); } else ctor = Class.generate(type).eof(type.name); // named constructor function (codegen is required anyway) // Let's pretend... ctor.constructor = Class; // new Class() -> Message.prototype (ctor.prototype = new Message()).constructor = ctor; // Static methods on Message are instance methods on Class and vice versa util.merge(ctor, Message, true); // Classes and messages reference their reflected type ctor.$type = type; ctor.prototype.$type = type; // Messages have non-enumerable default values on their prototype var i = 0; for (; i < /* initializes */ type.fieldsArray.length; ++i) { // objects on the prototype must be immmutable. users must assign a new object instance and // cannot use Array#push on empty arrays on the prototype for example, as this would modify // the value on the prototype for ALL messages of this type. Hence, these objects are frozen. ctor.prototype[type._fieldsArray[i].name] = Array.isArray(type._fieldsArray[i].resolve().defaultValue) ? util.emptyArray : util.isObject(type._fieldsArray[i].defaultValue) && !type._fieldsArray[i].long ? util.emptyObject : type._fieldsArray[i].defaultValue; // if a long, it is frozen when initialized } // Messages have non-enumerable getters and setters for each virtual oneof field var ctorProperties = {}; for (i = 0; i < /* initializes */ type.oneofsArray.length; ++i) ctorProperties[type._oneofsArray[i].resolve().name] = { get: util.oneOfGetter(type._oneofsArray[i].oneof), set: util.oneOfSetter(type._oneofsArray[i].oneof) }; if (i) Object.defineProperties(ctor.prototype, ctorProperties); // Register type.ctor = ctor; return ctor.prototype; } /** * Generates a constructor function for the specified type. * @param {Type} type Type to use * @returns {Codegen} Codegen instance */ Class.generate = function generate(type) { // eslint-disable-line no-unused-vars /* eslint-disable no-unexpected-multiline */ var gen = util.codegen("p"); // see issue #700 /* for (var i = 0, field; i < type.fieldsArray.length; ++i) if ((field = type._fieldsArray[i]).map) gen ("this%s={}", util.safeProp(field.name)); else if (field.repeated) gen ("this%s=[]", util.safeProp(field.name)); */ return gen ("if(p){") ("for(var ks=Object.keys(p),i=0;i<ks.length;++i)") ("this[ks[i]]=p[ks[i]];") ("}"); /* eslint-enable no-unexpected-multiline */ }; /** * Constructs a new message prototype for the specified reflected type and sets up its constructor. * @function * @param {Type} type Reflected message type * @param {*} [ctor] Custom constructor to set up, defaults to create a generic one if omitted * @returns {Message} Message prototype */ Class.create = Class; // Static methods on Message are instance methods on Class and vice versa Class.prototype = Message; /** * Creates a new message of this type from a plain object. Also converts values to their respective internal types. * @name Class#fromObject * @function * @param {Object.<string,*>} object Plain object * @returns {Message} Message instance */ /** * Creates a new message of this type from a plain object. Also converts values to their respective internal types. * This is an alias of {@link Class#fromObject}. * @name Class#from * @function * @param {Object.<string,*>} object Plain object * @returns {Message} Message instance */ /** * Creates a plain object from a message of this type. Also converts values to other types if specified. * @name Class#toObject * @function * @param {Message} message Message instance * @param {ConversionOptions} [options] Conversion options * @returns {Object.<string,*>} Plain object */ /** * Encodes a message of this type. * @name Class#encode * @function * @param {Message|Object} message Message to encode * @param {Writer} [writer] Writer to use * @returns {Writer} Writer */ /** * Encodes a message of this type preceeded by its length as a varint. * @name Class#encodeDelimited * @function * @param {Message|Object} message Message to encode * @param {Writer} [writer] Writer to use * @returns {Writer} Writer */ /** * Decodes a message of this type. * @name Class#decode * @function * @param {Reader|Uint8Array} reader Reader or buffer to decode * @returns {Message} Decoded message */ /** * Decodes a message of this type preceeded by its length as a varint. * @name Class#decodeDelimited * @function * @param {Reader|Uint8Array} reader Reader or buffer to decode * @returns {Message} Decoded message */ /** * Verifies a message of this type. * @name Class#verify * @function * @param {Message|Object} message Message or plain object to verify * @returns {?string} `null` if valid, otherwise the reason why it is not */ },{"21":21,"34":34,"36":36}],11:[function(require,module,exports){ "use strict"; module.exports = common; /** * Provides common type definitions. * Can also be used to provide additional google types or your own custom types. * @param {string} name Short name as in `google/protobuf/[name].proto` or full file name * @param {Object.<string,*>} json JSON definition within `google.protobuf` if a short name, otherwise the file's root definition * @returns {undefined} * @property {Object.<string,*>} google/protobuf/any.proto Any * @property {Object.<string,*>} google/protobuf/duration.proto Duration * @property {Object.<string,*>} google/protobuf/empty.proto Empty * @property {Object.<string,*>} google/protobuf/struct.proto Struct, Value, NullValue and ListValue * @property {Object.<string,*>} google/protobuf/timestamp.proto Timestamp * @property {Object.<string,*>} google/protobuf/wrappers.proto Wrappers * @example * // manually provides descriptor.proto (assumes google/protobuf/ namespace and .proto extension) * protobuf.common("descriptor", descriptorJson); * * // manually provides a custom definition (uses my.foo namespace) * protobuf.common("my/foo/bar.proto", myFooBarJson); */ function common(name, json) { if (!commonRe.test(name)) { name = "google/protobuf/" + name + ".proto"; json = { nested: { google: { nested: { protobuf: { nested: json } } } } }; } common[name] = json; } var commonRe = /\/|\./; // Not provided because of limited use (feel free to discuss or to provide yourself): // // google/protobuf/descriptor.proto // google/protobuf/field_mask.proto // google/protobuf/source_context.proto // google/protobuf/type.proto // // Stripped and pre-parsed versions of these non-bundled files are instead available as part of // the repository or package within the google/protobuf directory. common("any", { Any: { fields: { type_url: { type: "string", id: 1 }, value: { type: "bytes", id: 2 } } } }); var timeType; common("duration", { Duration: timeType = { fields: { seconds: { type: "int64", id: 1 }, nanos: { type: "int32", id: 2 } } } }); common("timestamp", { Timestamp: timeType }); common("empty", { Empty: { fields: {} } }); common("struct", { Struct: { fields: { fields: { keyType: "string", type: "Value", id: 1 } } }, Value: { oneofs: { kind: { oneof: [ "nullValue", "numberValue", "stringValue", "boolValue", "structValue", "listValue" ] } }, fields: { nullValue: { type: "NullValue", id: 1 }, numberValue: { type: "double", id: 2 }, stringValue: { type: "string", id: 3 }, boolValue: { type: "bool", id: 4 }, structValue: { type: "Struct", id: 5 }, listValue: { type: "ListValue", id: 6 } } }, NullValue: { values: { NULL_VALUE: 0 } }, ListValue: { fields: { values: { rule: "repeated", type: "Value", id: 1 } } } }); common("wrappers", { DoubleValue: { fields: { value: { type: "double", id: 1 } } }, FloatValue: { fields: { value: { type: "float", id: 1 } } }, Int64Value: { fields: { value: { type: "int64", id: 1 } } }, UInt64Value: { fields: { value: { type: "uint64", id: 1 } } }, Int32Value: { fields: { value: { type: "int32", id: 1 } } }, UInt32Value: { fields: { value: { type: "uint32", id: 1 } } }, BoolValue: { fields: { value: { type: "bool", id: 1 } } }, StringValue: { fields: { value: { type: "string", id: 1 } } }, BytesValue: { fields: { value: { type: "bytes", id: 1 } } } }); },{}],12:[function(require,module,exports){ "use strict"; /** * Runtime message from/to plain object converters. * @namespace */ var converter = exports; var Enum = require(15), util = require(36); /** * Generates a partial value fromObject conveter. * @param {Codegen} gen Codegen instance * @param {Field} field Reflected field * @param {number} fieldIndex Field index * @param {string} prop Property reference * @returns {Codegen} Codegen instance * @ignore */ function genValuePartial_fromObject(gen, field, fieldIndex, prop) { /* eslint-disable no-unexpected-multiline, block-scoped-var, no-redeclare */ if (field.resolvedType) { if (field.resolvedType instanceof Enum) { gen ("switch(d%s){", prop); for (var values = field.resolvedType.values, keys = Object.keys(values), i = 0; i < keys.length; ++i) { if (field.repeated && values[keys[i]] === field.typeDefault) gen ("default:"); gen ("case%j:", keys[i]) ("case %j:", values[keys[i]]) ("m%s=%j", prop, values[keys[i]]) ("break"); } gen ("}"); } else gen ("if(typeof d%s!==\"object\")", prop) ("throw TypeError(%j)", field.fullName + ": object expected") ("m%s=types[%d].fromObject(d%s)", prop, fieldIndex, prop); } else { var isUnsigned = false; switch (field.type) { case "double": case "float":gen ("m%s=Number(d%s)", prop, prop); break; case "uint32": case "fixed32": gen ("m%s=d%s>>>0", prop, prop); break; case "int32": case "sint32": case "sfixed32": gen ("m%s=d%s|0", prop, prop); break; case "uint64": isUnsigned = true; // eslint-disable-line no-fallthrough case "int64": case "sint64": case "fixed64": case "sfixed64": gen ("if(util.Long)") ("(m%s=util.Long.fromValue(d%s)).unsigned=%j", prop, prop, isUnsigned) ("else if(typeof d%s===\"string\")", prop) ("m%s=parseInt(d%s,10)", prop, prop) ("else if(typeof d%s===\"number\")", prop) ("m%s=d%s", prop, prop) ("else if(typeof d%s===\"object\")", prop) ("m%s=new util.LongBits(d%s.low>>>0,d%s.high>>>0).toNumber(%s)", prop, prop, prop, isUnsigned ? "true" : ""); break; case "bytes": gen ("if(typeof d%s===\"string\")", prop) ("util.base64.decode(d%s,m%s=util.newBuffer(util.base64.length(d%s)),0)", prop, prop, prop) ("else if(d%s.length)", prop) ("m%s=d%s", prop, prop); break; case "string": gen ("m%s=String(d%s)", prop, prop); break; case "bool": gen ("m%s=Boolean(d%s)", prop, prop); break; /* default: gen ("m%s=d%s", prop, prop); break; */ } } return gen; /* eslint-enable no-unexpected-multiline, block-scoped-var, no-redeclare */ } /** * Generates a plain object to runtime message converter specific to the specified message type. * @param {Type} mtype Message type * @returns {Codegen} Codegen instance */ converter.fromObject = function fromObject(mtype) { /* eslint-disable no-unexpected-multiline, block-scoped-var, no-redeclare */ var fields = mtype.fieldsArray; var gen = util.codegen("d") ("if(d instanceof this.ctor)") ("return d"); if (!fields.length) return gen ("return new this.ctor"); gen ("var m=new this.ctor"); for (var i = 0; i < fields.length; ++i) { var field = fields[i].resolve(), prop = util.safeProp(field.name); // Map fields if (field.map) { gen ("if(d%s){", prop) ("if(typeof d%s!==\"object\")", prop) ("throw TypeError(%j)", field.fullName + ": object expected") ("m%s={}", prop) ("for(var ks=Object.keys(d%s),i=0;i<ks.length;++i){", prop); genValuePartial_fromObject(gen, field, i, prop + "[ks[i]]") ("}") ("}"); // Repeated fields } else if (field.repeated) { gen ("if(d%s){", prop) ("if(!Array.isArray(d%s))", prop) ("throw TypeError(%j)", field.fullName + ": array expected") ("m%s=[]", prop) ("for(var i=0;i<d%s.length;++i){", prop); genValuePartial_fromObject(gen, field, i, prop + "[i]") ("}") ("}"); // Non-repeated fields } else { if (!(field.resolvedType instanceof Enum)) gen // no need to test for null/undefined if an enum (uses switch) ("if(d%s!==undefined&&d%s!==null){", prop, prop); genValuePartial_fromObject(gen, field, i, prop); if (!(field.resolvedType instanceof Enum)) gen ("}"); } } return gen ("return m"); /* eslint-enable no-unexpected-multiline, block-scoped-var, no-redeclare */ }; /** * Generates a partial value toObject converter. * @param {Codegen} gen Codegen instance * @param {Field} field Reflected field * @param {number} fieldIndex Field index * @param {string} prop Property reference * @returns {Codegen} Codegen instance * @ignore */ function genValuePartial_toObject(gen, field, fieldIndex, prop) { /* eslint-disable no-unexpected-multiline, block-scoped-var, no-redeclare */ if (field.resolvedType) { if (field.resolvedType instanceof Enum) gen ("d%s=o.enums===String?types[%d].values[m%s]:m%s", prop, fieldIndex, prop, prop); else gen ("d%s=types[%d].toObject(m%s,o)", prop, fieldIndex, prop); } else { var isUnsigned = false; switch (field.type) { case "uint64": isUnsigned = true; // eslint-disable-line no-fallthrough case "int64": case "sint64": case "fixed64": case "sfixed64": gen ("if(typeof m%s===\"number\")", prop) ("d%s=o.longs===String?String(m%s):m%s", prop, prop, prop) ("else") // Long-like ("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); break; case "bytes": gen ("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); break; default: gen ("d%s=m%s", prop, prop); break; } } return gen; /* eslint-enable no-unexpected-multiline, block-scoped-var, no-redeclare */ } /** * Generates a runtime message to plain object converter specific to the specified message type. * @param {Type} mtype Message type * @returns {Codegen} Codegen instance */ converter.toObject = function toObject(mtype) { /* eslint-disable no-unexpected-multiline, block-scoped-var, no-redeclare */ var fields = mtype.fieldsArray; if (!fields.length) return util.codegen()("return {}"); var gen = util.codegen("m", "o") ("if(!o)") ("o={}") ("var d={}"); var repeatedFields = [], mapFields = [], otherFields = [], i = 0; for (; i < fields.length; ++i) if (fields[i].resolve().repeated) repeatedFields.push(fields[i]); else if (fields[i].map) mapFields.push(fields[i]); else otherFields.push(fields[i]); if (repeatedFields.length) { gen ("if(o.arrays||o.defaults){"); for (i = 0; i < repeatedFields.length; ++i) gen ("d%s=[]", util.safeProp(repeatedFields[i].name)); gen ("}"); } if (mapFields.length) { gen ("if(o.objects||o.defaults){"); for (i = 0; i < mapFields.length; ++i) gen ("d%s={}", util.safeProp(mapFields[i].name)); gen ("}"); } if (otherFields.length) { gen ("if(o.defaults){"); for (i = 0, field; i < otherFields.length; ++i) { var field = otherFields[i], prop = util.safeProp(field.name); if (field.resolvedType instanceof Enum) gen ("d%s=o.enums===String?%j:%j", prop, field.resolvedType.valuesById[field.typeDefault], field.typeDefault); else if (field.long) gen ("if(util.Long){") ("var n=new util.Long(%d,%d,%j)", field.typeDefault.low, field.typeDefault.high, field.typeDefault.unsigned) ("d%s=o.longs===String?n.toString():o.longs===Number?n.toNumber():n", prop) ("}else") ("d%s=o.longs===String?%j:%d", prop, field.typeDefault.toString(), field.typeDefault.toNumber()); else if (field.bytes) gen ("d%s=o.bytes===String?%j:%s", prop, String.fromCharCode.apply(String, field.typeDefault), "[" + Array.prototype.slice.call(field.typeDefault).join(",") + "]"); else gen ("d%s=%j", prop, field.typeDefault); // also messages (=null) } gen ("}"); } for (i = 0, field; i < fields.length; ++i) { var field = fields[i], prop = util.safeProp(field.name); gen ("if(m%s!==undefined&&m%s!==null&&m.hasOwnProperty(%j)){", prop, prop, field.name); if (field.map) { gen ("d%s={}", prop) ("for(var ks2=Object.keys(m%s),j=0;j<ks2.length;++j){", prop); genValuePartial_toObject(gen, field, i, prop + "[ks2[j]]") ("}"); } else if (field.repeated) { gen ("d%s=[]", prop) ("for(var j=0;j<m%s.length;++j){", prop); genValuePartial_toObject(gen, field, i, prop + "[j]") ("}"); } else genValuePartial_toObject(gen, field, i, prop); gen ("}"); } return gen ("return d"); /* eslint-enable no-unexpected-multiline, block-scoped-var, no-redeclare */ }; },{"15":15,"36":36}],13:[function(require,module,exports){ "use strict"; module.exports = decoder; decoder.compat = true; var Enum = require(15), types = require(35), util = require(36); function missing(field) { return "missing required '" + field.name + "'"; } /** * Generates a decoder specific to the specified message type. * @param {Type} mtype Message type * @returns {Codegen} Codegen instance * @property {boolean} compat=true Generates backward/forward compatible decoders (packed fields) */ function decoder(mtype) { /* eslint-disable no-unexpected-multiline */ var gen = util.codegen("r", "l") ("if(!(r instanceof Reader))") ("r=Reader.create(r)") ("var c=l===undefined?r.len:r.pos+l,m=new this.ctor") ("while(r.pos<c){") ("var t=r.uint32()"); if (mtype.group) gen ("if((t&7)===4)") ("break"); gen ("switch(t>>>3){"); var i = 0; for (; i < /* initializes */ mtype.fieldsArray.length; ++i) { var field = mtype._fieldsArray[i].resolve(), type = field.resolvedType instanceof Enum ? "uint32" : field.type, ref = "m" + util.safeProp(field.name); gen ("case %d:", field.id); // Map fields if (field.map) { gen ("r.skip().pos++") // assumes id 1 + key wireType ("if(%s===util.emptyObject)", ref) ("%s={}", ref) ("var k=r.%s()", field.keyType) ("r.pos++"); // assumes id 2 + value wireType if (types.basic[type] === undefined) gen ("%s[typeof k===\"object\"?util.longToHash(k):k]=types[%d].decode(r,r.uint32())", ref, i); // can't be groups else gen ("%s[typeof k===\"object\"?util.longToHash(k):k]=r.%s()", ref, type); // Repeated fields } else if (field.repeated) { gen ("if(!(%s&&%s.length))", ref, ref) ("%s=[]", ref); // Packable (always check for forward and backward compatiblity) if ((decoder.compat || field.packed) && types.packed[type] !== undefined) gen ("if((t&7)===2){") ("var c2=r.uint32()+r.pos") ("while(r.pos<c2)") ("%s.push(r.%s())", ref, type) ("}else"); // Non-packed if (types.basic[type] === undefined) gen(field.resolvedType.group ? "%s.push(types[%d].decode(r))" : "%s.push(types[%d].decode(r,r.u