-},{}],191:[function(require,module,exports){
-// full library entry point.\r
-\r
-"use strict";\r
-module.exports = require("./src/index");\r
-
-},{"./src/index":200}],192:[function(require,module,exports){
-"use strict";\r
-module.exports = common;\r
-\r
-var commonRe = /\/|\./;\r
-\r
-/**\r
- * Provides common type definitions.\r
- * Can also be used to provide additional google types or your own custom types.\r
- * @param {string} name Short name as in `google/protobuf/[name].proto` or full file name\r
- * @param {Object.<string,*>} json JSON definition within `google.protobuf` if a short name, otherwise the file's root definition\r
- * @returns {undefined}\r
- * @property {INamespace} google/protobuf/any.proto Any\r
- * @property {INamespace} google/protobuf/duration.proto Duration\r
- * @property {INamespace} google/protobuf/empty.proto Empty\r
- * @property {INamespace} google/protobuf/field_mask.proto FieldMask\r
- * @property {INamespace} google/protobuf/struct.proto Struct, Value, NullValue and ListValue\r
- * @property {INamespace} google/protobuf/timestamp.proto Timestamp\r
- * @property {INamespace} google/protobuf/wrappers.proto Wrappers\r
- * @example\r
- * // manually provides descriptor.proto (assumes google/protobuf/ namespace and .proto extension)\r
- * protobuf.common("descriptor", descriptorJson);\r
- *\r
- * // manually provides a custom definition (uses my.foo namespace)\r
- * protobuf.common("my/foo/bar.proto", myFooBarJson);\r
- */\r
-function common(name, json) {\r
- if (!commonRe.test(name)) {\r
- name = "google/protobuf/" + name + ".proto";\r
- json = { nested: { google: { nested: { protobuf: { nested: json } } } } };\r
- }\r
- common[name] = json;\r
-}\r
-\r
-// Not provided because of limited use (feel free to discuss or to provide yourself):\r
-//\r
-// google/protobuf/descriptor.proto\r
-// google/protobuf/source_context.proto\r
-// google/protobuf/type.proto\r
-//\r
-// Stripped and pre-parsed versions of these non-bundled files are instead available as part of\r
-// the repository or package within the google/protobuf directory.\r
-\r
-common("any", {\r
-\r
- /**\r
- * Properties of a google.protobuf.Any message.\r
- * @interface IAny\r
- * @type {Object}\r
- * @property {string} [typeUrl]\r
- * @property {Uint8Array} [bytes]\r
- * @memberof common\r
- */\r
- Any: {\r
- fields: {\r
- type_url: {\r
- type: "string",\r
- id: 1\r
- },\r
- value: {\r
- type: "bytes",\r
- id: 2\r
- }\r
- }\r
- }\r
-});\r
-\r
-var timeType;\r
-\r
-common("duration", {\r
-\r
- /**\r
- * Properties of a google.protobuf.Duration message.\r
- * @interface IDuration\r
- * @type {Object}\r
- * @property {number|Long} [seconds]\r
- * @property {number} [nanos]\r
- * @memberof common\r
- */\r
- Duration: timeType = {\r
- fields: {\r
- seconds: {\r
- type: "int64",\r
- id: 1\r
- },\r
- nanos: {\r
- type: "int32",\r
- id: 2\r
- }\r
- }\r
- }\r
-});\r
-\r
-common("timestamp", {\r
-\r
- /**\r
- * Properties of a google.protobuf.Timestamp message.\r
- * @interface ITimestamp\r
- * @type {Object}\r
- * @property {number|Long} [seconds]\r
- * @property {number} [nanos]\r
- * @memberof common\r
- */\r
- Timestamp: timeType\r
-});\r
-\r
-common("empty", {\r
-\r
- /**\r
- * Properties of a google.protobuf.Empty message.\r
- * @interface IEmpty\r
- * @memberof common\r
- */\r
- Empty: {\r
- fields: {}\r
- }\r
-});\r
-\r
-common("struct", {\r
-\r
- /**\r
- * Properties of a google.protobuf.Struct message.\r
- * @interface IStruct\r
- * @type {Object}\r
- * @property {Object.<string,IValue>} [fields]\r
- * @memberof common\r
- */\r
- Struct: {\r
- fields: {\r
- fields: {\r
- keyType: "string",\r
- type: "Value",\r
- id: 1\r
- }\r
- }\r
- },\r
-\r
- /**\r
- * Properties of a google.protobuf.Value message.\r
- * @interface IValue\r
- * @type {Object}\r
- * @property {string} [kind]\r
- * @property {0} [nullValue]\r
- * @property {number} [numberValue]\r
- * @property {string} [stringValue]\r
- * @property {boolean} [boolValue]\r
- * @property {IStruct} [structValue]\r
- * @property {IListValue} [listValue]\r
- * @memberof common\r
- */\r
- Value: {\r
- oneofs: {\r
- kind: {\r
- oneof: [\r
- "nullValue",\r
- "numberValue",\r
- "stringValue",\r
- "boolValue",\r
- "structValue",\r
- "listValue"\r
- ]\r
- }\r
- },\r
- fields: {\r
- nullValue: {\r
- type: "NullValue",\r
- id: 1\r
- },\r
- numberValue: {\r
- type: "double",\r
- id: 2\r
- },\r
- stringValue: {\r
- type: "string",\r
- id: 3\r
- },\r
- boolValue: {\r
- type: "bool",\r
- id: 4\r
- },\r
- structValue: {\r
- type: "Struct",\r
- id: 5\r
- },\r
- listValue: {\r
- type: "ListValue",\r
- id: 6\r
- }\r
- }\r
- },\r
-\r
- NullValue: {\r
- values: {\r
- NULL_VALUE: 0\r
- }\r
- },\r
-\r
- /**\r
- * Properties of a google.protobuf.ListValue message.\r
- * @interface IListValue\r
- * @type {Object}\r
- * @property {Array.<IValue>} [values]\r
- * @memberof common\r
- */\r
- ListValue: {\r
- fields: {\r
- values: {\r
- rule: "repeated",\r
- type: "Value",\r
- id: 1\r
- }\r
- }\r
- }\r
-});\r
-\r
-common("wrappers", {\r
-\r
- /**\r
- * Properties of a google.protobuf.DoubleValue message.\r
- * @interface IDoubleValue\r
- * @type {Object}\r
- * @property {number} [value]\r
- * @memberof common\r
- */\r
- DoubleValue: {\r
- fields: {\r
- value: {\r
- type: "double",\r
- id: 1\r
- }\r
- }\r
- },\r
-\r
- /**\r
- * Properties of a google.protobuf.FloatValue message.\r
- * @interface IFloatValue\r
- * @type {Object}\r
- * @property {number} [value]\r
- * @memberof common\r
- */\r
- FloatValue: {\r
- fields: {\r
- value: {\r
- type: "float",\r
- id: 1\r
- }\r
- }\r
- },\r
-\r
- /**\r
- * Properties of a google.protobuf.Int64Value message.\r
- * @interface IInt64Value\r
- * @type {Object}\r
- * @property {number|Long} [value]\r
- * @memberof common\r
- */\r
- Int64Value: {\r
- fields: {\r
- value: {\r
- type: "int64",\r
- id: 1\r
- }\r
- }\r
- },\r
-\r
- /**\r
- * Properties of a google.protobuf.UInt64Value message.\r
- * @interface IUInt64Value\r
- * @type {Object}\r
- * @property {number|Long} [value]\r
- * @memberof common\r
- */\r
- UInt64Value: {\r
- fields: {\r
- value: {\r
- type: "uint64",\r
- id: 1\r
- }\r
- }\r
- },\r
-\r
- /**\r
- * Properties of a google.protobuf.Int32Value message.\r
- * @interface IInt32Value\r
- * @type {Object}\r
- * @property {number} [value]\r
- * @memberof common\r
- */\r
- Int32Value: {\r
- fields: {\r
- value: {\r
- type: "int32",\r
- id: 1\r
- }\r
- }\r
- },\r
-\r
- /**\r
- * Properties of a google.protobuf.UInt32Value message.\r
- * @interface IUInt32Value\r
- * @type {Object}\r
- * @property {number} [value]\r
- * @memberof common\r
- */\r
- UInt32Value: {\r
- fields: {\r
- value: {\r
- type: "uint32",\r
- id: 1\r
- }\r
- }\r
- },\r
-\r
- /**\r
- * Properties of a google.protobuf.BoolValue message.\r
- * @interface IBoolValue\r
- * @type {Object}\r
- * @property {boolean} [value]\r
- * @memberof common\r
- */\r
- BoolValue: {\r
- fields: {\r
- value: {\r
- type: "bool",\r
- id: 1\r
- }\r
- }\r
- },\r
-\r
- /**\r
- * Properties of a google.protobuf.StringValue message.\r
- * @interface IStringValue\r
- * @type {Object}\r
- * @property {string} [value]\r
- * @memberof common\r
- */\r
- StringValue: {\r
- fields: {\r
- value: {\r
- type: "string",\r
- id: 1\r
- }\r
- }\r
- },\r
-\r
- /**\r
- * Properties of a google.protobuf.BytesValue message.\r
- * @interface IBytesValue\r
- * @type {Object}\r
- * @property {Uint8Array} [value]\r
- * @memberof common\r
- */\r
- BytesValue: {\r
- fields: {\r
- value: {\r
- type: "bytes",\r
- id: 1\r
- }\r
- }\r
- }\r
-});\r
-\r
-common("field_mask", {\r
-\r
- /**\r
- * Properties of a google.protobuf.FieldMask message.\r
- * @interface IDoubleValue\r
- * @type {Object}\r
- * @property {number} [value]\r
- * @memberof common\r
- */\r
- FieldMask: {\r
- fields: {\r
- paths: {\r
- rule: "repeated",\r
- type: "string",\r
- id: 1\r
- }\r
- }\r
- }\r
-});\r
-\r
-/**\r
- * Gets the root definition of the specified common proto file.\r
- *\r
- * Bundled definitions are:\r
- * - google/protobuf/any.proto\r
- * - google/protobuf/duration.proto\r
- * - google/protobuf/empty.proto\r
- * - google/protobuf/field_mask.proto\r
- * - google/protobuf/struct.proto\r
- * - google/protobuf/timestamp.proto\r
- * - google/protobuf/wrappers.proto\r
- *\r
- * @param {string} file Proto file name\r
- * @returns {INamespace|null} Root definition or `null` if not defined\r
- */\r
-common.get = function get(file) {\r
- return common[file] || null;\r
-};\r
-
-},{}],193:[function(require,module,exports){
-"use strict";\r
-/**\r
- * Runtime message from/to plain object converters.\r
- * @namespace\r
- */\r
-var converter = exports;\r
-\r
-var Enum = require("./enum"),\r
- util = require("./util");\r
-\r
-/**\r
- * Generates a partial value fromObject conveter.\r
- * @param {Codegen} gen Codegen instance\r
- * @param {Field} field Reflected field\r
- * @param {number} fieldIndex Field index\r
- * @param {string} prop Property reference\r
- * @returns {Codegen} Codegen instance\r
- * @ignore\r
- */\r
-function genValuePartial_fromObject(gen, field, fieldIndex, prop) {\r
- /* eslint-disable no-unexpected-multiline, block-scoped-var, no-redeclare */\r
- if (field.resolvedType) {\r
- if (field.resolvedType instanceof Enum) { gen\r
- ("switch(d%s){", prop);\r
- for (var values = field.resolvedType.values, keys = Object.keys(values), i = 0; i < keys.length; ++i) {\r
- if (field.repeated && values[keys[i]] === field.typeDefault) gen\r
- ("default:");\r
- gen\r
- ("case%j:", keys[i])\r
- ("case %i:", values[keys[i]])\r
- ("m%s=%j", prop, values[keys[i]])\r
- ("break");\r
- } gen\r
- ("}");\r
- } else gen\r
- ("if(typeof d%s!==\"object\")", prop)\r
- ("throw TypeError(%j)", field.fullName + ": object expected")\r
- ("m%s=types[%i].fromObject(d%s)", prop, fieldIndex, prop);\r
- } else {\r
- var isUnsigned = false;\r
- switch (field.type) {\r
- case "double":\r
- case "float": gen\r
- ("m%s=Number(d%s)", prop, prop); // also catches "NaN", "Infinity"\r
- break;\r
- case "uint32":\r
- case "fixed32": gen\r
- ("m%s=d%s>>>0", prop, prop);\r
- break;\r
- case "int32":\r
- case "sint32":\r
- case "sfixed32": gen\r
- ("m%s=d%s|0", prop, prop);\r
- break;\r
- case "uint64":\r
- isUnsigned = true;\r
- // eslint-disable-line no-fallthrough\r
- case "int64":\r
- case "sint64":\r
- case "fixed64":\r
- case "sfixed64": gen\r
- ("if(util.Long)")\r
- ("(m%s=util.Long.fromValue(d%s)).unsigned=%j", prop, prop, isUnsigned)\r
- ("else if(typeof d%s===\"string\")", prop)\r
- ("m%s=parseInt(d%s,10)", prop, prop)\r
- ("else if(typeof d%s===\"number\")", prop)\r
- ("m%s=d%s", prop, prop)\r
- ("else if(typeof d%s===\"object\")", prop)\r
- ("m%s=new util.LongBits(d%s.low>>>0,d%s.high>>>0).toNumber(%s)", prop, prop, prop, isUnsigned ? "true" : "");\r
- break;\r
- case "bytes": gen\r
- ("if(typeof d%s===\"string\")", prop)\r
- ("util.base64.decode(d%s,m%s=util.newBuffer(util.base64.length(d%s)),0)", prop, prop, prop)\r
- ("else if(d%s.length)", prop)\r
- ("m%s=d%s", prop, prop);\r
- break;\r
- case "string": gen\r
- ("m%s=String(d%s)", prop, prop);\r
- break;\r
- case "bool": gen\r
- ("m%s=Boolean(d%s)", prop, prop);\r
- break;\r
- /* default: gen\r
- ("m%s=d%s", prop, prop);\r
- break; */\r
- }\r
- }\r
- return gen;\r
- /* eslint-enable no-unexpected-multiline, block-scoped-var, no-redeclare */\r
-}\r
-\r
-/**\r
- * Generates a plain object to runtime message converter specific to the specified message type.\r
- * @param {Type} mtype Message type\r
- * @returns {Codegen} Codegen instance\r
- */\r
-converter.fromObject = function fromObject(mtype) {\r
- /* eslint-disable no-unexpected-multiline, block-scoped-var, no-redeclare */\r
- var fields = mtype.fieldsArray;\r
- var gen = util.codegen(["d"], mtype.name + "$fromObject")\r
- ("if(d instanceof this.ctor)")\r
- ("return d");\r
- if (!fields.length) return gen\r
- ("return new this.ctor");\r
- gen\r
- ("var m=new this.ctor");\r
- for (var i = 0; i < fields.length; ++i) {\r
- var field = fields[i].resolve(),\r
- prop = util.safeProp(field.name);\r
-\r
- // Map fields\r
- if (field.map) { gen\r
- ("if(d%s){", prop)\r
- ("if(typeof d%s!==\"object\")", prop)\r
- ("throw TypeError(%j)", field.fullName + ": object expected")\r
- ("m%s={}", prop)\r
- ("for(var ks=Object.keys(d%s),i=0;i<ks.length;++i){", prop);\r
- genValuePartial_fromObject(gen, field, /* not sorted */ i, prop + "[ks[i]]")\r
- ("}")\r
- ("}");\r
-\r
- // Repeated fields\r
- } else if (field.repeated) { gen\r
- ("if(d%s){", prop)\r
- ("if(!Array.isArray(d%s))", prop)\r
- ("throw TypeError(%j)", field.fullName + ": array expected")\r
- ("m%s=[]", prop)\r
- ("for(var i=0;i<d%s.length;++i){", prop);\r
- genValuePartial_fromObject(gen, field, /* not sorted */ i, prop + "[i]")\r
- ("}")\r
- ("}");\r
-\r
- // Non-repeated fields\r
- } else {\r
- if (!(field.resolvedType instanceof Enum)) gen // no need to test for null/undefined if an enum (uses switch)\r
- ("if(d%s!=null){", prop); // !== undefined && !== null\r
- genValuePartial_fromObject(gen, field, /* not sorted */ i, prop);\r
- if (!(field.resolvedType instanceof Enum)) gen\r
- ("}");\r
- }\r
- } return gen\r
- ("return m");\r
- /* eslint-enable no-unexpected-multiline, block-scoped-var, no-redeclare */\r
-};\r
-\r
-/**\r
- * Generates a partial value toObject converter.\r
- * @param {Codegen} gen Codegen instance\r
- * @param {Field} field Reflected field\r
- * @param {number} fieldIndex Field index\r
- * @param {string} prop Property reference\r
- * @returns {Codegen} Codegen instance\r
- * @ignore\r
- */\r
-function genValuePartial_toObject(gen, field, fieldIndex, prop) {\r
- /* eslint-disable no-unexpected-multiline, block-scoped-var, no-redeclare */\r
- if (field.resolvedType) {\r
- if (field.resolvedType instanceof Enum) gen\r
- ("d%s=o.enums===String?types[%i].values[m%s]:m%s", prop, fieldIndex, prop, prop);\r
- else gen\r
- ("d%s=types[%i].toObject(m%s,o)", prop, fieldIndex, prop);\r
- } else {\r
- var isUnsigned = false;\r
- switch (field.type) {\r
- case "double":\r
- case "float": gen\r
- ("d%s=o.json&&!isFinite(m%s)?String(m%s):m%s", prop, prop, prop, prop);\r
- break;\r
- case "uint64":\r
- isUnsigned = true;\r
- // eslint-disable-line no-fallthrough\r
- case "int64":\r
- case "sint64":\r
- case "fixed64":\r
- case "sfixed64": gen\r
- ("if(typeof m%s===\"number\")", prop)\r
- ("d%s=o.longs===String?String(m%s):m%s", prop, prop, prop)\r
- ("else") // Long-like\r
- ("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);\r
- break;\r
- case "bytes": gen\r
- ("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);\r
- break;\r
- default: gen\r
- ("d%s=m%s", prop, prop);\r
- break;\r
- }\r
- }\r
- return gen;\r
- /* eslint-enable no-unexpected-multiline, block-scoped-var, no-redeclare */\r
-}\r
-\r
-/**\r
- * Generates a runtime message to plain object converter specific to the specified message type.\r
- * @param {Type} mtype Message type\r
- * @returns {Codegen} Codegen instance\r
- */\r
-converter.toObject = function toObject(mtype) {\r
- /* eslint-disable no-unexpected-multiline, block-scoped-var, no-redeclare */\r
- var fields = mtype.fieldsArray.slice().sort(util.compareFieldsById);\r
- if (!fields.length)\r
- return util.codegen()("return {}");\r
- var gen = util.codegen(["m", "o"], mtype.name + "$toObject")\r
- ("if(!o)")\r
- ("o={}")\r
- ("var d={}");\r
-\r
- var repeatedFields = [],\r
- mapFields = [],\r
- normalFields = [],\r
- i = 0;\r
- for (; i < fields.length; ++i)\r
- if (!fields[i].partOf)\r
- ( fields[i].resolve().repeated ? repeatedFields\r
- : fields[i].map ? mapFields\r
- : normalFields).push(fields[i]);\r
-\r
- if (repeatedFields.length) { gen\r
- ("if(o.arrays||o.defaults){");\r
- for (i = 0; i < repeatedFields.length; ++i) gen\r
- ("d%s=[]", util.safeProp(repeatedFields[i].name));\r
- gen\r
- ("}");\r
- }\r
-\r
- if (mapFields.length) { gen\r
- ("if(o.objects||o.defaults){");\r
- for (i = 0; i < mapFields.length; ++i) gen\r
- ("d%s={}", util.safeProp(mapFields[i].name));\r
- gen\r
- ("}");\r
- }\r
-\r
- if (normalFields.length) { gen\r
- ("if(o.defaults){");\r
- for (i = 0; i < normalFields.length; ++i) {\r
- var field = normalFields[i],\r
- prop = util.safeProp(field.name);\r
- if (field.resolvedType instanceof Enum) gen\r
- ("d%s=o.enums===String?%j:%j", prop, field.resolvedType.valuesById[field.typeDefault], field.typeDefault);\r
- else if (field.long) gen\r
- ("if(util.Long){")\r
- ("var n=new util.Long(%i,%i,%j)", field.typeDefault.low, field.typeDefault.high, field.typeDefault.unsigned)\r
- ("d%s=o.longs===String?n.toString():o.longs===Number?n.toNumber():n", prop)\r
- ("}else")\r
- ("d%s=o.longs===String?%j:%i", prop, field.typeDefault.toString(), field.typeDefault.toNumber());\r
- else if (field.bytes) gen\r
- ("d%s=o.bytes===String?%j:%s", prop, String.fromCharCode.apply(String, field.typeDefault), "[" + Array.prototype.slice.call(field.typeDefault).join(",") + "]");\r
- else gen\r
- ("d%s=%j", prop, field.typeDefault); // also messages (=null)\r
- } gen\r
- ("}");\r
- }\r
- var hasKs2 = false;\r
- for (i = 0; i < fields.length; ++i) {\r
- var field = fields[i],\r
- index = mtype._fieldsArray.indexOf(field),\r
- prop = util.safeProp(field.name);\r
- if (field.map) {\r
- if (!hasKs2) { hasKs2 = true; gen\r
- ("var ks2");\r
- } gen\r
- ("if(m%s&&(ks2=Object.keys(m%s)).length){", prop, prop)\r
- ("d%s={}", prop)\r
- ("for(var j=0;j<ks2.length;++j){");\r
- genValuePartial_toObject(gen, field, /* sorted */ index, prop + "[ks2[j]]")\r
- ("}");\r
- } else if (field.repeated) { gen\r
- ("if(m%s&&m%s.length){", prop, prop)\r
- ("d%s=[]", prop)\r
- ("for(var j=0;j<m%s.length;++j){", prop);\r
- genValuePartial_toObject(gen, field, /* sorted */ index, prop + "[j]")\r
- ("}");\r
- } else { gen\r
- ("if(m%s!=null&&m.hasOwnProperty(%j)){", prop, field.name); // !== undefined && !== null\r
- genValuePartial_toObject(gen, field, /* sorted */ index, prop);\r
- if (field.partOf) gen\r
- ("if(o.oneofs)")\r
- ("d%s=%j", util.safeProp(field.partOf.name), field.name);\r
- }\r
- gen\r
- ("}");\r
- }\r
- return gen\r
- ("return d");\r
- /* eslint-enable no-unexpected-multiline, block-scoped-var, no-redeclare */\r
-};\r
-
-},{"./enum":196,"./util":218}],194:[function(require,module,exports){
-"use strict";\r
-module.exports = decoder;\r
-\r
-var Enum = require("./enum"),\r
- types = require("./types"),\r
- util = require("./util");\r
-\r
-function missing(field) {\r
- return "missing required '" + field.name + "'";\r
-}\r
-\r
-/**\r
- * Generates a decoder specific to the specified message type.\r
- * @param {Type} mtype Message type\r
- * @returns {Codegen} Codegen instance\r
- */\r
-function decoder(mtype) {\r
- /* eslint-disable no-unexpected-multiline */\r
- var gen = util.codegen(["r", "l"], mtype.name + "$decode")\r
- ("if(!(r instanceof Reader))")\r
- ("r=Reader.create(r)")\r
- ("var c=l===undefined?r.len:r.pos+l,m=new this.ctor" + (mtype.fieldsArray.filter(function(field) { return field.map; }).length ? ",k" : ""))\r
- ("while(r.pos<c){")\r
- ("var t=r.uint32()");\r
- if (mtype.group) gen\r
- ("if((t&7)===4)")\r
- ("break");\r
- gen\r
- ("switch(t>>>3){");\r
-\r
- var i = 0;\r
- for (; i < /* initializes */ mtype.fieldsArray.length; ++i) {\r
- var field = mtype._fieldsArray[i].resolve(),\r
- type = field.resolvedType instanceof Enum ? "int32" : field.type,\r
- ref = "m" + util.safeProp(field.name); gen\r
- ("case %i:", field.id);\r
-\r
- // Map fields\r
- if (field.map) { gen\r
- ("r.skip().pos++") // assumes id 1 + key wireType\r
- ("if(%s===util.emptyObject)", ref)\r
- ("%s={}", ref)\r
- ("k=r.%s()", field.keyType)\r
- ("r.pos++"); // assumes id 2 + value wireType\r
- if (types.long[field.keyType] !== undefined) {\r
- if (types.basic[type] === undefined) gen\r
- ("%s[typeof k===\"object\"?util.longToHash(k):k]=types[%i].decode(r,r.uint32())", ref, i); // can't be groups\r
- else gen\r
- ("%s[typeof k===\"object\"?util.longToHash(k):k]=r.%s()", ref, type);\r
- } else {\r
- if (types.basic[type] === undefined) gen\r
- ("%s[k]=types[%i].decode(r,r.uint32())", ref, i); // can't be groups\r
- else gen\r
- ("%s[k]=r.%s()", ref, type);\r
- }\r
-\r
- // Repeated fields\r
- } else if (field.repeated) { gen\r
-\r
- ("if(!(%s&&%s.length))", ref, ref)\r
- ("%s=[]", ref);\r
-\r
- // Packable (always check for forward and backward compatiblity)\r
- if (types.packed[type] !== undefined) gen\r
- ("if((t&7)===2){")\r
- ("var c2=r.uint32()+r.pos")\r
- ("while(r.pos<c2)")\r
- ("%s.push(r.%s())", ref, type)\r
- ("}else");\r
-\r
- // Non-packed\r
- if (types.basic[type] === undefined) gen(field.resolvedType.group\r
- ? "%s.push(types[%i].decode(r))"\r
- : "%s.push(types[%i].decode(r,r.uint32()))", ref, i);\r
- else gen\r
- ("%s.push(r.%s())", ref, type);\r
-\r
- // Non-repeated\r
- } else if (types.basic[type] === undefined) gen(field.resolvedType.group\r
- ? "%s=types[%i].decode(r)"\r
- : "%s=types[%i].decode(r,r.uint32())", ref, i);\r
- else gen\r
- ("%s=r.%s()", ref, type);\r
- gen\r
- ("break");\r
- // Unknown fields\r
- } gen\r
- ("default:")\r
- ("r.skipType(t&7)")\r
- ("break")\r
-\r
- ("}")\r
- ("}");\r
-\r
- // Field presence\r
- for (i = 0; i < mtype._fieldsArray.length; ++i) {\r
- var rfield = mtype._fieldsArray[i];\r
- if (rfield.required) gen\r
- ("if(!m.hasOwnProperty(%j))", rfield.name)\r
- ("throw util.ProtocolError(%j,{instance:m})", missing(rfield));\r
- }\r
-\r
- return gen\r
- ("return m");\r
- /* eslint-enable no-unexpected-multiline */\r
-}\r
-
-},{"./enum":196,"./types":217,"./util":218}],195:[function(require,module,exports){
-"use strict";\r
-module.exports = encoder;\r
-\r
-var Enum = require("./enum"),\r
- types = require("./types"),\r
- util = require("./util");\r
-\r
-/**\r
- * Generates a partial message type encoder.\r
- * @param {Codegen} gen Codegen instance\r
- * @param {Field} field Reflected field\r
- * @param {number} fieldIndex Field index\r
- * @param {string} ref Variable reference\r
- * @returns {Codegen} Codegen instance\r
- * @ignore\r
- */\r
-function genTypePartial(gen, field, fieldIndex, ref) {\r
- return field.resolvedType.group\r
- ? gen("types[%i].encode(%s,w.uint32(%i)).uint32(%i)", fieldIndex, ref, (field.id << 3 | 3) >>> 0, (field.id << 3 | 4) >>> 0)\r
- : gen("types[%i].encode(%s,w.uint32(%i).fork()).ldelim()", fieldIndex, ref, (field.id << 3 | 2) >>> 0);\r
-}\r
-\r
-/**\r
- * Generates an encoder specific to the specified message type.\r
- * @param {Type} mtype Message type\r
- * @returns {Codegen} Codegen instance\r
- */\r
-function encoder(mtype) {\r
- /* eslint-disable no-unexpected-multiline, block-scoped-var, no-redeclare */\r
- var gen = util.codegen(["m", "w"], mtype.name + "$encode")\r
- ("if(!w)")\r
- ("w=Writer.create()");\r
-\r
- var i, ref;\r
-\r
- // "when a message is serialized its known fields should be written sequentially by field number"\r
- var fields = /* initializes */ mtype.fieldsArray.slice().sort(util.compareFieldsById);\r
-\r
- for (var i = 0; i < fields.length; ++i) {\r
- var field = fields[i].resolve(),\r
- index = mtype._fieldsArray.indexOf(field),\r
- type = field.resolvedType instanceof Enum ? "int32" : field.type,\r
- wireType = types.basic[type];\r
- ref = "m" + util.safeProp(field.name);\r
-\r
- // Map fields\r
- if (field.map) {\r
- gen\r
- ("if(%s!=null&&m.hasOwnProperty(%j)){", ref, field.name) // !== undefined && !== null\r
- ("for(var ks=Object.keys(%s),i=0;i<ks.length;++i){", ref)\r
- ("w.uint32(%i).fork().uint32(%i).%s(ks[i])", (field.id << 3 | 2) >>> 0, 8 | types.mapKey[field.keyType], field.keyType);\r
- if (wireType === undefined) gen\r
- ("types[%i].encode(%s[ks[i]],w.uint32(18).fork()).ldelim().ldelim()", index, ref); // can't be groups\r
- else gen\r
- (".uint32(%i).%s(%s[ks[i]]).ldelim()", 16 | wireType, type, ref);\r
- gen\r
- ("}")\r
- ("}");\r
-\r
- // Repeated fields\r
- } else if (field.repeated) { gen\r
- ("if(%s!=null&&%s.length){", ref, ref); // !== undefined && !== null\r
-\r
- // Packed repeated\r
- if (field.packed && types.packed[type] !== undefined) { gen\r
-\r
- ("w.uint32(%i).fork()", (field.id << 3 | 2) >>> 0)\r
- ("for(var i=0;i<%s.length;++i)", ref)\r
- ("w.%s(%s[i])", type, ref)\r
- ("w.ldelim()");\r
-\r
- // Non-packed\r
- } else { gen\r
-\r
- ("for(var i=0;i<%s.length;++i)", ref);\r
- if (wireType === undefined)\r
- genTypePartial(gen, field, index, ref + "[i]");\r
- else gen\r
- ("w.uint32(%i).%s(%s[i])", (field.id << 3 | wireType) >>> 0, type, ref);\r
-\r
- } gen\r
- ("}");\r
-\r
- // Non-repeated\r
- } else {\r
- if (field.optional) gen\r
- ("if(%s!=null&&m.hasOwnProperty(%j))", ref, field.name); // !== undefined && !== null\r
-\r
- if (wireType === undefined)\r
- genTypePartial(gen, field, index, ref);\r
- else gen\r
- ("w.uint32(%i).%s(%s)", (field.id << 3 | wireType) >>> 0, type, ref);\r
-\r
- }\r
- }\r
-\r
- return gen\r
- ("return w");\r
- /* eslint-enable no-unexpected-multiline, block-scoped-var, no-redeclare */\r
-}
-},{"./enum":196,"./types":217,"./util":218}],196:[function(require,module,exports){
-"use strict";\r
-module.exports = Enum;\r
-\r
-// extends ReflectionObject\r
-var ReflectionObject = require("./object");\r
-((Enum.prototype = Object.create(ReflectionObject.prototype)).constructor = Enum).className = "Enum";\r
-\r
-var Namespace = require("./namespace"),\r
- util = require("./util");\r
-\r
-/**\r
- * Constructs a new enum instance.\r
- * @classdesc Reflected enum.\r
- * @extends ReflectionObject\r
- * @constructor\r
- * @param {string} name Unique name within its namespace\r
- * @param {Object.<string,number>} [values] Enum values as an object, by name\r
- * @param {Object.<string,*>} [options] Declared options\r
- * @param {string} [comment] The comment for this enum\r
- * @param {Object.<string,string>} [comments] The value comments for this enum\r
- */\r
-function Enum(name, values, options, comment, comments) {\r
- ReflectionObject.call(this, name, options);\r
-\r
- if (values && typeof values !== "object")\r
- throw TypeError("values must be an object");\r
-\r
- /**\r
- * Enum values by id.\r
- * @type {Object.<number,string>}\r
- */\r
- this.valuesById = {};\r
-\r
- /**\r
- * Enum values by name.\r
- * @type {Object.<string,number>}\r
- */\r
- this.values = Object.create(this.valuesById); // toJSON, marker\r
-\r
- /**\r
- * Enum comment text.\r
- * @type {string|null}\r
- */\r
- this.comment = comment;\r
-\r
- /**\r
- * Value comment texts, if any.\r
- * @type {Object.<string,string>}\r
- */\r
- this.comments = comments || {};\r
-\r
- /**\r
- * Reserved ranges, if any.\r
- * @type {Array.<number[]|string>}\r
- */\r
- this.reserved = undefined; // toJSON\r
-\r
- // Note that values inherit valuesById on their prototype which makes them a TypeScript-\r
- // compatible enum. This is used by pbts to write actual enum definitions that work for\r
- // static and reflection code alike instead of emitting generic object definitions.\r
-\r
- if (values)\r
- for (var keys = Object.keys(values), i = 0; i < keys.length; ++i)\r
- if (typeof values[keys[i]] === "number") // use forward entries only\r
- this.valuesById[ this.values[keys[i]] = values[keys[i]] ] = keys[i];\r
-}\r
-\r
-/**\r
- * Enum descriptor.\r
- * @interface IEnum\r
- * @property {Object.<string,number>} values Enum values\r
- * @property {Object.<string,*>} [options] Enum options\r
- */\r
-\r
-/**\r
- * Constructs an enum from an enum descriptor.\r
- * @param {string} name Enum name\r
- * @param {IEnum} json Enum descriptor\r
- * @returns {Enum} Created enum\r
- * @throws {TypeError} If arguments are invalid\r
- */\r
-Enum.fromJSON = function fromJSON(name, json) {\r
- var enm = new Enum(name, json.values, json.options, json.comment, json.comments);\r
- enm.reserved = json.reserved;\r
- return enm;\r
-};\r
-\r
-/**\r
- * Converts this enum to an enum descriptor.\r
- * @param {IToJSONOptions} [toJSONOptions] JSON conversion options\r
- * @returns {IEnum} Enum descriptor\r
- */\r
-Enum.prototype.toJSON = function toJSON(toJSONOptions) {\r
- var keepComments = toJSONOptions ? Boolean(toJSONOptions.keepComments) : false;\r
- return util.toObject([\r
- "options" , this.options,\r
- "values" , this.values,\r
- "reserved" , this.reserved && this.reserved.length ? this.reserved : undefined,\r
- "comment" , keepComments ? this.comment : undefined,\r
- "comments" , keepComments ? this.comments : undefined\r
- ]);\r
-};\r
-\r
-/**\r
- * Adds a value to this enum.\r
- * @param {string} name Value name\r
- * @param {number} id Value id\r
- * @param {string} [comment] Comment, if any\r
- * @returns {Enum} `this`\r
- * @throws {TypeError} If arguments are invalid\r
- * @throws {Error} If there is already a value with this name or id\r
- */\r
-Enum.prototype.add = function add(name, id, comment) {\r
- // utilized by the parser but not by .fromJSON\r
-\r
- if (!util.isString(name))\r
- throw TypeError("name must be a string");\r
-\r
- if (!util.isInteger(id))\r
- throw TypeError("id must be an integer");\r
-\r
- if (this.values[name] !== undefined)\r
- throw Error("duplicate name '" + name + "' in " + this);\r
-\r
- if (this.isReservedId(id))\r
- throw Error("id " + id + " is reserved in " + this);\r
-\r
- if (this.isReservedName(name))\r
- throw Error("name '" + name + "' is reserved in " + this);\r
-\r
- if (this.valuesById[id] !== undefined) {\r
- if (!(this.options && this.options.allow_alias))\r
- throw Error("duplicate id " + id + " in " + this);\r
- this.values[name] = id;\r
- } else\r
- this.valuesById[this.values[name] = id] = name;\r
-\r
- this.comments[name] = comment || null;\r
- return this;\r
-};\r
-\r
-/**\r
- * Removes a value from this enum\r
- * @param {string} name Value name\r
- * @returns {Enum} `this`\r
- * @throws {TypeError} If arguments are invalid\r
- * @throws {Error} If `name` is not a name of this enum\r
- */\r
-Enum.prototype.remove = function remove(name) {\r
-\r
- if (!util.isString(name))\r
- throw TypeError("name must be a string");\r
-\r
- var val = this.values[name];\r
- if (val == null)\r
- throw Error("name '" + name + "' does not exist in " + this);\r
-\r
- delete this.valuesById[val];\r
- delete this.values[name];\r
- delete this.comments[name];\r
-\r
- return this;\r
-};\r
-\r
-/**\r
- * Tests if the specified id is reserved.\r
- * @param {number} id Id to test\r
- * @returns {boolean} `true` if reserved, otherwise `false`\r
- */\r
-Enum.prototype.isReservedId = function isReservedId(id) {\r
- return Namespace.isReservedId(this.reserved, id);\r
-};\r
-\r
-/**\r
- * Tests if the specified name is reserved.\r
- * @param {string} name Name to test\r
- * @returns {boolean} `true` if reserved, otherwise `false`\r
- */\r
-Enum.prototype.isReservedName = function isReservedName(name) {\r
- return Namespace.isReservedName(this.reserved, name);\r
-};\r
-
-},{"./namespace":204,"./object":205,"./util":218}],197:[function(require,module,exports){
-"use strict";\r
-module.exports = Field;\r
-\r
-// extends ReflectionObject\r
-var ReflectionObject = require("./object");\r
-((Field.prototype = Object.create(ReflectionObject.prototype)).constructor = Field).className = "Field";\r
-\r
-var Enum = require("./enum"),\r
- types = require("./types"),\r
- util = require("./util");\r
-\r
-var Type; // cyclic\r
-\r
-var ruleRe = /^required|optional|repeated$/;\r
-\r
-/**\r
- * Constructs a new message field instance. Note that {@link MapField|map fields} have their own class.\r
- * @name Field\r
- * @classdesc Reflected message field.\r
- * @extends FieldBase\r
- * @constructor\r
- * @param {string} name Unique name within its namespace\r
- * @param {number} id Unique id within its namespace\r
- * @param {string} type Value type\r
- * @param {string|Object.<string,*>} [rule="optional"] Field rule\r
- * @param {string|Object.<string,*>} [extend] Extended type if different from parent\r
- * @param {Object.<string,*>} [options] Declared options\r
- */\r
-\r
-/**\r
- * Constructs a field from a field descriptor.\r
- * @param {string} name Field name\r
- * @param {IField} json Field descriptor\r
- * @returns {Field} Created field\r
- * @throws {TypeError} If arguments are invalid\r
- */\r
-Field.fromJSON = function fromJSON(name, json) {\r
- return new Field(name, json.id, json.type, json.rule, json.extend, json.options, json.comment);\r
-};\r
-\r
-/**\r
- * Not an actual constructor. Use {@link Field} instead.\r
- * @classdesc Base class of all reflected message fields. This is not an actual class but here for the sake of having consistent type definitions.\r
- * @exports FieldBase\r
- * @extends ReflectionObject\r
- * @constructor\r
- * @param {string} name Unique name within its namespace\r
- * @param {number} id Unique id within its namespace\r
- * @param {string} type Value type\r
- * @param {string|Object.<string,*>} [rule="optional"] Field rule\r
- * @param {string|Object.<string,*>} [extend] Extended type if different from parent\r
- * @param {Object.<string,*>} [options] Declared options\r
- * @param {string} [comment] Comment associated with this field\r
- */\r
-function Field(name, id, type, rule, extend, options, comment) {\r
-\r
- if (util.isObject(rule)) {\r
- comment = extend;\r
- options = rule;\r
- rule = extend = undefined;\r
- } else if (util.isObject(extend)) {\r
- comment = options;\r
- options = extend;\r
- extend = undefined;\r
- }\r
-\r
- ReflectionObject.call(this, name, options);\r
-\r
- if (!util.isInteger(id) || id < 0)\r
- throw TypeError("id must be a non-negative integer");\r
-\r
- if (!util.isString(type))\r
- throw TypeError("type must be a string");\r
-\r
- if (rule !== undefined && !ruleRe.test(rule = rule.toString().toLowerCase()))\r
- throw TypeError("rule must be a string rule");\r
-\r
- if (extend !== undefined && !util.isString(extend))\r
- throw TypeError("extend must be a string");\r
-\r
- /**\r
- * Field rule, if any.\r
- * @type {string|undefined}\r
- */\r
- this.rule = rule && rule !== "optional" ? rule : undefined; // toJSON\r
-\r
- /**\r
- * Field type.\r
- * @type {string}\r
- */\r
- this.type = type; // toJSON\r
-\r
- /**\r
- * Unique field id.\r
- * @type {number}\r
- */\r
- this.id = id; // toJSON, marker\r
-\r
- /**\r
- * Extended type if different from parent.\r
- * @type {string|undefined}\r
- */\r
- this.extend = extend || undefined; // toJSON\r
-\r
- /**\r
- * Whether this field is required.\r
- * @type {boolean}\r
- */\r
- this.required = rule === "required";\r
-\r
- /**\r
- * Whether this field is optional.\r
- * @type {boolean}\r
- */\r
- this.optional = !this.required;\r
-\r
- /**\r
- * Whether this field is repeated.\r
- * @type {boolean}\r
- */\r
- this.repeated = rule === "repeated";\r
-\r
- /**\r
- * Whether this field is a map or not.\r
- * @type {boolean}\r
- */\r
- this.map = false;\r
-\r
- /**\r
- * Message this field belongs to.\r
- * @type {Type|null}\r
- */\r
- this.message = null;\r
-\r
- /**\r
- * OneOf this field belongs to, if any,\r
- * @type {OneOf|null}\r
- */\r
- this.partOf = null;\r
-\r
- /**\r
- * The field type's default value.\r
- * @type {*}\r
- */\r
- this.typeDefault = null;\r
-\r
- /**\r
- * The field's default value on prototypes.\r
- * @type {*}\r
- */\r
- this.defaultValue = null;\r
-\r
- /**\r
- * Whether this field's value should be treated as a long.\r
- * @type {boolean}\r
- */\r
- this.long = util.Long ? types.long[type] !== undefined : /* istanbul ignore next */ false;\r
-\r
- /**\r
- * Whether this field's value is a buffer.\r
- * @type {boolean}\r
- */\r
- this.bytes = type === "bytes";\r
-\r
- /**\r
- * Resolved type if not a basic type.\r
- * @type {Type|Enum|null}\r
- */\r
- this.resolvedType = null;\r
-\r
- /**\r
- * Sister-field within the extended type if a declaring extension field.\r
- * @type {Field|null}\r
- */\r
- this.extensionField = null;\r
-\r
- /**\r
- * Sister-field within the declaring namespace if an extended field.\r
- * @type {Field|null}\r
- */\r
- this.declaringField = null;\r
-\r
- /**\r
- * Internally remembers whether this field is packed.\r
- * @type {boolean|null}\r
- * @private\r
- */\r
- this._packed = null;\r
-\r
- /**\r
- * Comment for this field.\r
- * @type {string|null}\r
- */\r
- this.comment = comment;\r
-}\r
-\r
-/**\r
- * Determines whether this field is packed. Only relevant when repeated and working with proto2.\r
- * @name Field#packed\r
- * @type {boolean}\r
- * @readonly\r
- */\r
-Object.defineProperty(Field.prototype, "packed", {\r
- get: function() {\r
- // defaults to packed=true if not explicity set to false\r
- if (this._packed === null)\r
- this._packed = this.getOption("packed") !== false;\r
- return this._packed;\r
- }\r
-});\r
-\r
-/**\r
- * @override\r
- */\r
-Field.prototype.setOption = function setOption(name, value, ifNotSet) {\r
- if (name === "packed") // clear cached before setting\r
- this._packed = null;\r
- return ReflectionObject.prototype.setOption.call(this, name, value, ifNotSet);\r
-};\r
-\r
-/**\r
- * Field descriptor.\r
- * @interface IField\r
- * @property {string} [rule="optional"] Field rule\r
- * @property {string} type Field type\r
- * @property {number} id Field id\r
- * @property {Object.<string,*>} [options] Field options\r
- */\r
-\r
-/**\r
- * Extension field descriptor.\r
- * @interface IExtensionField\r
- * @extends IField\r
- * @property {string} extend Extended type\r
- */\r
-\r
-/**\r
- * Converts this field to a field descriptor.\r
- * @param {IToJSONOptions} [toJSONOptions] JSON conversion options\r
- * @returns {IField} Field descriptor\r
- */\r
-Field.prototype.toJSON = function toJSON(toJSONOptions) {\r
- var keepComments = toJSONOptions ? Boolean(toJSONOptions.keepComments) : false;\r
- return util.toObject([\r
- "rule" , this.rule !== "optional" && this.rule || undefined,\r
- "type" , this.type,\r
- "id" , this.id,\r
- "extend" , this.extend,\r
- "options" , this.options,\r
- "comment" , keepComments ? this.comment : undefined\r
- ]);\r
-};\r
-\r
-/**\r
- * Resolves this field's type references.\r
- * @returns {Field} `this`\r
- * @throws {Error} If any reference cannot be resolved\r
- */\r
-Field.prototype.resolve = function resolve() {\r
-\r
- if (this.resolved)\r
- return this;\r
-\r
- if ((this.typeDefault = types.defaults[this.type]) === undefined) { // if not a basic type, resolve it\r
- this.resolvedType = (this.declaringField ? this.declaringField.parent : this.parent).lookupTypeOrEnum(this.type);\r
- if (this.resolvedType instanceof Type)\r
- this.typeDefault = null;\r
- else // instanceof Enum\r
- this.typeDefault = this.resolvedType.values[Object.keys(this.resolvedType.values)[0]]; // first defined\r
- }\r
-\r
- // use explicitly set default value if present\r
- if (this.options && this.options["default"] != null) {\r
- this.typeDefault = this.options["default"];\r
- if (this.resolvedType instanceof Enum && typeof this.typeDefault === "string")\r
- this.typeDefault = this.resolvedType.values[this.typeDefault];\r
- }\r
-\r
- // remove unnecessary options\r
- if (this.options) {\r
- if (this.options.packed === true || this.options.packed !== undefined && this.resolvedType && !(this.resolvedType instanceof Enum))\r
- delete this.options.packed;\r
- if (!Object.keys(this.options).length)\r
- this.options = undefined;\r
- }\r
-\r
- // convert to internal data type if necesssary\r
- if (this.long) {\r
- this.typeDefault = util.Long.fromNumber(this.typeDefault, this.type.charAt(0) === "u");\r
-\r
- /* istanbul ignore else */\r
- if (Object.freeze)\r
- Object.freeze(this.typeDefault); // long instances are meant to be immutable anyway (i.e. use small int cache that even requires it)\r
-\r
- } else if (this.bytes && typeof this.typeDefault === "string") {\r
- var buf;\r
- if (util.base64.test(this.typeDefault))\r
- util.base64.decode(this.typeDefault, buf = util.newBuffer(util.base64.length(this.typeDefault)), 0);\r
- else\r
- util.utf8.write(this.typeDefault, buf = util.newBuffer(util.utf8.length(this.typeDefault)), 0);\r
- this.typeDefault = buf;\r
- }\r
-\r
- // take special care of maps and repeated fields\r
- if (this.map)\r
- this.defaultValue = util.emptyObject;\r
- else if (this.repeated)\r
- this.defaultValue = util.emptyArray;\r
- else\r
- this.defaultValue = this.typeDefault;\r
-\r
- // ensure proper value on prototype\r
- if (this.parent instanceof Type)\r
- this.parent.ctor.prototype[this.name] = this.defaultValue;\r
-\r
- return ReflectionObject.prototype.resolve.call(this);\r
-};\r
-\r
-/**\r
- * Decorator function as returned by {@link Field.d} and {@link MapField.d} (TypeScript).\r
- * @typedef FieldDecorator\r
- * @type {function}\r
- * @param {Object} prototype Target prototype\r
- * @param {string} fieldName Field name\r
- * @returns {undefined}\r
- */\r
-\r
-/**\r
- * Field decorator (TypeScript).\r
- * @name Field.d\r
- * @function\r
- * @param {number} fieldId Field id\r
- * @param {"double"|"float"|"int32"|"uint32"|"sint32"|"fixed32"|"sfixed32"|"int64"|"uint64"|"sint64"|"fixed64"|"sfixed64"|"string"|"bool"|"bytes"|Object} fieldType Field type\r
- * @param {"optional"|"required"|"repeated"} [fieldRule="optional"] Field rule\r
- * @param {T} [defaultValue] Default value\r
- * @returns {FieldDecorator} Decorator function\r
- * @template T extends number | number[] | Long | Long[] | string | string[] | boolean | boolean[] | Uint8Array | Uint8Array[] | Buffer | Buffer[]\r
- */\r
-Field.d = function decorateField(fieldId, fieldType, fieldRule, defaultValue) {\r
-\r
- // submessage: decorate the submessage and use its name as the type\r
- if (typeof fieldType === "function")\r
- fieldType = util.decorateType(fieldType).name;\r
-\r
- // enum reference: create a reflected copy of the enum and keep reuseing it\r
- else if (fieldType && typeof fieldType === "object")\r
- fieldType = util.decorateEnum(fieldType).name;\r
-\r
- return function fieldDecorator(prototype, fieldName) {\r
- util.decorateType(prototype.constructor)\r
- .add(new Field(fieldName, fieldId, fieldType, fieldRule, { "default": defaultValue }));\r
- };\r
-};\r
-\r
-/**\r
- * Field decorator (TypeScript).\r
- * @name Field.d\r
- * @function\r
- * @param {number} fieldId Field id\r
- * @param {Constructor<T>|string} fieldType Field type\r
- * @param {"optional"|"required"|"repeated"} [fieldRule="optional"] Field rule\r
- * @returns {FieldDecorator} Decorator function\r
- * @template T extends Message<T>\r
- * @variation 2\r
- */\r
-// like Field.d but without a default value\r
-\r
-Field._configure = function configure(Type_) {\r
- Type = Type_;\r
-};\r
-
-},{"./enum":196,"./object":205,"./types":217,"./util":218}],198:[function(require,module,exports){
-"use strict";\r
-var protobuf = module.exports = require("./index-minimal");\r
-\r
-protobuf.build = "light";\r
-\r
-/**\r
- * A node-style callback as used by {@link load} and {@link Root#load}.\r
- * @typedef LoadCallback\r
- * @type {function}\r
- * @param {Error|null} error Error, if any, otherwise `null`\r
- * @param {Root} [root] Root, if there hasn't been an error\r
- * @returns {undefined}\r
- */\r
-\r
-/**\r
- * Loads one or multiple .proto or preprocessed .json files into a common root namespace and calls the callback.\r
- * @param {string|string[]} filename One or multiple files to load\r
- * @param {Root} root Root namespace, defaults to create a new one if omitted.\r
- * @param {LoadCallback} callback Callback function\r
- * @returns {undefined}\r
- * @see {@link Root#load}\r
- */\r
-function load(filename, root, callback) {\r
- if (typeof root === "function") {\r
- callback = root;\r
- root = new protobuf.Root();\r
- } else if (!root)\r
- root = new protobuf.Root();\r
- return root.load(filename, callback);\r
-}\r
-\r
-/**\r
- * Loads one or multiple .proto or preprocessed .json files into a common root namespace and calls the callback.\r
- * @name load\r
- * @function\r
- * @param {string|string[]} filename One or multiple files to load\r
- * @param {LoadCallback} callback Callback function\r
- * @returns {undefined}\r
- * @see {@link Root#load}\r
- * @variation 2\r
- */\r
-// function load(filename:string, callback:LoadCallback):undefined\r
-\r
-/**\r
- * Loads one or multiple .proto or preprocessed .json files into a common root namespace and returns a promise.\r
- * @name load\r
- * @function\r
- * @param {string|string[]} filename One or multiple files to load\r
- * @param {Root} [root] Root namespace, defaults to create a new one if omitted.\r
- * @returns {Promise<Root>} Promise\r
- * @see {@link Root#load}\r
- * @variation 3\r
- */\r
-// function load(filename:string, [root:Root]):Promise<Root>\r
-\r
-protobuf.load = load;\r
-\r
-/**\r
- * Synchronously loads one or multiple .proto or preprocessed .json files into a common root namespace (node only).\r
- * @param {string|string[]} filename One or multiple files to load\r
- * @param {Root} [root] Root namespace, defaults to create a new one if omitted.\r
- * @returns {Root} Root namespace\r
- * @throws {Error} If synchronous fetching is not supported (i.e. in browsers) or if a file's syntax is invalid\r
- * @see {@link Root#loadSync}\r
- */\r
-function loadSync(filename, root) {\r
- if (!root)\r
- root = new protobuf.Root();\r
- return root.loadSync(filename);\r
-}\r
-\r
-protobuf.loadSync = loadSync;\r
-\r
-// Serialization\r
-protobuf.encoder = require("./encoder");\r
-protobuf.decoder = require("./decoder");\r
-protobuf.verifier = require("./verifier");\r
-protobuf.converter = require("./converter");\r
-\r
-// Reflection\r
-protobuf.ReflectionObject = require("./object");\r
-protobuf.Namespace = require("./namespace");\r
-protobuf.Root = require("./root");\r
-protobuf.Enum = require("./enum");\r
-protobuf.Type = require("./type");\r
-protobuf.Field = require("./field");\r
-protobuf.OneOf = require("./oneof");\r
-protobuf.MapField = require("./mapfield");\r
-protobuf.Service = require("./service");\r
-protobuf.Method = require("./method");\r
-\r
-// Runtime\r
-protobuf.Message = require("./message");\r
-protobuf.wrappers = require("./wrappers");\r
-\r
-// Utility\r
-protobuf.types = require("./types");\r
-protobuf.util = require("./util");\r
-\r
-// Configure reflection\r
-protobuf.ReflectionObject._configure(protobuf.Root);\r
-protobuf.Namespace._configure(protobuf.Type, protobuf.Service);\r
-protobuf.Root._configure(protobuf.Type);\r
-protobuf.Field._configure(protobuf.Type);\r
-
-},{"./converter":193,"./decoder":194,"./encoder":195,"./enum":196,"./field":197,"./index-minimal":199,"./mapfield":201,"./message":202,"./method":203,"./namespace":204,"./object":205,"./oneof":206,"./root":210,"./service":214,"./type":216,"./types":217,"./util":218,"./verifier":221,"./wrappers":222}],199:[function(require,module,exports){
-"use strict";\r
-var protobuf = exports;\r
-\r
-/**\r
- * Build type, one of `"full"`, `"light"` or `"minimal"`.\r
- * @name build\r
- * @type {string}\r
- * @const\r
- */\r
-protobuf.build = "minimal";\r
-\r
-// Serialization\r
-protobuf.Writer = require("./writer");\r
-protobuf.BufferWriter = require("./writer_buffer");\r
-protobuf.Reader = require("./reader");\r
-protobuf.BufferReader = require("./reader_buffer");\r
-\r
-// Utility\r
-protobuf.util = require("./util/minimal");\r
-protobuf.rpc = require("./rpc");\r
-protobuf.roots = require("./roots");\r
-protobuf.configure = configure;\r
-\r
-/* istanbul ignore next */\r
-/**\r
- * Reconfigures the library according to the environment.\r
- * @returns {undefined}\r
- */\r
-function configure() {\r
- protobuf.Reader._configure(protobuf.BufferReader);\r
- protobuf.util._configure();\r
-}\r
-\r
-// Configure serialization\r
-protobuf.Writer._configure(protobuf.BufferWriter);\r
-configure();\r
-
-},{"./reader":208,"./reader_buffer":209,"./roots":211,"./rpc":212,"./util/minimal":220,"./writer":223,"./writer_buffer":224}],200:[function(require,module,exports){
-"use strict";\r
-var protobuf = module.exports = require("./index-light");\r
-\r
-protobuf.build = "full";\r
-\r
-// Parser\r
-protobuf.tokenize = require("./tokenize");\r
-protobuf.parse = require("./parse");\r
-protobuf.common = require("./common");\r
-\r
-// Configure parser\r
-protobuf.Root._configure(protobuf.Type, protobuf.parse, protobuf.common);\r
-
-},{"./common":192,"./index-light":198,"./parse":207,"./tokenize":215}],201:[function(require,module,exports){
-"use strict";\r
-module.exports = MapField;\r
-\r
-// extends Field\r
-var Field = require("./field");\r
-((MapField.prototype = Object.create(Field.prototype)).constructor = MapField).className = "MapField";\r
-\r
-var types = require("./types"),\r
- util = require("./util");\r
-\r
-/**\r
- * Constructs a new map field instance.\r
- * @classdesc Reflected map field.\r
- * @extends FieldBase\r
- * @constructor\r
- * @param {string} name Unique name within its namespace\r
- * @param {number} id Unique id within its namespace\r
- * @param {string} keyType Key type\r
- * @param {string} type Value type\r
- * @param {Object.<string,*>} [options] Declared options\r
- * @param {string} [comment] Comment associated with this field\r
- */\r
-function MapField(name, id, keyType, type, options, comment) {\r
- Field.call(this, name, id, type, undefined, undefined, options, comment);\r
-\r
- /* istanbul ignore if */\r
- if (!util.isString(keyType))\r
- throw TypeError("keyType must be a string");\r
-\r
- /**\r
- * Key type.\r
- * @type {string}\r
- */\r
- this.keyType = keyType; // toJSON, marker\r
-\r
- /**\r
- * Resolved key type if not a basic type.\r
- * @type {ReflectionObject|null}\r
- */\r
- this.resolvedKeyType = null;\r
-\r
- // Overrides Field#map\r
- this.map = true;\r
-}\r
-\r
-/**\r
- * Map field descriptor.\r
- * @interface IMapField\r
- * @extends {IField}\r
- * @property {string} keyType Key type\r
- */\r
-\r
-/**\r
- * Extension map field descriptor.\r
- * @interface IExtensionMapField\r
- * @extends IMapField\r
- * @property {string} extend Extended type\r
- */\r
-\r
-/**\r
- * Constructs a map field from a map field descriptor.\r
- * @param {string} name Field name\r
- * @param {IMapField} json Map field descriptor\r
- * @returns {MapField} Created map field\r
- * @throws {TypeError} If arguments are invalid\r
- */\r
-MapField.fromJSON = function fromJSON(name, json) {\r
- return new MapField(name, json.id, json.keyType, json.type, json.options, json.comment);\r
-};\r
-\r
-/**\r
- * Converts this map field to a map field descriptor.\r
- * @param {IToJSONOptions} [toJSONOptions] JSON conversion options\r
- * @returns {IMapField} Map field descriptor\r
- */\r
-MapField.prototype.toJSON = function toJSON(toJSONOptions) {\r
- var keepComments = toJSONOptions ? Boolean(toJSONOptions.keepComments) : false;\r
- return util.toObject([\r
- "keyType" , this.keyType,\r
- "type" , this.type,\r
- "id" , this.id,\r
- "extend" , this.extend,\r
- "options" , this.options,\r
- "comment" , keepComments ? this.comment : undefined\r
- ]);\r
-};\r
-\r
-/**\r
- * @override\r
- */\r
-MapField.prototype.resolve = function resolve() {\r
- if (this.resolved)\r
- return this;\r
-\r
- // Besides a value type, map fields have a key type that may be "any scalar type except for floating point types and bytes"\r
- if (types.mapKey[this.keyType] === undefined)\r
- throw Error("invalid key type: " + this.keyType);\r
-\r
- return Field.prototype.resolve.call(this);\r
-};\r
-\r
-/**\r
- * Map field decorator (TypeScript).\r
- * @name MapField.d\r
- * @function\r
- * @param {number} fieldId Field id\r
- * @param {"int32"|"uint32"|"sint32"|"fixed32"|"sfixed32"|"int64"|"uint64"|"sint64"|"fixed64"|"sfixed64"|"bool"|"string"} fieldKeyType Field key type\r
- * @param {"double"|"float"|"int32"|"uint32"|"sint32"|"fixed32"|"sfixed32"|"int64"|"uint64"|"sint64"|"fixed64"|"sfixed64"|"bool"|"string"|"bytes"|Object|Constructor<{}>} fieldValueType Field value type\r
- * @returns {FieldDecorator} Decorator function\r
- * @template T extends { [key: string]: number | Long | string | boolean | Uint8Array | Buffer | number[] | Message<{}> }\r
- */\r
-MapField.d = function decorateMapField(fieldId, fieldKeyType, fieldValueType) {\r
-\r
- // submessage value: decorate the submessage and use its name as the type\r
- if (typeof fieldValueType === "function")\r
- fieldValueType = util.decorateType(fieldValueType).name;\r
-\r
- // enum reference value: create a reflected copy of the enum and keep reuseing it\r
- else if (fieldValueType && typeof fieldValueType === "object")\r
- fieldValueType = util.decorateEnum(fieldValueType).name;\r
-\r
- return function mapFieldDecorator(prototype, fieldName) {\r
- util.decorateType(prototype.constructor)\r
- .add(new MapField(fieldName, fieldId, fieldKeyType, fieldValueType));\r
- };\r
-};\r
-
-},{"./field":197,"./types":217,"./util":218}],202:[function(require,module,exports){
-"use strict";\r
-module.exports = Message;\r
-\r
-var util = require("./util/minimal");\r
-\r
-/**\r
- * Constructs a new message instance.\r
- * @classdesc Abstract runtime message.\r
- * @constructor\r
- * @param {Properties<T>} [properties] Properties to set\r
- * @template T extends object\r
- */\r
-function Message(properties) {\r
- // not used internally\r
- if (properties)\r
- for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)\r
- this[keys[i]] = properties[keys[i]];\r
-}\r
-\r
-/**\r
- * Reference to the reflected type.\r
- * @name Message.$type\r
- * @type {Type}\r
- * @readonly\r
- */\r
-\r
-/**\r
- * Reference to the reflected type.\r
- * @name Message#$type\r
- * @type {Type}\r
- * @readonly\r
- */\r
-\r
-/*eslint-disable valid-jsdoc*/\r
-\r
-/**\r
- * Creates a new message of this type using the specified properties.\r
- * @param {Object.<string,*>} [properties] Properties to set\r
- * @returns {Message<T>} Message instance\r
- * @template T extends Message<T>\r
- * @this Constructor<T>\r
- */\r
-Message.create = function create(properties) {\r
- return this.$type.create(properties);\r
-};\r
-\r
-/**\r
- * Encodes a message of this type.\r
- * @param {T|Object.<string,*>} message Message to encode\r
- * @param {Writer} [writer] Writer to use\r
- * @returns {Writer} Writer\r
- * @template T extends Message<T>\r
- * @this Constructor<T>\r
- */\r
-Message.encode = function encode(message, writer) {\r
- return this.$type.encode(message, writer);\r
-};\r
-\r
-/**\r
- * Encodes a message of this type preceeded by its length as a varint.\r
- * @param {T|Object.<string,*>} message Message to encode\r
- * @param {Writer} [writer] Writer to use\r
- * @returns {Writer} Writer\r
- * @template T extends Message<T>\r
- * @this Constructor<T>\r
- */\r
-Message.encodeDelimited = function encodeDelimited(message, writer) {\r
- return this.$type.encodeDelimited(message, writer);\r
-};\r
-\r
-/**\r
- * Decodes a message of this type.\r
- * @name Message.decode\r
- * @function\r
- * @param {Reader|Uint8Array} reader Reader or buffer to decode\r
- * @returns {T} Decoded message\r
- * @template T extends Message<T>\r
- * @this Constructor<T>\r
- */\r
-Message.decode = function decode(reader) {\r
- return this.$type.decode(reader);\r
-};\r
-\r
-/**\r
- * Decodes a message of this type preceeded by its length as a varint.\r
- * @name Message.decodeDelimited\r
- * @function\r
- * @param {Reader|Uint8Array} reader Reader or buffer to decode\r
- * @returns {T} Decoded message\r
- * @template T extends Message<T>\r
- * @this Constructor<T>\r
- */\r
-Message.decodeDelimited = function decodeDelimited(reader) {\r
- return this.$type.decodeDelimited(reader);\r
-};\r
-\r
-/**\r
- * Verifies a message of this type.\r
- * @name Message.verify\r
- * @function\r
- * @param {Object.<string,*>} message Plain object to verify\r
- * @returns {string|null} `null` if valid, otherwise the reason why it is not\r
- */\r
-Message.verify = function verify(message) {\r
- return this.$type.verify(message);\r
-};\r
-\r
-/**\r
- * Creates a new message of this type from a plain object. Also converts values to their respective internal types.\r
- * @param {Object.<string,*>} object Plain object\r
- * @returns {T} Message instance\r
- * @template T extends Message<T>\r
- * @this Constructor<T>\r
- */\r
-Message.fromObject = function fromObject(object) {\r
- return this.$type.fromObject(object);\r
-};\r
-\r
-/**\r
- * Creates a plain object from a message of this type. Also converts values to other types if specified.\r
- * @param {T} message Message instance\r
- * @param {IConversionOptions} [options] Conversion options\r
- * @returns {Object.<string,*>} Plain object\r
- * @template T extends Message<T>\r
- * @this Constructor<T>\r
- */\r
-Message.toObject = function toObject(message, options) {\r
- return this.$type.toObject(message, options);\r
-};\r
-\r
-/**\r
- * Converts this message to JSON.\r
- * @returns {Object.<string,*>} JSON object\r
- */\r
-Message.prototype.toJSON = function toJSON() {\r
- return this.$type.toObject(this, util.toJSONOptions);\r
-};\r
-\r
-/*eslint-enable valid-jsdoc*/
-},{"./util/minimal":220}],203:[function(require,module,exports){
-"use strict";\r
-module.exports = Method;\r
-\r
-// extends ReflectionObject\r
-var ReflectionObject = require("./object");\r
-((Method.prototype = Object.create(ReflectionObject.prototype)).constructor = Method).className = "Method";\r
-\r
-var util = require("./util");\r
-\r
-/**\r
- * Constructs a new service method instance.\r
- * @classdesc Reflected service method.\r
- * @extends ReflectionObject\r
- * @constructor\r
- * @param {string} name Method name\r
- * @param {string|undefined} type Method type, usually `"rpc"`\r
- * @param {string} requestType Request message type\r
- * @param {string} responseType Response message type\r
- * @param {boolean|Object.<string,*>} [requestStream] Whether the request is streamed\r
- * @param {boolean|Object.<string,*>} [responseStream] Whether the response is streamed\r
- * @param {Object.<string,*>} [options] Declared options\r
- * @param {string} [comment] The comment for this method\r
- */\r
-function Method(name, type, requestType, responseType, requestStream, responseStream, options, comment) {\r
-\r
- /* istanbul ignore next */\r
- if (util.isObject(requestStream)) {\r
- options = requestStream;\r
- requestStream = responseStream = undefined;\r
- } else if (util.isObject(responseStream)) {\r
- options = responseStream;\r
- responseStream = undefined;\r
- }\r
-\r
- /* istanbul ignore if */\r
- if (!(type === undefined || util.isString(type)))\r
- throw TypeError("type must be a string");\r
-\r
- /* istanbul ignore if */\r
- if (!util.isString(requestType))\r
- throw TypeError("requestType must be a string");\r
-\r
- /* istanbul ignore if */\r
- if (!util.isString(responseType))\r
- throw TypeError("responseType must be a string");\r
-\r
- ReflectionObject.call(this, name, options);\r
-\r
- /**\r
- * Method type.\r
- * @type {string}\r
- */\r
- this.type = type || "rpc"; // toJSON\r
-\r
- /**\r
- * Request type.\r
- * @type {string}\r
- */\r
- this.requestType = requestType; // toJSON, marker\r
-\r
- /**\r
- * Whether requests are streamed or not.\r
- * @type {boolean|undefined}\r
- */\r
- this.requestStream = requestStream ? true : undefined; // toJSON\r
-\r
- /**\r
- * Response type.\r
- * @type {string}\r
- */\r
- this.responseType = responseType; // toJSON\r
-\r
- /**\r
- * Whether responses are streamed or not.\r
- * @type {boolean|undefined}\r
- */\r
- this.responseStream = responseStream ? true : undefined; // toJSON\r
-\r
- /**\r
- * Resolved request type.\r
- * @type {Type|null}\r
- */\r
- this.resolvedRequestType = null;\r
-\r
- /**\r
- * Resolved response type.\r
- * @type {Type|null}\r
- */\r
- this.resolvedResponseType = null;\r
-\r
- /**\r
- * Comment for this method\r
- * @type {string|null}\r
- */\r
- this.comment = comment;\r
-}\r
-\r
-/**\r
- * Method descriptor.\r
- * @interface IMethod\r
- * @property {string} [type="rpc"] Method type\r
- * @property {string} requestType Request type\r
- * @property {string} responseType Response type\r
- * @property {boolean} [requestStream=false] Whether requests are streamed\r
- * @property {boolean} [responseStream=false] Whether responses are streamed\r
- * @property {Object.<string,*>} [options] Method options\r
- */\r
-\r
-/**\r
- * Constructs a method from a method descriptor.\r
- * @param {string} name Method name\r
- * @param {IMethod} json Method descriptor\r
- * @returns {Method} Created method\r
- * @throws {TypeError} If arguments are invalid\r
- */\r
-Method.fromJSON = function fromJSON(name, json) {\r
- return new Method(name, json.type, json.requestType, json.responseType, json.requestStream, json.responseStream, json.options, json.comment);\r
-};\r
-\r
-/**\r
- * Converts this method to a method descriptor.\r
- * @param {IToJSONOptions} [toJSONOptions] JSON conversion options\r
- * @returns {IMethod} Method descriptor\r
- */\r
-Method.prototype.toJSON = function toJSON(toJSONOptions) {\r
- var keepComments = toJSONOptions ? Boolean(toJSONOptions.keepComments) : false;\r
- return util.toObject([\r
- "type" , this.type !== "rpc" && /* istanbul ignore next */ this.type || undefined,\r
- "requestType" , this.requestType,\r
- "requestStream" , this.requestStream,\r
- "responseType" , this.responseType,\r
- "responseStream" , this.responseStream,\r
- "options" , this.options,\r
- "comment" , keepComments ? this.comment : undefined\r
- ]);\r
-};\r
-\r
-/**\r
- * @override\r
- */\r
-Method.prototype.resolve = function resolve() {\r
-\r
- /* istanbul ignore if */\r
- if (this.resolved)\r
- return this;\r
-\r
- this.resolvedRequestType = this.parent.lookupType(this.requestType);\r
- this.resolvedResponseType = this.parent.lookupType(this.responseType);\r
-\r
- return ReflectionObject.prototype.resolve.call(this);\r
-};\r
-
-},{"./object":205,"./util":218}],204:[function(require,module,exports){
-"use strict";\r
-module.exports = Namespace;\r
-\r
-// extends ReflectionObject\r
-var ReflectionObject = require("./object");\r
-((Namespace.prototype = Object.create(ReflectionObject.prototype)).constructor = Namespace).className = "Namespace";\r
-\r
-var Enum = require("./enum"),\r
- Field = require("./field"),\r
- util = require("./util");\r
-\r
-var Type, // cyclic\r
- Service; // "\r
-\r
-/**\r
- * Constructs a new namespace instance.\r
- * @name Namespace\r
- * @classdesc Reflected namespace.\r
- * @extends NamespaceBase\r
- * @constructor\r
- * @param {string} name Namespace name\r
- * @param {Object.<string,*>} [options] Declared options\r
- */\r
-\r
-/**\r
- * Constructs a namespace from JSON.\r
- * @memberof Namespace\r
- * @function\r
- * @param {string} name Namespace name\r
- * @param {Object.<string,*>} json JSON object\r
- * @returns {Namespace} Created namespace\r
- * @throws {TypeError} If arguments are invalid\r
- */\r
-Namespace.fromJSON = function fromJSON(name, json) {\r
- return new Namespace(name, json.options).addJSON(json.nested);\r
-};\r
-\r
-/**\r
- * Converts an array of reflection objects to JSON.\r
- * @memberof Namespace\r
- * @param {ReflectionObject[]} array Object array\r
- * @param {IToJSONOptions} [toJSONOptions] JSON conversion options\r
- * @returns {Object.<string,*>|undefined} JSON object or `undefined` when array is empty\r
- */\r
-function arrayToJSON(array, toJSONOptions) {\r
- if (!(array && array.length))\r
- return undefined;\r
- var obj = {};\r
- for (var i = 0; i < array.length; ++i)\r
- obj[array[i].name] = array[i].toJSON(toJSONOptions);\r
- return obj;\r
-}\r
-\r
-Namespace.arrayToJSON = arrayToJSON;\r
-\r
-/**\r
- * Tests if the specified id is reserved.\r
- * @param {Array.<number[]|string>|undefined} reserved Array of reserved ranges and names\r
- * @param {number} id Id to test\r
- * @returns {boolean} `true` if reserved, otherwise `false`\r
- */\r
-Namespace.isReservedId = function isReservedId(reserved, id) {\r
- if (reserved)\r
- for (var i = 0; i < reserved.length; ++i)\r
- if (typeof reserved[i] !== "string" && reserved[i][0] <= id && reserved[i][1] >= id)\r
- return true;\r
- return false;\r
-};\r
-\r
-/**\r
- * Tests if the specified name is reserved.\r
- * @param {Array.<number[]|string>|undefined} reserved Array of reserved ranges and names\r
- * @param {string} name Name to test\r
- * @returns {boolean} `true` if reserved, otherwise `false`\r
- */\r
-Namespace.isReservedName = function isReservedName(reserved, name) {\r
- if (reserved)\r
- for (var i = 0; i < reserved.length; ++i)\r
- if (reserved[i] === name)\r
- return true;\r
- return false;\r
-};\r
-\r
-/**\r
- * Not an actual constructor. Use {@link Namespace} instead.\r
- * @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.\r
- * @exports NamespaceBase\r
- * @extends ReflectionObject\r
- * @abstract\r
- * @constructor\r
- * @param {string} name Namespace name\r
- * @param {Object.<string,*>} [options] Declared options\r
- * @see {@link Namespace}\r
- */\r
-function Namespace(name, options) {\r
- ReflectionObject.call(this, name, options);\r
-\r
- /**\r
- * Nested objects by name.\r
- * @type {Object.<string,ReflectionObject>|undefined}\r
- */\r
- this.nested = undefined; // toJSON\r
-\r
- /**\r
- * Cached nested objects as an array.\r
- * @type {ReflectionObject[]|null}\r
- * @private\r
- */\r
- this._nestedArray = null;\r
-}\r
-\r
-function clearCache(namespace) {\r
- namespace._nestedArray = null;\r
- return namespace;\r
-}\r
-\r
-/**\r
- * Nested objects of this namespace as an array for iteration.\r
- * @name NamespaceBase#nestedArray\r
- * @type {ReflectionObject[]}\r
- * @readonly\r
- */\r
-Object.defineProperty(Namespace.prototype, "nestedArray", {\r
- get: function() {\r
- return this._nestedArray || (this._nestedArray = util.toArray(this.nested));\r
- }\r
-});\r
-\r
-/**\r
- * Namespace descriptor.\r
- * @interface INamespace\r
- * @property {Object.<string,*>} [options] Namespace options\r
- * @property {Object.<string,AnyNestedObject>} [nested] Nested object descriptors\r
- */\r
-\r
-/**\r
- * Any extension field descriptor.\r
- * @typedef AnyExtensionField\r
- * @type {IExtensionField|IExtensionMapField}\r
- */\r
-\r
-/**\r
- * Any nested object descriptor.\r
- * @typedef AnyNestedObject\r
- * @type {IEnum|IType|IService|AnyExtensionField|INamespace}\r
- */\r
-// ^ BEWARE: VSCode hangs forever when using more than 5 types (that's why AnyExtensionField exists in the first place)\r
-\r
-/**\r
- * Converts this namespace to a namespace descriptor.\r
- * @param {IToJSONOptions} [toJSONOptions] JSON conversion options\r
- * @returns {INamespace} Namespace descriptor\r
- */\r
-Namespace.prototype.toJSON = function toJSON(toJSONOptions) {\r
- return util.toObject([\r
- "options" , this.options,\r
- "nested" , arrayToJSON(this.nestedArray, toJSONOptions)\r
- ]);\r
-};\r
-\r
-/**\r
- * Adds nested objects to this namespace from nested object descriptors.\r
- * @param {Object.<string,AnyNestedObject>} nestedJson Any nested object descriptors\r
- * @returns {Namespace} `this`\r
- */\r
-Namespace.prototype.addJSON = function addJSON(nestedJson) {\r
- var ns = this;\r
- /* istanbul ignore else */\r
- if (nestedJson) {\r
- for (var names = Object.keys(nestedJson), i = 0, nested; i < names.length; ++i) {\r
- nested = nestedJson[names[i]];\r
- ns.add( // most to least likely\r
- ( nested.fields !== undefined\r
- ? Type.fromJSON\r
- : nested.values !== undefined\r
- ? Enum.fromJSON\r
- : nested.methods !== undefined\r
- ? Service.fromJSON\r
- : nested.id !== undefined\r
- ? Field.fromJSON\r
- : Namespace.fromJSON )(names[i], nested)\r
- );\r
- }\r
- }\r
- return this;\r
-};\r
-\r
-/**\r
- * Gets the nested object of the specified name.\r
- * @param {string} name Nested object name\r
- * @returns {ReflectionObject|null} The reflection object or `null` if it doesn't exist\r
- */\r
-Namespace.prototype.get = function get(name) {\r
- return this.nested && this.nested[name]\r
- || null;\r
-};\r
-\r
-/**\r
- * Gets the values of the nested {@link Enum|enum} of the specified name.\r
- * This methods differs from {@link Namespace#get|get} in that it returns an enum's values directly and throws instead of returning `null`.\r
- * @param {string} name Nested enum name\r
- * @returns {Object.<string,number>} Enum values\r
- * @throws {Error} If there is no such enum\r
- */\r
-Namespace.prototype.getEnum = function getEnum(name) {\r
- if (this.nested && this.nested[name] instanceof Enum)\r
- return this.nested[name].values;\r
- throw Error("no such enum: " + name);\r
-};\r
-\r
-/**\r
- * Adds a nested object to this namespace.\r
- * @param {ReflectionObject} object Nested object to add\r
- * @returns {Namespace} `this`\r
- * @throws {TypeError} If arguments are invalid\r
- * @throws {Error} If there is already a nested object with this name\r
- */\r
-Namespace.prototype.add = function add(object) {\r
-\r
- if (!(object instanceof Field && object.extend !== undefined || object instanceof Type || object instanceof Enum || object instanceof Service || object instanceof Namespace))\r
- throw TypeError("object must be a valid nested object");\r
-\r
- if (!this.nested)\r
- this.nested = {};\r
- else {\r
- var prev = this.get(object.name);\r
- if (prev) {\r
- if (prev instanceof Namespace && object instanceof Namespace && !(prev instanceof Type || prev instanceof Service)) {\r
- // replace plain namespace but keep existing nested elements and options\r
- var nested = prev.nestedArray;\r
- for (var i = 0; i < nested.length; ++i)\r
- object.add(nested[i]);\r
- this.remove(prev);\r
- if (!this.nested)\r
- this.nested = {};\r
- object.setOptions(prev.options, true);\r
-\r
- } else\r
- throw Error("duplicate name '" + object.name + "' in " + this);\r
- }\r
- }\r
- this.nested[object.name] = object;\r
- object.onAdd(this);\r
- return clearCache(this);\r
-};\r
-\r
-/**\r
- * Removes a nested object from this namespace.\r
- * @param {ReflectionObject} object Nested object to remove\r
- * @returns {Namespace} `this`\r
- * @throws {TypeError} If arguments are invalid\r
- * @throws {Error} If `object` is not a member of this namespace\r
- */\r
-Namespace.prototype.remove = function remove(object) {\r
-\r
- if (!(object instanceof ReflectionObject))\r
- throw TypeError("object must be a ReflectionObject");\r
- if (object.parent !== this)\r
- throw Error(object + " is not a member of " + this);\r
-\r
- delete this.nested[object.name];\r
- if (!Object.keys(this.nested).length)\r
- this.nested = undefined;\r
-\r
- object.onRemove(this);\r
- return clearCache(this);\r
-};\r
-\r
-/**\r
- * Defines additial namespaces within this one if not yet existing.\r
- * @param {string|string[]} path Path to create\r
- * @param {*} [json] Nested types to create from JSON\r
- * @returns {Namespace} Pointer to the last namespace created or `this` if path is empty\r
- */\r
-Namespace.prototype.define = function define(path, json) {\r
-\r
- if (util.isString(path))\r
- path = path.split(".");\r
- else if (!Array.isArray(path))\r
- throw TypeError("illegal path");\r
- if (path && path.length && path[0] === "")\r
- throw Error("path must be relative");\r
-\r
- var ptr = this;\r
- while (path.length > 0) {\r
- var part = path.shift();\r
- if (ptr.nested && ptr.nested[part]) {\r
- ptr = ptr.nested[part];\r
- if (!(ptr instanceof Namespace))\r
- throw Error("path conflicts with non-namespace objects");\r
- } else\r
- ptr.add(ptr = new Namespace(part));\r
- }\r
- if (json)\r
- ptr.addJSON(json);\r
- return ptr;\r
-};\r
-\r
-/**\r
- * Resolves this namespace's and all its nested objects' type references. Useful to validate a reflection tree, but comes at a cost.\r
- * @returns {Namespace} `this`\r
- */\r
-Namespace.prototype.resolveAll = function resolveAll() {\r
- var nested = this.nestedArray, i = 0;\r
- while (i < nested.length)\r
- if (nested[i] instanceof Namespace)\r
- nested[i++].resolveAll();\r
- else\r
- nested[i++].resolve();\r
- return this.resolve();\r
-};\r
-\r
-/**\r
- * Recursively looks up the reflection object matching the specified path in the scope of this namespace.\r
- * @param {string|string[]} path Path to look up\r
- * @param {*|Array.<*>} filterTypes Filter types, any combination of the constructors of `protobuf.Type`, `protobuf.Enum`, `protobuf.Service` etc.\r
- * @param {boolean} [parentAlreadyChecked=false] If known, whether the parent has already been checked\r
- * @returns {ReflectionObject|null} Looked up object or `null` if none could be found\r
- */\r
-Namespace.prototype.lookup = function lookup(path, filterTypes, parentAlreadyChecked) {\r
-\r
- /* istanbul ignore next */\r
- if (typeof filterTypes === "boolean") {\r
- parentAlreadyChecked = filterTypes;\r
- filterTypes = undefined;\r
- } else if (filterTypes && !Array.isArray(filterTypes))\r
- filterTypes = [ filterTypes ];\r
-\r
- if (util.isString(path) && path.length) {\r
- if (path === ".")\r
- return this.root;\r
- path = path.split(".");\r
- } else if (!path.length)\r
- return this;\r
-\r
- // Start at root if path is absolute\r
- if (path[0] === "")\r
- return this.root.lookup(path.slice(1), filterTypes);\r
-\r
- // Test if the first part matches any nested object, and if so, traverse if path contains more\r
- var found = this.get(path[0]);\r
- if (found) {\r
- if (path.length === 1) {\r
- if (!filterTypes || filterTypes.indexOf(found.constructor) > -1)\r
- return found;\r
- } else if (found instanceof Namespace && (found = found.lookup(path.slice(1), filterTypes, true)))\r
- return found;\r
-\r
- // Otherwise try each nested namespace\r
- } else\r
- for (var i = 0; i < this.nestedArray.length; ++i)\r
- if (this._nestedArray[i] instanceof Namespace && (found = this._nestedArray[i].lookup(path, filterTypes, true)))\r
- return found;\r
-\r
- // If there hasn't been a match, try again at the parent\r
- if (this.parent === null || parentAlreadyChecked)\r
- return null;\r
- return this.parent.lookup(path, filterTypes);\r
-};\r
-\r
-/**\r
- * Looks up the reflection object at the specified path, relative to this namespace.\r
- * @name NamespaceBase#lookup\r
- * @function\r
- * @param {string|string[]} path Path to look up\r
- * @param {boolean} [parentAlreadyChecked=false] Whether the parent has already been checked\r
- * @returns {ReflectionObject|null} Looked up object or `null` if none could be found\r
- * @variation 2\r
- */\r
-// lookup(path: string, [parentAlreadyChecked: boolean])\r
-\r
-/**\r
- * Looks up the {@link Type|type} at the specified path, relative to this namespace.\r
- * Besides its signature, this methods differs from {@link Namespace#lookup|lookup} in that it throws instead of returning `null`.\r
- * @param {string|string[]} path Path to look up\r
- * @returns {Type} Looked up type\r
- * @throws {Error} If `path` does not point to a type\r
- */\r
-Namespace.prototype.lookupType = function lookupType(path) {\r
- var found = this.lookup(path, [ Type ]);\r
- if (!found)\r
- throw Error("no such type: " + path);\r
- return found;\r
-};\r
-\r
-/**\r
- * Looks up the values of the {@link Enum|enum} at the specified path, relative to this namespace.\r
- * Besides its signature, this methods differs from {@link Namespace#lookup|lookup} in that it throws instead of returning `null`.\r
- * @param {string|string[]} path Path to look up\r
- * @returns {Enum} Looked up enum\r
- * @throws {Error} If `path` does not point to an enum\r
- */\r
-Namespace.prototype.lookupEnum = function lookupEnum(path) {\r
- var found = this.lookup(path, [ Enum ]);\r
- if (!found)\r
- throw Error("no such Enum '" + path + "' in " + this);\r
- return found;\r
-};\r
-\r
-/**\r
- * Looks up the {@link Type|type} or {@link Enum|enum} at the specified path, relative to this namespace.\r
- * Besides its signature, this methods differs from {@link Namespace#lookup|lookup} in that it throws instead of returning `null`.\r
- * @param {string|string[]} path Path to look up\r
- * @returns {Type} Looked up type or enum\r
- * @throws {Error} If `path` does not point to a type or enum\r
- */\r
-Namespace.prototype.lookupTypeOrEnum = function lookupTypeOrEnum(path) {\r
- var found = this.lookup(path, [ Type, Enum ]);\r
- if (!found)\r
- throw Error("no such Type or Enum '" + path + "' in " + this);\r
- return found;\r
-};\r
-\r
-/**\r
- * Looks up the {@link Service|service} at the specified path, relative to this namespace.\r
- * Besides its signature, this methods differs from {@link Namespace#lookup|lookup} in that it throws instead of returning `null`.\r
- * @param {string|string[]} path Path to look up\r
- * @returns {Service} Looked up service\r
- * @throws {Error} If `path` does not point to a service\r
- */\r
-Namespace.prototype.lookupService = function lookupService(path) {\r
- var found = this.lookup(path, [ Service ]);\r
- if (!found)\r
- throw Error("no such Service '" + path + "' in " + this);\r
- return found;\r
-};\r
-\r
-Namespace._configure = function(Type_, Service_) {\r
- Type = Type_;\r
- Service = Service_;\r
-};\r
-
-},{"./enum":196,"./field":197,"./object":205,"./util":218}],205:[function(require,module,exports){
-"use strict";\r
-module.exports = ReflectionObject;\r
-\r
-ReflectionObject.className = "ReflectionObject";\r
-\r
-var util = require("./util");\r
-\r
-var Root; // cyclic\r
-\r
-/**\r
- * Constructs a new reflection object instance.\r
- * @classdesc Base class of all reflection objects.\r
- * @constructor\r
- * @param {string} name Object name\r
- * @param {Object.<string,*>} [options] Declared options\r
- * @abstract\r
- */\r
-function ReflectionObject(name, options) {\r
-\r
- if (!util.isString(name))\r
- throw TypeError("name must be a string");\r
-\r
- if (options && !util.isObject(options))\r
- throw TypeError("options must be an object");\r
-\r
- /**\r
- * Options.\r
- * @type {Object.<string,*>|undefined}\r
- */\r
- this.options = options; // toJSON\r
-\r
- /**\r
- * Unique name within its namespace.\r
- * @type {string}\r
- */\r
- this.name = name;\r
-\r
- /**\r
- * Parent namespace.\r
- * @type {Namespace|null}\r
- */\r
- this.parent = null;\r
-\r
- /**\r
- * Whether already resolved or not.\r
- * @type {boolean}\r
- */\r
- this.resolved = false;\r
-\r
- /**\r
- * Comment text, if any.\r
- * @type {string|null}\r
- */\r
- this.comment = null;\r
-\r
- /**\r
- * Defining file name.\r
- * @type {string|null}\r
- */\r
- this.filename = null;\r
-}\r
-\r
-Object.defineProperties(ReflectionObject.prototype, {\r
-\r
- /**\r
- * Reference to the root namespace.\r
- * @name ReflectionObject#root\r
- * @type {Root}\r
- * @readonly\r
- */\r
- root: {\r
- get: function() {\r
- var ptr = this;\r
- while (ptr.parent !== null)\r
- ptr = ptr.parent;\r
- return ptr;\r
- }\r
- },\r
-\r
- /**\r
- * Full name including leading dot.\r
- * @name ReflectionObject#fullName\r
- * @type {string}\r
- * @readonly\r
- */\r
- fullName: {\r
- get: function() {\r
- var path = [ this.name ],\r
- ptr = this.parent;\r
- while (ptr) {\r
- path.unshift(ptr.name);\r
- ptr = ptr.parent;\r
- }\r
- return path.join(".");\r
- }\r
- }\r
-});\r
-\r
-/**\r
- * Converts this reflection object to its descriptor representation.\r
- * @returns {Object.<string,*>} Descriptor\r
- * @abstract\r
- */\r
-ReflectionObject.prototype.toJSON = /* istanbul ignore next */ function toJSON() {\r
- throw Error(); // not implemented, shouldn't happen\r
-};\r
-\r
-/**\r
- * Called when this object is added to a parent.\r
- * @param {ReflectionObject} parent Parent added to\r
- * @returns {undefined}\r
- */\r
-ReflectionObject.prototype.onAdd = function onAdd(parent) {\r
- if (this.parent && this.parent !== parent)\r
- this.parent.remove(this);\r
- this.parent = parent;\r
- this.resolved = false;\r
- var root = parent.root;\r
- if (root instanceof Root)\r
- root._handleAdd(this);\r
-};\r
-\r
-/**\r
- * Called when this object is removed from a parent.\r
- * @param {ReflectionObject} parent Parent removed from\r
- * @returns {undefined}\r
- */\r
-ReflectionObject.prototype.onRemove = function onRemove(parent) {\r
- var root = parent.root;\r
- if (root instanceof Root)\r
- root._handleRemove(this);\r
- this.parent = null;\r
- this.resolved = false;\r
-};\r
-\r
-/**\r
- * Resolves this objects type references.\r
- * @returns {ReflectionObject} `this`\r
- */\r
-ReflectionObject.prototype.resolve = function resolve() {\r
- if (this.resolved)\r
- return this;\r
- if (this.root instanceof Root)\r
- this.resolved = true; // only if part of a root\r
- return this;\r
-};\r
-\r
-/**\r
- * Gets an option value.\r
- * @param {string} name Option name\r
- * @returns {*} Option value or `undefined` if not set\r
- */\r
-ReflectionObject.prototype.getOption = function getOption(name) {\r
- if (this.options)\r
- return this.options[name];\r
- return undefined;\r
-};\r
-\r
-/**\r
- * Sets an option.\r
- * @param {string} name Option name\r
- * @param {*} value Option value\r
- * @param {boolean} [ifNotSet] Sets the option only if it isn't currently set\r
- * @returns {ReflectionObject} `this`\r
- */\r
-ReflectionObject.prototype.setOption = function setOption(name, value, ifNotSet) {\r
- if (!ifNotSet || !this.options || this.options[name] === undefined)\r
- (this.options || (this.options = {}))[name] = value;\r
- return this;\r
-};\r
-\r
-/**\r
- * Sets multiple options.\r
- * @param {Object.<string,*>} options Options to set\r
- * @param {boolean} [ifNotSet] Sets an option only if it isn't currently set\r
- * @returns {ReflectionObject} `this`\r
- */\r
-ReflectionObject.prototype.setOptions = function setOptions(options, ifNotSet) {\r
- if (options)\r
- for (var keys = Object.keys(options), i = 0; i < keys.length; ++i)\r
- this.setOption(keys[i], options[keys[i]], ifNotSet);\r
- return this;\r
-};\r
-\r
-/**\r
- * Converts this instance to its string representation.\r
- * @returns {string} Class name[, space, full name]\r
- */\r
-ReflectionObject.prototype.toString = function toString() {\r
- var className = this.constructor.className,\r
- fullName = this.fullName;\r
- if (fullName.length)\r
- return className + " " + fullName;\r
- return className;\r
-};\r
-\r
-ReflectionObject._configure = function(Root_) {\r
- Root = Root_;\r
-};\r
-
-},{"./util":218}],206:[function(require,module,exports){
-"use strict";\r
-module.exports = OneOf;\r
-\r
-// extends ReflectionObject\r
-var ReflectionObject = require("./object");\r
-((OneOf.prototype = Object.create(ReflectionObject.prototype)).constructor = OneOf).className = "OneOf";\r
-\r
-var Field = require("./field"),\r
- util = require("./util");\r
-\r
-/**\r
- * Constructs a new oneof instance.\r
- * @classdesc Reflected oneof.\r
- * @extends ReflectionObject\r
- * @constructor\r
- * @param {string} name Oneof name\r
- * @param {string[]|Object.<string,*>} [fieldNames] Field names\r
- * @param {Object.<string,*>} [options] Declared options\r
- * @param {string} [comment] Comment associated with this field\r
- */\r
-function OneOf(name, fieldNames, options, comment) {\r
- if (!Array.isArray(fieldNames)) {\r
- options = fieldNames;\r
- fieldNames = undefined;\r
- }\r
- ReflectionObject.call(this, name, options);\r
-\r
- /* istanbul ignore if */\r
- if (!(fieldNames === undefined || Array.isArray(fieldNames)))\r
- throw TypeError("fieldNames must be an Array");\r
-\r
- /**\r
- * Field names that belong to this oneof.\r
- * @type {string[]}\r
- */\r
- this.oneof = fieldNames || []; // toJSON, marker\r
-\r
- /**\r
- * Fields that belong to this oneof as an array for iteration.\r
- * @type {Field[]}\r
- * @readonly\r
- */\r
- this.fieldsArray = []; // declared readonly for conformance, possibly not yet added to parent\r
-\r
- /**\r
- * Comment for this field.\r
- * @type {string|null}\r
- */\r
- this.comment = comment;\r
-}\r
-\r
-/**\r
- * Oneof descriptor.\r
- * @interface IOneOf\r
- * @property {Array.<string>} oneof Oneof field names\r
- * @property {Object.<string,*>} [options] Oneof options\r
- */\r
-\r
-/**\r
- * Constructs a oneof from a oneof descriptor.\r
- * @param {string} name Oneof name\r
- * @param {IOneOf} json Oneof descriptor\r
- * @returns {OneOf} Created oneof\r
- * @throws {TypeError} If arguments are invalid\r
- */\r
-OneOf.fromJSON = function fromJSON(name, json) {\r
- return new OneOf(name, json.oneof, json.options, json.comment);\r
-};\r
-\r
-/**\r
- * Converts this oneof to a oneof descriptor.\r
- * @param {IToJSONOptions} [toJSONOptions] JSON conversion options\r
- * @returns {IOneOf} Oneof descriptor\r
- */\r
-OneOf.prototype.toJSON = function toJSON(toJSONOptions) {\r
- var keepComments = toJSONOptions ? Boolean(toJSONOptions.keepComments) : false;\r
- return util.toObject([\r
- "options" , this.options,\r
- "oneof" , this.oneof,\r
- "comment" , keepComments ? this.comment : undefined\r
- ]);\r
-};\r
-\r
-/**\r
- * Adds the fields of the specified oneof to the parent if not already done so.\r
- * @param {OneOf} oneof The oneof\r
- * @returns {undefined}\r
- * @inner\r
- * @ignore\r
- */\r
-function addFieldsToParent(oneof) {\r
- if (oneof.parent)\r
- for (var i = 0; i < oneof.fieldsArray.length; ++i)\r
- if (!oneof.fieldsArray[i].parent)\r
- oneof.parent.add(oneof.fieldsArray[i]);\r
-}\r
-\r
-/**\r
- * Adds a field to this oneof and removes it from its current parent, if any.\r
- * @param {Field} field Field to add\r
- * @returns {OneOf} `this`\r
- */\r
-OneOf.prototype.add = function add(field) {\r
-\r
- /* istanbul ignore if */\r
- if (!(field instanceof Field))\r
- throw TypeError("field must be a Field");\r
-\r
- if (field.parent && field.parent !== this.parent)\r
- field.parent.remove(field);\r
- this.oneof.push(field.name);\r
- this.fieldsArray.push(field);\r
- field.partOf = this; // field.parent remains null\r
- addFieldsToParent(this);\r
- return this;\r
-};\r
-\r
-/**\r
- * Removes a field from this oneof and puts it back to the oneof's parent.\r
- * @param {Field} field Field to remove\r
- * @returns {OneOf} `this`\r
- */\r
-OneOf.prototype.remove = function remove(field) {\r
-\r
- /* istanbul ignore if */\r
- if (!(field instanceof Field))\r
- throw TypeError("field must be a Field");\r
-\r
- var index = this.fieldsArray.indexOf(field);\r
-\r
- /* istanbul ignore if */\r
- if (index < 0)\r
- throw Error(field + " is not a member of " + this);\r
-\r
- this.fieldsArray.splice(index, 1);\r
- index = this.oneof.indexOf(field.name);\r
-\r
- /* istanbul ignore else */\r
- if (index > -1) // theoretical\r
- this.oneof.splice(index, 1);\r
-\r
- field.partOf = null;\r
- return this;\r
-};\r
-\r
-/**\r
- * @override\r
- */\r
-OneOf.prototype.onAdd = function onAdd(parent) {\r
- ReflectionObject.prototype.onAdd.call(this, parent);\r
- var self = this;\r
- // Collect present fields\r
- for (var i = 0; i < this.oneof.length; ++i) {\r
- var field = parent.get(this.oneof[i]);\r
- if (field && !field.partOf) {\r
- field.partOf = self;\r
- self.fieldsArray.push(field);\r
- }\r
- }\r
- // Add not yet present fields\r
- addFieldsToParent(this);\r
-};\r
-\r
-/**\r
- * @override\r
- */\r
-OneOf.prototype.onRemove = function onRemove(parent) {\r
- for (var i = 0, field; i < this.fieldsArray.length; ++i)\r
- if ((field = this.fieldsArray[i]).parent)\r
- field.parent.remove(field);\r
- ReflectionObject.prototype.onRemove.call(this, parent);\r
-};\r
-\r
-/**\r
- * Decorator function as returned by {@link OneOf.d} (TypeScript).\r
- * @typedef OneOfDecorator\r
- * @type {function}\r
- * @param {Object} prototype Target prototype\r
- * @param {string} oneofName OneOf name\r
- * @returns {undefined}\r
- */\r
-\r
-/**\r
- * OneOf decorator (TypeScript).\r
- * @function\r
- * @param {...string} fieldNames Field names\r
- * @returns {OneOfDecorator} Decorator function\r
- * @template T extends string\r
- */\r
-OneOf.d = function decorateOneOf() {\r
- var fieldNames = new Array(arguments.length),\r
- index = 0;\r
- while (index < arguments.length)\r
- fieldNames[index] = arguments[index++];\r
- return function oneOfDecorator(prototype, oneofName) {\r
- util.decorateType(prototype.constructor)\r
- .add(new OneOf(oneofName, fieldNames));\r
- Object.defineProperty(prototype, oneofName, {\r
- get: util.oneOfGetter(fieldNames),\r
- set: util.oneOfSetter(fieldNames)\r
- });\r
- };\r
-};\r
-
-},{"./field":197,"./object":205,"./util":218}],207:[function(require,module,exports){
-"use strict";\r
-module.exports = parse;\r
-\r
-parse.filename = null;\r
-parse.defaults = { keepCase: false };\r
-\r
-var tokenize = require("./tokenize"),\r
- Root = require("./root"),\r
- Type = require("./type"),\r
- Field = require("./field"),\r
- MapField = require("./mapfield"),\r
- OneOf = require("./oneof"),\r
- Enum = require("./enum"),\r
- Service = require("./service"),\r
- Method = require("./method"),\r
- types = require("./types"),\r
- util = require("./util");\r
-\r
-var base10Re = /^[1-9][0-9]*$/,\r
- base10NegRe = /^-?[1-9][0-9]*$/,\r
- base16Re = /^0[x][0-9a-fA-F]+$/,\r
- base16NegRe = /^-?0[x][0-9a-fA-F]+$/,\r
- base8Re = /^0[0-7]+$/,\r
- base8NegRe = /^-?0[0-7]+$/,\r
- numberRe = /^(?![eE])[0-9]*(?:\.[0-9]*)?(?:[eE][+-]?[0-9]+)?$/,\r
- nameRe = /^[a-zA-Z_][a-zA-Z_0-9]*$/,\r
- typeRefRe = /^(?:\.?[a-zA-Z_][a-zA-Z_0-9]*)(?:\.[a-zA-Z_][a-zA-Z_0-9]*)*$/,\r
- fqTypeRefRe = /^(?:\.[a-zA-Z_][a-zA-Z_0-9]*)+$/;\r
-\r
-/**\r
- * Result object returned from {@link parse}.\r
- * @interface IParserResult\r
- * @property {string|undefined} package Package name, if declared\r
- * @property {string[]|undefined} imports Imports, if any\r
- * @property {string[]|undefined} weakImports Weak imports, if any\r
- * @property {string|undefined} syntax Syntax, if specified (either `"proto2"` or `"proto3"`)\r
- * @property {Root} root Populated root instance\r
- */\r
-\r
-/**\r
- * Options modifying the behavior of {@link parse}.\r
- * @interface IParseOptions\r
- * @property {boolean} [keepCase=false] Keeps field casing instead of converting to camel case\r
- * @property {boolean} [alternateCommentMode=false] Recognize double-slash comments in addition to doc-block comments.\r
- */\r
-\r
-/**\r
- * Options modifying the behavior of JSON serialization.\r
- * @interface IToJSONOptions\r
- * @property {boolean} [keepComments=false] Serializes comments.\r
- */\r
-\r
-/**\r
- * Parses the given .proto source and returns an object with the parsed contents.\r
- * @param {string} source Source contents\r
- * @param {Root} root Root to populate\r
- * @param {IParseOptions} [options] Parse options. Defaults to {@link parse.defaults} when omitted.\r
- * @returns {IParserResult} Parser result\r
- * @property {string} filename=null Currently processing file name for error reporting, if known\r
- * @property {IParseOptions} defaults Default {@link IParseOptions}\r
- */\r
-function parse(source, root, options) {\r
- /* eslint-disable callback-return */\r
- if (!(root instanceof Root)) {\r
- options = root;\r
- root = new Root();\r
- }\r
- if (!options)\r
- options = parse.defaults;\r
-\r
- var tn = tokenize(source, options.alternateCommentMode || false),\r
- next = tn.next,\r
- push = tn.push,\r
- peek = tn.peek,\r
- skip = tn.skip,\r
- cmnt = tn.cmnt;\r
-\r
- var head = true,\r
- pkg,\r
- imports,\r
- weakImports,\r
- syntax,\r
- isProto3 = false;\r
-\r
- var ptr = root;\r
-\r
- var applyCase = options.keepCase ? function(name) { return name; } : util.camelCase;\r
-\r
- /* istanbul ignore next */\r
- function illegal(token, name, insideTryCatch) {\r
- var filename = parse.filename;\r
- if (!insideTryCatch)\r
- parse.filename = null;\r
- return Error("illegal " + (name || "token") + " '" + token + "' (" + (filename ? filename + ", " : "") + "line " + tn.line + ")");\r
- }\r
-\r
- function readString() {\r
- var values = [],\r
- token;\r
- do {\r
- /* istanbul ignore if */\r
- if ((token = next()) !== "\"" && token !== "'")\r
- throw illegal(token);\r
-\r
- values.push(next());\r
- skip(token);\r
- token = peek();\r
- } while (token === "\"" || token === "'");\r
- return values.join("");\r
- }\r
-\r
- function readValue(acceptTypeRef) {\r
- var token = next();\r
- switch (token) {\r
- case "'":\r
- case "\"":\r
- push(token);\r
- return readString();\r
- case "true": case "TRUE":\r
- return true;\r
- case "false": case "FALSE":\r
- return false;\r
- }\r
- try {\r
- return parseNumber(token, /* insideTryCatch */ true);\r
- } catch (e) {\r
-\r
- /* istanbul ignore else */\r
- if (acceptTypeRef && typeRefRe.test(token))\r
- return token;\r
-\r
- /* istanbul ignore next */\r
- throw illegal(token, "value");\r
- }\r
- }\r
-\r
- function readRanges(target, acceptStrings) {\r
- var token, start;\r
- do {\r
- if (acceptStrings && ((token = peek()) === "\"" || token === "'"))\r
- target.push(readString());\r
- else\r
- target.push([ start = parseId(next()), skip("to", true) ? parseId(next()) : start ]);\r
- } while (skip(",", true));\r
- skip(";");\r
- }\r
-\r
- function parseNumber(token, insideTryCatch) {\r
- var sign = 1;\r
- if (token.charAt(0) === "-") {\r
- sign = -1;\r
- token = token.substring(1);\r
- }\r
- switch (token) {\r
- case "inf": case "INF": case "Inf":\r
- return sign * Infinity;\r
- case "nan": case "NAN": case "Nan": case "NaN":\r
- return NaN;\r
- case "0":\r
- return 0;\r
- }\r
- if (base10Re.test(token))\r
- return sign * parseInt(token, 10);\r
- if (base16Re.test(token))\r
- return sign * parseInt(token, 16);\r
- if (base8Re.test(token))\r
- return sign * parseInt(token, 8);\r
-\r
- /* istanbul ignore else */\r
- if (numberRe.test(token))\r
- return sign * parseFloat(token);\r
-\r
- /* istanbul ignore next */\r
- throw illegal(token, "number", insideTryCatch);\r
- }\r
-\r
- function parseId(token, acceptNegative) {\r
- switch (token) {\r
- case "max": case "MAX": case "Max":\r
- return 536870911;\r
- case "0":\r
- return 0;\r
- }\r
-\r
- /* istanbul ignore if */\r
- if (!acceptNegative && token.charAt(0) === "-")\r
- throw illegal(token, "id");\r
-\r
- if (base10NegRe.test(token))\r
- return parseInt(token, 10);\r
- if (base16NegRe.test(token))\r
- return parseInt(token, 16);\r
-\r
- /* istanbul ignore else */\r
- if (base8NegRe.test(token))\r
- return parseInt(token, 8);\r
-\r
- /* istanbul ignore next */\r
- throw illegal(token, "id");\r
- }\r
-\r
- function parsePackage() {\r
-\r
- /* istanbul ignore if */\r
- if (pkg !== undefined)\r
- throw illegal("package");\r
-\r
- pkg = next();\r
-\r
- /* istanbul ignore if */\r
- if (!typeRefRe.test(pkg))\r
- throw illegal(pkg, "name");\r
-\r
- ptr = ptr.define(pkg);\r
- skip(";");\r
- }\r
-\r
- function parseImport() {\r
- var token = peek();\r
- var whichImports;\r
- switch (token) {\r
- case "weak":\r
- whichImports = weakImports || (weakImports = []);\r
- next();\r
- break;\r
- case "public":\r
- next();\r
- // eslint-disable-line no-fallthrough\r
- default:\r
- whichImports = imports || (imports = []);\r
- break;\r
- }\r
- token = readString();\r
- skip(";");\r
- whichImports.push(token);\r
- }\r
-\r
- function parseSyntax() {\r
- skip("=");\r
- syntax = readString();\r
- isProto3 = syntax === "proto3";\r
-\r
- /* istanbul ignore if */\r
- if (!isProto3 && syntax !== "proto2")\r
- throw illegal(syntax, "syntax");\r
-\r
- skip(";");\r
- }\r
-\r
- function parseCommon(parent, token) {\r
- switch (token) {\r
-\r
- case "option":\r
- parseOption(parent, token);\r
- skip(";");\r
- return true;\r
-\r
- case "message":\r
- parseType(parent, token);\r
- return true;\r
-\r
- case "enum":\r
- parseEnum(parent, token);\r
- return true;\r
-\r
- case "service":\r
- parseService(parent, token);\r
- return true;\r
-\r
- case "extend":\r
- parseExtension(parent, token);\r
- return true;\r
- }\r
- return false;\r
- }\r
-\r
- function ifBlock(obj, fnIf, fnElse) {\r
- var trailingLine = tn.line;\r
- if (obj) {\r
- obj.comment = cmnt(); // try block-type comment\r
- obj.filename = parse.filename;\r
- }\r
- if (skip("{", true)) {\r
- var token;\r
- while ((token = next()) !== "}")\r
- fnIf(token);\r
- skip(";", true);\r
- } else {\r
- if (fnElse)\r
- fnElse();\r
- skip(";");\r
- if (obj && typeof obj.comment !== "string")\r
- obj.comment = cmnt(trailingLine); // try line-type comment if no block\r
- }\r
- }\r
-\r
- function parseType(parent, token) {\r
-\r
- /* istanbul ignore if */\r
- if (!nameRe.test(token = next()))\r
- throw illegal(token, "type name");\r
-\r
- var type = new Type(token);\r
- ifBlock(type, function parseType_block(token) {\r
- if (parseCommon(type, token))\r
- return;\r
-\r
- switch (token) {\r
-\r
- case "map":\r
- parseMapField(type, token);\r
- break;\r
-\r
- case "required":\r
- case "optional":\r
- case "repeated":\r
- parseField(type, token);\r
- break;\r
-\r
- case "oneof":\r
- parseOneOf(type, token);\r
- break;\r
-\r
- case "extensions":\r
- readRanges(type.extensions || (type.extensions = []));\r
- break;\r
-\r
- case "reserved":\r
- readRanges(type.reserved || (type.reserved = []), true);\r
- break;\r
-\r
- default:\r
- /* istanbul ignore if */\r
- if (!isProto3 || !typeRefRe.test(token))\r
- throw illegal(token);\r
-\r
- push(token);\r
- parseField(type, "optional");\r
- break;\r
- }\r
- });\r
- parent.add(type);\r
- }\r
-\r
- function parseField(parent, rule, extend) {\r
- var type = next();\r
- if (type === "group") {\r
- parseGroup(parent, rule);\r
- return;\r
- }\r
-\r
- /* istanbul ignore if */\r
- if (!typeRefRe.test(type))\r
- throw illegal(type, "type");\r
-\r
- var name = next();\r
-\r
- /* istanbul ignore if */\r
- if (!nameRe.test(name))\r
- throw illegal(name, "name");\r
-\r
- name = applyCase(name);\r
- skip("=");\r
-\r
- var field = new Field(name, parseId(next()), type, rule, extend);\r
- ifBlock(field, function parseField_block(token) {\r
-\r
- /* istanbul ignore else */\r
- if (token === "option") {\r
- parseOption(field, token);\r
- skip(";");\r
- } else\r
- throw illegal(token);\r
-\r
- }, function parseField_line() {\r
- parseInlineOptions(field);\r
- });\r
- parent.add(field);\r
-\r
- // JSON defaults to packed=true if not set so we have to set packed=false explicity when\r
- // parsing proto2 descriptors without the option, where applicable. This must be done for\r
- // all known packable types and anything that could be an enum (= is not a basic type).\r
- if (!isProto3 && field.repeated && (types.packed[type] !== undefined || types.basic[type] === undefined))\r
- field.setOption("packed", false, /* ifNotSet */ true);\r
- }\r
-\r
- function parseGroup(parent, rule) {\r
- var name = next();\r
-\r
- /* istanbul ignore if */\r
- if (!nameRe.test(name))\r
- throw illegal(name, "name");\r
-\r
- var fieldName = util.lcFirst(name);\r
- if (name === fieldName)\r
- name = util.ucFirst(name);\r
- skip("=");\r
- var id = parseId(next());\r
- var type = new Type(name);\r
- type.group = true;\r
- var field = new Field(fieldName, id, name, rule);\r
- field.filename = parse.filename;\r
- ifBlock(type, function parseGroup_block(token) {\r
- switch (token) {\r
-\r
- case "option":\r
- parseOption(type, token);\r
- skip(";");\r
- break;\r
-\r
- case "required":\r
- case "optional":\r
- case "repeated":\r
- parseField(type, token);\r
- break;\r
-\r
- /* istanbul ignore next */\r
- default:\r
- throw illegal(token); // there are no groups with proto3 semantics\r
- }\r
- });\r
- parent.add(type)\r
- .add(field);\r
- }\r
-\r
- function parseMapField(parent) {\r
- skip("<");\r
- var keyType = next();\r
-\r
- /* istanbul ignore if */\r
- if (types.mapKey[keyType] === undefined)\r
- throw illegal(keyType, "type");\r
-\r
- skip(",");\r
- var valueType = next();\r
-\r
- /* istanbul ignore if */\r
- if (!typeRefRe.test(valueType))\r
- throw illegal(valueType, "type");\r
-\r
- skip(">");\r
- var name = next();\r
-\r
- /* istanbul ignore if */\r
- if (!nameRe.test(name))\r
- throw illegal(name, "name");\r
-\r
- skip("=");\r
- var field = new MapField(applyCase(name), parseId(next()), keyType, valueType);\r
- ifBlock(field, function parseMapField_block(token) {\r
-\r
- /* istanbul ignore else */\r
- if (token === "option") {\r
- parseOption(field, token);\r
- skip(";");\r
- } else\r
- throw illegal(token);\r
-\r
- }, function parseMapField_line() {\r
- parseInlineOptions(field);\r
- });\r
- parent.add(field);\r
- }\r
-\r
- function parseOneOf(parent, token) {\r
-\r
- /* istanbul ignore if */\r
- if (!nameRe.test(token = next()))\r
- throw illegal(token, "name");\r
-\r
- var oneof = new OneOf(applyCase(token));\r
- ifBlock(oneof, function parseOneOf_block(token) {\r
- if (token === "option") {\r
- parseOption(oneof, token);\r
- skip(";");\r
- } else {\r
- push(token);\r
- parseField(oneof, "optional");\r
- }\r
- });\r
- parent.add(oneof);\r
- }\r
-\r
- function parseEnum(parent, token) {\r
-\r
- /* istanbul ignore if */\r
- if (!nameRe.test(token = next()))\r
- throw illegal(token, "name");\r
-\r
- var enm = new Enum(token);\r
- ifBlock(enm, function parseEnum_block(token) {\r
- switch(token) {\r
- case "option":\r
- parseOption(enm, token);\r
- skip(";");\r
- break;\r
-\r
- case "reserved":\r
- readRanges(enm.reserved || (enm.reserved = []), true);\r
- break;\r
-\r
- default:\r
- parseEnumValue(enm, token);\r
- }\r
- });\r
- parent.add(enm);\r
- }\r
-\r
- function parseEnumValue(parent, token) {\r
-\r
- /* istanbul ignore if */\r
- if (!nameRe.test(token))\r
- throw illegal(token, "name");\r
-\r
- skip("=");\r
- var value = parseId(next(), true),\r
- dummy = {};\r
- ifBlock(dummy, function parseEnumValue_block(token) {\r
-\r
- /* istanbul ignore else */\r
- if (token === "option") {\r
- parseOption(dummy, token); // skip\r
- skip(";");\r
- } else\r
- throw illegal(token);\r
-\r
- }, function parseEnumValue_line() {\r
- parseInlineOptions(dummy); // skip\r
- });\r
- parent.add(token, value, dummy.comment);\r
- }\r
-\r
- function parseOption(parent, token) {\r
- var isCustom = skip("(", true);\r
-\r
- /* istanbul ignore if */\r
- if (!typeRefRe.test(token = next()))\r
- throw illegal(token, "name");\r
-\r
- var name = token;\r
- if (isCustom) {\r
- skip(")");\r
- name = "(" + name + ")";\r
- token = peek();\r
- if (fqTypeRefRe.test(token)) {\r
- name += token;\r
- next();\r
- }\r
- }\r
- skip("=");\r
- parseOptionValue(parent, name);\r
- }\r
-\r
- function parseOptionValue(parent, name) {\r
- if (skip("{", true)) { // { a: "foo" b { c: "bar" } }\r
- do {\r
- /* istanbul ignore if */\r
- if (!nameRe.test(token = next()))\r
- throw illegal(token, "name");\r
-\r
- if (peek() === "{")\r
- parseOptionValue(parent, name + "." + token);\r
- else {\r
- skip(":");\r
- if (peek() === "{")\r
- parseOptionValue(parent, name + "." + token);\r
- else\r
- setOption(parent, name + "." + token, readValue(true));\r
- }\r
- } while (!skip("}", true));\r
- } else\r
- setOption(parent, name, readValue(true));\r
- // Does not enforce a delimiter to be universal\r
- }\r
-\r
- function setOption(parent, name, value) {\r
- if (parent.setOption)\r
- parent.setOption(name, value);\r
- }\r
-\r
- function parseInlineOptions(parent) {\r
- if (skip("[", true)) {\r
- do {\r
- parseOption(parent, "option");\r
- } while (skip(",", true));\r
- skip("]");\r
- }\r
- return parent;\r
- }\r
-\r
- function parseService(parent, token) {\r
-\r
- /* istanbul ignore if */\r
- if (!nameRe.test(token = next()))\r
- throw illegal(token, "service name");\r
-\r
- var service = new Service(token);\r
- ifBlock(service, function parseService_block(token) {\r
- if (parseCommon(service, token))\r
- return;\r
-\r
- /* istanbul ignore else */\r
- if (token === "rpc")\r
- parseMethod(service, token);\r
- else\r
- throw illegal(token);\r
- });\r
- parent.add(service);\r
- }\r
-\r
- function parseMethod(parent, token) {\r
- var type = token;\r
-\r
- /* istanbul ignore if */\r
- if (!nameRe.test(token = next()))\r
- throw illegal(token, "name");\r
-\r
- var name = token,\r
- requestType, requestStream,\r
- responseType, responseStream;\r
-\r
- skip("(");\r
- if (skip("stream", true))\r
- requestStream = true;\r
-\r
- /* istanbul ignore if */\r
- if (!typeRefRe.test(token = next()))\r
- throw illegal(token);\r
-\r
- requestType = token;\r
- skip(")"); skip("returns"); skip("(");\r
- if (skip("stream", true))\r
- responseStream = true;\r
-\r
- /* istanbul ignore if */\r
- if (!typeRefRe.test(token = next()))\r
- throw illegal(token);\r
-\r
- responseType = token;\r
- skip(")");\r
-\r
- var method = new Method(name, type, requestType, responseType, requestStream, responseStream);\r
- ifBlock(method, function parseMethod_block(token) {\r
-\r
- /* istanbul ignore else */\r
- if (token === "option") {\r
- parseOption(method, token);\r
- skip(";");\r
- } else\r
- throw illegal(token);\r
-\r
- });\r
- parent.add(method);\r
- }\r
-\r
- function parseExtension(parent, token) {\r
-\r
- /* istanbul ignore if */\r
- if (!typeRefRe.test(token = next()))\r
- throw illegal(token, "reference");\r
-\r
- var reference = token;\r
- ifBlock(null, function parseExtension_block(token) {\r
- switch (token) {\r
-\r
- case "required":\r
- case "repeated":\r
- case "optional":\r
- parseField(parent, token, reference);\r
- break;\r
-\r
- default:\r
- /* istanbul ignore if */\r
- if (!isProto3 || !typeRefRe.test(token))\r
- throw illegal(token);\r
- push(token);\r
- parseField(parent, "optional", reference);\r
- break;\r
- }\r
- });\r
- }\r
-\r
- var token;\r
- while ((token = next()) !== null) {\r
- switch (token) {\r
-\r
- case "package":\r
-\r
- /* istanbul ignore if */\r
- if (!head)\r
- throw illegal(token);\r
-\r
- parsePackage();\r
- break;\r
-\r
- case "import":\r
-\r
- /* istanbul ignore if */\r
- if (!head)\r
- throw illegal(token);\r
-\r
- parseImport();\r
- break;\r
-\r
- case "syntax":\r
-\r
- /* istanbul ignore if */\r
- if (!head)\r
- throw illegal(token);\r
-\r
- parseSyntax();\r
- break;\r
-\r
- case "option":\r
-\r
- /* istanbul ignore if */\r
- if (!head)\r
- throw illegal(token);\r
-\r
- parseOption(ptr, token);\r
- skip(";");\r
- break;\r
-\r
- default:\r
-\r
- /* istanbul ignore else */\r
- if (parseCommon(ptr, token)) {\r
- head = false;\r
- continue;\r
- }\r
-\r
- /* istanbul ignore next */\r
- throw illegal(token);\r
- }\r
- }\r
-\r
- parse.filename = null;\r
- return {\r
- "package" : pkg,\r
- "imports" : imports,\r
- weakImports : weakImports,\r
- syntax : syntax,\r
- root : root\r
- };\r
-}\r
-\r
-/**\r
- * Parses the given .proto source and returns an object with the parsed contents.\r
- * @name parse\r
- * @function\r
- * @param {string} source Source contents\r
- * @param {IParseOptions} [options] Parse options. Defaults to {@link parse.defaults} when omitted.\r
- * @returns {IParserResult} Parser result\r
- * @property {string} filename=null Currently processing file name for error reporting, if known\r
- * @property {IParseOptions} defaults Default {@link IParseOptions}\r
- * @variation 2\r
- */\r
-
-},{"./enum":196,"./field":197,"./mapfield":201,"./method":203,"./oneof":206,"./root":210,"./service":214,"./tokenize":215,"./type":216,"./types":217,"./util":218}],208:[function(require,module,exports){
-"use strict";\r
-module.exports = Reader;\r
-\r
-var util = require("./util/minimal");\r
-\r
-var BufferReader; // cyclic\r
-\r
-var LongBits = util.LongBits,\r
- utf8 = util.utf8;\r
-\r
-/* istanbul ignore next */\r
-function indexOutOfRange(reader, writeLength) {\r
- return RangeError("index out of range: " + reader.pos + " + " + (writeLength || 1) + " > " + reader.len);\r
-}\r
-\r
-/**\r
- * Constructs a new reader instance using the specified buffer.\r
- * @classdesc Wire format reader using `Uint8Array` if available, otherwise `Array`.\r
- * @constructor\r
- * @param {Uint8Array} buffer Buffer to read from\r
- */\r
-function Reader(buffer) {\r
-\r
- /**\r
- * Read buffer.\r
- * @type {Uint8Array}\r
- */\r
- this.buf = buffer;\r
-\r
- /**\r
- * Read buffer position.\r
- * @type {number}\r
- */\r
- this.pos = 0;\r
-\r
- /**\r
- * Read buffer length.\r
- * @type {number}\r
- */\r
- this.len = buffer.length;\r
-}\r
-\r
-var create_array = typeof Uint8Array !== "undefined"\r
- ? function create_typed_array(buffer) {\r
- if (buffer instanceof Uint8Array || Array.isArray(buffer))\r
- return new Reader(buffer);\r
- throw Error("illegal buffer");\r
- }\r
- /* istanbul ignore next */\r
- : function create_array(buffer) {\r
- if (Array.isArray(buffer))\r
- return new Reader(buffer);\r
- throw Error("illegal buffer");\r
- };\r
-\r
-/**\r
- * Creates a new reader using the specified buffer.\r
- * @function\r
- * @param {Uint8Array|Buffer} buffer Buffer to read from\r
- * @returns {Reader|BufferReader} A {@link BufferReader} if `buffer` is a Buffer, otherwise a {@link Reader}\r
- * @throws {Error} If `buffer` is not a valid buffer\r
- */\r
-Reader.create = util.Buffer\r
- ? function create_buffer_setup(buffer) {\r
- return (Reader.create = function create_buffer(buffer) {\r
- return util.Buffer.isBuffer(buffer)\r
- ? new BufferReader(buffer)\r
- /* istanbul ignore next */\r
- : create_array(buffer);\r
- })(buffer);\r
- }\r
- /* istanbul ignore next */\r
- : create_array;\r
-\r
-Reader.prototype._slice = util.Array.prototype.subarray || /* istanbul ignore next */ util.Array.prototype.slice;\r
-\r
-/**\r
- * Reads a varint as an unsigned 32 bit value.\r
- * @function\r
- * @returns {number} Value read\r
- */\r
-Reader.prototype.uint32 = (function read_uint32_setup() {\r
- var value = 4294967295; // optimizer type-hint, tends to deopt otherwise (?!)\r
- return function read_uint32() {\r
- value = ( this.buf[this.pos] & 127 ) >>> 0; if (this.buf[this.pos++] < 128) return value;\r
- value = (value | (this.buf[this.pos] & 127) << 7) >>> 0; if (this.buf[this.pos++] < 128) return value;\r
- value = (value | (this.buf[this.pos] & 127) << 14) >>> 0; if (this.buf[this.pos++] < 128) return value;\r
- value = (value | (this.buf[this.pos] & 127) << 21) >>> 0; if (this.buf[this.pos++] < 128) return value;\r
- value = (value | (this.buf[this.pos] & 15) << 28) >>> 0; if (this.buf[this.pos++] < 128) return value;\r
-\r
- /* istanbul ignore if */\r
- if ((this.pos += 5) > this.len) {\r
- this.pos = this.len;\r
- throw indexOutOfRange(this, 10);\r
- }\r
- return value;\r
- };\r
-})();\r
-\r
-/**\r
- * Reads a varint as a signed 32 bit value.\r
- * @returns {number} Value read\r
- */\r
-Reader.prototype.int32 = function read_int32() {\r
- return this.uint32() | 0;\r
-};\r
-\r
-/**\r
- * Reads a zig-zag encoded varint as a signed 32 bit value.\r
- * @returns {number} Value read\r
- */\r
-Reader.prototype.sint32 = function read_sint32() {\r
- var value = this.uint32();\r
- return value >>> 1 ^ -(value & 1) | 0;\r
-};\r
-\r
-/* eslint-disable no-invalid-this */\r
-\r
-function readLongVarint() {\r
- // tends to deopt with local vars for octet etc.\r
- var bits = new LongBits(0, 0);\r
- var i = 0;\r
- if (this.len - this.pos > 4) { // fast route (lo)\r
- for (; i < 4; ++i) {\r
- // 1st..4th\r
- bits.lo = (bits.lo | (this.buf[this.pos] & 127) << i * 7) >>> 0;\r
- if (this.buf[this.pos++] < 128)\r
- return bits;\r
- }\r
- // 5th\r
- bits.lo = (bits.lo | (this.buf[this.pos] & 127) << 28) >>> 0;\r
- bits.hi = (bits.hi | (this.buf[this.pos] & 127) >> 4) >>> 0;\r
- if (this.buf[this.pos++] < 128)\r
- return bits;\r
- i = 0;\r
- } else {\r
- for (; i < 3; ++i) {\r
- /* istanbul ignore if */\r
- if (this.pos >= this.len)\r
- throw indexOutOfRange(this);\r
- // 1st..3th\r
- bits.lo = (bits.lo | (this.buf[this.pos] & 127) << i * 7) >>> 0;\r
- if (this.buf[this.pos++] < 128)\r
- return bits;\r
- }\r
- // 4th\r
- bits.lo = (bits.lo | (this.buf[this.pos++] & 127) << i * 7) >>> 0;\r
- return bits;\r
- }\r
- if (this.len - this.pos > 4) { // fast route (hi)\r
- for (; i < 5; ++i) {\r
- // 6th..10th\r
- bits.hi = (bits.hi | (this.buf[this.pos] & 127) << i * 7 + 3) >>> 0;\r
- if (this.buf[this.pos++] < 128)\r
- return bits;\r
- }\r
- } else {\r
- for (; i < 5; ++i) {\r
- /* istanbul ignore if */\r
- if (this.pos >= this.len)\r
- throw indexOutOfRange(this);\r
- // 6th..10th\r
- bits.hi = (bits.hi | (this.buf[this.pos] & 127) << i * 7 + 3) >>> 0;\r
- if (this.buf[this.pos++] < 128)\r
- return bits;\r
- }\r
- }\r
- /* istanbul ignore next */\r
- throw Error("invalid varint encoding");\r
-}\r
-\r
-/* eslint-enable no-invalid-this */\r
-\r
-/**\r
- * Reads a varint as a signed 64 bit value.\r
- * @name Reader#int64\r
- * @function\r
- * @returns {Long} Value read\r
- */\r
-\r
-/**\r
- * Reads a varint as an unsigned 64 bit value.\r
- * @name Reader#uint64\r
- * @function\r
- * @returns {Long} Value read\r
- */\r
-\r
-/**\r
- * Reads a zig-zag encoded varint as a signed 64 bit value.\r
- * @name Reader#sint64\r
- * @function\r
- * @returns {Long} Value read\r
- */\r
-\r
-/**\r
- * Reads a varint as a boolean.\r
- * @returns {boolean} Value read\r
- */\r
-Reader.prototype.bool = function read_bool() {\r
- return this.uint32() !== 0;\r
-};\r
-\r
-function readFixed32_end(buf, end) { // note that this uses `end`, not `pos`\r
- return (buf[end - 4]\r
- | buf[end - 3] << 8\r
- | buf[end - 2] << 16\r
- | buf[end - 1] << 24) >>> 0;\r
-}\r
-\r
-/**\r
- * Reads fixed 32 bits as an unsigned 32 bit integer.\r
- * @returns {number} Value read\r
- */\r
-Reader.prototype.fixed32 = function read_fixed32() {\r
-\r
- /* istanbul ignore if */\r
- if (this.pos + 4 > this.len)\r
- throw indexOutOfRange(this, 4);\r
-\r
- return readFixed32_end(this.buf, this.pos += 4);\r
-};\r
-\r
-/**\r
- * Reads fixed 32 bits as a signed 32 bit integer.\r
- * @returns {number} Value read\r
- */\r
-Reader.prototype.sfixed32 = function read_sfixed32() {\r
-\r
- /* istanbul ignore if */\r
- if (this.pos + 4 > this.len)\r
- throw indexOutOfRange(this, 4);\r
-\r
- return readFixed32_end(this.buf, this.pos += 4) | 0;\r
-};\r
-\r
-/* eslint-disable no-invalid-this */\r
-\r
-function readFixed64(/* this: Reader */) {\r
-\r
- /* istanbul ignore if */\r
- if (this.pos + 8 > this.len)\r
- throw indexOutOfRange(this, 8);\r
-\r
- return new LongBits(readFixed32_end(this.buf, this.pos += 4), readFixed32_end(this.buf, this.pos += 4));\r
-}\r
-\r
-/* eslint-enable no-invalid-this */\r
-\r
-/**\r
- * Reads fixed 64 bits.\r
- * @name Reader#fixed64\r
- * @function\r
- * @returns {Long} Value read\r
- */\r
-\r
-/**\r
- * Reads zig-zag encoded fixed 64 bits.\r
- * @name Reader#sfixed64\r
- * @function\r
- * @returns {Long} Value read\r
- */\r
-\r
-/**\r
- * Reads a float (32 bit) as a number.\r
- * @function\r
- * @returns {number} Value read\r
- */\r
-Reader.prototype.float = function read_float() {\r
-\r
- /* istanbul ignore if */\r
- if (this.pos + 4 > this.len)\r
- throw indexOutOfRange(this, 4);\r
-\r
- var value = util.float.readFloatLE(this.buf, this.pos);\r
- this.pos += 4;\r
- return value;\r
-};\r
-\r
-/**\r
- * Reads a double (64 bit float) as a number.\r
- * @function\r
- * @returns {number} Value read\r
- */\r
-Reader.prototype.double = function read_double() {\r
-\r
- /* istanbul ignore if */\r
- if (this.pos + 8 > this.len)\r
- throw indexOutOfRange(this, 4);\r
-\r
- var value = util.float.readDoubleLE(this.buf, this.pos);\r
- this.pos += 8;\r
- return value;\r
-};\r
-\r
-/**\r
- * Reads a sequence of bytes preceeded by its length as a varint.\r
- * @returns {Uint8Array} Value read\r
- */\r
-Reader.prototype.bytes = function read_bytes() {\r
- var length = this.uint32(),\r
- start = this.pos,\r
- end = this.pos + length;\r
-\r
- /* istanbul ignore if */\r
- if (end > this.len)\r
- throw indexOutOfRange(this, length);\r
-\r
- this.pos += length;\r
- if (Array.isArray(this.buf)) // plain array\r
- return this.buf.slice(start, end);\r
- return start === end // fix for IE 10/Win8 and others' subarray returning array of size 1\r
- ? new this.buf.constructor(0)\r
- : this._slice.call(this.buf, start, end);\r
-};\r
-\r
-/**\r
- * Reads a string preceeded by its byte length as a varint.\r
- * @returns {string} Value read\r
- */\r
-Reader.prototype.string = function read_string() {\r
- var bytes = this.bytes();\r
- return utf8.read(bytes, 0, bytes.length);\r
-};\r
-\r
-/**\r
- * Skips the specified number of bytes if specified, otherwise skips a varint.\r
- * @param {number} [length] Length if known, otherwise a varint is assumed\r
- * @returns {Reader} `this`\r
- */\r
-Reader.prototype.skip = function skip(length) {\r
- if (typeof length === "number") {\r
- /* istanbul ignore if */\r
- if (this.pos + length > this.len)\r
- throw indexOutOfRange(this, length);\r
- this.pos += length;\r
- } else {\r
- do {\r
- /* istanbul ignore if */\r
- if (this.pos >= this.len)\r
- throw indexOutOfRange(this);\r
- } while (this.buf[this.pos++] & 128);\r
- }\r
- return this;\r
-};\r
-\r
-/**\r
- * Skips the next element of the specified wire type.\r
- * @param {number} wireType Wire type received\r
- * @returns {Reader} `this`\r
- */\r
-Reader.prototype.skipType = function(wireType) {\r
- switch (wireType) {\r
- case 0:\r
- this.skip();\r
- break;\r
- case 1:\r
- this.skip(8);\r
- break;\r
- case 2:\r
- this.skip(this.uint32());\r
- break;\r
- case 3:\r
- do { // eslint-disable-line no-constant-condition\r
- if ((wireType = this.uint32() & 7) === 4)\r
- break;\r
- this.skipType(wireType);\r
- } while (true);\r
- break;\r
- case 5:\r
- this.skip(4);\r
- break;\r
-\r
- /* istanbul ignore next */\r
- default:\r
- throw Error("invalid wire type " + wireType + " at offset " + this.pos);\r
- }\r
- return this;\r
-};\r
-\r
-Reader._configure = function(BufferReader_) {\r
- BufferReader = BufferReader_;\r
-\r
- var fn = util.Long ? "toLong" : /* istanbul ignore next */ "toNumber";\r
- util.merge(Reader.prototype, {\r
-\r
- int64: function read_int64() {\r
- return readLongVarint.call(this)[fn](false);\r
- },\r
-\r
- uint64: function read_uint64() {\r
- return readLongVarint.call(this)[fn](true);\r
- },\r
-\r
- sint64: function read_sint64() {\r
- return readLongVarint.call(this).zzDecode()[fn](false);\r
- },\r
-\r
- fixed64: function read_fixed64() {\r
- return readFixed64.call(this)[fn](true);\r
- },\r
-\r
- sfixed64: function read_sfixed64() {\r
- return readFixed64.call(this)[fn](false);\r
- }\r
-\r
- });\r
-};\r
-
-},{"./util/minimal":220}],209:[function(require,module,exports){
-"use strict";\r
-module.exports = BufferReader;\r
-\r
-// extends Reader\r
-var Reader = require("./reader");\r
-(BufferReader.prototype = Object.create(Reader.prototype)).constructor = BufferReader;\r
-\r
-var util = require("./util/minimal");\r
-\r
-/**\r
- * Constructs a new buffer reader instance.\r
- * @classdesc Wire format reader using node buffers.\r
- * @extends Reader\r
- * @constructor\r
- * @param {Buffer} buffer Buffer to read from\r
- */\r
-function BufferReader(buffer) {\r
- Reader.call(this, buffer);\r
-\r
- /**\r
- * Read buffer.\r
- * @name BufferReader#buf\r
- * @type {Buffer}\r
- */\r
-}\r
-\r
-/* istanbul ignore else */\r
-if (util.Buffer)\r
- BufferReader.prototype._slice = util.Buffer.prototype.slice;\r
-\r
-/**\r
- * @override\r
- */\r
-BufferReader.prototype.string = function read_string_buffer() {\r
- var len = this.uint32(); // modifies pos\r
- return this.buf.utf8Slice(this.pos, this.pos = Math.min(this.pos + len, this.len));\r
-};\r
-\r
-/**\r
- * Reads a sequence of bytes preceeded by its length as a varint.\r
- * @name BufferReader#bytes\r
- * @function\r
- * @returns {Buffer} Value read\r
- */\r
-
-},{"./reader":208,"./util/minimal":220}],210:[function(require,module,exports){
-"use strict";\r
-module.exports = Root;\r
-\r
-// extends Namespace\r
-var Namespace = require("./namespace");\r
-((Root.prototype = Object.create(Namespace.prototype)).constructor = Root).className = "Root";\r
-\r
-var Field = require("./field"),\r
- Enum = require("./enum"),\r
- OneOf = require("./oneof"),\r
- util = require("./util");\r
-\r
-var Type, // cyclic\r
- parse, // might be excluded\r
- common; // "\r
-\r
-/**\r
- * Constructs a new root namespace instance.\r
- * @classdesc Root namespace wrapping all types, enums, services, sub-namespaces etc. that belong together.\r
- * @extends NamespaceBase\r
- * @constructor\r
- * @param {Object.<string,*>} [options] Top level options\r
- */\r
-function Root(options) {\r
- Namespace.call(this, "", options);\r
-\r
- /**\r
- * Deferred extension fields.\r
- * @type {Field[]}\r
- */\r
- this.deferred = [];\r
-\r
- /**\r
- * Resolved file names of loaded files.\r
- * @type {string[]}\r
- */\r
- this.files = [];\r
-}\r
-\r
-/**\r
- * Loads a namespace descriptor into a root namespace.\r
- * @param {INamespace} json Nameespace descriptor\r
- * @param {Root} [root] Root namespace, defaults to create a new one if omitted\r
- * @returns {Root} Root namespace\r
- */\r
-Root.fromJSON = function fromJSON(json, root) {\r
- if (!root)\r
- root = new Root();\r
- if (json.options)\r
- root.setOptions(json.options);\r
- return root.addJSON(json.nested);\r
-};\r
-\r
-/**\r
- * Resolves the path of an imported file, relative to the importing origin.\r
- * This method exists so you can override it with your own logic in case your imports are scattered over multiple directories.\r
- * @function\r
- * @param {string} origin The file name of the importing file\r
- * @param {string} target The file name being imported\r
- * @returns {string|null} Resolved path to `target` or `null` to skip the file\r
- */\r
-Root.prototype.resolvePath = util.path.resolve;\r
-\r
-// A symbol-like function to safely signal synchronous loading\r
-/* istanbul ignore next */\r
-function SYNC() {} // eslint-disable-line no-empty-function\r
-\r
-/**\r
- * Loads one or multiple .proto or preprocessed .json files into this root namespace and calls the callback.\r
- * @param {string|string[]} filename Names of one or multiple files to load\r
- * @param {IParseOptions} options Parse options\r
- * @param {LoadCallback} callback Callback function\r
- * @returns {undefined}\r
- */\r
-Root.prototype.load = function load(filename, options, callback) {\r
- if (typeof options === "function") {\r
- callback = options;\r
- options = undefined;\r
- }\r
- var self = this;\r
- if (!callback)\r
- return util.asPromise(load, self, filename, options);\r
-\r
- var sync = callback === SYNC; // undocumented\r
-\r
- // Finishes loading by calling the callback (exactly once)\r
- function finish(err, root) {\r
- /* istanbul ignore if */\r
- if (!callback)\r
- return;\r
- var cb = callback;\r
- callback = null;\r
- if (sync)\r
- throw err;\r
- cb(err, root);\r
- }\r
-\r
- // Processes a single file\r
- function process(filename, source) {\r
- try {\r
- if (util.isString(source) && source.charAt(0) === "{")\r
- source = JSON.parse(source);\r
- if (!util.isString(source))\r
- self.setOptions(source.options).addJSON(source.nested);\r
- else {\r
- parse.filename = filename;\r
- var parsed = parse(source, self, options),\r
- resolved,\r
- i = 0;\r
- if (parsed.imports)\r
- for (; i < parsed.imports.length; ++i)\r
- if (resolved = self.resolvePath(filename, parsed.imports[i]))\r
- fetch(resolved);\r
- if (parsed.weakImports)\r
- for (i = 0; i < parsed.weakImports.length; ++i)\r
- if (resolved = self.resolvePath(filename, parsed.weakImports[i]))\r
- fetch(resolved, true);\r
- }\r
- } catch (err) {\r
- finish(err);\r
- }\r
- if (!sync && !queued)\r
- finish(null, self); // only once anyway\r
- }\r
-\r
- // Fetches a single file\r
- function fetch(filename, weak) {\r
-\r
- // Strip path if this file references a bundled definition\r
- var idx = filename.lastIndexOf("google/protobuf/");\r
- if (idx > -1) {\r
- var altname = filename.substring(idx);\r
- if (altname in common)\r
- filename = altname;\r
- }\r
-\r
- // Skip if already loaded / attempted\r
- if (self.files.indexOf(filename) > -1)\r
- return;\r
- self.files.push(filename);\r
-\r
- // Shortcut bundled definitions\r
- if (filename in common) {\r
- if (sync)\r
- process(filename, common[filename]);\r
- else {\r
- ++queued;\r
- setTimeout(function() {\r
- --queued;\r
- process(filename, common[filename]);\r
- });\r
- }\r
- return;\r
- }\r
-\r
- // Otherwise fetch from disk or network\r
- if (sync) {\r
- var source;\r
- try {\r
- source = util.fs.readFileSync(filename).toString("utf8");\r
- } catch (err) {\r
- if (!weak)\r
- finish(err);\r
- return;\r
- }\r
- process(filename, source);\r
- } else {\r
- ++queued;\r
- util.fetch(filename, function(err, source) {\r
- --queued;\r
- /* istanbul ignore if */\r
- if (!callback)\r
- return; // terminated meanwhile\r
- if (err) {\r
- /* istanbul ignore else */\r
- if (!weak)\r
- finish(err);\r
- else if (!queued) // can't be covered reliably\r
- finish(null, self);\r
- return;\r
- }\r
- process(filename, source);\r
- });\r
- }\r
- }\r
- var queued = 0;\r
-\r
- // Assembling the root namespace doesn't require working type\r
- // references anymore, so we can load everything in parallel\r
- if (util.isString(filename))\r
- filename = [ filename ];\r
- for (var i = 0, resolved; i < filename.length; ++i)\r
- if (resolved = self.resolvePath("", filename[i]))\r
- fetch(resolved);\r
-\r
- if (sync)\r
- return self;\r
- if (!queued)\r
- finish(null, self);\r
- return undefined;\r
-};\r
-// function load(filename:string, options:IParseOptions, callback:LoadCallback):undefined\r
-\r
-/**\r
- * Loads one or multiple .proto or preprocessed .json files into this root namespace and calls the callback.\r
- * @function Root#load\r
- * @param {string|string[]} filename Names of one or multiple files to load\r
- * @param {LoadCallback} callback Callback function\r
- * @returns {undefined}\r
- * @variation 2\r
- */\r
-// function load(filename:string, callback:LoadCallback):undefined\r
-\r
-/**\r
- * Loads one or multiple .proto or preprocessed .json files into this root namespace and returns a promise.\r
- * @function Root#load\r
- * @param {string|string[]} filename Names of one or multiple files to load\r
- * @param {IParseOptions} [options] Parse options. Defaults to {@link parse.defaults} when omitted.\r
- * @returns {Promise<Root>} Promise\r
- * @variation 3\r
- */\r
-// function load(filename:string, [options:IParseOptions]):Promise<Root>\r
-\r
-/**\r
- * Synchronously loads one or multiple .proto or preprocessed .json files into this root namespace (node only).\r
- * @function Root#loadSync\r
- * @param {string|string[]} filename Names of one or multiple files to load\r
- * @param {IParseOptions} [options] Parse options. Defaults to {@link parse.defaults} when omitted.\r
- * @returns {Root} Root namespace\r
- * @throws {Error} If synchronous fetching is not supported (i.e. in browsers) or if a file's syntax is invalid\r
- */\r
-Root.prototype.loadSync = function loadSync(filename, options) {\r
- if (!util.isNode)\r
- throw Error("not supported");\r
- return this.load(filename, options, SYNC);\r
-};\r
-\r
-/**\r
- * @override\r
- */\r
-Root.prototype.resolveAll = function resolveAll() {\r
- if (this.deferred.length)\r
- throw Error("unresolvable extensions: " + this.deferred.map(function(field) {\r
- return "'extend " + field.extend + "' in " + field.parent.fullName;\r
- }).join(", "));\r
- return Namespace.prototype.resolveAll.call(this);\r
-};\r
-\r
-// only uppercased (and thus conflict-free) children are exposed, see below\r
-var exposeRe = /^[A-Z]/;\r
-\r
-/**\r
- * Handles a deferred declaring extension field by creating a sister field to represent it within its extended type.\r
- * @param {Root} root Root instance\r
- * @param {Field} field Declaring extension field witin the declaring type\r
- * @returns {boolean} `true` if successfully added to the extended type, `false` otherwise\r
- * @inner\r
- * @ignore\r
- */\r
-function tryHandleExtension(root, field) {\r
- var extendedType = field.parent.lookup(field.extend);\r
- if (extendedType) {\r
- var sisterField = new Field(field.fullName, field.id, field.type, field.rule, undefined, field.options);\r
- sisterField.declaringField = field;\r
- field.extensionField = sisterField;\r
- extendedType.add(sisterField);\r
- return true;\r
- }\r
- return false;\r
-}\r
-\r
-/**\r
- * Called when any object is added to this root or its sub-namespaces.\r
- * @param {ReflectionObject} object Object added\r
- * @returns {undefined}\r
- * @private\r
- */\r
-Root.prototype._handleAdd = function _handleAdd(object) {\r
- if (object instanceof Field) {\r
-\r
- if (/* an extension field (implies not part of a oneof) */ object.extend !== undefined && /* not already handled */ !object.extensionField)\r
- if (!tryHandleExtension(this, object))\r
- this.deferred.push(object);\r
-\r
- } else if (object instanceof Enum) {\r
-\r
- if (exposeRe.test(object.name))\r
- object.parent[object.name] = object.values; // expose enum values as property of its parent\r
-\r
- } else if (!(object instanceof OneOf)) /* everything else is a namespace */ {\r
-\r
- if (object instanceof Type) // Try to handle any deferred extensions\r
- for (var i = 0; i < this.deferred.length;)\r
- if (tryHandleExtension(this, this.deferred[i]))\r
- this.deferred.splice(i, 1);\r
- else\r
- ++i;\r
- for (var j = 0; j < /* initializes */ object.nestedArray.length; ++j) // recurse into the namespace\r
- this._handleAdd(object._nestedArray[j]);\r
- if (exposeRe.test(object.name))\r
- object.parent[object.name] = object; // expose namespace as property of its parent\r
- }\r
-\r
- // The above also adds uppercased (and thus conflict-free) nested types, services and enums as\r
- // properties of namespaces just like static code does. This allows using a .d.ts generated for\r
- // a static module with reflection-based solutions where the condition is met.\r
-};\r
-\r
-/**\r
- * Called when any object is removed from this root or its sub-namespaces.\r
- * @param {ReflectionObject} object Object removed\r
- * @returns {undefined}\r
- * @private\r
- */\r
-Root.prototype._handleRemove = function _handleRemove(object) {\r
- if (object instanceof Field) {\r
-\r
- if (/* an extension field */ object.extend !== undefined) {\r
- if (/* already handled */ object.extensionField) { // remove its sister field\r
- object.extensionField.parent.remove(object.extensionField);\r
- object.extensionField = null;\r
- } else { // cancel the extension\r
- var index = this.deferred.indexOf(object);\r
- /* istanbul ignore else */\r
- if (index > -1)\r
- this.deferred.splice(index, 1);\r
- }\r
- }\r
-\r
- } else if (object instanceof Enum) {\r
-\r
- if (exposeRe.test(object.name))\r
- delete object.parent[object.name]; // unexpose enum values\r
-\r
- } else if (object instanceof Namespace) {\r
-\r
- for (var i = 0; i < /* initializes */ object.nestedArray.length; ++i) // recurse into the namespace\r
- this._handleRemove(object._nestedArray[i]);\r
-\r
- if (exposeRe.test(object.name))\r
- delete object.parent[object.name]; // unexpose namespaces\r
-\r
- }\r
-};\r
-\r
-Root._configure = function(Type_, parse_, common_) {\r
- Type = Type_;\r
- parse = parse_;\r
- common = common_;\r
-};\r
-
-},{"./enum":196,"./field":197,"./namespace":204,"./oneof":206,"./util":218}],211:[function(require,module,exports){
-"use strict";\r
-module.exports = {};\r
-\r
-/**\r
- * Named roots.\r
- * This is where pbjs stores generated structures (the option `-r, --root` specifies a name).\r
- * Can also be used manually to make roots available accross modules.\r
- * @name roots\r
- * @type {Object.<string,Root>}\r
- * @example\r
- * // pbjs -r myroot -o compiled.js ...\r
- *\r
- * // in another module:\r
- * require("./compiled.js");\r
- *\r
- * // in any subsequent module:\r
- * var root = protobuf.roots["myroot"];\r
- */\r
-
-},{}],212:[function(require,module,exports){
-"use strict";\r
-\r
-/**\r
- * Streaming RPC helpers.\r
- * @namespace\r
- */\r
-var rpc = exports;\r
-\r
-/**\r
- * RPC implementation passed to {@link Service#create} performing a service request on network level, i.e. by utilizing http requests or websockets.\r
- * @typedef RPCImpl\r
- * @type {function}\r
- * @param {Method|rpc.ServiceMethod<Message<{}>,Message<{}>>} method Reflected or static method being called\r
- * @param {Uint8Array} requestData Request data\r
- * @param {RPCImplCallback} callback Callback function\r
- * @returns {undefined}\r
- * @example\r
- * function rpcImpl(method, requestData, callback) {\r
- * if (protobuf.util.lcFirst(method.name) !== "myMethod") // compatible with static code\r
- * throw Error("no such method");\r
- * asynchronouslyObtainAResponse(requestData, function(err, responseData) {\r
- * callback(err, responseData);\r
- * });\r
- * }\r
- */\r
-\r
-/**\r
- * Node-style callback as used by {@link RPCImpl}.\r
- * @typedef RPCImplCallback\r
- * @type {function}\r
- * @param {Error|null} error Error, if any, otherwise `null`\r
- * @param {Uint8Array|null} [response] Response data or `null` to signal end of stream, if there hasn't been an error\r
- * @returns {undefined}\r
- */\r
-\r
-rpc.Service = require("./rpc/service");\r
-
-},{"./rpc/service":213}],213:[function(require,module,exports){
-"use strict";\r
-module.exports = Service;\r
-\r
-var util = require("../util/minimal");\r
-\r
-// Extends EventEmitter\r
-(Service.prototype = Object.create(util.EventEmitter.prototype)).constructor = Service;\r
-\r
-/**\r
- * A service method callback as used by {@link rpc.ServiceMethod|ServiceMethod}.\r
- *\r
- * Differs from {@link RPCImplCallback} in that it is an actual callback of a service method which may not return `response = null`.\r
- * @typedef rpc.ServiceMethodCallback\r
- * @template TRes extends Message<TRes>\r
- * @type {function}\r
- * @param {Error|null} error Error, if any\r
- * @param {TRes} [response] Response message\r
- * @returns {undefined}\r
- */\r
-\r
-/**\r
- * A service method part of a {@link rpc.Service} as created by {@link Service.create}.\r
- * @typedef rpc.ServiceMethod\r
- * @template TReq extends Message<TReq>\r
- * @template TRes extends Message<TRes>\r
- * @type {function}\r
- * @param {TReq|Properties<TReq>} request Request message or plain object\r
- * @param {rpc.ServiceMethodCallback<TRes>} [callback] Node-style callback called with the error, if any, and the response message\r
- * @returns {Promise<Message<TRes>>} Promise if `callback` has been omitted, otherwise `undefined`\r
- */\r
-\r
-/**\r
- * Constructs a new RPC service instance.\r
- * @classdesc An RPC service as returned by {@link Service#create}.\r
- * @exports rpc.Service\r
- * @extends util.EventEmitter\r
- * @constructor\r
- * @param {RPCImpl} rpcImpl RPC implementation\r
- * @param {boolean} [requestDelimited=false] Whether requests are length-delimited\r
- * @param {boolean} [responseDelimited=false] Whether responses are length-delimited\r
- */\r
-function Service(rpcImpl, requestDelimited, responseDelimited) {\r
-\r
- if (typeof rpcImpl !== "function")\r
- throw TypeError("rpcImpl must be a function");\r
-\r
- util.EventEmitter.call(this);\r
-\r
- /**\r
- * RPC implementation. Becomes `null` once the service is ended.\r
- * @type {RPCImpl|null}\r
- */\r
- this.rpcImpl = rpcImpl;\r
-\r
- /**\r
- * Whether requests are length-delimited.\r
- * @type {boolean}\r
- */\r
- this.requestDelimited = Boolean(requestDelimited);\r
-\r
- /**\r
- * Whether responses are length-delimited.\r
- * @type {boolean}\r
- */\r
- this.responseDelimited = Boolean(responseDelimited);\r
-}\r
-\r
-/**\r
- * Calls a service method through {@link rpc.Service#rpcImpl|rpcImpl}.\r
- * @param {Method|rpc.ServiceMethod<TReq,TRes>} method Reflected or static method\r
- * @param {Constructor<TReq>} requestCtor Request constructor\r
- * @param {Constructor<TRes>} responseCtor Response constructor\r
- * @param {TReq|Properties<TReq>} request Request message or plain object\r
- * @param {rpc.ServiceMethodCallback<TRes>} callback Service callback\r
- * @returns {undefined}\r
- * @template TReq extends Message<TReq>\r
- * @template TRes extends Message<TRes>\r
- */\r
-Service.prototype.rpcCall = function rpcCall(method, requestCtor, responseCtor, request, callback) {\r
-\r
- if (!request)\r
- throw TypeError("request must be specified");\r
-\r
- var self = this;\r
- if (!callback)\r
- return util.asPromise(rpcCall, self, method, requestCtor, responseCtor, request);\r
-\r
- if (!self.rpcImpl) {\r
- setTimeout(function() { callback(Error("already ended")); }, 0);\r
- return undefined;\r
- }\r
-\r
- try {\r
- return self.rpcImpl(\r
- method,\r
- requestCtor[self.requestDelimited ? "encodeDelimited" : "encode"](request).finish(),\r
- function rpcCallback(err, response) {\r
-\r
- if (err) {\r
- self.emit("error", err, method);\r
- return callback(err);\r
- }\r
-\r
- if (response === null) {\r
- self.end(/* endedByRPC */ true);\r
- return undefined;\r
- }\r
-\r
- if (!(response instanceof responseCtor)) {\r
- try {\r
- response = responseCtor[self.responseDelimited ? "decodeDelimited" : "decode"](response);\r
- } catch (err) {\r
- self.emit("error", err, method);\r
- return callback(err);\r
- }\r
- }\r
-\r
- self.emit("data", response, method);\r
- return callback(null, response);\r
- }\r
- );\r
- } catch (err) {\r
- self.emit("error", err, method);\r
- setTimeout(function() { callback(err); }, 0);\r
- return undefined;\r
- }\r
-};\r
-\r
-/**\r
- * Ends this service and emits the `end` event.\r
- * @param {boolean} [endedByRPC=false] Whether the service has been ended by the RPC implementation.\r
- * @returns {rpc.Service} `this`\r
- */\r
-Service.prototype.end = function end(endedByRPC) {\r
- if (this.rpcImpl) {\r
- if (!endedByRPC) // signal end to rpcImpl\r
- this.rpcImpl(null, null, null);\r
- this.rpcImpl = null;\r
- this.emit("end").off();\r
- }\r
- return this;\r
-};\r
-
-},{"../util/minimal":220}],214:[function(require,module,exports){
-"use strict";\r
-module.exports = Service;\r
-\r
-// extends Namespace\r
-var Namespace = require("./namespace");\r
-((Service.prototype = Object.create(Namespace.prototype)).constructor = Service).className = "Service";\r
-\r
-var Method = require("./method"),\r
- util = require("./util"),\r
- rpc = require("./rpc");\r
-\r
-/**\r
- * Constructs a new service instance.\r
- * @classdesc Reflected service.\r
- * @extends NamespaceBase\r
- * @constructor\r
- * @param {string} name Service name\r
- * @param {Object.<string,*>} [options] Service options\r
- * @throws {TypeError} If arguments are invalid\r
- */\r
-function Service(name, options) {\r
- Namespace.call(this, name, options);\r
-\r
- /**\r
- * Service methods.\r
- * @type {Object.<string,Method>}\r
- */\r
- this.methods = {}; // toJSON, marker\r
-\r
- /**\r
- * Cached methods as an array.\r
- * @type {Method[]|null}\r
- * @private\r
- */\r
- this._methodsArray = null;\r
-}\r
-\r
-/**\r
- * Service descriptor.\r
- * @interface IService\r
- * @extends INamespace\r
- * @property {Object.<string,IMethod>} methods Method descriptors\r
- */\r
-\r
-/**\r
- * Constructs a service from a service descriptor.\r
- * @param {string} name Service name\r
- * @param {IService} json Service descriptor\r
- * @returns {Service} Created service\r
- * @throws {TypeError} If arguments are invalid\r
- */\r
-Service.fromJSON = function fromJSON(name, json) {\r
- var service = new Service(name, json.options);\r
- /* istanbul ignore else */\r
- if (json.methods)\r
- for (var names = Object.keys(json.methods), i = 0; i < names.length; ++i)\r
- service.add(Method.fromJSON(names[i], json.methods[names[i]]));\r
- if (json.nested)\r
- service.addJSON(json.nested);\r
- service.comment = json.comment;\r
- return service;\r
-};\r
-\r
-/**\r
- * Converts this service to a service descriptor.\r
- * @param {IToJSONOptions} [toJSONOptions] JSON conversion options\r
- * @returns {IService} Service descriptor\r
- */\r
-Service.prototype.toJSON = function toJSON(toJSONOptions) {\r
- var inherited = Namespace.prototype.toJSON.call(this, toJSONOptions);\r
- var keepComments = toJSONOptions ? Boolean(toJSONOptions.keepComments) : false;\r
- return util.toObject([\r
- "options" , inherited && inherited.options || undefined,\r
- "methods" , Namespace.arrayToJSON(this.methodsArray, toJSONOptions) || /* istanbul ignore next */ {},\r
- "nested" , inherited && inherited.nested || undefined,\r
- "comment" , keepComments ? this.comment : undefined\r
- ]);\r
-};\r
-\r
-/**\r
- * Methods of this service as an array for iteration.\r
- * @name Service#methodsArray\r
- * @type {Method[]}\r
- * @readonly\r
- */\r
-Object.defineProperty(Service.prototype, "methodsArray", {\r
- get: function() {\r
- return this._methodsArray || (this._methodsArray = util.toArray(this.methods));\r
- }\r
-});\r
-\r
-function clearCache(service) {\r
- service._methodsArray = null;\r
- return service;\r
-}\r
-\r
-/**\r
- * @override\r
- */\r
-Service.prototype.get = function get(name) {\r
- return this.methods[name]\r
- || Namespace.prototype.get.call(this, name);\r
-};\r
-\r
-/**\r
- * @override\r
- */\r
-Service.prototype.resolveAll = function resolveAll() {\r
- var methods = this.methodsArray;\r
- for (var i = 0; i < methods.length; ++i)\r
- methods[i].resolve();\r
- return Namespace.prototype.resolve.call(this);\r
-};\r
-\r
-/**\r
- * @override\r
- */\r
-Service.prototype.add = function add(object) {\r
-\r
- /* istanbul ignore if */\r
- if (this.get(object.name))\r
- throw Error("duplicate name '" + object.name + "' in " + this);\r
-\r
- if (object instanceof Method) {\r
- this.methods[object.name] = object;\r
- object.parent = this;\r
- return clearCache(this);\r
- }\r
- return Namespace.prototype.add.call(this, object);\r
-};\r
-\r
-/**\r
- * @override\r
- */\r
-Service.prototype.remove = function remove(object) {\r
- if (object instanceof Method) {\r
-\r
- /* istanbul ignore if */\r
- if (this.methods[object.name] !== object)\r
- throw Error(object + " is not a member of " + this);\r
-\r
- delete this.methods[object.name];\r
- object.parent = null;\r
- return clearCache(this);\r
- }\r
- return Namespace.prototype.remove.call(this, object);\r
-};\r
-\r
-/**\r
- * Creates a runtime service using the specified rpc implementation.\r
- * @param {RPCImpl} rpcImpl RPC implementation\r
- * @param {boolean} [requestDelimited=false] Whether requests are length-delimited\r
- * @param {boolean} [responseDelimited=false] Whether responses are length-delimited\r
- * @returns {rpc.Service} RPC service. Useful where requests and/or responses are streamed.\r
- */\r
-Service.prototype.create = function create(rpcImpl, requestDelimited, responseDelimited) {\r
- var rpcService = new rpc.Service(rpcImpl, requestDelimited, responseDelimited);\r
- for (var i = 0, method; i < /* initializes */ this.methodsArray.length; ++i) {\r
- var methodName = util.lcFirst((method = this._methodsArray[i]).resolve().name).replace(/[^$\w_]/g, "");\r
- rpcService[methodName] = util.codegen(["r","c"], util.isReserved(methodName) ? methodName + "_" : methodName)("return this.rpcCall(m,q,s,r,c)")({\r
- m: method,\r
- q: method.resolvedRequestType.ctor,\r
- s: method.resolvedResponseType.ctor\r
- });\r
- }\r
- return rpcService;\r
-};\r
-
-},{"./method":203,"./namespace":204,"./rpc":212,"./util":218}],215:[function(require,module,exports){
-"use strict";\r
-module.exports = tokenize;\r
-\r
-var delimRe = /[\s{}=;:[\],'"()<>]/g,\r
- stringDoubleRe = /(?:"([^"\\]*(?:\\.[^"\\]*)*)")/g,\r
- stringSingleRe = /(?:'([^'\\]*(?:\\.[^'\\]*)*)')/g;\r
-\r
-var setCommentRe = /^ *[*/]+ */,\r
- setCommentAltRe = /^\s*\*?\/*/,\r
- setCommentSplitRe = /\n/g,\r
- whitespaceRe = /\s/,\r
- unescapeRe = /\\(.?)/g;\r
-\r
-var unescapeMap = {\r
- "0": "\0",\r
- "r": "\r",\r
- "n": "\n",\r
- "t": "\t"\r
-};\r
-\r
-/**\r
- * Unescapes a string.\r
- * @param {string} str String to unescape\r
- * @returns {string} Unescaped string\r
- * @property {Object.<string,string>} map Special characters map\r
- * @memberof tokenize\r
- */\r
-function unescape(str) {\r
- return str.replace(unescapeRe, function($0, $1) {\r
- switch ($1) {\r
- case "\\":\r
- case "":\r
- return $1;\r
- default:\r
- return unescapeMap[$1] || "";\r
- }\r
- });\r
-}\r
-\r
-tokenize.unescape = unescape;\r
-\r
-/**\r
- * Gets the next token and advances.\r
- * @typedef TokenizerHandleNext\r
- * @type {function}\r
- * @returns {string|null} Next token or `null` on eof\r
- */\r
-\r
-/**\r
- * Peeks for the next token.\r
- * @typedef TokenizerHandlePeek\r
- * @type {function}\r
- * @returns {string|null} Next token or `null` on eof\r
- */\r
-\r
-/**\r
- * Pushes a token back to the stack.\r
- * @typedef TokenizerHandlePush\r
- * @type {function}\r
- * @param {string} token Token\r
- * @returns {undefined}\r
- */\r
-\r
-/**\r
- * Skips the next token.\r
- * @typedef TokenizerHandleSkip\r
- * @type {function}\r
- * @param {string} expected Expected token\r
- * @param {boolean} [optional=false] If optional\r
- * @returns {boolean} Whether the token matched\r
- * @throws {Error} If the token didn't match and is not optional\r
- */\r
-\r
-/**\r
- * Gets the comment on the previous line or, alternatively, the line comment on the specified line.\r
- * @typedef TokenizerHandleCmnt\r
- * @type {function}\r
- * @param {number} [line] Line number\r
- * @returns {string|null} Comment text or `null` if none\r
- */\r
-\r
-/**\r
- * Handle object returned from {@link tokenize}.\r
- * @interface ITokenizerHandle\r
- * @property {TokenizerHandleNext} next Gets the next token and advances (`null` on eof)\r
- * @property {TokenizerHandlePeek} peek Peeks for the next token (`null` on eof)\r
- * @property {TokenizerHandlePush} push Pushes a token back to the stack\r
- * @property {TokenizerHandleSkip} skip Skips a token, returns its presence and advances or, if non-optional and not present, throws\r
- * @property {TokenizerHandleCmnt} cmnt Gets the comment on the previous line or the line comment on the specified line, if any\r
- * @property {number} line Current line number\r
- */\r
-\r
-/**\r
- * Tokenizes the given .proto source and returns an object with useful utility functions.\r
- * @param {string} source Source contents\r
- * @param {boolean} alternateCommentMode Whether we should activate alternate comment parsing mode.\r
- * @returns {ITokenizerHandle} Tokenizer handle\r
- */\r
-function tokenize(source, alternateCommentMode) {\r
- /* eslint-disable callback-return */\r
- source = source.toString();\r
-\r
- var offset = 0,\r
- length = source.length,\r
- line = 1,\r
- commentType = null,\r
- commentText = null,\r
- commentLine = 0,\r
- commentLineEmpty = false;\r
-\r
- var stack = [];\r
-\r
- var stringDelim = null;\r
-\r
- /* istanbul ignore next */\r
- /**\r
- * Creates an error for illegal syntax.\r
- * @param {string} subject Subject\r
- * @returns {Error} Error created\r
- * @inner\r
- */\r
- function illegal(subject) {\r
- return Error("illegal " + subject + " (line " + line + ")");\r
- }\r
-\r
- /**\r
- * Reads a string till its end.\r
- * @returns {string} String read\r
- * @inner\r
- */\r
- function readString() {\r
- var re = stringDelim === "'" ? stringSingleRe : stringDoubleRe;\r
- re.lastIndex = offset - 1;\r
- var match = re.exec(source);\r
- if (!match)\r
- throw illegal("string");\r
- offset = re.lastIndex;\r
- push(stringDelim);\r
- stringDelim = null;\r
- return unescape(match[1]);\r
- }\r
-\r
- /**\r
- * Gets the character at `pos` within the source.\r
- * @param {number} pos Position\r
- * @returns {string} Character\r
- * @inner\r
- */\r
- function charAt(pos) {\r
- return source.charAt(pos);\r
- }\r
-\r
- /**\r
- * Sets the current comment text.\r
- * @param {number} start Start offset\r
- * @param {number} end End offset\r
- * @returns {undefined}\r
- * @inner\r
- */\r
- function setComment(start, end) {\r
- commentType = source.charAt(start++);\r
- commentLine = line;\r
- commentLineEmpty = false;\r
- var lookback;\r
- if (alternateCommentMode) {\r
- lookback = 2; // alternate comment parsing: "//" or "/*"\r
- } else {\r
- lookback = 3; // "///" or "/**"\r
- }\r
- var commentOffset = start - lookback,\r
- c;\r
- do {\r
- if (--commentOffset < 0 ||\r
- (c = source.charAt(commentOffset)) === "\n") {\r
- commentLineEmpty = true;\r
- break;\r
- }\r
- } while (c === " " || c === "\t");\r
- var lines = source\r
- .substring(start, end)\r
- .split(setCommentSplitRe);\r
- for (var i = 0; i < lines.length; ++i)\r
- lines[i] = lines[i]\r
- .replace(alternateCommentMode ? setCommentAltRe : setCommentRe, "")\r
- .trim();\r
- commentText = lines\r
- .join("\n")\r
- .trim();\r
- }\r
-\r
- function isDoubleSlashCommentLine(startOffset) {\r
- var endOffset = findEndOfLine(startOffset);\r
-\r
- // see if remaining line matches comment pattern\r
- var lineText = source.substring(startOffset, endOffset);\r
- // look for 1 or 2 slashes since startOffset would already point past\r
- // the first slash that started the comment.\r
- var isComment = /^\s*\/{1,2}/.test(lineText);\r
- return isComment;\r
- }\r
-\r
- function findEndOfLine(cursor) {\r
- // find end of cursor's line\r
- var endOffset = cursor;\r
- while (endOffset < length && charAt(endOffset) !== "\n") {\r
- endOffset++;\r
- }\r
- return endOffset;\r
- }\r
-\r
- /**\r
- * Obtains the next token.\r
- * @returns {string|null} Next token or `null` on eof\r
- * @inner\r
- */\r
- function next() {\r
- if (stack.length > 0)\r
- return stack.shift();\r
- if (stringDelim)\r
- return readString();\r
- var repeat,\r
- prev,\r
- curr,\r
- start,\r
- isDoc;\r
- do {\r
- if (offset === length)\r
- return null;\r
- repeat = false;\r
- while (whitespaceRe.test(curr = charAt(offset))) {\r
- if (curr === "\n")\r
- ++line;\r
- if (++offset === length)\r
- return null;\r
- }\r
-\r
- if (charAt(offset) === "/") {\r
- if (++offset === length) {\r
- throw illegal("comment");\r
- }\r
- if (charAt(offset) === "/") { // Line\r
- if (!alternateCommentMode) {\r
- // check for triple-slash comment\r
- isDoc = charAt(start = offset + 1) === "/";\r
-\r
- while (charAt(++offset) !== "\n") {\r
- if (offset === length) {\r
- return null;\r
- }\r
- }\r
- ++offset;\r
- if (isDoc) {\r
- setComment(start, offset - 1);\r
- }\r
- ++line;\r
- repeat = true;\r
- } else {\r
- // check for double-slash comments, consolidating consecutive lines\r
- start = offset;\r
- isDoc = false;\r
- if (isDoubleSlashCommentLine(offset)) {\r
- isDoc = true;\r
- do {\r
- offset = findEndOfLine(offset);\r
- if (offset === length) {\r
- break;\r
- }\r
- offset++;\r
- } while (isDoubleSlashCommentLine(offset));\r
- } else {\r
- offset = Math.min(length, findEndOfLine(offset) + 1);\r
- }\r
- if (isDoc) {\r
- setComment(start, offset);\r
- }\r
- line++;\r
- repeat = true;\r
- }\r
- } else if ((curr = charAt(offset)) === "*") { /* Block */\r
- // check for /** (regular comment mode) or /* (alternate comment mode)\r
- start = offset + 1;\r
- isDoc = alternateCommentMode || charAt(start) === "*";\r
- do {\r
- if (curr === "\n") {\r
- ++line;\r
- }\r
- if (++offset === length) {\r
- throw illegal("comment");\r
- }\r
- prev = curr;\r
- curr = charAt(offset);\r
- } while (prev !== "*" || curr !== "/");\r
- ++offset;\r
- if (isDoc) {\r
- setComment(start, offset - 2);\r
- }\r
- repeat = true;\r
- } else {\r
- return "/";\r
- }\r
- }\r
- } while (repeat);\r
-\r
- // offset !== length if we got here\r
-\r
- var end = offset;\r
- delimRe.lastIndex = 0;\r
- var delim = delimRe.test(charAt(end++));\r
- if (!delim)\r
- while (end < length && !delimRe.test(charAt(end)))\r
- ++end;\r
- var token = source.substring(offset, offset = end);\r
- if (token === "\"" || token === "'")\r
- stringDelim = token;\r
- return token;\r
- }\r
-\r
- /**\r
- * Pushes a token back to the stack.\r
- * @param {string} token Token\r
- * @returns {undefined}\r
- * @inner\r
- */\r
- function push(token) {\r
- stack.push(token);\r
- }\r
-\r
- /**\r
- * Peeks for the next token.\r
- * @returns {string|null} Token or `null` on eof\r
- * @inner\r
- */\r
- function peek() {\r
- if (!stack.length) {\r
- var token = next();\r
- if (token === null)\r
- return null;\r
- push(token);\r
- }\r
- return stack[0];\r
- }\r
-\r
- /**\r
- * Skips a token.\r
- * @param {string} expected Expected token\r
- * @param {boolean} [optional=false] Whether the token is optional\r
- * @returns {boolean} `true` when skipped, `false` if not\r
- * @throws {Error} When a required token is not present\r
- * @inner\r
- */\r
- function skip(expected, optional) {\r
- var actual = peek(),\r
- equals = actual === expected;\r
- if (equals) {\r
- next();\r
- return true;\r
- }\r
- if (!optional)\r
- throw illegal("token '" + actual + "', '" + expected + "' expected");\r
- return false;\r
- }\r
-\r
- /**\r
- * Gets a comment.\r
- * @param {number} [trailingLine] Line number if looking for a trailing comment\r
- * @returns {string|null} Comment text\r
- * @inner\r
- */\r
- function cmnt(trailingLine) {\r
- var ret = null;\r
- if (trailingLine === undefined) {\r
- if (commentLine === line - 1 && (alternateCommentMode || commentType === "*" || commentLineEmpty)) {\r
- ret = commentText;\r
- }\r
- } else {\r
- /* istanbul ignore else */\r
- if (commentLine < trailingLine) {\r
- peek();\r
- }\r
- if (commentLine === trailingLine && !commentLineEmpty && (alternateCommentMode || commentType === "/")) {\r
- ret = commentText;\r
- }\r
- }\r
- return ret;\r
- }\r
-\r
- return Object.defineProperty({\r
- next: next,\r
- peek: peek,\r
- push: push,\r
- skip: skip,\r
- cmnt: cmnt\r
- }, "line", {\r
- get: function() { return line; }\r
- });\r
- /* eslint-enable callback-return */\r
-}\r
-
-},{}],216:[function(require,module,exports){
-"use strict";\r
-module.exports = Type;\r
-\r
-// extends Namespace\r
-var Namespace = require("./namespace");\r
-((Type.prototype = Object.create(Namespace.prototype)).constructor = Type).className = "Type";\r
-\r
-var Enum = require("./enum"),\r
- OneOf = require("./oneof"),\r
- Field = require("./field"),\r
- MapField = require("./mapfield"),\r
- Service = require("./service"),\r
- Message = require("./message"),\r
- Reader = require("./reader"),\r
- Writer = require("./writer"),\r
- util = require("./util"),\r
- encoder = require("./encoder"),\r
- decoder = require("./decoder"),\r
- verifier = require("./verifier"),\r
- converter = require("./converter"),\r
- wrappers = require("./wrappers");\r
-\r
-/**\r
- * Constructs a new reflected message type instance.\r
- * @classdesc Reflected message type.\r
- * @extends NamespaceBase\r
- * @constructor\r
- * @param {string} name Message name\r
- * @param {Object.<string,*>} [options] Declared options\r
- */\r
-function Type(name, options) {\r
- Namespace.call(this, name, options);\r
-\r
- /**\r
- * Message fields.\r
- * @type {Object.<string,Field>}\r
- */\r
- this.fields = {}; // toJSON, marker\r
-\r
- /**\r
- * Oneofs declared within this namespace, if any.\r
- * @type {Object.<string,OneOf>}\r
- */\r
- this.oneofs = undefined; // toJSON\r
-\r
- /**\r
- * Extension ranges, if any.\r
- * @type {number[][]}\r
- */\r
- this.extensions = undefined; // toJSON\r
-\r
- /**\r
- * Reserved ranges, if any.\r
- * @type {Array.<number[]|string>}\r
- */\r
- this.reserved = undefined; // toJSON\r
-\r
- /*?\r
- * Whether this type is a legacy group.\r
- * @type {boolean|undefined}\r
- */\r
- this.group = undefined; // toJSON\r
-\r
- /**\r
- * Cached fields by id.\r
- * @type {Object.<number,Field>|null}\r
- * @private\r
- */\r
- this._fieldsById = null;\r
-\r
- /**\r
- * Cached fields as an array.\r
- * @type {Field[]|null}\r
- * @private\r
- */\r
- this._fieldsArray = null;\r
-\r
- /**\r
- * Cached oneofs as an array.\r
- * @type {OneOf[]|null}\r
- * @private\r
- */\r
- this._oneofsArray = null;\r
-\r
- /**\r
- * Cached constructor.\r
- * @type {Constructor<{}>}\r
- * @private\r
- */\r
- this._ctor = null;\r
-}\r
-\r
-Object.defineProperties(Type.prototype, {\r
-\r
- /**\r
- * Message fields by id.\r
- * @name Type#fieldsById\r
- * @type {Object.<number,Field>}\r
- * @readonly\r
- */\r
- fieldsById: {\r
- get: function() {\r
-\r
- /* istanbul ignore if */\r
- if (this._fieldsById)\r
- return this._fieldsById;\r
-\r
- this._fieldsById = {};\r
- for (var names = Object.keys(this.fields), i = 0; i < names.length; ++i) {\r
- var field = this.fields[names[i]],\r
- id = field.id;\r
-\r
- /* istanbul ignore if */\r
- if (this._fieldsById[id])\r
- throw Error("duplicate id " + id + " in " + this);\r
-\r
- this._fieldsById[id] = field;\r
- }\r
- return this._fieldsById;\r
- }\r
- },\r
-\r
- /**\r
- * Fields of this message as an array for iteration.\r
- * @name Type#fieldsArray\r
- * @type {Field[]}\r
- * @readonly\r
- */\r
- fieldsArray: {\r
- get: function() {\r
- return this._fieldsArray || (this._fieldsArray = util.toArray(this.fields));\r
- }\r
- },\r
-\r
- /**\r
- * Oneofs of this message as an array for iteration.\r
- * @name Type#oneofsArray\r
- * @type {OneOf[]}\r
- * @readonly\r
- */\r
- oneofsArray: {\r
- get: function() {\r
- return this._oneofsArray || (this._oneofsArray = util.toArray(this.oneofs));\r
- }\r
- },\r
-\r
- /**\r
- * The registered constructor, if any registered, otherwise a generic constructor.\r
- * 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.\r
- * @name Type#ctor\r
- * @type {Constructor<{}>}\r
- */\r
- ctor: {\r
- get: function() {\r
- return this._ctor || (this.ctor = Type.generateConstructor(this)());\r
- },\r
- set: function(ctor) {\r
-\r
- // Ensure proper prototype\r
- var prototype = ctor.prototype;\r
- if (!(prototype instanceof Message)) {\r
- (ctor.prototype = new Message()).constructor = ctor;\r
- util.merge(ctor.prototype, prototype);\r
- }\r
-\r
- // Classes and messages reference their reflected type\r
- ctor.$type = ctor.prototype.$type = this;\r
-\r
- // Mix in static methods\r
- util.merge(ctor, Message, true);\r
-\r
- this._ctor = ctor;\r
-\r
- // Messages have non-enumerable default values on their prototype\r
- var i = 0;\r
- for (; i < /* initializes */ this.fieldsArray.length; ++i)\r
- this._fieldsArray[i].resolve(); // ensures a proper value\r
-\r
- // Messages have non-enumerable getters and setters for each virtual oneof field\r
- var ctorProperties = {};\r
- for (i = 0; i < /* initializes */ this.oneofsArray.length; ++i)\r
- ctorProperties[this._oneofsArray[i].resolve().name] = {\r
- get: util.oneOfGetter(this._oneofsArray[i].oneof),\r
- set: util.oneOfSetter(this._oneofsArray[i].oneof)\r
- };\r
- if (i)\r
- Object.defineProperties(ctor.prototype, ctorProperties);\r
- }\r
- }\r
-});\r
-\r
-/**\r
- * Generates a constructor function for the specified type.\r
- * @param {Type} mtype Message type\r
- * @returns {Codegen} Codegen instance\r
- */\r
-Type.generateConstructor = function generateConstructor(mtype) {\r
- /* eslint-disable no-unexpected-multiline */\r
- var gen = util.codegen(["p"], mtype.name);\r
- // explicitly initialize mutable object/array fields so that these aren't just inherited from the prototype\r
- for (var i = 0, field; i < mtype.fieldsArray.length; ++i)\r
- if ((field = mtype._fieldsArray[i]).map) gen\r
- ("this%s={}", util.safeProp(field.name));\r
- else if (field.repeated) gen\r
- ("this%s=[]", util.safeProp(field.name));\r
- return gen\r
- ("if(p)for(var ks=Object.keys(p),i=0;i<ks.length;++i)if(p[ks[i]]!=null)") // omit undefined or null\r
- ("this[ks[i]]=p[ks[i]]");\r
- /* eslint-enable no-unexpected-multiline */\r
-};\r
-\r
-function clearCache(type) {\r
- type._fieldsById = type._fieldsArray = type._oneofsArray = null;\r
- delete type.encode;\r
- delete type.decode;\r
- delete type.verify;\r
- return type;\r
-}\r
-\r
-/**\r
- * Message type descriptor.\r
- * @interface IType\r
- * @extends INamespace\r
- * @property {Object.<string,IOneOf>} [oneofs] Oneof descriptors\r
- * @property {Object.<string,IField>} fields Field descriptors\r
- * @property {number[][]} [extensions] Extension ranges\r
- * @property {number[][]} [reserved] Reserved ranges\r
- * @property {boolean} [group=false] Whether a legacy group or not\r
- */\r
-\r
-/**\r
- * Creates a message type from a message type descriptor.\r
- * @param {string} name Message name\r
- * @param {IType} json Message type descriptor\r
- * @returns {Type} Created message type\r
- */\r
-Type.fromJSON = function fromJSON(name, json) {\r
- var type = new Type(name, json.options);\r
- type.extensions = json.extensions;\r
- type.reserved = json.reserved;\r
- var names = Object.keys(json.fields),\r
- i = 0;\r
- for (; i < names.length; ++i)\r
- type.add(\r
- ( typeof json.fields[names[i]].keyType !== "undefined"\r
- ? MapField.fromJSON\r
- : Field.fromJSON )(names[i], json.fields[names[i]])\r
- );\r
- if (json.oneofs)\r
- for (names = Object.keys(json.oneofs), i = 0; i < names.length; ++i)\r
- type.add(OneOf.fromJSON(names[i], json.oneofs[names[i]]));\r
- if (json.nested)\r
- for (names = Object.keys(json.nested), i = 0; i < names.length; ++i) {\r
- var nested = json.nested[names[i]];\r
- type.add( // most to least likely\r
- ( nested.id !== undefined\r
- ? Field.fromJSON\r
- : nested.fields !== undefined\r
- ? Type.fromJSON\r
- : nested.values !== undefined\r
- ? Enum.fromJSON\r
- : nested.methods !== undefined\r
- ? Service.fromJSON\r
- : Namespace.fromJSON )(names[i], nested)\r
- );\r
- }\r
- if (json.extensions && json.extensions.length)\r
- type.extensions = json.extensions;\r
- if (json.reserved && json.reserved.length)\r
- type.reserved = json.reserved;\r
- if (json.group)\r
- type.group = true;\r
- if (json.comment)\r
- type.comment = json.comment;\r
- return type;\r
-};\r
-\r
-/**\r
- * Converts this message type to a message type descriptor.\r
- * @param {IToJSONOptions} [toJSONOptions] JSON conversion options\r
- * @returns {IType} Message type descriptor\r
- */\r
-Type.prototype.toJSON = function toJSON(toJSONOptions) {\r
- var inherited = Namespace.prototype.toJSON.call(this, toJSONOptions);\r
- var keepComments = toJSONOptions ? Boolean(toJSONOptions.keepComments) : false;\r
- return util.toObject([\r
- "options" , inherited && inherited.options || undefined,\r
- "oneofs" , Namespace.arrayToJSON(this.oneofsArray, toJSONOptions),\r
- "fields" , Namespace.arrayToJSON(this.fieldsArray.filter(function(obj) { return !obj.declaringField; }), toJSONOptions) || {},\r
- "extensions" , this.extensions && this.extensions.length ? this.extensions : undefined,\r
- "reserved" , this.reserved && this.reserved.length ? this.reserved : undefined,\r
- "group" , this.group || undefined,\r
- "nested" , inherited && inherited.nested || undefined,\r
- "comment" , keepComments ? this.comment : undefined\r
- ]);\r
-};\r
-\r
-/**\r
- * @override\r
- */\r
-Type.prototype.resolveAll = function resolveAll() {\r
- var fields = this.fieldsArray, i = 0;\r
- while (i < fields.length)\r
- fields[i++].resolve();\r
- var oneofs = this.oneofsArray; i = 0;\r
- while (i < oneofs.length)\r
- oneofs[i++].resolve();\r
- return Namespace.prototype.resolveAll.call(this);\r
-};\r
-\r
-/**\r
- * @override\r
- */\r
-Type.prototype.get = function get(name) {\r
- return this.fields[name]\r
- || this.oneofs && this.oneofs[name]\r
- || this.nested && this.nested[name]\r
- || null;\r
-};\r
-\r
-/**\r
- * Adds a nested object to this type.\r
- * @param {ReflectionObject} object Nested object to add\r
- * @returns {Type} `this`\r
- * @throws {TypeError} If arguments are invalid\r
- * @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\r
- */\r
-Type.prototype.add = function add(object) {\r
-\r
- if (this.get(object.name))\r
- throw Error("duplicate name '" + object.name + "' in " + this);\r
-\r
- if (object instanceof Field && object.extend === undefined) {\r
- // NOTE: Extension fields aren't actual fields on the declaring type, but nested objects.\r
- // The root object takes care of adding distinct sister-fields to the respective extended\r
- // type instead.\r
-\r
- // avoids calling the getter if not absolutely necessary because it's called quite frequently\r
- if (this._fieldsById ? /* istanbul ignore next */ this._fieldsById[object.id] : this.fieldsById[object.id])\r
- throw Error("duplicate id " + object.id + " in " + this);\r
- if (this.isReservedId(object.id))\r
- throw Error("id " + object.id + " is reserved in " + this);\r
- if (this.isReservedName(object.name))\r
- throw Error("name '" + object.name + "' is reserved in " + this);\r
-\r
- if (object.parent)\r
- object.parent.remove(object);\r
- this.fields[object.name] = object;\r
- object.message = this;\r
- object.onAdd(this);\r
- return clearCache(this);\r
- }\r
- if (object instanceof OneOf) {\r
- if (!this.oneofs)\r
- this.oneofs = {};\r
- this.oneofs[object.name] = object;\r
- object.onAdd(this);\r
- return clearCache(this);\r
- }\r
- return Namespace.prototype.add.call(this, object);\r
-};\r
-\r
-/**\r
- * Removes a nested object from this type.\r
- * @param {ReflectionObject} object Nested object to remove\r
- * @returns {Type} `this`\r
- * @throws {TypeError} If arguments are invalid\r
- * @throws {Error} If `object` is not a member of this type\r
- */\r
-Type.prototype.remove = function remove(object) {\r
- if (object instanceof Field && object.extend === undefined) {\r
- // See Type#add for the reason why extension fields are excluded here.\r
-\r
- /* istanbul ignore if */\r
- if (!this.fields || this.fields[object.name] !== object)\r
- throw Error(object + " is not a member of " + this);\r
-\r
- delete this.fields[object.name];\r
- object.parent = null;\r
- object.onRemove(this);\r
- return clearCache(this);\r
- }\r
- if (object instanceof OneOf) {\r
-\r
- /* istanbul ignore if */\r
- if (!this.oneofs || this.oneofs[object.name] !== object)\r
- throw Error(object + " is not a member of " + this);\r
-\r
- delete this.oneofs[object.name];\r
- object.parent = null;\r
- object.onRemove(this);\r
- return clearCache(this);\r
- }\r
- return Namespace.prototype.remove.call(this, object);\r
-};\r
-\r
-/**\r
- * Tests if the specified id is reserved.\r
- * @param {number} id Id to test\r
- * @returns {boolean} `true` if reserved, otherwise `false`\r
- */\r
-Type.prototype.isReservedId = function isReservedId(id) {\r
- return Namespace.isReservedId(this.reserved, id);\r
-};\r
-\r
-/**\r
- * Tests if the specified name is reserved.\r
- * @param {string} name Name to test\r
- * @returns {boolean} `true` if reserved, otherwise `false`\r
- */\r
-Type.prototype.isReservedName = function isReservedName(name) {\r
- return Namespace.isReservedName(this.reserved, name);\r
-};\r
-\r
-/**\r
- * Creates a new message of this type using the specified properties.\r
- * @param {Object.<string,*>} [properties] Properties to set\r
- * @returns {Message<{}>} Message instance\r
- */\r
-Type.prototype.create = function create(properties) {\r
- return new this.ctor(properties);\r
-};\r
-\r
-/**\r
- * Sets up {@link Type#encode|encode}, {@link Type#decode|decode} and {@link Type#verify|verify}.\r
- * @returns {Type} `this`\r
- */\r
-Type.prototype.setup = function setup() {\r
- // Sets up everything at once so that the prototype chain does not have to be re-evaluated\r
- // multiple times (V8, soft-deopt prototype-check).\r
-\r
- var fullName = this.fullName,\r
- types = [];\r
- for (var i = 0; i < /* initializes */ this.fieldsArray.length; ++i)\r
- types.push(this._fieldsArray[i].resolve().resolvedType);\r
-\r
- // Replace setup methods with type-specific generated functions\r
- this.encode = encoder(this)({\r
- Writer : Writer,\r
- types : types,\r
- util : util\r
- });\r
- this.decode = decoder(this)({\r
- Reader : Reader,\r
- types : types,\r
- util : util\r
- });\r
- this.verify = verifier(this)({\r
- types : types,\r
- util : util\r
- });\r
- this.fromObject = converter.fromObject(this)({\r
- types : types,\r
- util : util\r
- });\r
- this.toObject = converter.toObject(this)({\r
- types : types,\r
- util : util\r
- });\r
-\r
- // Inject custom wrappers for common types\r
- var wrapper = wrappers[fullName];\r
- if (wrapper) {\r
- var originalThis = Object.create(this);\r
- // if (wrapper.fromObject) {\r
- originalThis.fromObject = this.fromObject;\r
- this.fromObject = wrapper.fromObject.bind(originalThis);\r
- // }\r
- // if (wrapper.toObject) {\r
- originalThis.toObject = this.toObject;\r
- this.toObject = wrapper.toObject.bind(originalThis);\r
- // }\r
- }\r
-\r
- return this;\r
-};\r
-\r
-/**\r
- * Encodes a message of this type. Does not implicitly {@link Type#verify|verify} messages.\r
- * @param {Message<{}>|Object.<string,*>} message Message instance or plain object\r
- * @param {Writer} [writer] Writer to encode to\r
- * @returns {Writer} writer\r
- */\r
-Type.prototype.encode = function encode_setup(message, writer) {\r
- return this.setup().encode(message, writer); // overrides this method\r
-};\r
-\r
-/**\r
- * Encodes a message of this type preceeded by its byte length as a varint. Does not implicitly {@link Type#verify|verify} messages.\r
- * @param {Message<{}>|Object.<string,*>} message Message instance or plain object\r
- * @param {Writer} [writer] Writer to encode to\r
- * @returns {Writer} writer\r
- */\r
-Type.prototype.encodeDelimited = function encodeDelimited(message, writer) {\r
- return this.encode(message, writer && writer.len ? writer.fork() : writer).ldelim();\r
-};\r
-\r
-/**\r
- * Decodes a message of this type.\r
- * @param {Reader|Uint8Array} reader Reader or buffer to decode from\r
- * @param {number} [length] Length of the message, if known beforehand\r
- * @returns {Message<{}>} Decoded message\r
- * @throws {Error} If the payload is not a reader or valid buffer\r
- * @throws {util.ProtocolError<{}>} If required fields are missing\r
- */\r
-Type.prototype.decode = function decode_setup(reader, length) {\r
- return this.setup().decode(reader, length); // overrides this method\r
-};\r
-\r
-/**\r
- * Decodes a message of this type preceeded by its byte length as a varint.\r
- * @param {Reader|Uint8Array} reader Reader or buffer to decode from\r
- * @returns {Message<{}>} Decoded message\r
- * @throws {Error} If the payload is not a reader or valid buffer\r
- * @throws {util.ProtocolError} If required fields are missing\r
- */\r
-Type.prototype.decodeDelimited = function decodeDelimited(reader) {\r
- if (!(reader instanceof Reader))\r
- reader = Reader.create(reader);\r
- return this.decode(reader, reader.uint32());\r
-};\r
-\r
-/**\r
- * Verifies that field values are valid and that required fields are present.\r
- * @param {Object.<string,*>} message Plain object to verify\r
- * @returns {null|string} `null` if valid, otherwise the reason why it is not\r
- */\r
-Type.prototype.verify = function verify_setup(message) {\r
- return this.setup().verify(message); // overrides this method\r
-};\r
-\r
-/**\r
- * Creates a new message of this type from a plain object. Also converts values to their respective internal types.\r
- * @param {Object.<string,*>} object Plain object to convert\r
- * @returns {Message<{}>} Message instance\r
- */\r
-Type.prototype.fromObject = function fromObject(object) {\r
- return this.setup().fromObject(object);\r
-};\r
-\r
-/**\r
- * Conversion options as used by {@link Type#toObject} and {@link Message.toObject}.\r
- * @interface IConversionOptions\r
- * @property {Function} [longs] Long conversion type.\r
- * Valid values are `String` and `Number` (the global types).\r
- * Defaults to copy the present value, which is a possibly unsafe number without and a {@link Long} with a long library.\r
- * @property {Function} [enums] Enum value conversion type.\r
- * Only valid value is `String` (the global type).\r
- * Defaults to copy the present value, which is the numeric id.\r
- * @property {Function} [bytes] Bytes value conversion type.\r
- * Valid values are `Array` and (a base64 encoded) `String` (the global types).\r
- * Defaults to copy the present value, which usually is a Buffer under node and an Uint8Array in the browser.\r
- * @property {boolean} [defaults=false] Also sets default values on the resulting object\r
- * @property {boolean} [arrays=false] Sets empty arrays for missing repeated fields even if `defaults=false`\r
- * @property {boolean} [objects=false] Sets empty objects for missing map fields even if `defaults=false`\r
- * @property {boolean} [oneofs=false] Includes virtual oneof properties set to the present field's name, if any\r
- * @property {boolean} [json=false] Performs additional JSON compatibility conversions, i.e. NaN and Infinity to strings\r
- */\r
-\r
-/**\r
- * Creates a plain object from a message of this type. Also converts values to other types if specified.\r
- * @param {Message<{}>} message Message instance\r
- * @param {IConversionOptions} [options] Conversion options\r
- * @returns {Object.<string,*>} Plain object\r
- */\r
-Type.prototype.toObject = function toObject(message, options) {\r
- return this.setup().toObject(message, options);\r
-};\r
-\r
-/**\r
- * Decorator function as returned by {@link Type.d} (TypeScript).\r
- * @typedef TypeDecorator\r
- * @type {function}\r
- * @param {Constructor<T>} target Target constructor\r
- * @returns {undefined}\r
- * @template T extends Message<T>\r
- */\r
-\r
-/**\r
- * Type decorator (TypeScript).\r
- * @param {string} [typeName] Type name, defaults to the constructor's name\r
- * @returns {TypeDecorator<T>} Decorator function\r
- * @template T extends Message<T>\r
- */\r
-Type.d = function decorateType(typeName) {\r
- return function typeDecorator(target) {\r
- util.decorateType(target, typeName);\r
- };\r
-};\r
-
-},{"./converter":193,"./decoder":194,"./encoder":195,"./enum":196,"./field":197,"./mapfield":201,"./message":202,"./namespace":204,"./oneof":206,"./reader":208,"./service":214,"./util":218,"./verifier":221,"./wrappers":222,"./writer":223}],217:[function(require,module,exports){
-"use strict";\r
-\r
-/**\r
- * Common type constants.\r
- * @namespace\r
- */\r
-var types = exports;\r
-\r
-var util = require("./util");\r
-\r
-var s = [\r
- "double", // 0\r
- "float", // 1\r
- "int32", // 2\r
- "uint32", // 3\r
- "sint32", // 4\r
- "fixed32", // 5\r
- "sfixed32", // 6\r
- "int64", // 7\r
- "uint64", // 8\r
- "sint64", // 9\r
- "fixed64", // 10\r
- "sfixed64", // 11\r
- "bool", // 12\r
- "string", // 13\r
- "bytes" // 14\r
-];\r
-\r
-function bake(values, offset) {\r
- var i = 0, o = {};\r
- offset |= 0;\r
- while (i < values.length) o[s[i + offset]] = values[i++];\r
- return o;\r
-}\r
-\r
-/**\r
- * Basic type wire types.\r
- * @type {Object.<string,number>}\r
- * @const\r
- * @property {number} double=1 Fixed64 wire type\r
- * @property {number} float=5 Fixed32 wire type\r
- * @property {number} int32=0 Varint wire type\r
- * @property {number} uint32=0 Varint wire type\r
- * @property {number} sint32=0 Varint wire type\r
- * @property {number} fixed32=5 Fixed32 wire type\r
- * @property {number} sfixed32=5 Fixed32 wire type\r
- * @property {number} int64=0 Varint wire type\r
- * @property {number} uint64=0 Varint wire type\r
- * @property {number} sint64=0 Varint wire type\r
- * @property {number} fixed64=1 Fixed64 wire type\r
- * @property {number} sfixed64=1 Fixed64 wire type\r
- * @property {number} bool=0 Varint wire type\r
- * @property {number} string=2 Ldelim wire type\r
- * @property {number} bytes=2 Ldelim wire type\r
- */\r
-types.basic = bake([\r
- /* double */ 1,\r
- /* float */ 5,\r
- /* int32 */ 0,\r
- /* uint32 */ 0,\r
- /* sint32 */ 0,\r
- /* fixed32 */ 5,\r
- /* sfixed32 */ 5,\r
- /* int64 */ 0,\r
- /* uint64 */ 0,\r
- /* sint64 */ 0,\r
- /* fixed64 */ 1,\r
- /* sfixed64 */ 1,\r
- /* bool */ 0,\r
- /* string */ 2,\r
- /* bytes */ 2\r
-]);\r
-\r
-/**\r
- * Basic type defaults.\r
- * @type {Object.<string,*>}\r
- * @const\r
- * @property {number} double=0 Double default\r
- * @property {number} float=0 Float default\r
- * @property {number} int32=0 Int32 default\r
- * @property {number} uint32=0 Uint32 default\r
- * @property {number} sint32=0 Sint32 default\r
- * @property {number} fixed32=0 Fixed32 default\r
- * @property {number} sfixed32=0 Sfixed32 default\r
- * @property {number} int64=0 Int64 default\r
- * @property {number} uint64=0 Uint64 default\r
- * @property {number} sint64=0 Sint32 default\r
- * @property {number} fixed64=0 Fixed64 default\r
- * @property {number} sfixed64=0 Sfixed64 default\r
- * @property {boolean} bool=false Bool default\r
- * @property {string} string="" String default\r
- * @property {Array.<number>} bytes=Array(0) Bytes default\r
- * @property {null} message=null Message default\r
- */\r
-types.defaults = bake([\r
- /* double */ 0,\r
- /* float */ 0,\r
- /* int32 */ 0,\r
- /* uint32 */ 0,\r
- /* sint32 */ 0,\r
- /* fixed32 */ 0,\r
- /* sfixed32 */ 0,\r
- /* int64 */ 0,\r
- /* uint64 */ 0,\r
- /* sint64 */ 0,\r
- /* fixed64 */ 0,\r
- /* sfixed64 */ 0,\r
- /* bool */ false,\r
- /* string */ "",\r
- /* bytes */ util.emptyArray,\r
- /* message */ null\r
-]);\r
-\r
-/**\r
- * Basic long type wire types.\r
- * @type {Object.<string,number>}\r
- * @const\r
- * @property {number} int64=0 Varint wire type\r
- * @property {number} uint64=0 Varint wire type\r
- * @property {number} sint64=0 Varint wire type\r
- * @property {number} fixed64=1 Fixed64 wire type\r
- * @property {number} sfixed64=1 Fixed64 wire type\r
- */\r
-types.long = bake([\r
- /* int64 */ 0,\r
- /* uint64 */ 0,\r
- /* sint64 */ 0,\r
- /* fixed64 */ 1,\r
- /* sfixed64 */ 1\r
-], 7);\r
-\r
-/**\r
- * Allowed types for map keys with their associated wire type.\r
- * @type {Object.<string,number>}\r
- * @const\r
- * @property {number} int32=0 Varint wire type\r
- * @property {number} uint32=0 Varint wire type\r
- * @property {number} sint32=0 Varint wire type\r
- * @property {number} fixed32=5 Fixed32 wire type\r
- * @property {number} sfixed32=5 Fixed32 wire type\r
- * @property {number} int64=0 Varint wire type\r
- * @property {number} uint64=0 Varint wire type\r
- * @property {number} sint64=0 Varint wire type\r
- * @property {number} fixed64=1 Fixed64 wire type\r
- * @property {number} sfixed64=1 Fixed64 wire type\r
- * @property {number} bool=0 Varint wire type\r
- * @property {number} string=2 Ldelim wire type\r
- */\r
-types.mapKey = bake([\r
- /* int32 */ 0,\r
- /* uint32 */ 0,\r
- /* sint32 */ 0,\r
- /* fixed32 */ 5,\r
- /* sfixed32 */ 5,\r
- /* int64 */ 0,\r
- /* uint64 */ 0,\r
- /* sint64 */ 0,\r
- /* fixed64 */ 1,\r
- /* sfixed64 */ 1,\r
- /* bool */ 0,\r
- /* string */ 2\r
-], 2);\r
-\r
-/**\r
- * Allowed types for packed repeated fields with their associated wire type.\r
- * @type {Object.<string,number>}\r
- * @const\r
- * @property {number} double=1 Fixed64 wire type\r
- * @property {number} float=5 Fixed32 wire type\r
- * @property {number} int32=0 Varint wire type\r
- * @property {number} uint32=0 Varint wire type\r
- * @property {number} sint32=0 Varint wire type\r
- * @property {number} fixed32=5 Fixed32 wire type\r
- * @property {number} sfixed32=5 Fixed32 wire type\r
- * @property {number} int64=0 Varint wire type\r
- * @property {number} uint64=0 Varint wire type\r
- * @property {number} sint64=0 Varint wire type\r
- * @property {number} fixed64=1 Fixed64 wire type\r
- * @property {number} sfixed64=1 Fixed64 wire type\r
- * @property {number} bool=0 Varint wire type\r
- */\r
-types.packed = bake([\r
- /* double */ 1,\r
- /* float */ 5,\r
- /* int32 */ 0,\r
- /* uint32 */ 0,\r
- /* sint32 */ 0,\r
- /* fixed32 */ 5,\r
- /* sfixed32 */ 5,\r
- /* int64 */ 0,\r
- /* uint64 */ 0,\r
- /* sint64 */ 0,\r
- /* fixed64 */ 1,\r
- /* sfixed64 */ 1,\r
- /* bool */ 0\r
-]);\r
-
-},{"./util":218}],218:[function(require,module,exports){
-"use strict";\r
-\r
-/**\r
- * Various utility functions.\r
- * @namespace\r
- */\r
-var util = module.exports = require("./util/minimal");\r
-\r
-var roots = require("./roots");\r
-\r
-var Type, // cyclic\r
- Enum;\r
-\r
-util.codegen = require("@protobufjs/codegen");\r
-util.fetch = require("@protobufjs/fetch");\r
-util.path = require("@protobufjs/path");\r
-\r
-/**\r
- * Node's fs module if available.\r
- * @type {Object.<string,*>}\r
- */\r
-util.fs = util.inquire("fs");\r
-\r
-/**\r
- * Converts an object's values to an array.\r
- * @param {Object.<string,*>} object Object to convert\r
- * @returns {Array.<*>} Converted array\r
- */\r
-util.toArray = function toArray(object) {\r
- if (object) {\r
- var keys = Object.keys(object),\r
- array = new Array(keys.length),\r
- index = 0;\r
- while (index < keys.length)\r
- array[index] = object[keys[index++]];\r
- return array;\r
- }\r
- return [];\r
-};\r
-\r
-/**\r
- * Converts an array of keys immediately followed by their respective value to an object, omitting undefined values.\r
- * @param {Array.<*>} array Array to convert\r
- * @returns {Object.<string,*>} Converted object\r
- */\r
-util.toObject = function toObject(array) {\r
- var object = {},\r
- index = 0;\r
- while (index < array.length) {\r
- var key = array[index++],\r
- val = array[index++];\r
- if (val !== undefined)\r
- object[key] = val;\r
- }\r
- return object;\r
-};\r
-\r
-var safePropBackslashRe = /\\/g,\r
- safePropQuoteRe = /"/g;\r
-\r
-/**\r
- * Tests whether the specified name is a reserved word in JS.\r
- * @param {string} name Name to test\r
- * @returns {boolean} `true` if reserved, otherwise `false`\r
- */\r
-util.isReserved = function isReserved(name) {\r
- 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);\r
-};\r
-\r
-/**\r
- * Returns a safe property accessor for the specified property name.\r
- * @param {string} prop Property name\r
- * @returns {string} Safe accessor\r
- */\r
-util.safeProp = function safeProp(prop) {\r
- if (!/^[$\w_]+$/.test(prop) || util.isReserved(prop))\r
- return "[\"" + prop.replace(safePropBackslashRe, "\\\\").replace(safePropQuoteRe, "\\\"") + "\"]";\r
- return "." + prop;\r
-};\r
-\r
-/**\r
- * Converts the first character of a string to upper case.\r
- * @param {string} str String to convert\r
- * @returns {string} Converted string\r
- */\r
-util.ucFirst = function ucFirst(str) {\r
- return str.charAt(0).toUpperCase() + str.substring(1);\r
-};\r
-\r
-var camelCaseRe = /_([a-z])/g;\r
-\r
-/**\r
- * Converts a string to camel case.\r
- * @param {string} str String to convert\r
- * @returns {string} Converted string\r
- */\r
-util.camelCase = function camelCase(str) {\r
- return str.substring(0, 1)\r
- + str.substring(1)\r
- .replace(camelCaseRe, function($0, $1) { return $1.toUpperCase(); });\r
-};\r
-\r
-/**\r
- * Compares reflected fields by id.\r
- * @param {Field} a First field\r
- * @param {Field} b Second field\r
- * @returns {number} Comparison value\r
- */\r
-util.compareFieldsById = function compareFieldsById(a, b) {\r
- return a.id - b.id;\r
-};\r
-\r
-/**\r
- * Decorator helper for types (TypeScript).\r
- * @param {Constructor<T>} ctor Constructor function\r
- * @param {string} [typeName] Type name, defaults to the constructor's name\r
- * @returns {Type} Reflected type\r
- * @template T extends Message<T>\r
- * @property {Root} root Decorators root\r
- */\r
-util.decorateType = function decorateType(ctor, typeName) {\r
-\r
- /* istanbul ignore if */\r
- if (ctor.$type) {\r
- if (typeName && ctor.$type.name !== typeName) {\r
- util.decorateRoot.remove(ctor.$type);\r
- ctor.$type.name = typeName;\r
- util.decorateRoot.add(ctor.$type);\r
- }\r
- return ctor.$type;\r
- }\r
-\r
- /* istanbul ignore next */\r
- if (!Type)\r
- Type = require("./type");\r
-\r
- var type = new Type(typeName || ctor.name);\r
- util.decorateRoot.add(type);\r
- type.ctor = ctor; // sets up .encode, .decode etc.\r
- Object.defineProperty(ctor, "$type", { value: type, enumerable: false });\r
- Object.defineProperty(ctor.prototype, "$type", { value: type, enumerable: false });\r
- return type;\r
-};\r
-\r
-var decorateEnumIndex = 0;\r
-\r
-/**\r
- * Decorator helper for enums (TypeScript).\r
- * @param {Object} object Enum object\r
- * @returns {Enum} Reflected enum\r
- */\r
-util.decorateEnum = function decorateEnum(object) {\r
-\r
- /* istanbul ignore if */\r
- if (object.$type)\r
- return object.$type;\r
-\r
- /* istanbul ignore next */\r
- if (!Enum)\r
- Enum = require("./enum");\r
-\r
- var enm = new Enum("Enum" + decorateEnumIndex++, object);\r
- util.decorateRoot.add(enm);\r
- Object.defineProperty(object, "$type", { value: enm, enumerable: false });\r
- return enm;\r
-};\r
-\r
-/**\r
- * Decorator root (TypeScript).\r
- * @name util.decorateRoot\r
- * @type {Root}\r
- * @readonly\r
- */\r
-Object.defineProperty(util, "decorateRoot", {\r
- get: function() {\r
- return roots["decorated"] || (roots["decorated"] = new (require("./root"))());\r
- }\r
-});\r
-
-},{"./enum":196,"./root":210,"./roots":211,"./type":216,"./util/minimal":220,"@protobufjs/codegen":24,"@protobufjs/fetch":26,"@protobufjs/path":29}],219:[function(require,module,exports){
-"use strict";\r
-module.exports = LongBits;\r
-\r
-var util = require("../util/minimal");\r
-\r
-/**\r
- * Constructs new long bits.\r
- * @classdesc Helper class for working with the low and high bits of a 64 bit value.\r
- * @memberof util\r
- * @constructor\r
- * @param {number} lo Low 32 bits, unsigned\r
- * @param {number} hi High 32 bits, unsigned\r
- */\r
-function LongBits(lo, hi) {\r
-\r
- // note that the casts below are theoretically unnecessary as of today, but older statically\r
- // generated converter code might still call the ctor with signed 32bits. kept for compat.\r
-\r
- /**\r
- * Low bits.\r
- * @type {number}\r
- */\r
- this.lo = lo >>> 0;\r
-\r
- /**\r
- * High bits.\r
- * @type {number}\r
- */\r
- this.hi = hi >>> 0;\r
-}\r
-\r
-/**\r
- * Zero bits.\r
- * @memberof util.LongBits\r
- * @type {util.LongBits}\r
- */\r
-var zero = LongBits.zero = new LongBits(0, 0);\r
-\r
-zero.toNumber = function() { return 0; };\r
-zero.zzEncode = zero.zzDecode = function() { return this; };\r
-zero.length = function() { return 1; };\r
-\r
-/**\r
- * Zero hash.\r
- * @memberof util.LongBits\r
- * @type {string}\r
- */\r
-var zeroHash = LongBits.zeroHash = "\0\0\0\0\0\0\0\0";\r
-\r
-/**\r
- * Constructs new long bits from the specified number.\r
- * @param {number} value Value\r
- * @returns {util.LongBits} Instance\r
- */\r
-LongBits.fromNumber = function fromNumber(value) {\r
- if (value === 0)\r
- return zero;\r
- var sign = value < 0;\r
- if (sign)\r
- value = -value;\r
- var lo = value >>> 0,\r
- hi = (value - lo) / 4294967296 >>> 0;\r
- if (sign) {\r
- hi = ~hi >>> 0;\r
- lo = ~lo >>> 0;\r
- if (++lo > 4294967295) {\r
- lo = 0;\r
- if (++hi > 4294967295)\r
- hi = 0;\r
- }\r
- }\r
- return new LongBits(lo, hi);\r
-};\r
-\r
-/**\r
- * Constructs new long bits from a number, long or string.\r
- * @param {Long|number|string} value Value\r
- * @returns {util.LongBits} Instance\r
- */\r
-LongBits.from = function from(value) {\r
- if (typeof value === "number")\r
- return LongBits.fromNumber(value);\r
- if (util.isString(value)) {\r
- /* istanbul ignore else */\r
- if (util.Long)\r
- value = util.Long.fromString(value);\r
- else\r
- return LongBits.fromNumber(parseInt(value, 10));\r
- }\r
- return value.low || value.high ? new LongBits(value.low >>> 0, value.high >>> 0) : zero;\r
-};\r
-\r
-/**\r
- * Converts this long bits to a possibly unsafe JavaScript number.\r
- * @param {boolean} [unsigned=false] Whether unsigned or not\r
- * @returns {number} Possibly unsafe number\r
- */\r
-LongBits.prototype.toNumber = function toNumber(unsigned) {\r
- if (!unsigned && this.hi >>> 31) {\r
- var lo = ~this.lo + 1 >>> 0,\r
- hi = ~this.hi >>> 0;\r
- if (!lo)\r
- hi = hi + 1 >>> 0;\r
- return -(lo + hi * 4294967296);\r
- }\r
- return this.lo + this.hi * 4294967296;\r
-};\r
-\r
-/**\r
- * Converts this long bits to a long.\r
- * @param {boolean} [unsigned=false] Whether unsigned or not\r
- * @returns {Long} Long\r
- */\r
-LongBits.prototype.toLong = function toLong(unsigned) {\r
- return util.Long\r
- ? new util.Long(this.lo | 0, this.hi | 0, Boolean(unsigned))\r
- /* istanbul ignore next */\r
- : { low: this.lo | 0, high: this.hi | 0, unsigned: Boolean(unsigned) };\r
-};\r
-\r
-var charCodeAt = String.prototype.charCodeAt;\r
-\r
-/**\r
- * Constructs new long bits from the specified 8 characters long hash.\r
- * @param {string} hash Hash\r
- * @returns {util.LongBits} Bits\r
- */\r
-LongBits.fromHash = function fromHash(hash) {\r
- if (hash === zeroHash)\r
- return zero;\r
- return new LongBits(\r
- ( charCodeAt.call(hash, 0)\r
- | charCodeAt.call(hash, 1) << 8\r
- | charCodeAt.call(hash, 2) << 16\r
- | charCodeAt.call(hash, 3) << 24) >>> 0\r
- ,\r
- ( charCodeAt.call(hash, 4)\r
- | charCodeAt.call(hash, 5) << 8\r
- | charCodeAt.call(hash, 6) << 16\r
- | charCodeAt.call(hash, 7) << 24) >>> 0\r
- );\r
-};\r
-\r
-/**\r
- * Converts this long bits to a 8 characters long hash.\r
- * @returns {string} Hash\r
- */\r
-LongBits.prototype.toHash = function toHash() {\r
- return String.fromCharCode(\r
- this.lo & 255,\r
- this.lo >>> 8 & 255,\r
- this.lo >>> 16 & 255,\r
- this.lo >>> 24 ,\r
- this.hi & 255,\r
- this.hi >>> 8 & 255,\r
- this.hi >>> 16 & 255,\r
- this.hi >>> 24\r
- );\r
-};\r
-\r
-/**\r
- * Zig-zag encodes this long bits.\r
- * @returns {util.LongBits} `this`\r
- */\r
-LongBits.prototype.zzEncode = function zzEncode() {\r
- var mask = this.hi >> 31;\r
- this.hi = ((this.hi << 1 | this.lo >>> 31) ^ mask) >>> 0;\r
- this.lo = ( this.lo << 1 ^ mask) >>> 0;\r
- return this;\r
-};\r
-\r
-/**\r
- * Zig-zag decodes this long bits.\r
- * @returns {util.LongBits} `this`\r
- */\r
-LongBits.prototype.zzDecode = function zzDecode() {\r
- var mask = -(this.lo & 1);\r
- this.lo = ((this.lo >>> 1 | this.hi << 31) ^ mask) >>> 0;\r
- this.hi = ( this.hi >>> 1 ^ mask) >>> 0;\r
- return this;\r
-};\r
-\r
-/**\r
- * Calculates the length of this longbits when encoded as a varint.\r
- * @returns {number} Length\r
- */\r
-LongBits.prototype.length = function length() {\r
- var part0 = this.lo,\r
- part1 = (this.lo >>> 28 | this.hi << 4) >>> 0,\r
- part2 = this.hi >>> 24;\r
- return part2 === 0\r
- ? part1 === 0\r
- ? part0 < 16384\r
- ? part0 < 128 ? 1 : 2\r
- : part0 < 2097152 ? 3 : 4\r
- : part1 < 16384\r
- ? part1 < 128 ? 5 : 6\r
- : part1 < 2097152 ? 7 : 8\r
- : part2 < 128 ? 9 : 10;\r
-};\r
-
-},{"../util/minimal":220}],220:[function(require,module,exports){
-(function (global){
-"use strict";\r
-var util = exports;\r
-\r
-// used to return a Promise where callback is omitted\r
-util.asPromise = require("@protobufjs/aspromise");\r
-\r
-// converts to / from base64 encoded strings\r
-util.base64 = require("@protobufjs/base64");\r
-\r
-// base class of rpc.Service\r
-util.EventEmitter = require("@protobufjs/eventemitter");\r
-\r
-// float handling accross browsers\r
-util.float = require("@protobufjs/float");\r
-\r
-// requires modules optionally and hides the call from bundlers\r
-util.inquire = require("@protobufjs/inquire");\r
-\r
-// converts to / from utf8 encoded strings\r
-util.utf8 = require("@protobufjs/utf8");\r
-\r
-// provides a node-like buffer pool in the browser\r
-util.pool = require("@protobufjs/pool");\r
-\r
-// utility to work with the low and high bits of a 64 bit value\r
-util.LongBits = require("./longbits");\r
-\r
-/**\r
- * An immuable empty array.\r
- * @memberof util\r
- * @type {Array.<*>}\r
- * @const\r
- */\r
-util.emptyArray = Object.freeze ? Object.freeze([]) : /* istanbul ignore next */ []; // used on prototypes\r
-\r
-/**\r
- * An immutable empty object.\r
- * @type {Object}\r
- * @const\r
- */\r
-util.emptyObject = Object.freeze ? Object.freeze({}) : /* istanbul ignore next */ {}; // used on prototypes\r
-\r
-/**\r
- * Whether running within node or not.\r
- * @memberof util\r
- * @type {boolean}\r
- * @const\r
- */\r
-util.isNode = Boolean(global.process && global.process.versions && global.process.versions.node);\r
-\r
-/**\r
- * Tests if the specified value is an integer.\r
- * @function\r
- * @param {*} value Value to test\r
- * @returns {boolean} `true` if the value is an integer\r
- */\r
-util.isInteger = Number.isInteger || /* istanbul ignore next */ function isInteger(value) {\r
- return typeof value === "number" && isFinite(value) && Math.floor(value) === value;\r
-};\r
-\r
-/**\r
- * Tests if the specified value is a string.\r
- * @param {*} value Value to test\r
- * @returns {boolean} `true` if the value is a string\r
- */\r
-util.isString = function isString(value) {\r
- return typeof value === "string" || value instanceof String;\r
-};\r
-\r
-/**\r
- * Tests if the specified value is a non-null object.\r
- * @param {*} value Value to test\r
- * @returns {boolean} `true` if the value is a non-null object\r
- */\r
-util.isObject = function isObject(value) {\r
- return value && typeof value === "object";\r
-};\r
-\r
-/**\r
- * Checks if a property on a message is considered to be present.\r
- * This is an alias of {@link util.isSet}.\r
- * @function\r
- * @param {Object} obj Plain object or message instance\r
- * @param {string} prop Property name\r
- * @returns {boolean} `true` if considered to be present, otherwise `false`\r
- */\r
-util.isset =\r
-\r
-/**\r
- * Checks if a property on a message is considered to be present.\r
- * @param {Object} obj Plain object or message instance\r
- * @param {string} prop Property name\r
- * @returns {boolean} `true` if considered to be present, otherwise `false`\r
- */\r
-util.isSet = function isSet(obj, prop) {\r
- var value = obj[prop];\r
- if (value != null && obj.hasOwnProperty(prop)) // eslint-disable-line eqeqeq, no-prototype-builtins\r
- return typeof value !== "object" || (Array.isArray(value) ? value.length : Object.keys(value).length) > 0;\r
- return false;\r
-};\r
-\r
-/**\r
- * Any compatible Buffer instance.\r
- * This is a minimal stand-alone definition of a Buffer instance. The actual type is that exported by node's typings.\r
- * @interface Buffer\r
- * @extends Uint8Array\r
- */\r
-\r
-/**\r
- * Node's Buffer class if available.\r
- * @type {Constructor<Buffer>}\r
- */\r
-util.Buffer = (function() {\r
- try {\r
- var Buffer = util.inquire("buffer").Buffer;\r
- // refuse to use non-node buffers if not explicitly assigned (perf reasons):\r
- return Buffer.prototype.utf8Write ? Buffer : /* istanbul ignore next */ null;\r
- } catch (e) {\r
- /* istanbul ignore next */\r
- return null;\r
- }\r
-})();\r
-\r
-// Internal alias of or polyfull for Buffer.from.\r
-util._Buffer_from = null;\r
-\r
-// Internal alias of or polyfill for Buffer.allocUnsafe.\r
-util._Buffer_allocUnsafe = null;\r
-\r
-/**\r
- * Creates a new buffer of whatever type supported by the environment.\r
- * @param {number|number[]} [sizeOrArray=0] Buffer size or number array\r
- * @returns {Uint8Array|Buffer} Buffer\r
- */\r
-util.newBuffer = function newBuffer(sizeOrArray) {\r
- /* istanbul ignore next */\r
- return typeof sizeOrArray === "number"\r
- ? util.Buffer\r
- ? util._Buffer_allocUnsafe(sizeOrArray)\r
- : new util.Array(sizeOrArray)\r
- : util.Buffer\r
- ? util._Buffer_from(sizeOrArray)\r
- : typeof Uint8Array === "undefined"\r
- ? sizeOrArray\r
- : new Uint8Array(sizeOrArray);\r
-};\r
-\r
-/**\r
- * Array implementation used in the browser. `Uint8Array` if supported, otherwise `Array`.\r
- * @type {Constructor<Uint8Array>}\r
- */\r
-util.Array = typeof Uint8Array !== "undefined" ? Uint8Array /* istanbul ignore next */ : Array;\r
-\r
-/**\r
- * Any compatible Long instance.\r
- * This is a minimal stand-alone definition of a Long instance. The actual type is that exported by long.js.\r
- * @interface Long\r
- * @property {number} low Low bits\r
- * @property {number} high High bits\r
- * @property {boolean} unsigned Whether unsigned or not\r
- */\r
-\r
-/**\r
- * Long.js's Long class if available.\r
- * @type {Constructor<Long>}\r
- */\r
-util.Long = /* istanbul ignore next */ global.dcodeIO && /* istanbul ignore next */ global.dcodeIO.Long || util.inquire("long");\r
-\r
-/**\r
- * Regular expression used to verify 2 bit (`bool`) map keys.\r
- * @type {RegExp}\r
- * @const\r
- */\r
-util.key2Re = /^true|false|0|1$/;\r
-\r
-/**\r
- * Regular expression used to verify 32 bit (`int32` etc.) map keys.\r
- * @type {RegExp}\r
- * @const\r
- */\r
-util.key32Re = /^-?(?:0|[1-9][0-9]*)$/;\r
-\r
-/**\r
- * Regular expression used to verify 64 bit (`int64` etc.) map keys.\r
- * @type {RegExp}\r
- * @const\r
- */\r
-util.key64Re = /^(?:[\\x00-\\xff]{8}|-?(?:0|[1-9][0-9]*))$/;\r
-\r
-/**\r
- * Converts a number or long to an 8 characters long hash string.\r
- * @param {Long|number} value Value to convert\r
- * @returns {string} Hash\r
- */\r
-util.longToHash = function longToHash(value) {\r
- return value\r
- ? util.LongBits.from(value).toHash()\r
- : util.LongBits.zeroHash;\r
-};\r
-\r
-/**\r
- * Converts an 8 characters long hash string to a long or number.\r
- * @param {string} hash Hash\r
- * @param {boolean} [unsigned=false] Whether unsigned or not\r
- * @returns {Long|number} Original value\r
- */\r
-util.longFromHash = function longFromHash(hash, unsigned) {\r
- var bits = util.LongBits.fromHash(hash);\r
- if (util.Long)\r
- return util.Long.fromBits(bits.lo, bits.hi, unsigned);\r
- return bits.toNumber(Boolean(unsigned));\r
-};\r
-\r
-/**\r
- * Merges the properties of the source object into the destination object.\r
- * @memberof util\r
- * @param {Object.<string,*>} dst Destination object\r
- * @param {Object.<string,*>} src Source object\r
- * @param {boolean} [ifNotSet=false] Merges only if the key is not already set\r
- * @returns {Object.<string,*>} Destination object\r
- */\r
-function merge(dst, src, ifNotSet) { // used by converters\r
- for (var keys = Object.keys(src), i = 0; i < keys.length; ++i)\r
- if (dst[keys[i]] === undefined || !ifNotSet)\r
- dst[keys[i]] = src[keys[i]];\r
- return dst;\r
-}\r
-\r
-util.merge = merge;\r
-\r
-/**\r
- * Converts the first character of a string to lower case.\r
- * @param {string} str String to convert\r
- * @returns {string} Converted string\r
- */\r
-util.lcFirst = function lcFirst(str) {\r
- return str.charAt(0).toLowerCase() + str.substring(1);\r
-};\r
-\r
-/**\r
- * Creates a custom error constructor.\r
- * @memberof util\r
- * @param {string} name Error name\r
- * @returns {Constructor<Error>} Custom error constructor\r
- */\r
-function newError(name) {\r
-\r
- function CustomError(message, properties) {\r
-\r
- if (!(this instanceof CustomError))\r
- return new CustomError(message, properties);\r
-\r
- // Error.call(this, message);\r
- // ^ just returns a new error instance because the ctor can be called as a function\r
-\r
- Object.defineProperty(this, "message", { get: function() { return message; } });\r
-\r
- /* istanbul ignore next */\r
- if (Error.captureStackTrace) // node\r
- Error.captureStackTrace(this, CustomError);\r
- else\r
- Object.defineProperty(this, "stack", { value: (new Error()).stack || "" });\r
-\r
- if (properties)\r
- merge(this, properties);\r
- }\r
-\r
- (CustomError.prototype = Object.create(Error.prototype)).constructor = CustomError;\r
-\r
- Object.defineProperty(CustomError.prototype, "name", { get: function() { return name; } });\r
-\r
- CustomError.prototype.toString = function toString() {\r
- return this.name + ": " + this.message;\r
- };\r
-\r
- return CustomError;\r
-}\r
-\r
-util.newError = newError;\r
-\r
-/**\r
- * Constructs a new protocol error.\r
- * @classdesc Error subclass indicating a protocol specifc error.\r
- * @memberof util\r
- * @extends Error\r
- * @template T extends Message<T>\r
- * @constructor\r
- * @param {string} message Error message\r
- * @param {Object.<string,*>} [properties] Additional properties\r
- * @example\r
- * try {\r
- * MyMessage.decode(someBuffer); // throws if required fields are missing\r
- * } catch (e) {\r
- * if (e instanceof ProtocolError && e.instance)\r
- * console.log("decoded so far: " + JSON.stringify(e.instance));\r
- * }\r
- */\r
-util.ProtocolError = newError("ProtocolError");\r
-\r
-/**\r
- * So far decoded message instance.\r
- * @name util.ProtocolError#instance\r
- * @type {Message<T>}\r
- */\r
-\r
-/**\r
- * A OneOf getter as returned by {@link util.oneOfGetter}.\r
- * @typedef OneOfGetter\r
- * @type {function}\r
- * @returns {string|undefined} Set field name, if any\r
- */\r
-\r
-/**\r
- * Builds a getter for a oneof's present field name.\r
- * @param {string[]} fieldNames Field names\r
- * @returns {OneOfGetter} Unbound getter\r
- */\r
-util.oneOfGetter = function getOneOf(fieldNames) {\r
- var fieldMap = {};\r
- for (var i = 0; i < fieldNames.length; ++i)\r
- fieldMap[fieldNames[i]] = 1;\r
-\r
- /**\r
- * @returns {string|undefined} Set field name, if any\r
- * @this Object\r
- * @ignore\r
- */\r
- return function() { // eslint-disable-line consistent-return\r
- for (var keys = Object.keys(this), i = keys.length - 1; i > -1; --i)\r
- if (fieldMap[keys[i]] === 1 && this[keys[i]] !== undefined && this[keys[i]] !== null)\r
- return keys[i];\r
- };\r
-};\r
-\r
-/**\r
- * A OneOf setter as returned by {@link util.oneOfSetter}.\r
- * @typedef OneOfSetter\r
- * @type {function}\r
- * @param {string|undefined} value Field name\r
- * @returns {undefined}\r
- */\r
-\r
-/**\r
- * Builds a setter for a oneof's present field name.\r
- * @param {string[]} fieldNames Field names\r
- * @returns {OneOfSetter} Unbound setter\r
- */\r
-util.oneOfSetter = function setOneOf(fieldNames) {\r
-\r
- /**\r
- * @param {string} name Field name\r
- * @returns {undefined}\r
- * @this Object\r
- * @ignore\r
- */\r
- return function(name) {\r
- for (var i = 0; i < fieldNames.length; ++i)\r
- if (fieldNames[i] !== name)\r
- delete this[fieldNames[i]];\r
- };\r
-};\r
-\r
-/**\r
- * Default conversion options used for {@link Message#toJSON} implementations.\r
- *\r
- * These options are close to proto3's JSON mapping with the exception that internal types like Any are handled just like messages. More precisely:\r
- *\r
- * - Longs become strings\r
- * - Enums become string keys\r
- * - Bytes become base64 encoded strings\r
- * - (Sub-)Messages become plain objects\r
- * - Maps become plain objects with all string keys\r
- * - Repeated fields become arrays\r
- * - NaN and Infinity for float and double fields become strings\r
- *\r
- * @type {IConversionOptions}\r
- * @see https://developers.google.com/protocol-buffers/docs/proto3?hl=en#json\r
- */\r
-util.toJSONOptions = {\r
- longs: String,\r
- enums: String,\r
- bytes: String,\r
- json: true\r
-};\r
-\r
-util._configure = function() {\r
- var Buffer = util.Buffer;\r
- /* istanbul ignore if */\r
- if (!Buffer) {\r
- util._Buffer_from = util._Buffer_allocUnsafe = null;\r
- return;\r
- }\r
- // because node 4.x buffers are incompatible & immutable\r
- // see: https://github.com/dcodeIO/protobuf.js/pull/665\r
- util._Buffer_from = Buffer.from !== Uint8Array.from && Buffer.from ||\r
- /* istanbul ignore next */\r
- function Buffer_from(value, encoding) {\r
- return new Buffer(value, encoding);\r
- };\r
- util._Buffer_allocUnsafe = Buffer.allocUnsafe ||\r
- /* istanbul ignore next */\r
- function Buffer_allocUnsafe(size) {\r
- return new Buffer(size);\r
- };\r
-};\r
-
-}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
-},{"./longbits":219,"@protobufjs/aspromise":22,"@protobufjs/base64":23,"@protobufjs/eventemitter":25,"@protobufjs/float":27,"@protobufjs/inquire":28,"@protobufjs/pool":30,"@protobufjs/utf8":31}],221:[function(require,module,exports){
-"use strict";\r
-module.exports = verifier;\r
-\r
-var Enum = require("./enum"),\r
- util = require("./util");\r
-\r
-function invalid(field, expected) {\r
- return field.name + ": " + expected + (field.repeated && expected !== "array" ? "[]" : field.map && expected !== "object" ? "{k:"+field.keyType+"}" : "") + " expected";\r
-}\r
-\r
-/**\r
- * Generates a partial value verifier.\r
- * @param {Codegen} gen Codegen instance\r
- * @param {Field} field Reflected field\r
- * @param {number} fieldIndex Field index\r
- * @param {string} ref Variable reference\r
- * @returns {Codegen} Codegen instance\r
- * @ignore\r
- */\r
-function genVerifyValue(gen, field, fieldIndex, ref) {\r
- /* eslint-disable no-unexpected-multiline */\r
- if (field.resolvedType) {\r
- if (field.resolvedType instanceof Enum) { gen\r
- ("switch(%s){", ref)\r
- ("default:")\r
- ("return%j", invalid(field, "enum value"));\r
- for (var keys = Object.keys(field.resolvedType.values), j = 0; j < keys.length; ++j) gen\r
- ("case %i:", field.resolvedType.values[keys[j]]);\r
- gen\r
- ("break")\r
- ("}");\r
- } else {\r
- gen\r
- ("{")\r
- ("var e=types[%i].verify(%s);", fieldIndex, ref)\r
- ("if(e)")\r
- ("return%j+e", field.name + ".")\r
- ("}");\r
- }\r
- } else {\r
- switch (field.type) {\r
- case "int32":\r
- case "uint32":\r
- case "sint32":\r
- case "fixed32":\r
- case "sfixed32": gen\r
- ("if(!util.isInteger(%s))", ref)\r
- ("return%j", invalid(field, "integer"));\r
- break;\r
- case "int64":\r
- case "uint64":\r
- case "sint64":\r
- case "fixed64":\r
- case "sfixed64": gen\r
- ("if(!util.isInteger(%s)&&!(%s&&util.isInteger(%s.low)&&util.isInteger(%s.high)))", ref, ref, ref, ref)\r
- ("return%j", invalid(field, "integer|Long"));\r
- break;\r
- case "float":\r
- case "double": gen\r
- ("if(typeof %s!==\"number\")", ref)\r
- ("return%j", invalid(field, "number"));\r
- break;\r
- case "bool": gen\r
- ("if(typeof %s!==\"boolean\")", ref)\r
- ("return%j", invalid(field, "boolean"));\r
- break;\r
- case "string": gen\r
- ("if(!util.isString(%s))", ref)\r
- ("return%j", invalid(field, "string"));\r
- break;\r
- case "bytes": gen\r
- ("if(!(%s&&typeof %s.length===\"number\"||util.isString(%s)))", ref, ref, ref)\r
- ("return%j", invalid(field, "buffer"));\r
- break;\r
- }\r
- }\r
- return gen;\r
- /* eslint-enable no-unexpected-multiline */\r
-}\r
-\r
-/**\r
- * Generates a partial key verifier.\r
- * @param {Codegen} gen Codegen instance\r
- * @param {Field} field Reflected field\r
- * @param {string} ref Variable reference\r
- * @returns {Codegen} Codegen instance\r
- * @ignore\r
- */\r
-function genVerifyKey(gen, field, ref) {\r
- /* eslint-disable no-unexpected-multiline */\r
- switch (field.keyType) {\r
- case "int32":\r
- case "uint32":\r
- case "sint32":\r
- case "fixed32":\r
- case "sfixed32": gen\r
- ("if(!util.key32Re.test(%s))", ref)\r
- ("return%j", invalid(field, "integer key"));\r
- break;\r
- case "int64":\r
- case "uint64":\r
- case "sint64":\r
- case "fixed64":\r
- case "sfixed64": gen\r
- ("if(!util.key64Re.test(%s))", ref) // see comment above: x is ok, d is not\r
- ("return%j", invalid(field, "integer|Long key"));\r
- break;\r
- case "bool": gen\r
- ("if(!util.key2Re.test(%s))", ref)\r
- ("return%j", invalid(field, "boolean key"));\r
- break;\r
- }\r
- return gen;\r
- /* eslint-enable no-unexpected-multiline */\r
-}\r
-\r
-/**\r
- * Generates a verifier specific to the specified message type.\r
- * @param {Type} mtype Message type\r
- * @returns {Codegen} Codegen instance\r
- */\r
-function verifier(mtype) {\r
- /* eslint-disable no-unexpected-multiline */\r
-\r
- var gen = util.codegen(["m"], mtype.name + "$verify")\r
- ("if(typeof m!==\"object\"||m===null)")\r
- ("return%j", "object expected");\r
- var oneofs = mtype.oneofsArray,\r
- seenFirstField = {};\r
- if (oneofs.length) gen\r
- ("var p={}");\r
-\r
- for (var i = 0; i < /* initializes */ mtype.fieldsArray.length; ++i) {\r
- var field = mtype._fieldsArray[i].resolve(),\r
- ref = "m" + util.safeProp(field.name);\r
-\r
- if (field.optional) gen\r
- ("if(%s!=null&&m.hasOwnProperty(%j)){", ref, field.name); // !== undefined && !== null\r
-\r
- // map fields\r
- if (field.map) { gen\r
- ("if(!util.isObject(%s))", ref)\r
- ("return%j", invalid(field, "object"))\r
- ("var k=Object.keys(%s)", ref)\r
- ("for(var i=0;i<k.length;++i){");\r
- genVerifyKey(gen, field, "k[i]");\r
- genVerifyValue(gen, field, i, ref + "[k[i]]")\r
- ("}");\r
-\r
- // repeated fields\r
- } else if (field.repeated) { gen\r
- ("if(!Array.isArray(%s))", ref)\r
- ("return%j", invalid(field, "array"))\r
- ("for(var i=0;i<%s.length;++i){", ref);\r
- genVerifyValue(gen, field, i, ref + "[i]")\r
- ("}");\r
-\r
- // required or present fields\r
- } else {\r
- if (field.partOf) {\r
- var oneofProp = util.safeProp(field.partOf.name);\r
- if (seenFirstField[field.partOf.name] === 1) gen\r
- ("if(p%s===1)", oneofProp)\r
- ("return%j", field.partOf.name + ": multiple values");\r
- seenFirstField[field.partOf.name] = 1;\r
- gen\r
- ("p%s=1", oneofProp);\r
- }\r
- genVerifyValue(gen, field, i, ref);\r
- }\r
- if (field.optional) gen\r
- ("}");\r
- }\r
- return gen\r
- ("return null");\r
- /* eslint-enable no-unexpected-multiline */\r
-}
-},{"./enum":196,"./util":218}],222:[function(require,module,exports){
-"use strict";\r
-\r
-/**\r
- * Wrappers for common types.\r
- * @type {Object.<string,IWrapper>}\r
- * @const\r
- */\r
-var wrappers = exports;\r
-\r
-var Message = require("./message");\r
-\r
-/**\r
- * From object converter part of an {@link IWrapper}.\r
- * @typedef WrapperFromObjectConverter\r
- * @type {function}\r
- * @param {Object.<string,*>} object Plain object\r
- * @returns {Message<{}>} Message instance\r
- * @this Type\r
- */\r
-\r
-/**\r
- * To object converter part of an {@link IWrapper}.\r
- * @typedef WrapperToObjectConverter\r
- * @type {function}\r
- * @param {Message<{}>} message Message instance\r
- * @param {IConversionOptions} [options] Conversion options\r
- * @returns {Object.<string,*>} Plain object\r
- * @this Type\r
- */\r
-\r
-/**\r
- * Common type wrapper part of {@link wrappers}.\r
- * @interface IWrapper\r
- * @property {WrapperFromObjectConverter} [fromObject] From object converter\r
- * @property {WrapperToObjectConverter} [toObject] To object converter\r
- */\r
-\r
-// Custom wrapper for Any\r
-wrappers[".google.protobuf.Any"] = {\r
-\r
- fromObject: function(object) {\r
-\r
- // unwrap value type if mapped\r
- if (object && object["@type"]) {\r
- var type = this.lookup(object["@type"]);\r
- /* istanbul ignore else */\r
- if (type) {\r
- // type_url does not accept leading "."\r
- var type_url = object["@type"].charAt(0) === "." ?\r
- object["@type"].substr(1) : object["@type"];\r
- // type_url prefix is optional, but path seperator is required\r
- return this.create({\r
- type_url: "/" + type_url,\r
- value: type.encode(type.fromObject(object)).finish()\r
- });\r
- }\r
- }\r
-\r
- return this.fromObject(object);\r
- },\r
-\r
- toObject: function(message, options) {\r
-\r
- // decode value if requested and unmapped\r
- if (options && options.json && message.type_url && message.value) {\r
- // Only use fully qualified type name after the last '/'\r
- var name = message.type_url.substring(message.type_url.lastIndexOf("/") + 1);\r
- var type = this.lookup(name);\r
- /* istanbul ignore else */\r
- if (type)\r
- message = type.decode(message.value);\r
- }\r
-\r
- // wrap value if unmapped\r
- if (!(message instanceof this.ctor) && message instanceof Message) {\r
- var object = message.$type.toObject(message, options);\r
- object["@type"] = message.$type.fullName;\r
- return object;\r
- }\r
-\r
- return this.toObject(message, options);\r
- }\r
-};\r
-
-},{"./message":202}],223:[function(require,module,exports){
-"use strict";\r
-module.exports = Writer;\r
-\r
-var util = require("./util/minimal");\r
-\r
-var BufferWriter; // cyclic\r
-\r
-var LongBits = util.LongBits,\r
- base64 = util.base64,\r
- utf8 = util.utf8;\r
-\r
-/**\r
- * Constructs a new writer operation instance.\r
- * @classdesc Scheduled writer operation.\r
- * @constructor\r
- * @param {function(*, Uint8Array, number)} fn Function to call\r
- * @param {number} len Value byte length\r
- * @param {*} val Value to write\r
- * @ignore\r
- */\r
-function Op(fn, len, val) {\r
-\r
- /**\r
- * Function to call.\r
- * @type {function(Uint8Array, number, *)}\r
- */\r
- this.fn = fn;\r
-\r
- /**\r
- * Value byte length.\r
- * @type {number}\r
- */\r
- this.len = len;\r
-\r
- /**\r
- * Next operation.\r
- * @type {Writer.Op|undefined}\r
- */\r
- this.next = undefined;\r
-\r
- /**\r
- * Value to write.\r
- * @type {*}\r
- */\r
- this.val = val; // type varies\r
-}\r
-\r
-/* istanbul ignore next */\r
-function noop() {} // eslint-disable-line no-empty-function\r
-\r
-/**\r
- * Constructs a new writer state instance.\r
- * @classdesc Copied writer state.\r
- * @memberof Writer\r
- * @constructor\r
- * @param {Writer} writer Writer to copy state from\r
- * @ignore\r
- */\r
-function State(writer) {\r
-\r
- /**\r
- * Current head.\r
- * @type {Writer.Op}\r
- */\r
- this.head = writer.head;\r
-\r
- /**\r
- * Current tail.\r
- * @type {Writer.Op}\r
- */\r
- this.tail = writer.tail;\r
-\r
- /**\r
- * Current buffer length.\r
- * @type {number}\r
- */\r
- this.len = writer.len;\r
-\r
- /**\r
- * Next state.\r
- * @type {State|null}\r
- */\r
- this.next = writer.states;\r
-}\r
-\r
-/**\r
- * Constructs a new writer instance.\r
- * @classdesc Wire format writer using `Uint8Array` if available, otherwise `Array`.\r
- * @constructor\r
- */\r
-function Writer() {\r
-\r
- /**\r
- * Current length.\r
- * @type {number}\r
- */\r
- this.len = 0;\r
-\r
- /**\r
- * Operations head.\r
- * @type {Object}\r
- */\r
- this.head = new Op(noop, 0, 0);\r
-\r
- /**\r
- * Operations tail\r
- * @type {Object}\r
- */\r
- this.tail = this.head;\r
-\r
- /**\r
- * Linked forked states.\r
- * @type {Object|null}\r
- */\r
- this.states = null;\r
-\r
- // When a value is written, the writer calculates its byte length and puts it into a linked\r
- // list of operations to perform when finish() is called. This both allows us to allocate\r
- // buffers of the exact required size and reduces the amount of work we have to do compared\r
- // to first calculating over objects and then encoding over objects. In our case, the encoding\r
- // part is just a linked list walk calling operations with already prepared values.\r
-}\r
-\r
-/**\r
- * Creates a new writer.\r
- * @function\r
- * @returns {BufferWriter|Writer} A {@link BufferWriter} when Buffers are supported, otherwise a {@link Writer}\r
- */\r
-Writer.create = util.Buffer\r
- ? function create_buffer_setup() {\r
- return (Writer.create = function create_buffer() {\r
- return new BufferWriter();\r
- })();\r
- }\r
- /* istanbul ignore next */\r
- : function create_array() {\r
- return new Writer();\r
- };\r
-\r
-/**\r
- * Allocates a buffer of the specified size.\r
- * @param {number} size Buffer size\r
- * @returns {Uint8Array} Buffer\r
- */\r
-Writer.alloc = function alloc(size) {\r
- return new util.Array(size);\r
-};\r
-\r
-// Use Uint8Array buffer pool in the browser, just like node does with buffers\r
-/* istanbul ignore else */\r
-if (util.Array !== Array)\r
- Writer.alloc = util.pool(Writer.alloc, util.Array.prototype.subarray);\r
-\r
-/**\r
- * Pushes a new operation to the queue.\r
- * @param {function(Uint8Array, number, *)} fn Function to call\r
- * @param {number} len Value byte length\r
- * @param {number} val Value to write\r
- * @returns {Writer} `this`\r
- * @private\r
- */\r
-Writer.prototype._push = function push(fn, len, val) {\r
- this.tail = this.tail.next = new Op(fn, len, val);\r
- this.len += len;\r
- return this;\r
-};\r
-\r
-function writeByte(val, buf, pos) {\r
- buf[pos] = val & 255;\r
-}\r
-\r
-function writeVarint32(val, buf, pos) {\r
- while (val > 127) {\r
- buf[pos++] = val & 127 | 128;\r
- val >>>= 7;\r
- }\r
- buf[pos] = val;\r
-}\r
-\r
-/**\r
- * Constructs a new varint writer operation instance.\r
- * @classdesc Scheduled varint writer operation.\r
- * @extends Op\r
- * @constructor\r
- * @param {number} len Value byte length\r
- * @param {number} val Value to write\r
- * @ignore\r
- */\r
-function VarintOp(len, val) {\r
- this.len = len;\r
- this.next = undefined;\r
- this.val = val;\r
-}\r
-\r
-VarintOp.prototype = Object.create(Op.prototype);\r
-VarintOp.prototype.fn = writeVarint32;\r
-\r
-/**\r
- * Writes an unsigned 32 bit value as a varint.\r
- * @param {number} value Value to write\r
- * @returns {Writer} `this`\r
- */\r
-Writer.prototype.uint32 = function write_uint32(value) {\r
- // here, the call to this.push has been inlined and a varint specific Op subclass is used.\r
- // uint32 is by far the most frequently used operation and benefits significantly from this.\r
- this.len += (this.tail = this.tail.next = new VarintOp(\r
- (value = value >>> 0)\r
- < 128 ? 1\r
- : value < 16384 ? 2\r
- : value < 2097152 ? 3\r
- : value < 268435456 ? 4\r
- : 5,\r
- value)).len;\r
- return this;\r
-};\r
-\r
-/**\r
- * Writes a signed 32 bit value as a varint.\r
- * @function\r
- * @param {number} value Value to write\r
- * @returns {Writer} `this`\r
- */\r
-Writer.prototype.int32 = function write_int32(value) {\r
- return value < 0\r
- ? this._push(writeVarint64, 10, LongBits.fromNumber(value)) // 10 bytes per spec\r
- : this.uint32(value);\r
-};\r
-\r
-/**\r
- * Writes a 32 bit value as a varint, zig-zag encoded.\r
- * @param {number} value Value to write\r
- * @returns {Writer} `this`\r
- */\r
-Writer.prototype.sint32 = function write_sint32(value) {\r
- return this.uint32((value << 1 ^ value >> 31) >>> 0);\r
-};\r
-\r
-function writeVarint64(val, buf, pos) {\r
- while (val.hi) {\r
- buf[pos++] = val.lo & 127 | 128;\r
- val.lo = (val.lo >>> 7 | val.hi << 25) >>> 0;\r
- val.hi >>>= 7;\r
- }\r
- while (val.lo > 127) {\r
- buf[pos++] = val.lo & 127 | 128;\r
- val.lo = val.lo >>> 7;\r
- }\r
- buf[pos++] = val.lo;\r
-}\r
-\r
-/**\r
- * Writes an unsigned 64 bit value as a varint.\r
- * @param {Long|number|string} value Value to write\r
- * @returns {Writer} `this`\r
- * @throws {TypeError} If `value` is a string and no long library is present.\r
- */\r
-Writer.prototype.uint64 = function write_uint64(value) {\r
- var bits = LongBits.from(value);\r
- return this._push(writeVarint64, bits.length(), bits);\r
-};\r
-\r
-/**\r
- * Writes a signed 64 bit value as a varint.\r
- * @function\r
- * @param {Long|number|string} value Value to write\r
- * @returns {Writer} `this`\r
- * @throws {TypeError} If `value` is a string and no long library is present.\r
- */\r
-Writer.prototype.int64 = Writer.prototype.uint64;\r
-\r
-/**\r
- * Writes a signed 64 bit value as a varint, zig-zag encoded.\r
- * @param {Long|number|string} value Value to write\r
- * @returns {Writer} `this`\r
- * @throws {TypeError} If `value` is a string and no long library is present.\r
- */\r
-Writer.prototype.sint64 = function write_sint64(value) {\r
- var bits = LongBits.from(value).zzEncode();\r
- return this._push(writeVarint64, bits.length(), bits);\r
-};\r
-\r
-/**\r
- * Writes a boolish value as a varint.\r
- * @param {boolean} value Value to write\r
- * @returns {Writer} `this`\r
- */\r
-Writer.prototype.bool = function write_bool(value) {\r
- return this._push(writeByte, 1, value ? 1 : 0);\r
-};\r
-\r
-function writeFixed32(val, buf, pos) {\r
- buf[pos ] = val & 255;\r
- buf[pos + 1] = val >>> 8 & 255;\r
- buf[pos + 2] = val >>> 16 & 255;\r
- buf[pos + 3] = val >>> 24;\r
-}\r
-\r
-/**\r
- * Writes an unsigned 32 bit value as fixed 32 bits.\r
- * @param {number} value Value to write\r
- * @returns {Writer} `this`\r
- */\r
-Writer.prototype.fixed32 = function write_fixed32(value) {\r
- return this._push(writeFixed32, 4, value >>> 0);\r
-};\r
-\r
-/**\r
- * Writes a signed 32 bit value as fixed 32 bits.\r
- * @function\r
- * @param {number} value Value to write\r
- * @returns {Writer} `this`\r
- */\r
-Writer.prototype.sfixed32 = Writer.prototype.fixed32;\r
-\r
-/**\r
- * Writes an unsigned 64 bit value as fixed 64 bits.\r
- * @param {Long|number|string} value Value to write\r
- * @returns {Writer} `this`\r
- * @throws {TypeError} If `value` is a string and no long library is present.\r
- */\r
-Writer.prototype.fixed64 = function write_fixed64(value) {\r
- var bits = LongBits.from(value);\r
- return this._push(writeFixed32, 4, bits.lo)._push(writeFixed32, 4, bits.hi);\r
-};\r
-\r
-/**\r
- * Writes a signed 64 bit value as fixed 64 bits.\r
- * @function\r
- * @param {Long|number|string} value Value to write\r
- * @returns {Writer} `this`\r
- * @throws {TypeError} If `value` is a string and no long library is present.\r
- */\r
-Writer.prototype.sfixed64 = Writer.prototype.fixed64;\r
-\r
-/**\r
- * Writes a float (32 bit).\r
- * @function\r
- * @param {number} value Value to write\r
- * @returns {Writer} `this`\r
- */\r
-Writer.prototype.float = function write_float(value) {\r
- return this._push(util.float.writeFloatLE, 4, value);\r
-};\r
-\r
-/**\r
- * Writes a double (64 bit float).\r
- * @function\r
- * @param {number} value Value to write\r
- * @returns {Writer} `this`\r
- */\r
-Writer.prototype.double = function write_double(value) {\r
- return this._push(util.float.writeDoubleLE, 8, value);\r
-};\r
-\r
-var writeBytes = util.Array.prototype.set\r
- ? function writeBytes_set(val, buf, pos) {\r
- buf.set(val, pos); // also works for plain array values\r
- }\r
- /* istanbul ignore next */\r
- : function writeBytes_for(val, buf, pos) {\r
- for (var i = 0; i < val.length; ++i)\r
- buf[pos + i] = val[i];\r
- };\r
-\r
-/**\r
- * Writes a sequence of bytes.\r
- * @param {Uint8Array|string} value Buffer or base64 encoded string to write\r
- * @returns {Writer} `this`\r
- */\r
-Writer.prototype.bytes = function write_bytes(value) {\r
- var len = value.length >>> 0;\r
- if (!len)\r
- return this._push(writeByte, 1, 0);\r
- if (util.isString(value)) {\r
- var buf = Writer.alloc(len = base64.length(value));\r
- base64.decode(value, buf, 0);\r
- value = buf;\r
- }\r
- return this.uint32(len)._push(writeBytes, len, value);\r
-};\r
-\r
-/**\r
- * Writes a string.\r
- * @param {string} value Value to write\r
- * @returns {Writer} `this`\r
- */\r
-Writer.prototype.string = function write_string(value) {\r
- var len = utf8.length(value);\r
- return len\r
- ? this.uint32(len)._push(utf8.write, len, value)\r
- : this._push(writeByte, 1, 0);\r
-};\r
-\r
-/**\r
- * Forks this writer's state by pushing it to a stack.\r
- * Calling {@link Writer#reset|reset} or {@link Writer#ldelim|ldelim} resets the writer to the previous state.\r
- * @returns {Writer} `this`\r
- */\r
-Writer.prototype.fork = function fork() {\r
- this.states = new State(this);\r
- this.head = this.tail = new Op(noop, 0, 0);\r
- this.len = 0;\r
- return this;\r
-};\r
-\r
-/**\r
- * Resets this instance to the last state.\r
- * @returns {Writer} `this`\r
- */\r
-Writer.prototype.reset = function reset() {\r
- if (this.states) {\r
- this.head = this.states.head;\r
- this.tail = this.states.tail;\r
- this.len = this.states.len;\r
- this.states = this.states.next;\r
- } else {\r
- this.head = this.tail = new Op(noop, 0, 0);\r
- this.len = 0;\r
- }\r
- return this;\r
-};\r
-\r
-/**\r
- * Resets to the last state and appends the fork state's current write length as a varint followed by its operations.\r
- * @returns {Writer} `this`\r
- */\r
-Writer.prototype.ldelim = function ldelim() {\r
- var head = this.head,\r
- tail = this.tail,\r
- len = this.len;\r
- this.reset().uint32(len);\r
- if (len) {\r
- this.tail.next = head.next; // skip noop\r
- this.tail = tail;\r
- this.len += len;\r
- }\r
- return this;\r
-};\r
-\r
-/**\r
- * Finishes the write operation.\r
- * @returns {Uint8Array} Finished buffer\r
- */\r
-Writer.prototype.finish = function finish() {\r
- var head = this.head.next, // skip noop\r
- buf = this.constructor.alloc(this.len),\r
- pos = 0;\r
- while (head) {\r
- head.fn(head.val, buf, pos);\r
- pos += head.len;\r
- head = head.next;\r
- }\r
- // this.head = this.tail = null;\r
- return buf;\r
-};\r
-\r
-Writer._configure = function(BufferWriter_) {\r
- BufferWriter = BufferWriter_;\r
-};\r
-
-},{"./util/minimal":220}],224:[function(require,module,exports){
-"use strict";\r
-module.exports = BufferWriter;\r
-\r
-// extends Writer\r
-var Writer = require("./writer");\r
-(BufferWriter.prototype = Object.create(Writer.prototype)).constructor = BufferWriter;\r
-\r
-var util = require("./util/minimal");\r
-\r
-var Buffer = util.Buffer;\r
-\r
-/**\r
- * Constructs a new buffer writer instance.\r
- * @classdesc Wire format writer using node buffers.\r
- * @extends Writer\r
- * @constructor\r
- */\r
-function BufferWriter() {\r
- Writer.call(this);\r
-}\r
-\r
-/**\r
- * Allocates a buffer of the specified size.\r
- * @param {number} size Buffer size\r
- * @returns {Buffer} Buffer\r
- */\r
-BufferWriter.alloc = function alloc_buffer(size) {\r
- return (BufferWriter.alloc = util._Buffer_allocUnsafe)(size);\r
-};\r
-\r
-var writeBytesBuffer = Buffer && Buffer.prototype instanceof Uint8Array && Buffer.prototype.set.name === "set"\r
- ? function writeBytesBuffer_set(val, buf, pos) {\r
- buf.set(val, pos); // faster than copy (requires node >= 4 where Buffers extend Uint8Array and set is properly inherited)\r
- // also works for plain array values\r
- }\r
- /* istanbul ignore next */\r
- : function writeBytesBuffer_copy(val, buf, pos) {\r
- if (val.copy) // Buffer values\r
- val.copy(buf, pos, 0, val.length);\r
- else for (var i = 0; i < val.length;) // plain array values\r
- buf[pos++] = val[i++];\r
- };\r
-\r
-/**\r
- * @override\r
- */\r
-BufferWriter.prototype.bytes = function write_bytes_buffer(value) {\r
- if (util.isString(value))\r
- value = util._Buffer_from(value, "base64");\r
- var len = value.length >>> 0;\r
- this.uint32(len);\r
- if (len)\r
- this._push(writeBytesBuffer, len, value);\r
- return this;\r
-};\r
-\r
-function writeStringBuffer(val, buf, pos) {\r
- if (val.length < 40) // plain js is faster for short strings (probably due to redundant assertions)\r
- util.utf8.write(val, buf, pos);\r
- else\r
- buf.utf8Write(val, pos);\r
-}\r
-\r
-/**\r
- * @override\r
- */\r
-BufferWriter.prototype.string = function write_string_buffer(value) {\r
- var len = Buffer.byteLength(value);\r
- this.uint32(len);\r
- if (len)\r
- this._push(writeStringBuffer, len, value);\r
- return this;\r
-};\r
-\r
-\r
-/**\r
- * Finishes the write operation.\r
- * @name BufferWriter#finish\r
- * @function\r
- * @returns {Buffer} Finished buffer\r
- */\r
-
-},{"./util/minimal":220,"./writer":223}],225:[function(require,module,exports){