@apollo/protobufjs
Version:
Protocol Buffers for JavaScript (& TypeScript).
1,640 lines (1,486 loc) • 269 kB
JavaScript
/*!
* protobuf.js (c) 2016, daniel wirtz
* licensed under the bsd-3-clause license
* see: https://github.com/apollographql/protobuf.js for details
*/
(function(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 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;
}
var protobuf = $require(entries[0]);
// Expose globally
protobuf.util.global.protobuf = protobuf;
// Be nice to AMD
if (typeof define === "function" && define.amd)
define(["long"], function(Long) {
if (Long && Long.isLong) {
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;
/**
* Callback as used by {@link util.asPromise}.
* @typedef asPromiseCallback
* @type {function}
* @param {Error|null} error Error, if any
* @param {...*} params Additional arguments
* @returns {undefined}
*/
/**
* Returns a promise from a node-style callback function.
* @memberof util
* @param {asPromiseCallback} fn Function to call
* @param {*} ctx Function context
* @param {...*} params Function arguments
* @returns {Promise<*>} Promisified function
*/
function asPromise(fn, ctx/*, varargs */) {
var params = new Array(arguments.length - 1),
offset = 0,
index = 2,
pending = true;
while (index < arguments.length)
params[offset++] = arguments[index++];
return new Promise(function executor(resolve, reject) {
params[offset] = function callback(err/*, varargs */) {
if (pending) {
pending = false;
if (err)
reject(err);
else {
var params = new Array(arguments.length - 1),
offset = 0;
while (offset < params.length)
params[offset++] = arguments[offset];
resolve.apply(null, params);
}
}
};
try {
fn.apply(ctx || null, params);
} 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 parts = null,
chunk = [];
var i = 0, // output index
j = 0, // goto index
t; // temporary
while (start < end) {
var b = buffer[start++];
switch (j) {
case 0:
chunk[i++] = b64[b >> 2];
t = (b & 3) << 4;
j = 1;
break;
case 1:
chunk[i++] = b64[t | b >> 4];
t = (b & 15) << 2;
j = 2;
break;
case 2:
chunk[i++] = b64[t | b >> 6];
chunk[i++] = b64[b & 63];
j = 0;
break;
}
if (i > 8191) {
(parts || (parts = [])).push(String.fromCharCode.apply(String, chunk));
i = 0;
}
}
if (j) {
chunk[i++] = b64[t];
chunk[i++] = 61;
if (j === 1)
chunk[i++] = 61;
}
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));
};
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;
/**
* Begins generating a function.
* @memberof util
* @param {string[]} functionParams Function parameter names
* @param {string} [functionName] Function name if not anonymous
* @returns {Codegen} Appender that appends code to the function's body
*/
function codegen(functionParams, functionName) {
/* istanbul ignore if */
if (typeof functionParams === "string") {
functionName = functionParams;
functionParams = undefined;
}
var body = [];
/**
* Appends code to the function's body or finishes generation.
* @typedef Codegen
* @type {function}
* @param {string|Object.<string,*>} [formatStringOrScope] Format string or, to finish the function, an object of additional scope variables, if any
* @param {...*} [formatParams] Format parameters
* @returns {Codegen|Function} Itself or the generated function if finished
* @throws {Error} If format parameter counts do not match
*/
function Codegen(formatStringOrScope) {
// note that explicit array handling below makes this ~50% faster
// finish the function
if (typeof formatStringOrScope !== "string") {
var source = toString();
if (codegen.verbose)
console.log("codegen: " + source); // eslint-disable-line no-console
source = "return " + source;
if (formatStringOrScope) {
var scopeKeys = Object.keys(formatStringOrScope),
scopeParams = new Array(scopeKeys.length + 1),
scopeValues = new Array(scopeKeys.length),
scopeOffset = 0;
while (scopeOffset < scopeKeys.length) {
scopeParams[scopeOffset] = scopeKeys[scopeOffset];
scopeValues[scopeOffset] = formatStringOrScope[scopeKeys[scopeOffset++]];
}
scopeParams[scopeOffset] = source;
return Function.apply(null, scopeParams).apply(null, scopeValues); // eslint-disable-line no-new-func
}
return Function(source)(); // eslint-disable-line no-new-func
}
// otherwise append to body
var formatParams = new Array(arguments.length - 1),
formatOffset = 0;
while (formatOffset < formatParams.length)
formatParams[formatOffset] = arguments[++formatOffset];
formatOffset = 0;
formatStringOrScope = formatStringOrScope.replace(/%([%dfijs])/g, function replace($0, $1) {
var value = formatParams[formatOffset++];
switch ($1) {
case "d": case "f": return String(Number(value));
case "i": return String(Math.floor(value));
case "j": return JSON.stringify(value);
case "s": return String(value);
}
return "%";
});
if (formatOffset !== formatParams.length)
throw Error("parameter count mismatch");
body.push(formatStringOrScope);
return Codegen;
}
function toString(functionNameOverride) {
return "function " + (functionNameOverride || functionName || "") + "(" + (functionParams && functionParams.join(",") || "") + "){\n " + body.join("\n ") + "\n}";
}
Codegen.toString = toString;
return Codegen;
}
/**
* Begins generating a function.
* @memberof util
* @function codegen
* @param {string} [functionName] Function name if not anonymous
* @returns {Codegen} Appender that appends code to the function's body
* @variation 2
*/
/**
* When set to `true`, codegen will log generated code to console. Useful for debugging.
* @name util.codegen.verbose
* @type {boolean}
*/
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(7);
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,"7":7}],6:[function(require,module,exports){
"use strict";
module.exports = factory(factory);
/**
* Reads / writes floats / doubles from / to buffers.
* @name util.float
* @namespace
*/
/**
* Writes a 32 bit float to a buffer using little endian byte order.
* @name util.float.writeFloatLE
* @function
* @param {number} val Value to write
* @param {Uint8Array} buf Target buffer
* @param {number} pos Target buffer offset
* @returns {undefined}
*/
/**
* Writes a 32 bit float to a buffer using big endian byte order.
* @name util.float.writeFloatBE
* @function
* @param {number} val Value to write
* @param {Uint8Array} buf Target buffer
* @param {number} pos Target buffer offset
* @returns {undefined}
*/
/**
* Reads a 32 bit float from a buffer using little endian byte order.
* @name util.float.readFloatLE
* @function
* @param {Uint8Array} buf Source buffer
* @param {number} pos Source buffer offset
* @returns {number} Value read
*/
/**
* Reads a 32 bit float from a buffer using big endian byte order.
* @name util.float.readFloatBE
* @function
* @param {Uint8Array} buf Source buffer
* @param {number} pos Source buffer offset
* @returns {number} Value read
*/
/**
* Writes a 64 bit double to a buffer using little endian byte order.
* @name util.float.writeDoubleLE
* @function
* @param {number} val Value to write
* @param {Uint8Array} buf Target buffer
* @param {number} pos Target buffer offset
* @returns {undefined}
*/
/**
* Writes a 64 bit double to a buffer using big endian byte order.
* @name util.float.writeDoubleBE
* @function
* @param {number} val Value to write
* @param {Uint8Array} buf Target buffer
* @param {number} pos Target buffer offset
* @returns {undefined}
*/
/**
* Reads a 64 bit double from a buffer using little endian byte order.
* @name util.float.readDoubleLE
* @function
* @param {Uint8Array} buf Source buffer
* @param {number} pos Source buffer offset
* @returns {number} Value read
*/
/**
* Reads a 64 bit double from a buffer using big endian byte order.
* @name util.float.readDoubleBE
* @function
* @param {Uint8Array} buf Source buffer
* @param {number} pos Source buffer offset
* @returns {number} Value read
*/
// Factory function for the purpose of node-based testing in modified global environments
function factory(exports) {
// float: typed array
if (typeof Float32Array !== "undefined") (function() {
var f32 = new Float32Array([ -0 ]),
f8b = new Uint8Array(f32.buffer),
le = f8b[3] === 128;
function writeFloat_f32_cpy(val, buf, pos) {
f32[0] = val;
buf[pos ] = f8b[0];
buf[pos + 1] = f8b[1];
buf[pos + 2] = f8b[2];
buf[pos + 3] = f8b[3];
}
function writeFloat_f32_rev(val, buf, pos) {
f32[0] = val;
buf[pos ] = f8b[3];
buf[pos + 1] = f8b[2];
buf[pos + 2] = f8b[1];
buf[pos + 3] = f8b[0];
}
/* istanbul ignore next */
exports.writeFloatLE = le ? writeFloat_f32_cpy : writeFloat_f32_rev;
/* istanbul ignore next */
exports.writeFloatBE = le ? writeFloat_f32_rev : writeFloat_f32_cpy;
function readFloat_f32_cpy(buf, pos) {
f8b[0] = buf[pos ];
f8b[1] = buf[pos + 1];
f8b[2] = buf[pos + 2];
f8b[3] = buf[pos + 3];
return f32[0];
}
function readFloat_f32_rev(buf, pos) {
f8b[3] = buf[pos ];
f8b[2] = buf[pos + 1];
f8b[1] = buf[pos + 2];
f8b[0] = buf[pos + 3];
return f32[0];
}
/* istanbul ignore next */
exports.readFloatLE = le ? readFloat_f32_cpy : readFloat_f32_rev;
/* istanbul ignore next */
exports.readFloatBE = le ? readFloat_f32_rev : readFloat_f32_cpy;
// float: ieee754
})(); else (function() {
function writeFloat_ieee754(writeUint, val, buf, pos) {
var sign = val < 0 ? 1 : 0;
if (sign)
val = -val;
if (val === 0)
writeUint(1 / val > 0 ? /* positive */ 0 : /* negative 0 */ 2147483648, buf, pos);
else if (isNaN(val))
writeUint(2143289344, buf, pos);
else if (val > 3.4028234663852886e+38) // +-Infinity
writeUint((sign << 31 | 2139095040) >>> 0, buf, pos);
else if (val < 1.1754943508222875e-38) // denormal
writeUint((sign << 31 | Math.round(val / 1.401298464324817e-45)) >>> 0, buf, pos);
else {
var exponent = Math.floor(Math.log(val) / Math.LN2),
mantissa = Math.round(val * Math.pow(2, -exponent) * 8388608) & 8388607;
writeUint((sign << 31 | exponent + 127 << 23 | mantissa) >>> 0, buf, pos);
}
}
exports.writeFloatLE = writeFloat_ieee754.bind(null, writeUintLE);
exports.writeFloatBE = writeFloat_ieee754.bind(null, writeUintBE);
function readFloat_ieee754(readUint, buf, pos) {
var uint = readUint(buf, pos),
sign = (uint >> 31) * 2 + 1,
exponent = uint >>> 23 & 255,
mantissa = uint & 8388607;
return exponent === 255
? mantissa
? NaN
: sign * Infinity
: exponent === 0 // denormal
? sign * 1.401298464324817e-45 * mantissa
: sign * Math.pow(2, exponent - 150) * (mantissa + 8388608);
}
exports.readFloatLE = readFloat_ieee754.bind(null, readUintLE);
exports.readFloatBE = readFloat_ieee754.bind(null, readUintBE);
})();
// double: typed array
if (typeof Float64Array !== "undefined") (function() {
var f64 = new Float64Array([-0]),
f8b = new Uint8Array(f64.buffer),
le = f8b[7] === 128;
function writeDouble_f64_cpy(val, buf, pos) {
f64[0] = val;
buf[pos ] = f8b[0];
buf[pos + 1] = f8b[1];
buf[pos + 2] = f8b[2];
buf[pos + 3] = f8b[3];
buf[pos + 4] = f8b[4];
buf[pos + 5] = f8b[5];
buf[pos + 6] = f8b[6];
buf[pos + 7] = f8b[7];
}
function writeDouble_f64_rev(val, buf, pos) {
f64[0] = val;
buf[pos ] = f8b[7];
buf[pos + 1] = f8b[6];
buf[pos + 2] = f8b[5];
buf[pos + 3] = f8b[4];
buf[pos + 4] = f8b[3];
buf[pos + 5] = f8b[2];
buf[pos + 6] = f8b[1];
buf[pos + 7] = f8b[0];
}
/* istanbul ignore next */
exports.writeDoubleLE = le ? writeDouble_f64_cpy : writeDouble_f64_rev;
/* istanbul ignore next */
exports.writeDoubleBE = le ? writeDouble_f64_rev : writeDouble_f64_cpy;
function readDouble_f64_cpy(buf, pos) {
f8b[0] = buf[pos ];
f8b[1] = buf[pos + 1];
f8b[2] = buf[pos + 2];
f8b[3] = buf[pos + 3];
f8b[4] = buf[pos + 4];
f8b[5] = buf[pos + 5];
f8b[6] = buf[pos + 6];
f8b[7] = buf[pos + 7];
return f64[0];
}
function readDouble_f64_rev(buf, pos) {
f8b[7] = buf[pos ];
f8b[6] = buf[pos + 1];
f8b[5] = buf[pos + 2];
f8b[4] = buf[pos + 3];
f8b[3] = buf[pos + 4];
f8b[2] = buf[pos + 5];
f8b[1] = buf[pos + 6];
f8b[0] = buf[pos + 7];
return f64[0];
}
/* istanbul ignore next */
exports.readDoubleLE = le ? readDouble_f64_cpy : readDouble_f64_rev;
/* istanbul ignore next */
exports.readDoubleBE = le ? readDouble_f64_rev : readDouble_f64_cpy;
// double: ieee754
})(); else (function() {
function writeDouble_ieee754(writeUint, off0, off1, val, buf, pos) {
var sign = val < 0 ? 1 : 0;
if (sign)
val = -val;
if (val === 0) {
writeUint(0, buf, pos + off0);
writeUint(1 / val > 0 ? /* positive */ 0 : /* negative 0 */ 2147483648, buf, pos + off1);
} else if (isNaN(val)) {
writeUint(0, buf, pos + off0);
writeUint(2146959360, buf, pos + off1);
} else if (val > 1.7976931348623157e+308) { // +-Infinity
writeUint(0, buf, pos + off0);
writeUint((sign << 31 | 2146435072) >>> 0, buf, pos + off1);
} else {
var mantissa;
if (val < 2.2250738585072014e-308) { // denormal
mantissa = val / 5e-324;
writeUint(mantissa >>> 0, buf, pos + off0);
writeUint((sign << 31 | mantissa / 4294967296) >>> 0, buf, pos + off1);
} else {
var exponent = Math.floor(Math.log(val) / Math.LN2);
if (exponent === 1024)
exponent = 1023;
mantissa = val * Math.pow(2, -exponent);
writeUint(mantissa * 4503599627370496 >>> 0, buf, pos + off0);
writeUint((sign << 31 | exponent + 1023 << 20 | mantissa * 1048576 & 1048575) >>> 0, buf, pos + off1);
}
}
}
exports.writeDoubleLE = writeDouble_ieee754.bind(null, writeUintLE, 0, 4);
exports.writeDoubleBE = writeDouble_ieee754.bind(null, writeUintBE, 4, 0);
function readDouble_ieee754(readUint, off0, off1, buf, pos) {
var lo = readUint(buf, pos + off0),
hi = readUint(buf, pos + off1);
var sign = (hi >> 31) * 2 + 1,
exponent = hi >>> 20 & 2047,
mantissa = 4294967296 * (hi & 1048575) + lo;
return exponent === 2047
? mantissa
? NaN
: sign * Infinity
: exponent === 0 // denormal
? sign * 5e-324 * mantissa
: sign * Math.pow(2, exponent - 1075) * (mantissa + 4503599627370496);
}
exports.readDoubleLE = readDouble_ieee754.bind(null, readUintLE, 0, 4);
exports.readDoubleBE = readDouble_ieee754.bind(null, readUintBE, 4, 0);
})();
return exports;
}
// uint helpers
function writeUintLE(val, buf, pos) {
buf[pos ] = val & 255;
buf[pos + 1] = val >>> 8 & 255;
buf[pos + 2] = val >>> 16 & 255;
buf[pos + 3] = val >>> 24;
}
function writeUintBE(val, buf, pos) {
buf[pos ] = val >>> 24;
buf[pos + 1] = val >>> 16 & 255;
buf[pos + 2] = val >>> 8 & 255;
buf[pos + 3] = val & 255;
}
function readUintLE(buf, pos) {
return (buf[pos ]
| buf[pos + 1] << 8
| buf[pos + 2] << 16
| buf[pos + 3] << 24) >>> 0;
}
function readUintBE(buf, pos) {
return (buf[pos ] << 24
| buf[pos + 1] << 16
| buf[pos + 2] << 8
| buf[pos + 3]) >>> 0;
}
},{}],7:[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;
}
},{}],8:[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;
};
},{}],9:[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;
};
}
},{}],10:[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;
};
},{}],11:[function(require,module,exports){
"use strict";
module.exports = common;
var commonRe = /\/|\./;
/**
* 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 {INamespace} google/protobuf/any.proto Any
* @property {INamespace} google/protobuf/duration.proto Duration
* @property {INamespace} google/protobuf/empty.proto Empty
* @property {INamespace} google/protobuf/field_mask.proto FieldMask
* @property {INamespace} google/protobuf/struct.proto Struct, Value, NullValue and ListValue
* @property {INamespace} google/protobuf/timestamp.proto Timestamp
* @property {INamespace} 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;
}
// Not provided because of limited use (feel free to discuss or to provide yourself):
//
// google/protobuf/descriptor.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", {
/**
* Properties of a google.protobuf.Any message.
* @interface IAny
* @type {Object}
* @property {string} [typeUrl]
* @property {Uint8Array} [bytes]
* @memberof common
*/
Any: {
fields: {
type_url: {
type: "string",
id: 1
},
value: {
type: "bytes",
id: 2
}
}
}
});
var timeType;
common("duration", {
/**
* Properties of a google.protobuf.Duration message.
* @interface IDuration
* @type {Object}
* @property {number} [seconds]
* @property {number} [nanos]
* @memberof common
*/
Duration: timeType = {
fields: {
seconds: {
type: "int64",
id: 1
},
nanos: {
type: "int32",
id: 2
}
}
}
});
common("timestamp", {
/**
* Properties of a google.protobuf.Timestamp message.
* @interface ITimestamp
* @type {Object}
* @property {number} [seconds]
* @property {number} [nanos]
* @memberof common
*/
Timestamp: timeType
});
common("empty", {
/**
* Properties of a google.protobuf.Empty message.
* @interface IEmpty
* @memberof common
*/
Empty: {
fields: {}
}
});
common("struct", {
/**
* Properties of a google.protobuf.Struct message.
* @interface IStruct
* @type {Object}
* @property {Object.<string,IValue>} [fields]
* @memberof common
*/
Struct: {
fields: {
fields: {
keyType: "string",
type: "Value",
id: 1
}
}
},
/**
* Properties of a google.protobuf.Value message.
* @interface IValue
* @type {Object}
* @property {string} [kind]
* @property {0} [nullValue]
* @property {number} [numberValue]
* @property {string} [stringValue]
* @property {boolean} [boolValue]
* @property {IStruct} [structValue]
* @property {IListValue} [listValue]
* @memberof common
*/
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
}
},
/**
* Properties of a google.protobuf.ListValue message.
* @interface IListValue
* @type {Object}
* @property {Array.<IValue>} [values]
* @memberof common
*/
ListValue: {
fields: {
values: {
rule: "repeated",
type: "Value",
id: 1
}
}
}
});
common("wrappers", {
/**
* Properties of a google.protobuf.DoubleValue message.
* @interface IDoubleValue
* @type {Object}
* @property {number} [value]
* @memberof common
*/
DoubleValue: {
fields: {
value: {
type: "double",
id: 1
}
}
},
/**
* Properties of a google.protobuf.FloatValue message.
* @interface IFloatValue
* @type {Object}
* @property {number} [value]
* @memberof common
*/
FloatValue: {
fields: {
value: {
type: "float",
id: 1
}
}
},
/**
* Properties of a google.protobuf.Int64Value message.
* @interface IInt64Value
* @type {Object}
* @property {number} [value]
* @memberof common
*/
Int64Value: {
fields: {
value: {
type: "int64",
id: 1
}
}
},
/**
* Properties of a google.protobuf.UInt64Value message.
* @interface IUInt64Value
* @type {Object}
* @property {number} [value]
* @memberof common
*/
UInt64Value: {
fields: {
value: {
type: "uint64",
id: 1
}
}
},
/**
* Properties of a google.protobuf.Int32Value message.
* @interface IInt32Value
* @type {Object}
* @property {number} [value]
* @memberof common
*/
Int32Value: {
fields: {
value: {
type: "int32",
id: 1
}
}
},
/**
* Properties of a google.protobuf.UInt32Value message.
* @interface IUInt32Value
* @type {Object}
* @property {number} [value]
* @memberof common
*/
UInt32Value: {
fields: {
value: {
type: "uint32",
id: 1
}
}
},
/**
* Properties of a google.protobuf.BoolValue message.
* @interface IBoolValue
* @type {Object}
* @property {boolean} [value]
* @memberof common
*/
BoolValue: {
fields: {
value: {
type: "bool",
id: 1
}
}
},
/**
* Properties of a google.protobuf.StringValue message.
* @interface IStringValue
* @type {Object}
* @property {string} [value]
* @memberof common
*/
StringValue: {
fields: {
value: {
type: "string",
id: 1
}
}
},
/**
* Properties of a google.protobuf.BytesValue message.
* @interface IBytesValue
* @type {Object}
* @property {Uint8Array} [value]
* @memberof common
*/
BytesValue: {
fields: {
value: {
type: "bytes",
id: 1
}
}
}
});
common("field_mask", {
/**
* Properties of a google.protobuf.FieldMask message.
* @interface IDoubleValue
* @type {Object}
* @property {number} [value]
* @memberof common
*/
FieldMask: {
fields: {
paths: {
rule: "repeated",
type: "string",
id: 1
}
}
}
});
/**
* Gets the root definition of the specified common proto file.
*
* Bundled definitions are:
* - google/protobuf/any.proto
* - google/protobuf/duration.proto
* - google/protobuf/empty.proto
* - google/protobuf/field_mask.proto
* - google/protobuf/struct.proto
* - google/protobuf/timestamp.proto
* - google/protobuf/wrappers.proto
*
* @param {string} file Proto file name
* @returns {INamespace|null} Root definition or `null` if not defined
*/
common.get = function get(file) {
return common[file] || null;
};
},{}],12:[function(require,module,exports){
"use strict";
/**
* Runtime message from/to plain object converters.
* @namespace
*/
var converter = exports;
var Enum = require(15),
util = require(37);
/**
* 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, ref) {
/* eslint-disable no-unexpected-multiline, block-scoped-var, no-redeclare */
if (ref === undefined) {
ref = "d" + prop;
}
if (field.resolvedType) {
if (field.resolvedType instanceof Enum) { gen
("switch(%s){", ref);
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 %i:", values[keys[i]])
("m%s=%j", prop, values[keys[i]])
("break");
} gen
("}");
} else gen
("if(typeof %s!==\"object\")", ref)
("throw TypeError(%j)", field.fullName + ": object expected")
("m%s=types[%i].fromObject(%s)", prop, fieldIndex, ref);
} else {
var isUnsigned = false;
switch (field.type) {
case "double":
case "float": gen
("m%s=Number(%s)", prop, ref); // also catches "NaN", "Infinity"
break;
case "uint32":
case "fixed32": gen
("m%s=%s>>>0", prop, ref);
break;
case "int32":
case "sint32":
case "sfixed32": gen
("m%s=%s|0", prop, ref);
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(%s)).unsigned=%j", prop, ref, isUnsigned)
("else if(typeof %s===\"string\")", ref)
("m%s=parseInt(%s,10)", prop, ref)
("else if(typeof %s===\"number\")", ref)
("m%s=%s", prop, ref)
("else if(typeof %s===\"object\")", ref)
("m%s=new util.LongBits(%s.low>>>0,%s.high>>>0).toNumber(%s)", prop, ref, ref, isUnsigned ? "true" : "");
break;
case "bytes": gen
("if(typeof %s===\"string\")", ref)
("util.base64.decode(%s,m%s=util.newBuffer(util.base64.length(%s)),0)", ref, prop, ref)
("else if(%s.length)", ref)
("m%s=%s", prop, ref);
break;
case "string": gen
("m%s=String(%s)", prop, ref);
break;
case "bool": gen
("m%s=Boolean(%s)", prop, ref);
break;
/* default: gen
("m%s=%s", prop, ref);
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"], mtype.name + "$fromObject")
("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, /* not sorted */ i, prop + "[ks[i]]")
("}")
("}");
// Repeated fields
} else if (field.repeated) {
gen("if(d%s){", prop);
var arrayRef = "d" + prop;