New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

protobufjs

Package Overview
Dependencies
Maintainers
1
Versions
168
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

protobufjs - npm Package Compare versions

Comparing version 3.4.0 to 3.4.1

2

bower.json
{
"name": "protobuf",
"description": "Protocol Buffers for JavaScript. Finally.",
"version": "3.4.0",
"version": "3.4.1",
"main": "dist/ProtoBuf.js",

@@ -6,0 +6,0 @@ "license": "Apache-2.0",

@@ -6,3 +6,3 @@ /*

*/
(function(q){function r(k){var g={VERSION:"3.4.0",WIRE_TYPES:{}};g.WIRE_TYPES.VARINT=0;g.WIRE_TYPES.BITS64=1;g.WIRE_TYPES.LDELIM=2;g.WIRE_TYPES.STARTGROUP=3;g.WIRE_TYPES.ENDGROUP=4;g.WIRE_TYPES.BITS32=5;g.PACKABLE_WIRE_TYPES=[g.WIRE_TYPES.VARINT,g.WIRE_TYPES.BITS64,g.WIRE_TYPES.BITS32];g.TYPES={int32:{name:"int32",wireType:g.WIRE_TYPES.VARINT},uint32:{name:"uint32",wireType:g.WIRE_TYPES.VARINT},sint32:{name:"sint32",wireType:g.WIRE_TYPES.VARINT},int64:{name:"int64",wireType:g.WIRE_TYPES.VARINT},uint64:{name:"uint64",
(function(q){function r(k){var g={VERSION:"3.4.1",WIRE_TYPES:{}};g.WIRE_TYPES.VARINT=0;g.WIRE_TYPES.BITS64=1;g.WIRE_TYPES.LDELIM=2;g.WIRE_TYPES.STARTGROUP=3;g.WIRE_TYPES.ENDGROUP=4;g.WIRE_TYPES.BITS32=5;g.PACKABLE_WIRE_TYPES=[g.WIRE_TYPES.VARINT,g.WIRE_TYPES.BITS64,g.WIRE_TYPES.BITS32];g.TYPES={int32:{name:"int32",wireType:g.WIRE_TYPES.VARINT},uint32:{name:"uint32",wireType:g.WIRE_TYPES.VARINT},sint32:{name:"sint32",wireType:g.WIRE_TYPES.VARINT},int64:{name:"int64",wireType:g.WIRE_TYPES.VARINT},uint64:{name:"uint64",
wireType:g.WIRE_TYPES.VARINT},sint64:{name:"sint64",wireType:g.WIRE_TYPES.VARINT},bool:{name:"bool",wireType:g.WIRE_TYPES.VARINT},"double":{name:"double",wireType:g.WIRE_TYPES.BITS64},string:{name:"string",wireType:g.WIRE_TYPES.LDELIM},bytes:{name:"bytes",wireType:g.WIRE_TYPES.LDELIM},fixed32:{name:"fixed32",wireType:g.WIRE_TYPES.BITS32},sfixed32:{name:"sfixed32",wireType:g.WIRE_TYPES.BITS32},fixed64:{name:"fixed64",wireType:g.WIRE_TYPES.BITS64},sfixed64:{name:"sfixed64",wireType:g.WIRE_TYPES.BITS64},

@@ -50,3 +50,3 @@ "float":{name:"float",wireType:g.WIRE_TYPES.BITS32},"enum":{name:"enum",wireType:g.WIRE_TYPES.VARINT},message:{name:"message",wireType:g.WIRE_TYPES.LDELIM},group:{name:"group",wireType:g.WIRE_TYPES.STARTGROUP}};g.ID_MIN=1;g.ID_MAX=536870911;g.ByteBuffer=k;g.Long=k.Long||null;g.convertFieldsToCamelCase=!1;g.populateAccessors=!0;g.Util=function(){Object.create||(Object.create=function(e){function d(){}if(1<arguments.length)throw Error("Object.create polyfill only accepts the first parameter.");d.prototype=

!!f};a.prototype=Object.create(b.prototype);a.prototype.build=function(b){if(this.clazz&&!b)return this.clazz;b=function(a,d){function b(a,d){var c={},e;for(e in a)a.hasOwnProperty(e)&&(null===a[e]||"object"!==typeof a[e]?c[e]=a[e]:a[e]instanceof k?d&&(c[e]=a.toBuffer()):c[e]=b(a[e],d));return c}var c=d.getChildren(a.Reflect.Message.Field),e=function(b,e){a.Builder.Message.call(this);var m,f;Object.defineProperty&&Object.defineProperty(this,"$type",{get:function(){return d}});for(m=0;m<c.length;m++)f=
c[m],this[f.name]=f.repeated?[]:null;for(m=0;m<c.length;m++)if(f=c[m],f.required&&"undefined"!==typeof f.options["default"])try{this.$set(f.name,f.options["default"])}catch(t){throw Error("[INTERNAL] "+t);}if(1!=arguments.length||"object"!=typeof b||"function"==typeof b.encode||a.Util.isArray(b)||b instanceof k||b instanceof ArrayBuffer||a.Long&&b instanceof a.Long)for(m=0;m<arguments.length;m++)m<c.length&&this.$set(c[m].name,arguments[m]);else for(f=Object.keys(b),m=0;m<f.length;m++)this.$set(f[m],
c[m],this[f.name]=f.repeated?[]:null;for(m=0;m<c.length;m++)if(f=c[m],f.required&&"undefined"!==typeof f.options["default"])try{this.$set(f.name,f.options["default"])}catch(t){throw Error("[INTERNAL] "+t);}if(1!==arguments.length||"object"!==typeof b||"function"===typeof b.encode||a.Util.isArray(b)||b instanceof k||b instanceof ArrayBuffer||a.Long&&b instanceof a.Long)for(m=0;m<arguments.length;m++)m<c.length&&this.$set(c[m].name,arguments[m]);else for(f=Object.keys(b),m=0;m<f.length;m++)this.$set(f[m],
b[f[m]])};e.prototype=Object.create(a.Builder.Message.prototype);e.prototype.add=function(b,c,e){var m=d.getChild(b);if(!m)throw Error(this+"#"+b+" is undefined");if(!(m instanceof a.Reflect.Message.Field))throw Error(this+"#"+b+" is not a field: "+m.toString(!0));if(!m.repeated)throw Error(this+"#"+b+" is not a repeated field");null===this[m.name]&&(this[m.name]=[]);this[m.name].push(e?c:m.verifyValue(c,!0))};e.prototype.$add=e.prototype.add;e.prototype.set=function(b,c,e){var m=d.getChild(b);if(!m)throw Error(this+

@@ -66,39 +66,40 @@ "#"+b+" is not a field: undefined");if(!(m instanceof a.Reflect.Message.Field))throw Error(this+"#"+b+" is not a field: "+m.toString(!0));this[m.name]=e?c:m.verifyValue(c)};e.prototype.$set=e.prototype.set;e.prototype.get=function(b){var c=d.getChild(b);if(!(c&&c instanceof a.Reflect.Message.Field))throw Error(this+"#"+b+" is not a field: undefined");if(!(c instanceof a.Reflect.Message.Field))throw Error(this+"#"+b+" is not a field: "+c.toString(!0));return this[c.name]};e.prototype.$get=e.prototype.get;

!1)}catch(f){c(typeof a,f.message)}else c(typeof a,"requires Long.js");case d.TYPES.uint64:case d.TYPES.fixed64:if(d.Long)try{return g(a,!0)}catch(l){c(typeof a,l.message)}else c(typeof a,"requires Long.js");case d.TYPES.bool:return"boolean"!==typeof a&&c(typeof a,"not a boolean"),a;case d.TYPES["float"]:case d.TYPES["double"]:return"number"!==typeof a&&c(typeof a,"not a number"),a;case d.TYPES.string:return"string"===typeof a||a&&a instanceof String||c(typeof a,"not a string"),""+a;case d.TYPES.bytes:return a&&
a instanceof k?a:k.wrap(a);case d.TYPES["enum"]:var n=this.resolvedType.getChildren(h.Value);for(e=0;e<n.length;e++)if(n[e].name==a||n[e].id==a)return n[e].id;c(a,"not a valid enum value");case d.TYPES.group:case d.TYPES.message:return a&&"object"===typeof a||c(typeof a,"object expected"),a instanceof this.resolvedType.clazz?a:new this.resolvedType.clazz(a)}throw Error("[INTERNAL] Illegal value for "+this.toString(!0)+": "+a+" (undefined type "+this.type+")");};f.prototype.encode=function(a,b){a=
this.verifyValue(a);if(null===this.type||"object"!==typeof this.type)throw Error("[INTERNAL] Unresolved type in "+this.toString(!0)+": "+this.type);if(null===a||this.repeated&&0==a.length)return b;try{if(this.repeated){var c;if(this.options.packed&&0<=d.PACKABLE_WIRE_TYPES.indexOf(this.type.wireType)){b.writeVarint32(this.id<<3|d.WIRE_TYPES.LDELIM);b.ensureCapacity(b.offset+=1);var e=b.offset;for(c=0;c<a.length;c++)this.encodeValue(a[c],b);var f=b.offset-e,g=k.calculateVarint32(f);if(1<g){var h=b.slice(e,
b.offset),e=e+(g-1);b.offset=e;b.append(h)}b.writeVarint32(f,e-g)}else for(c=0;c<a.length;c++)b.writeVarint32(this.id<<3|this.type.wireType),this.encodeValue(a[c],b)}else b.writeVarint32(this.id<<3|this.type.wireType),this.encodeValue(a,b)}catch(l){throw Error("Illegal value for "+this.toString(!0)+": "+a+" ("+l+")");}return b};f.prototype.encodeValue=function(a,b){if(null===a)return b;switch(this.type){case d.TYPES.int32:0>a?b.writeVarint64(a):b.writeVarint32(a);break;case d.TYPES.uint32:b.writeVarint32(a);
break;case d.TYPES.sint32:b.writeVarint32ZigZag(a);break;case d.TYPES.fixed32:b.writeUint32(a);break;case d.TYPES.sfixed32:b.writeInt32(a);break;case d.TYPES.int64:case d.TYPES.uint64:b.writeVarint64(a);break;case d.TYPES.sint64:b.writeVarint64ZigZag(a);break;case d.TYPES.fixed64:b.writeUint64(a);break;case d.TYPES.sfixed64:b.writeInt64(a);break;case d.TYPES.bool:"string"===typeof a?b.writeVarint32("false"===a.toLowerCase()?0:!!a):b.writeVarint32(a?1:0);break;case d.TYPES["enum"]:b.writeVarint32(a);
break;case d.TYPES["float"]:b.writeFloat32(a);break;case d.TYPES["double"]:b.writeFloat64(a);break;case d.TYPES.string:b.writeVString(a);break;case d.TYPES.bytes:if(0>a.remaining())throw Error("Illegal value for "+this.toString(!0)+": "+a.remaining()+" bytes remaining");var c=a.offset;b.writeVarint32(a.remaining());b.append(a);a.offset=c;break;case d.TYPES.message:c=(new k).LE();this.resolvedType.encode(a,c);b.writeVarint32(c.offset);b.append(c.flip());break;case d.TYPES.group:this.resolvedType.encode(a,
b);b.writeVarint32(this.id<<3|d.WIRE_TYPES.ENDGROUP);break;default:throw Error("[INTERNAL] Illegal value to encode in "+this.toString(!0)+": "+a+" (unknown type)");}return b};f.prototype.calculate=function(a){a=this.verifyValue(a);if(null===this.type||"object"!==typeof this.type)throw Error("[INTERNAL] Unresolved type in "+this.toString(!0)+": "+this.type);if(null===a||this.repeated&&0==a.length)return 0;var b=0;try{if(this.repeated){var c,e;if(this.options.packed&&0<=d.PACKABLE_WIRE_TYPES.indexOf(this.type.wireType)){b+=
k.calculateVarint32(this.id<<3|d.WIRE_TYPES.LDELIM);for(c=e=0;c<a.length;c++)e+=this.calculateValue(a[c]);b+=k.calculateVarint32(e);b+=e}else for(c=0;c<a.length;c++)b+=k.calculateVarint32(this.id<<3|this.type.wireType),b+=this.calculateValue(a[c])}else b+=k.calculateVarint32(this.id<<3|this.type.wireType),b+=this.calculateValue(a)}catch(f){throw Error("Illegal value for "+this.toString(!0)+": "+a+" ("+f+")");}return b};f.prototype.calculateValue=function(a){if(null===a)return 0;switch(this.type){case d.TYPES.int32:return 0>
a?k.calculateVarint64(a):k.calculateVarint32(a);case d.TYPES.uint32:return k.calculateVarint32(a);case d.TYPES.sint32:return k.calculateVarint32(k.zigZagEncode32(a));case d.TYPES.fixed32:case d.TYPES.sfixed32:case d.TYPES["float"]:return 4;case d.TYPES.int64:case d.TYPES.uint64:return k.calculateVarint64(a);case d.TYPES.sint64:return k.calculateVarint64(k.zigZagEncode64(a));case d.TYPES.fixed64:case d.TYPES.sfixed64:return 8;case d.TYPES.bool:return 1;case d.TYPES["enum"]:return k.calculateVarint32(a);
case d.TYPES["double"]:return 8;case d.TYPES.string:return a=k.calculateUTF8Bytes(a),k.calculateVarint32(a)+a;case d.TYPES.bytes:if(0>a.remaining())throw Error("Illegal value for "+this.toString(!0)+": "+a.remaining()+" bytes remaining");return k.calculateVarint32(a.remaining())+a.remaining();case d.TYPES.message:return a=this.resolvedType.calculate(a),k.calculateVarint32(a)+a;case d.TYPES.group:return a=this.resolvedType.calculate(a),a+k.calculateVarint32(this.id<<3|d.WIRE_TYPES.ENDGROUP)}throw Error("[INTERNAL] Illegal value to encode in "+
this.toString(!0)+": "+a+" (unknown type)");};f.prototype.decode=function(a,b,c){if(a!=this.type.wireType&&(c||a!=d.WIRE_TYPES.LDELIM||!this.repeated))throw Error("Illegal wire type for field "+this.toString(!0)+": "+a+" ("+this.type.wireType+" expected)");if(a==d.WIRE_TYPES.LDELIM&&this.repeated&&this.options.packed&&0<=d.PACKABLE_WIRE_TYPES.indexOf(this.type.wireType)&&!c){a=b.readVarint32();a=b.offset+a;for(c=[];b.offset<a;)c.push(this.decode(this.type.wireType,b,!0));return c}switch(this.type){case d.TYPES.int32:return b.readVarint32()|
0;case d.TYPES.uint32:return b.readVarint32()>>>0;case d.TYPES.sint32:return b.readVarint32ZigZag()|0;case d.TYPES.fixed32:return b.readUint32()>>>0;case d.TYPES.sfixed32:return b.readInt32()|0;case d.TYPES.int64:return b.readVarint64();case d.TYPES.uint64:return b.readVarint64().toUnsigned();case d.TYPES.sint64:return b.readVarint64ZigZag();case d.TYPES.fixed64:return b.readUint64();case d.TYPES.sfixed64:return b.readInt64();case d.TYPES.bool:return!!b.readVarint32();case d.TYPES["enum"]:return b.readVarint32();
case d.TYPES["float"]:return b.readFloat();case d.TYPES["double"]:return b.readDouble();case d.TYPES.string:return b.readVString();case d.TYPES.bytes:a=b.readVarint32();if(b.remaining()<a)throw Error("Illegal number of bytes for "+this.toString(!0)+": "+a+" required but got only "+b.remaining());c=b.clone();c.limit=c.offset+a;b.offset+=a;return c;case d.TYPES.message:return a=b.readVarint32(),this.resolvedType.decode(b,a);case d.TYPES.group:return this.resolvedType.decode(b,-1,this.id)}throw Error("[INTERNAL] Illegal wire type for "+
this.toString(!0)+": "+a);};l.Message.Field=f;var n=function(a,b,c,d,e,g){f.call(this,a,b,c,d,e,g)};n.prototype=Object.create(f.prototype);l.Message.ExtensionField=n;var h=function(a,c,d){b.call(this,a,c,d);this.className="Enum";this.object=null};h.prototype=Object.create(b.prototype);h.prototype.build=function(){for(var a={},b=this.getChildren(h.Value),c=0;c<b.length;c++)a[b[c].name]=b[c].id;Object.defineProperty&&Object.defineProperty(a,"$options",{value:this.buildOpt()});return this.object=a};
l.Enum=h;n=function(a,b,d){c.call(this,a,b);this.className="Enum.Value";this.id=d};n.prototype=Object.create(c.prototype);l.Enum.Value=n;n=function(a,c,d){b.call(this,a,c,d);this.className="Service";this.clazz=null};n.prototype=Object.create(b.prototype);n.prototype.build=function(a){return this.clazz&&!a?this.clazz:this.clazz=function(a,b){var c=function(b){a.Builder.Service.call(this);this.rpcImpl=b||function(a,b,c){setTimeout(c.bind(this,Error("Not implemented, see: https://github.com/dcodeIO/ProtoBuf.js/wiki/Services")),
0)}};c.prototype=Object.create(a.Builder.Service.prototype);Object.defineProperty&&(Object.defineProperty(c,"$options",{value:b.buildOpt()}),Object.defineProperty(c.prototype,"$options",{value:c.$options}));for(var d=b.getChildren(a.Reflect.Service.RPCMethod),e=0;e<d.length;e++)(function(a){c.prototype[a.name]=function(c,d){try{c&&c instanceof a.resolvedRequestType.clazz?this.rpcImpl(a.fqn(),c,function(c,e){if(c)d(c);else{try{e=a.resolvedResponseType.clazz.decode(e)}catch(f){}e&&e instanceof a.resolvedResponseType.clazz?
d(null,e):d(Error("Illegal response type received in service method "+b.name+"#"+a.name))}}):setTimeout(d.bind(this,Error("Illegal request type provided to service method "+b.name+"#"+a.name)),0)}catch(e){setTimeout(d.bind(this,e),0)}};c[a.name]=function(b,d,e){(new c(b))[a.name](d,e)};Object.defineProperty&&(Object.defineProperty(c[a.name],"$options",{value:a.buildOpt()}),Object.defineProperty(c.prototype[a.name],"$options",{value:c[a.name].$options}))})(d[e]);return c}(d,this)};l.Service=n;var p=
function(a,b,d){c.call(this,a,b);this.className="Service.Method";this.options=d||{}};p.prototype=Object.create(c.prototype);p.prototype.buildOpt=b.prototype.buildOpt;l.Service.Method=p;n=function(a,b,c,d,e){p.call(this,a,b,e);this.className="Service.RPCMethod";this.requestName=c;this.responseName=d;this.resolvedResponseType=this.resolvedRequestType=null};n.prototype=Object.create(p.prototype);l.Service.RPCMethod=n;return l}(g);g.Builder=function(d,e,g){var l=function(){this.ptr=this.ns=new g.Namespace(null,
"");this.resolved=!1;this.result=null;this.files={};this.importRoot=null};l.prototype.reset=function(){this.ptr=this.ns};l.prototype.define=function(c,b){if("string"!==typeof c||!e.TYPEREF.test(c))throw Error("Illegal package: "+c);var a=c.split("."),d;for(d=0;d<a.length;d++)if(!e.NAME.test(a[d]))throw Error("Illegal package: "+a[d]);for(d=0;d<a.length;d++)this.ptr.hasChild(a[d])||this.ptr.addChild(new g.Namespace(this.ptr,a[d],b)),this.ptr=this.ptr.getChild(a[d]);return this};l.isValidMessage=function(c){if("string"!==
typeof c.name||!e.NAME.test(c.name)||"undefined"!==typeof c.values||"undefined"!==typeof c.rpc)return!1;var b;if("undefined"!==typeof c.fields){if(!d.Util.isArray(c.fields))return!1;var a=[],f;for(b=0;b<c.fields.length;b++){if(!l.isValidMessageField(c.fields[b]))return!1;f=parseInt(c.fields[b].id,10);if(0<=a.indexOf(f))return!1;a.push(f)}}if("undefined"!==typeof c.enums){if(!d.Util.isArray(c.enums))return!1;for(b=0;b<c.enums.length;b++)if(!l.isValidEnum(c.enums[b]))return!1}if("undefined"!==typeof c.messages){if(!d.Util.isArray(c.messages))return!1;
for(b=0;b<c.messages.length;b++)if(!l.isValidMessage(c.messages[b])&&!l.isValidExtend(c.messages[b]))return!1}return"undefined"===typeof c.extensions||d.Util.isArray(c.extensions)&&2===c.extensions.length&&"number"===typeof c.extensions[0]&&"number"===typeof c.extensions[1]?!0:!1};l.isValidMessageField=function(c){if("string"!==typeof c.rule||"string"!==typeof c.name||"string"!==typeof c.type||"undefined"===typeof c.id||!(e.RULE.test(c.rule)&&e.NAME.test(c.name)&&e.TYPEREF.test(c.type)&&e.ID.test(""+
c.id)))return!1;if("undefined"!==typeof c.options){if("object"!==typeof c.options)return!1;for(var b=Object.keys(c.options),a=0,d;a<b.length;a++)if("string"!==typeof(d=b[a])||"string"!==typeof c.options[d]&&"number"!==typeof c.options[d]&&"boolean"!==typeof c.options[d])return!1}return!0};l.isValidEnum=function(c){if("string"!==typeof c.name||!e.NAME.test(c.name)||"undefined"===typeof c.values||!d.Util.isArray(c.values)||0==c.values.length)return!1;for(var b=0;b<c.values.length;b++)if("object"!=typeof c.values[b]||
"string"!==typeof c.values[b].name||"undefined"===typeof c.values[b].id||!e.NAME.test(c.values[b].name)||!e.NEGID.test(""+c.values[b].id))return!1;return!0};l.prototype.create=function(c){if(!c)return this;d.Util.isArray(c)||(c=[c]);if(0==c.length)return this;var b=[],a,e,k,h,p;for(b.push(c);0<b.length;){c=b.pop();if(d.Util.isArray(c))for(;0<c.length;)if(a=c.shift(),l.isValidMessage(a)){e=new g.Message(this.ptr,a.name,a.options,a.isGroup);if(a.fields&&0<a.fields.length)for(h=0;h<a.fields.length;h++){if(e.hasChild(a.fields[h].id))throw Error("Duplicate field id in message "+
e.name+": "+a.fields[h].id);if(a.fields[h].options)for(k=Object.keys(a.fields[h].options),p=0;p<k.length;p++){if("string"!==typeof k[p])throw Error("Illegal field option name in message "+e.name+"#"+a.fields[h].name+": "+k[p]);if("string"!==typeof a.fields[h].options[k[p]]&&"number"!==typeof a.fields[h].options[k[p]]&&"boolean"!==typeof a.fields[h].options[k[p]])throw Error("Illegal field option value in message "+e.name+"#"+a.fields[h].name+"#"+k[p]+": "+a.fields[h].options[k[p]]);}e.addChild(new g.Message.Field(e,
a.fields[h].rule,a.fields[h].type,a.fields[h].name,a.fields[h].id,a.fields[h].options))}k=[];if("undefined"!==typeof a.enums&&0<a.enums.length)for(h=0;h<a.enums.length;h++)k.push(a.enums[h]);if(a.messages&&0<a.messages.length)for(h=0;h<a.messages.length;h++)k.push(a.messages[h]);a.extensions&&(e.extensions=a.extensions,e.extensions[0]<d.ID_MIN&&(e.extensions[0]=d.ID_MIN),e.extensions[1]>d.ID_MAX&&(e.extensions[1]=d.ID_MAX));this.ptr.addChild(e);0<k.length&&(b.push(c),c=k,this.ptr=e)}else if(l.isValidEnum(a)){e=
new g.Enum(this.ptr,a.name,a.options);for(h=0;h<a.values.length;h++)e.addChild(new g.Enum.Value(e,a.values[h].name,a.values[h].id));this.ptr.addChild(e)}else if(l.isValidService(a)){e=new g.Service(this.ptr,a.name,a.options);for(h in a.rpc)a.rpc.hasOwnProperty(h)&&e.addChild(new g.Service.RPCMethod(e,h,a.rpc[h].request,a.rpc[h].response,a.rpc[h].options));this.ptr.addChild(e)}else if(l.isValidExtend(a))if(e=this.ptr.resolve(a.ref))for(h=0;h<a.fields.length;h++){if(e.hasChild(a.fields[h].id))throw Error("Duplicate extended field id in message "+
e.name+": "+a.fields[h].id);if(a.fields[h].id<e.extensions[0]||a.fields[h].id>e.extensions[1])throw Error("Illegal extended field id in message "+e.name+": "+a.fields[h].id+" ("+e.extensions.join(" to ")+" expected)");e.addChild(new g.Message.Field(e,a.fields[h].rule,a.fields[h].type,a.fields[h].name,a.fields[h].id,a.fields[h].options))}else{if(!/\.?google\.protobuf\./.test(a.ref))throw Error("Extended message "+a.ref+" is not defined");}else throw Error("Not a valid definition: "+JSON.stringify(a));
else throw Error("Not a valid namespace: "+JSON.stringify(c));this.ptr=this.ptr.parent}this.resolved=!1;this.result=null;return this};l.prototype["import"]=function(c,b){if("string"===typeof b){d.Util.IS_NODE&&(b=require("path").resolve(b));if(!0===this.files[b])return this.reset(),this;this.files[b]=!0}if(c.imports&&0<c.imports.length){var a,e="/",g=!1;if("object"===typeof b){if(this.importRoot=b.root,g=!0,a=this.importRoot,b=b.file,0<=a.indexOf("\\")||0<=b.indexOf("\\"))e="\\"}else"string"===typeof b?
this.importRoot?a=this.importRoot:0<=b.indexOf("/")?(a=b.replace(/\/[^\/]*$/,""),""===a&&(a="/")):0<=b.indexOf("\\")?(a=b.replace(/\\[^\\]*$/,""),e="\\"):a=".":a=null;for(var h=0;h<c.imports.length;h++)if("string"===typeof c.imports[h]){if(!a)throw Error("Cannot determine import root: File name is unknown");var l=c.imports[h];if(!/^google\/protobuf\//.test(l)&&(l=a+e+l,!0!==this.files[l])){/\.proto$/i.test(l)&&!d.DotProto&&(l=l.replace(/\.proto$/,".json"));var k=d.Util.fetch(l);if(null===k)throw Error("Failed to import '"+
l+"' in '"+b+"': File not found");if(/\.json$/i.test(l))this["import"](JSON.parse(k+""),l);else this["import"]((new d.DotProto.Parser(k+"")).parse(),l)}}else if(b)if(/\.(\w+)$/.test(b))this["import"](c.imports[h],b.replace(/^(.+)\.(\w+)$/,function(a,b,c){return b+"_import"+h+"."+c}));else this["import"](c.imports[h],b+"_import"+h);else this["import"](c.imports[h]);g&&(this.importRoot=null)}c.messages&&(c["package"]&&this.define(c["package"],c.options),this.create(c.messages),this.reset());c.enums&&
(c["package"]&&this.define(c["package"],c.options),this.create(c.enums),this.reset());c.services&&(c["package"]&&this.define(c["package"],c.options),this.create(c.services),this.reset());c["extends"]&&(c["package"]&&this.define(c["package"],c.options),this.create(c["extends"]),this.reset());return this};l.isValidService=function(c){return!("string"!==typeof c.name||!e.NAME.test(c.name)||"object"!==typeof c.rpc)};l.isValidExtend=function(c){if("string"!==typeof c.ref||!e.TYPEREF.test(c.ref))return!1;
var b;if("undefined"!==typeof c.fields){if(!d.Util.isArray(c.fields))return!1;var a=[],f;for(b=0;b<c.fields.length;b++){if(!l.isValidMessageField(c.fields[b]))return!1;f=parseInt(c.id,10);if(0<=a.indexOf(f))return!1;a.push(f)}}return!0};l.prototype.resolveAll=function(){var c;if(null!=this.ptr&&"object"!==typeof this.ptr.type){if(this.ptr instanceof g.Namespace){c=this.ptr.getChildren();for(var b=0;b<c.length;b++)this.ptr=c[b],this.resolveAll()}else if(this.ptr instanceof g.Message.Field)if(e.TYPE.test(this.ptr.type))this.ptr.type=
d.TYPES[this.ptr.type];else{if(!e.TYPEREF.test(this.ptr.type))throw Error("Illegal type reference in "+this.ptr.toString(!0)+": "+this.ptr.type);c=this.ptr.parent.resolve(this.ptr.type,!0);if(!c)throw Error("Unresolvable type reference in "+this.ptr.toString(!0)+": "+this.ptr.type);this.ptr.resolvedType=c;if(c instanceof g.Enum)this.ptr.type=d.TYPES["enum"];else if(c instanceof g.Message)this.ptr.type=c.isGroup?d.TYPES.group:d.TYPES.message;else throw Error("Illegal type reference in "+this.ptr.toString(!0)+
": "+this.ptr.type);}else if(!(this.ptr instanceof d.Reflect.Enum.Value))if(this.ptr instanceof d.Reflect.Service.Method)if(this.ptr instanceof d.Reflect.Service.RPCMethod){c=this.ptr.parent.resolve(this.ptr.requestName);if(!(c&&c instanceof d.Reflect.Message))throw Error("Illegal type reference in "+this.ptr.toString(!0)+": "+this.ptr.requestName);this.ptr.resolvedRequestType=c;c=this.ptr.parent.resolve(this.ptr.responseName);if(!(c&&c instanceof d.Reflect.Message))throw Error("Illegal type reference in "+
this.ptr.toString(!0)+": "+this.ptr.responseName);this.ptr.resolvedResponseType=c}else throw Error("Illegal service type in "+this.ptr.toString(!0));else throw Error("Illegal object in namespace: "+typeof this.ptr+":"+this.ptr);this.reset()}};l.prototype.build=function(c){this.reset();this.resolved||(this.resolveAll(),this.resolved=!0,this.result=null);null==this.result&&(this.result=this.ns.build());if(c){c=c.split(".");for(var b=this.result,a=0;a<c.length;a++)if(b[c[a]])b=b[c[a]];else{b=null;break}return b}return this.result};
l.prototype.lookup=function(c){return c?this.ns.resolve(c):this.ns};l.prototype.toString=function(){return"Builder"};l.Message=function(){};l.Service=function(){};return l}(g,g.Lang,g.Reflect);g.loadProto=function(d,e,k){if("string"===typeof e||e&&"string"===typeof e.file&&"string"===typeof e.root)k=e,e=null;return g.loadJson((new g.DotProto.Parser(d)).parse(),e,k)};g.protoFromString=g.loadProto;g.loadProtoFile=function(d,e,k){e&&"object"===typeof e?(k=e,e=null):e&&"function"===typeof e||(e=null);
if(e)return g.Util.fetch("string"===typeof d?d:d.root+"/"+d.file,function(c){if(null===c)e(Error("Failed to fetch file"));else try{e(null,g.loadProto(c,k,d))}catch(b){e(b)}});var l=g.Util.fetch("object"===typeof d?d.root+"/"+d.file:d);return null===l?null:g.loadProto(l,k,d)};g.protoFromFile=g.loadProtoFile;g.newBuilder=function(d,e){var k=new g.Builder;"undefined"!==typeof d&&null!==d&&k.define(d,e);return k};g.loadJson=function(d,e,k){if("string"===typeof e||e&&"string"===typeof e.file&&"string"===
typeof e.root)k=e,e=null;e&&"object"===typeof e||(e=g.newBuilder());"string"===typeof d&&(d=JSON.parse(d));e["import"](d,k);e.resolveAll();e.build();return e};g.loadJsonFile=function(d,e,k){e&&"object"===typeof e?(k=e,e=null):e&&"function"===typeof e||(e=null);if(e)return g.Util.fetch("string"===typeof d?d:d.root+"/"+d.file,function(c){if(null===c)e(Error("Failed to fetch file"));else try{e(null,g.loadJson(JSON.parse(c),k,d))}catch(b){e(b)}});var l=g.Util.fetch("object"===typeof d?d.root+"/"+d.file:
d);return null===l?null:g.loadJson(JSON.parse(l),k,d)};return g}"undefined"!==typeof module&&module.exports?module.exports=r(require("bytebuffer")):"function"===typeof define&&define.amd?define(["ByteBuffer"],r):(q.dcodeIO=q.dcodeIO||{}).ProtoBuf=r(q.dcodeIO.ByteBuffer)})(this);
a instanceof k?a:k.wrap(a);case d.TYPES["enum"]:var n=this.resolvedType.getChildren(h.Value);for(e=0;e<n.length;e++)if(n[e].name==a||n[e].id==a)return n[e].id;c(a,"not a valid enum value");case d.TYPES.group:case d.TYPES.message:a&&"object"===typeof a||c(typeof a,"object expected");if(a instanceof this.resolvedType.clazz)return a;if(a instanceof d.Builder.Message){c={};for(e in a)a.hasOwnProperty(e)&&(c[e]=a[e]);a=c}return new this.resolvedType.clazz(a)}throw Error("[INTERNAL] Illegal value for "+
this.toString(!0)+": "+a+" (undefined type "+this.type+")");};f.prototype.encode=function(a,b){a=this.verifyValue(a);if(null===this.type||"object"!==typeof this.type)throw Error("[INTERNAL] Unresolved type in "+this.toString(!0)+": "+this.type);if(null===a||this.repeated&&0==a.length)return b;try{if(this.repeated){var c;if(this.options.packed&&0<=d.PACKABLE_WIRE_TYPES.indexOf(this.type.wireType)){b.writeVarint32(this.id<<3|d.WIRE_TYPES.LDELIM);b.ensureCapacity(b.offset+=1);var e=b.offset;for(c=0;c<
a.length;c++)this.encodeValue(a[c],b);var f=b.offset-e,g=k.calculateVarint32(f);if(1<g){var h=b.slice(e,b.offset),e=e+(g-1);b.offset=e;b.append(h)}b.writeVarint32(f,e-g)}else for(c=0;c<a.length;c++)b.writeVarint32(this.id<<3|this.type.wireType),this.encodeValue(a[c],b)}else b.writeVarint32(this.id<<3|this.type.wireType),this.encodeValue(a,b)}catch(l){throw Error("Illegal value for "+this.toString(!0)+": "+a+" ("+l+")");}return b};f.prototype.encodeValue=function(a,b){if(null===a)return b;switch(this.type){case d.TYPES.int32:0>
a?b.writeVarint64(a):b.writeVarint32(a);break;case d.TYPES.uint32:b.writeVarint32(a);break;case d.TYPES.sint32:b.writeVarint32ZigZag(a);break;case d.TYPES.fixed32:b.writeUint32(a);break;case d.TYPES.sfixed32:b.writeInt32(a);break;case d.TYPES.int64:case d.TYPES.uint64:b.writeVarint64(a);break;case d.TYPES.sint64:b.writeVarint64ZigZag(a);break;case d.TYPES.fixed64:b.writeUint64(a);break;case d.TYPES.sfixed64:b.writeInt64(a);break;case d.TYPES.bool:"string"===typeof a?b.writeVarint32("false"===a.toLowerCase()?
0:!!a):b.writeVarint32(a?1:0);break;case d.TYPES["enum"]:b.writeVarint32(a);break;case d.TYPES["float"]:b.writeFloat32(a);break;case d.TYPES["double"]:b.writeFloat64(a);break;case d.TYPES.string:b.writeVString(a);break;case d.TYPES.bytes:if(0>a.remaining())throw Error("Illegal value for "+this.toString(!0)+": "+a.remaining()+" bytes remaining");var c=a.offset;b.writeVarint32(a.remaining());b.append(a);a.offset=c;break;case d.TYPES.message:c=(new k).LE();this.resolvedType.encode(a,c);b.writeVarint32(c.offset);
b.append(c.flip());break;case d.TYPES.group:this.resolvedType.encode(a,b);b.writeVarint32(this.id<<3|d.WIRE_TYPES.ENDGROUP);break;default:throw Error("[INTERNAL] Illegal value to encode in "+this.toString(!0)+": "+a+" (unknown type)");}return b};f.prototype.calculate=function(a){a=this.verifyValue(a);if(null===this.type||"object"!==typeof this.type)throw Error("[INTERNAL] Unresolved type in "+this.toString(!0)+": "+this.type);if(null===a||this.repeated&&0==a.length)return 0;var b=0;try{if(this.repeated){var c,
e;if(this.options.packed&&0<=d.PACKABLE_WIRE_TYPES.indexOf(this.type.wireType)){b+=k.calculateVarint32(this.id<<3|d.WIRE_TYPES.LDELIM);for(c=e=0;c<a.length;c++)e+=this.calculateValue(a[c]);b+=k.calculateVarint32(e);b+=e}else for(c=0;c<a.length;c++)b+=k.calculateVarint32(this.id<<3|this.type.wireType),b+=this.calculateValue(a[c])}else b+=k.calculateVarint32(this.id<<3|this.type.wireType),b+=this.calculateValue(a)}catch(f){throw Error("Illegal value for "+this.toString(!0)+": "+a+" ("+f+")");}return b};
f.prototype.calculateValue=function(a){if(null===a)return 0;switch(this.type){case d.TYPES.int32:return 0>a?k.calculateVarint64(a):k.calculateVarint32(a);case d.TYPES.uint32:return k.calculateVarint32(a);case d.TYPES.sint32:return k.calculateVarint32(k.zigZagEncode32(a));case d.TYPES.fixed32:case d.TYPES.sfixed32:case d.TYPES["float"]:return 4;case d.TYPES.int64:case d.TYPES.uint64:return k.calculateVarint64(a);case d.TYPES.sint64:return k.calculateVarint64(k.zigZagEncode64(a));case d.TYPES.fixed64:case d.TYPES.sfixed64:return 8;
case d.TYPES.bool:return 1;case d.TYPES["enum"]:return k.calculateVarint32(a);case d.TYPES["double"]:return 8;case d.TYPES.string:return a=k.calculateUTF8Bytes(a),k.calculateVarint32(a)+a;case d.TYPES.bytes:if(0>a.remaining())throw Error("Illegal value for "+this.toString(!0)+": "+a.remaining()+" bytes remaining");return k.calculateVarint32(a.remaining())+a.remaining();case d.TYPES.message:return a=this.resolvedType.calculate(a),k.calculateVarint32(a)+a;case d.TYPES.group:return a=this.resolvedType.calculate(a),
a+k.calculateVarint32(this.id<<3|d.WIRE_TYPES.ENDGROUP)}throw Error("[INTERNAL] Illegal value to encode in "+this.toString(!0)+": "+a+" (unknown type)");};f.prototype.decode=function(a,b,c){if(a!=this.type.wireType&&(c||a!=d.WIRE_TYPES.LDELIM||!this.repeated))throw Error("Illegal wire type for field "+this.toString(!0)+": "+a+" ("+this.type.wireType+" expected)");if(a==d.WIRE_TYPES.LDELIM&&this.repeated&&this.options.packed&&0<=d.PACKABLE_WIRE_TYPES.indexOf(this.type.wireType)&&!c){a=b.readVarint32();
a=b.offset+a;for(c=[];b.offset<a;)c.push(this.decode(this.type.wireType,b,!0));return c}switch(this.type){case d.TYPES.int32:return b.readVarint32()|0;case d.TYPES.uint32:return b.readVarint32()>>>0;case d.TYPES.sint32:return b.readVarint32ZigZag()|0;case d.TYPES.fixed32:return b.readUint32()>>>0;case d.TYPES.sfixed32:return b.readInt32()|0;case d.TYPES.int64:return b.readVarint64();case d.TYPES.uint64:return b.readVarint64().toUnsigned();case d.TYPES.sint64:return b.readVarint64ZigZag();case d.TYPES.fixed64:return b.readUint64();
case d.TYPES.sfixed64:return b.readInt64();case d.TYPES.bool:return!!b.readVarint32();case d.TYPES["enum"]:return b.readVarint32();case d.TYPES["float"]:return b.readFloat();case d.TYPES["double"]:return b.readDouble();case d.TYPES.string:return b.readVString();case d.TYPES.bytes:a=b.readVarint32();if(b.remaining()<a)throw Error("Illegal number of bytes for "+this.toString(!0)+": "+a+" required but got only "+b.remaining());c=b.clone();c.limit=c.offset+a;b.offset+=a;return c;case d.TYPES.message:return a=
b.readVarint32(),this.resolvedType.decode(b,a);case d.TYPES.group:return this.resolvedType.decode(b,-1,this.id)}throw Error("[INTERNAL] Illegal wire type for "+this.toString(!0)+": "+a);};l.Message.Field=f;var n=function(a,b,c,d,e,g){f.call(this,a,b,c,d,e,g)};n.prototype=Object.create(f.prototype);l.Message.ExtensionField=n;var h=function(a,c,d){b.call(this,a,c,d);this.className="Enum";this.object=null};h.prototype=Object.create(b.prototype);h.prototype.build=function(){for(var a={},b=this.getChildren(h.Value),
c=0;c<b.length;c++)a[b[c].name]=b[c].id;Object.defineProperty&&Object.defineProperty(a,"$options",{value:this.buildOpt()});return this.object=a};l.Enum=h;n=function(a,b,d){c.call(this,a,b);this.className="Enum.Value";this.id=d};n.prototype=Object.create(c.prototype);l.Enum.Value=n;n=function(a,c,d){b.call(this,a,c,d);this.className="Service";this.clazz=null};n.prototype=Object.create(b.prototype);n.prototype.build=function(a){return this.clazz&&!a?this.clazz:this.clazz=function(a,b){var c=function(b){a.Builder.Service.call(this);
this.rpcImpl=b||function(a,b,c){setTimeout(c.bind(this,Error("Not implemented, see: https://github.com/dcodeIO/ProtoBuf.js/wiki/Services")),0)}};c.prototype=Object.create(a.Builder.Service.prototype);Object.defineProperty&&(Object.defineProperty(c,"$options",{value:b.buildOpt()}),Object.defineProperty(c.prototype,"$options",{value:c.$options}));for(var d=b.getChildren(a.Reflect.Service.RPCMethod),e=0;e<d.length;e++)(function(a){c.prototype[a.name]=function(c,d){try{c&&c instanceof a.resolvedRequestType.clazz?
this.rpcImpl(a.fqn(),c,function(c,e){if(c)d(c);else{try{e=a.resolvedResponseType.clazz.decode(e)}catch(f){}e&&e instanceof a.resolvedResponseType.clazz?d(null,e):d(Error("Illegal response type received in service method "+b.name+"#"+a.name))}}):setTimeout(d.bind(this,Error("Illegal request type provided to service method "+b.name+"#"+a.name)),0)}catch(e){setTimeout(d.bind(this,e),0)}};c[a.name]=function(b,d,e){(new c(b))[a.name](d,e)};Object.defineProperty&&(Object.defineProperty(c[a.name],"$options",
{value:a.buildOpt()}),Object.defineProperty(c.prototype[a.name],"$options",{value:c[a.name].$options}))})(d[e]);return c}(d,this)};l.Service=n;var p=function(a,b,d){c.call(this,a,b);this.className="Service.Method";this.options=d||{}};p.prototype=Object.create(c.prototype);p.prototype.buildOpt=b.prototype.buildOpt;l.Service.Method=p;n=function(a,b,c,d,e){p.call(this,a,b,e);this.className="Service.RPCMethod";this.requestName=c;this.responseName=d;this.resolvedResponseType=this.resolvedRequestType=null};
n.prototype=Object.create(p.prototype);l.Service.RPCMethod=n;return l}(g);g.Builder=function(d,e,g){var l=function(){this.ptr=this.ns=new g.Namespace(null,"");this.resolved=!1;this.result=null;this.files={};this.importRoot=null};l.prototype.reset=function(){this.ptr=this.ns};l.prototype.define=function(c,b){if("string"!==typeof c||!e.TYPEREF.test(c))throw Error("Illegal package: "+c);var a=c.split("."),d;for(d=0;d<a.length;d++)if(!e.NAME.test(a[d]))throw Error("Illegal package: "+a[d]);for(d=0;d<
a.length;d++)this.ptr.hasChild(a[d])||this.ptr.addChild(new g.Namespace(this.ptr,a[d],b)),this.ptr=this.ptr.getChild(a[d]);return this};l.isValidMessage=function(c){if("string"!==typeof c.name||!e.NAME.test(c.name)||"undefined"!==typeof c.values||"undefined"!==typeof c.rpc)return!1;var b;if("undefined"!==typeof c.fields){if(!d.Util.isArray(c.fields))return!1;var a=[],f;for(b=0;b<c.fields.length;b++){if(!l.isValidMessageField(c.fields[b]))return!1;f=parseInt(c.fields[b].id,10);if(0<=a.indexOf(f))return!1;
a.push(f)}}if("undefined"!==typeof c.enums){if(!d.Util.isArray(c.enums))return!1;for(b=0;b<c.enums.length;b++)if(!l.isValidEnum(c.enums[b]))return!1}if("undefined"!==typeof c.messages){if(!d.Util.isArray(c.messages))return!1;for(b=0;b<c.messages.length;b++)if(!l.isValidMessage(c.messages[b])&&!l.isValidExtend(c.messages[b]))return!1}return"undefined"===typeof c.extensions||d.Util.isArray(c.extensions)&&2===c.extensions.length&&"number"===typeof c.extensions[0]&&"number"===typeof c.extensions[1]?!0:
!1};l.isValidMessageField=function(c){if("string"!==typeof c.rule||"string"!==typeof c.name||"string"!==typeof c.type||"undefined"===typeof c.id||!(e.RULE.test(c.rule)&&e.NAME.test(c.name)&&e.TYPEREF.test(c.type)&&e.ID.test(""+c.id)))return!1;if("undefined"!==typeof c.options){if("object"!==typeof c.options)return!1;for(var b=Object.keys(c.options),a=0,d;a<b.length;a++)if("string"!==typeof(d=b[a])||"string"!==typeof c.options[d]&&"number"!==typeof c.options[d]&&"boolean"!==typeof c.options[d])return!1}return!0};
l.isValidEnum=function(c){if("string"!==typeof c.name||!e.NAME.test(c.name)||"undefined"===typeof c.values||!d.Util.isArray(c.values)||0==c.values.length)return!1;for(var b=0;b<c.values.length;b++)if("object"!=typeof c.values[b]||"string"!==typeof c.values[b].name||"undefined"===typeof c.values[b].id||!e.NAME.test(c.values[b].name)||!e.NEGID.test(""+c.values[b].id))return!1;return!0};l.prototype.create=function(c){if(!c)return this;d.Util.isArray(c)||(c=[c]);if(0==c.length)return this;var b=[],a,
e,k,h,p;for(b.push(c);0<b.length;){c=b.pop();if(d.Util.isArray(c))for(;0<c.length;)if(a=c.shift(),l.isValidMessage(a)){e=new g.Message(this.ptr,a.name,a.options,a.isGroup);if(a.fields&&0<a.fields.length)for(h=0;h<a.fields.length;h++){if(e.hasChild(a.fields[h].id))throw Error("Duplicate field id in message "+e.name+": "+a.fields[h].id);if(a.fields[h].options)for(k=Object.keys(a.fields[h].options),p=0;p<k.length;p++){if("string"!==typeof k[p])throw Error("Illegal field option name in message "+e.name+
"#"+a.fields[h].name+": "+k[p]);if("string"!==typeof a.fields[h].options[k[p]]&&"number"!==typeof a.fields[h].options[k[p]]&&"boolean"!==typeof a.fields[h].options[k[p]])throw Error("Illegal field option value in message "+e.name+"#"+a.fields[h].name+"#"+k[p]+": "+a.fields[h].options[k[p]]);}e.addChild(new g.Message.Field(e,a.fields[h].rule,a.fields[h].type,a.fields[h].name,a.fields[h].id,a.fields[h].options))}k=[];if("undefined"!==typeof a.enums&&0<a.enums.length)for(h=0;h<a.enums.length;h++)k.push(a.enums[h]);
if(a.messages&&0<a.messages.length)for(h=0;h<a.messages.length;h++)k.push(a.messages[h]);a.extensions&&(e.extensions=a.extensions,e.extensions[0]<d.ID_MIN&&(e.extensions[0]=d.ID_MIN),e.extensions[1]>d.ID_MAX&&(e.extensions[1]=d.ID_MAX));this.ptr.addChild(e);0<k.length&&(b.push(c),c=k,this.ptr=e)}else if(l.isValidEnum(a)){e=new g.Enum(this.ptr,a.name,a.options);for(h=0;h<a.values.length;h++)e.addChild(new g.Enum.Value(e,a.values[h].name,a.values[h].id));this.ptr.addChild(e)}else if(l.isValidService(a)){e=
new g.Service(this.ptr,a.name,a.options);for(h in a.rpc)a.rpc.hasOwnProperty(h)&&e.addChild(new g.Service.RPCMethod(e,h,a.rpc[h].request,a.rpc[h].response,a.rpc[h].options));this.ptr.addChild(e)}else if(l.isValidExtend(a))if(e=this.ptr.resolve(a.ref))for(h=0;h<a.fields.length;h++){if(e.hasChild(a.fields[h].id))throw Error("Duplicate extended field id in message "+e.name+": "+a.fields[h].id);if(a.fields[h].id<e.extensions[0]||a.fields[h].id>e.extensions[1])throw Error("Illegal extended field id in message "+
e.name+": "+a.fields[h].id+" ("+e.extensions.join(" to ")+" expected)");e.addChild(new g.Message.Field(e,a.fields[h].rule,a.fields[h].type,a.fields[h].name,a.fields[h].id,a.fields[h].options))}else{if(!/\.?google\.protobuf\./.test(a.ref))throw Error("Extended message "+a.ref+" is not defined");}else throw Error("Not a valid definition: "+JSON.stringify(a));else throw Error("Not a valid namespace: "+JSON.stringify(c));this.ptr=this.ptr.parent}this.resolved=!1;this.result=null;return this};l.prototype["import"]=
function(c,b){if("string"===typeof b){d.Util.IS_NODE&&(b=require("path").resolve(b));if(!0===this.files[b])return this.reset(),this;this.files[b]=!0}if(c.imports&&0<c.imports.length){var a,e="/",g=!1;if("object"===typeof b){if(this.importRoot=b.root,g=!0,a=this.importRoot,b=b.file,0<=a.indexOf("\\")||0<=b.indexOf("\\"))e="\\"}else"string"===typeof b?this.importRoot?a=this.importRoot:0<=b.indexOf("/")?(a=b.replace(/\/[^\/]*$/,""),""===a&&(a="/")):0<=b.indexOf("\\")?(a=b.replace(/\\[^\\]*$/,""),e="\\"):
a=".":a=null;for(var h=0;h<c.imports.length;h++)if("string"===typeof c.imports[h]){if(!a)throw Error("Cannot determine import root: File name is unknown");var l=c.imports[h];if(!/^google\/protobuf\//.test(l)&&(l=a+e+l,!0!==this.files[l])){/\.proto$/i.test(l)&&!d.DotProto&&(l=l.replace(/\.proto$/,".json"));var k=d.Util.fetch(l);if(null===k)throw Error("Failed to import '"+l+"' in '"+b+"': File not found");if(/\.json$/i.test(l))this["import"](JSON.parse(k+""),l);else this["import"]((new d.DotProto.Parser(k+
"")).parse(),l)}}else if(b)if(/\.(\w+)$/.test(b))this["import"](c.imports[h],b.replace(/^(.+)\.(\w+)$/,function(a,b,c){return b+"_import"+h+"."+c}));else this["import"](c.imports[h],b+"_import"+h);else this["import"](c.imports[h]);g&&(this.importRoot=null)}c.messages&&(c["package"]&&this.define(c["package"],c.options),this.create(c.messages),this.reset());c.enums&&(c["package"]&&this.define(c["package"],c.options),this.create(c.enums),this.reset());c.services&&(c["package"]&&this.define(c["package"],
c.options),this.create(c.services),this.reset());c["extends"]&&(c["package"]&&this.define(c["package"],c.options),this.create(c["extends"]),this.reset());return this};l.isValidService=function(c){return!("string"!==typeof c.name||!e.NAME.test(c.name)||"object"!==typeof c.rpc)};l.isValidExtend=function(c){if("string"!==typeof c.ref||!e.TYPEREF.test(c.ref))return!1;var b;if("undefined"!==typeof c.fields){if(!d.Util.isArray(c.fields))return!1;var a=[],f;for(b=0;b<c.fields.length;b++){if(!l.isValidMessageField(c.fields[b]))return!1;
f=parseInt(c.id,10);if(0<=a.indexOf(f))return!1;a.push(f)}}return!0};l.prototype.resolveAll=function(){var c;if(null!=this.ptr&&"object"!==typeof this.ptr.type){if(this.ptr instanceof g.Namespace){c=this.ptr.getChildren();for(var b=0;b<c.length;b++)this.ptr=c[b],this.resolveAll()}else if(this.ptr instanceof g.Message.Field)if(e.TYPE.test(this.ptr.type))this.ptr.type=d.TYPES[this.ptr.type];else{if(!e.TYPEREF.test(this.ptr.type))throw Error("Illegal type reference in "+this.ptr.toString(!0)+": "+this.ptr.type);
c=this.ptr.parent.resolve(this.ptr.type,!0);if(!c)throw Error("Unresolvable type reference in "+this.ptr.toString(!0)+": "+this.ptr.type);this.ptr.resolvedType=c;if(c instanceof g.Enum)this.ptr.type=d.TYPES["enum"];else if(c instanceof g.Message)this.ptr.type=c.isGroup?d.TYPES.group:d.TYPES.message;else throw Error("Illegal type reference in "+this.ptr.toString(!0)+": "+this.ptr.type);}else if(!(this.ptr instanceof d.Reflect.Enum.Value))if(this.ptr instanceof d.Reflect.Service.Method)if(this.ptr instanceof
d.Reflect.Service.RPCMethod){c=this.ptr.parent.resolve(this.ptr.requestName);if(!(c&&c instanceof d.Reflect.Message))throw Error("Illegal type reference in "+this.ptr.toString(!0)+": "+this.ptr.requestName);this.ptr.resolvedRequestType=c;c=this.ptr.parent.resolve(this.ptr.responseName);if(!(c&&c instanceof d.Reflect.Message))throw Error("Illegal type reference in "+this.ptr.toString(!0)+": "+this.ptr.responseName);this.ptr.resolvedResponseType=c}else throw Error("Illegal service type in "+this.ptr.toString(!0));
else throw Error("Illegal object in namespace: "+typeof this.ptr+":"+this.ptr);this.reset()}};l.prototype.build=function(c){this.reset();this.resolved||(this.resolveAll(),this.resolved=!0,this.result=null);null==this.result&&(this.result=this.ns.build());if(c){c=c.split(".");for(var b=this.result,a=0;a<c.length;a++)if(b[c[a]])b=b[c[a]];else{b=null;break}return b}return this.result};l.prototype.lookup=function(c){return c?this.ns.resolve(c):this.ns};l.prototype.toString=function(){return"Builder"};
l.Message=function(){};l.Service=function(){};return l}(g,g.Lang,g.Reflect);g.loadProto=function(d,e,k){if("string"===typeof e||e&&"string"===typeof e.file&&"string"===typeof e.root)k=e,e=null;return g.loadJson((new g.DotProto.Parser(d)).parse(),e,k)};g.protoFromString=g.loadProto;g.loadProtoFile=function(d,e,k){e&&"object"===typeof e?(k=e,e=null):e&&"function"===typeof e||(e=null);if(e)return g.Util.fetch("string"===typeof d?d:d.root+"/"+d.file,function(c){if(null===c)e(Error("Failed to fetch file"));
else try{e(null,g.loadProto(c,k,d))}catch(b){e(b)}});var l=g.Util.fetch("object"===typeof d?d.root+"/"+d.file:d);return null===l?null:g.loadProto(l,k,d)};g.protoFromFile=g.loadProtoFile;g.newBuilder=function(d,e){var k=new g.Builder;"undefined"!==typeof d&&null!==d&&k.define(d,e);return k};g.loadJson=function(d,e,k){if("string"===typeof e||e&&"string"===typeof e.file&&"string"===typeof e.root)k=e,e=null;e&&"object"===typeof e||(e=g.newBuilder());"string"===typeof d&&(d=JSON.parse(d));e["import"](d,
k);e.resolveAll();e.build();return e};g.loadJsonFile=function(d,e,k){e&&"object"===typeof e?(k=e,e=null):e&&"function"===typeof e||(e=null);if(e)return g.Util.fetch("string"===typeof d?d:d.root+"/"+d.file,function(c){if(null===c)e(Error("Failed to fetch file"));else try{e(null,g.loadJson(JSON.parse(c),k,d))}catch(b){e(b)}});var l=g.Util.fetch("object"===typeof d?d.root+"/"+d.file:d);return null===l?null:g.loadJson(JSON.parse(l),k,d)};return g}"undefined"!==typeof module&&module.exports?module.exports=
r(require("bytebuffer")):"function"===typeof define&&define.amd?define(["ByteBuffer"],r):(q.dcodeIO=q.dcodeIO||{}).ProtoBuf=r(q.dcodeIO.ByteBuffer)})(this);

@@ -6,68 +6,69 @@ /*

*/
(function(s){function t(l){var g={VERSION:"3.4.0",WIRE_TYPES:{}};g.WIRE_TYPES.VARINT=0;g.WIRE_TYPES.BITS64=1;g.WIRE_TYPES.LDELIM=2;g.WIRE_TYPES.STARTGROUP=3;g.WIRE_TYPES.ENDGROUP=4;g.WIRE_TYPES.BITS32=5;g.PACKABLE_WIRE_TYPES=[g.WIRE_TYPES.VARINT,g.WIRE_TYPES.BITS64,g.WIRE_TYPES.BITS32];g.TYPES={int32:{name:"int32",wireType:g.WIRE_TYPES.VARINT},uint32:{name:"uint32",wireType:g.WIRE_TYPES.VARINT},sint32:{name:"sint32",wireType:g.WIRE_TYPES.VARINT},int64:{name:"int64",wireType:g.WIRE_TYPES.VARINT},uint64:{name:"uint64",
wireType:g.WIRE_TYPES.VARINT},sint64:{name:"sint64",wireType:g.WIRE_TYPES.VARINT},bool:{name:"bool",wireType:g.WIRE_TYPES.VARINT},"double":{name:"double",wireType:g.WIRE_TYPES.BITS64},string:{name:"string",wireType:g.WIRE_TYPES.LDELIM},bytes:{name:"bytes",wireType:g.WIRE_TYPES.LDELIM},fixed32:{name:"fixed32",wireType:g.WIRE_TYPES.BITS32},sfixed32:{name:"sfixed32",wireType:g.WIRE_TYPES.BITS32},fixed64:{name:"fixed64",wireType:g.WIRE_TYPES.BITS64},sfixed64:{name:"sfixed64",wireType:g.WIRE_TYPES.BITS64},
"float":{name:"float",wireType:g.WIRE_TYPES.BITS32},"enum":{name:"enum",wireType:g.WIRE_TYPES.VARINT},message:{name:"message",wireType:g.WIRE_TYPES.LDELIM},group:{name:"group",wireType:g.WIRE_TYPES.STARTGROUP}};g.ID_MIN=1;g.ID_MAX=536870911;g.ByteBuffer=l;g.Long=l.Long||null;g.convertFieldsToCamelCase=!1;g.populateAccessors=!0;g.Util=function(){Object.create||(Object.create=function(d){function m(){}if(1<arguments.length)throw Error("Object.create polyfill only accepts the first parameter.");m.prototype=
d;return new m});var d={IS_NODE:!1};try{d.IS_NODE="function"===typeof require&&"function"===typeof require("fs").readFileSync&&"function"===typeof require("path").resolve}catch(g){}d.XHR=function(){for(var d=[function(){return new XMLHttpRequest},function(){return new ActiveXObject("Msxml2.XMLHTTP")},function(){return new ActiveXObject("Msxml3.XMLHTTP")},function(){return new ActiveXObject("Microsoft.XMLHTTP")}],m=null,b=0;b<d.length;b++){try{m=d[b]()}catch(e){continue}break}if(!m)throw Error("XMLHttpRequest is not supported");
return m};d.fetch=function(g,m){m&&"function"!=typeof m&&(m=null);if(d.IS_NODE)if(m)require("fs").readFile(g,function(d,b){d?m(null):m(""+b)});else try{return require("fs").readFileSync(g)}catch(b){return null}else{var e=d.XHR();e.open("GET",g,m?!0:!1);e.setRequestHeader("Accept","text/plain");"function"===typeof e.overrideMimeType&&e.overrideMimeType("text/plain");if(m)e.onreadystatechange=function(){4==e.readyState&&(200==e.status||0==e.status&&"string"===typeof e.responseText?m(e.responseText):
m(null))},4!=e.readyState&&e.send(null);else return e.send(null),200==e.status||0==e.status&&"string"===typeof e.responseText?e.responseText:null}};d.isArray=Array.isArray||function(d){return"[object Array]"===Object.prototype.toString.call(d)};return d}();g.Lang={OPEN:"{",CLOSE:"}",OPTOPEN:"[",OPTCLOSE:"]",OPTEND:",",EQUAL:"=",END:";",STRINGOPEN:'"',STRINGCLOSE:'"',STRINGOPEN_SQ:"'",STRINGCLOSE_SQ:"'",COPTOPEN:"(",COPTCLOSE:")",DELIM:/[\s\{\}=;\[\],'"\(\)]/g,RULE:/^(?:required|optional|repeated)$/,
(function(s){function t(m){var h={VERSION:"3.4.1",WIRE_TYPES:{}};h.WIRE_TYPES.VARINT=0;h.WIRE_TYPES.BITS64=1;h.WIRE_TYPES.LDELIM=2;h.WIRE_TYPES.STARTGROUP=3;h.WIRE_TYPES.ENDGROUP=4;h.WIRE_TYPES.BITS32=5;h.PACKABLE_WIRE_TYPES=[h.WIRE_TYPES.VARINT,h.WIRE_TYPES.BITS64,h.WIRE_TYPES.BITS32];h.TYPES={int32:{name:"int32",wireType:h.WIRE_TYPES.VARINT},uint32:{name:"uint32",wireType:h.WIRE_TYPES.VARINT},sint32:{name:"sint32",wireType:h.WIRE_TYPES.VARINT},int64:{name:"int64",wireType:h.WIRE_TYPES.VARINT},uint64:{name:"uint64",
wireType:h.WIRE_TYPES.VARINT},sint64:{name:"sint64",wireType:h.WIRE_TYPES.VARINT},bool:{name:"bool",wireType:h.WIRE_TYPES.VARINT},"double":{name:"double",wireType:h.WIRE_TYPES.BITS64},string:{name:"string",wireType:h.WIRE_TYPES.LDELIM},bytes:{name:"bytes",wireType:h.WIRE_TYPES.LDELIM},fixed32:{name:"fixed32",wireType:h.WIRE_TYPES.BITS32},sfixed32:{name:"sfixed32",wireType:h.WIRE_TYPES.BITS32},fixed64:{name:"fixed64",wireType:h.WIRE_TYPES.BITS64},sfixed64:{name:"sfixed64",wireType:h.WIRE_TYPES.BITS64},
"float":{name:"float",wireType:h.WIRE_TYPES.BITS32},"enum":{name:"enum",wireType:h.WIRE_TYPES.VARINT},message:{name:"message",wireType:h.WIRE_TYPES.LDELIM},group:{name:"group",wireType:h.WIRE_TYPES.STARTGROUP}};h.ID_MIN=1;h.ID_MAX=536870911;h.ByteBuffer=m;h.Long=m.Long||null;h.convertFieldsToCamelCase=!1;h.populateAccessors=!0;h.Util=function(){Object.create||(Object.create=function(c){function k(){}if(1<arguments.length)throw Error("Object.create polyfill only accepts the first parameter.");k.prototype=
c;return new k});var c={IS_NODE:!1};try{c.IS_NODE="function"===typeof require&&"function"===typeof require("fs").readFileSync&&"function"===typeof require("path").resolve}catch(h){}c.XHR=function(){for(var c=[function(){return new XMLHttpRequest},function(){return new ActiveXObject("Msxml2.XMLHTTP")},function(){return new ActiveXObject("Msxml3.XMLHTTP")},function(){return new ActiveXObject("Microsoft.XMLHTTP")}],k=null,b=0;b<c.length;b++){try{k=c[b]()}catch(e){continue}break}if(!k)throw Error("XMLHttpRequest is not supported");
return k};c.fetch=function(h,k){k&&"function"!=typeof k&&(k=null);if(c.IS_NODE)if(k)require("fs").readFile(h,function(c,b){c?k(null):k(""+b)});else try{return require("fs").readFileSync(h)}catch(b){return null}else{var e=c.XHR();e.open("GET",h,k?!0:!1);e.setRequestHeader("Accept","text/plain");"function"===typeof e.overrideMimeType&&e.overrideMimeType("text/plain");if(k)e.onreadystatechange=function(){4==e.readyState&&(200==e.status||0==e.status&&"string"===typeof e.responseText?k(e.responseText):
k(null))},4!=e.readyState&&e.send(null);else return e.send(null),200==e.status||0==e.status&&"string"===typeof e.responseText?e.responseText:null}};c.isArray=Array.isArray||function(c){return"[object Array]"===Object.prototype.toString.call(c)};return c}();h.Lang={OPEN:"{",CLOSE:"}",OPTOPEN:"[",OPTCLOSE:"]",OPTEND:",",EQUAL:"=",END:";",STRINGOPEN:'"',STRINGCLOSE:'"',STRINGOPEN_SQ:"'",STRINGCLOSE_SQ:"'",COPTOPEN:"(",COPTCLOSE:")",DELIM:/[\s\{\}=;\[\],'"\(\)]/g,RULE:/^(?:required|optional|repeated)$/,
TYPE:/^(?:double|float|int32|uint32|sint32|int64|uint64|sint64|fixed32|sfixed32|fixed64|sfixed64|bool|string|bytes)$/,NAME:/^[a-zA-Z_][a-zA-Z_0-9]*$/,TYPEDEF:/^[a-zA-Z][a-zA-Z_0-9]*$/,TYPEREF:/^(?:\.?[a-zA-Z_][a-zA-Z_0-9]*)+$/,FQTYPEREF:/^(?:\.[a-zA-Z][a-zA-Z_0-9]*)+$/,NUMBER:/^-?(?:[1-9][0-9]*|0|0x[0-9a-fA-F]+|0[0-7]+|([0-9]*\.[0-9]+([Ee][+-]?[0-9]+)?))$/,NUMBER_DEC:/^(?:[1-9][0-9]*|0)$/,NUMBER_HEX:/^0x[0-9a-fA-F]+$/,NUMBER_OCT:/^0[0-7]+$/,NUMBER_FLT:/^[0-9]*\.[0-9]+([Ee][+-]?[0-9]+)?$/,ID:/^(?:[1-9][0-9]*|0|0x[0-9a-fA-F]+|0[0-7]+)$/,
NEGID:/^\-?(?:[1-9][0-9]*|0|0x[0-9a-fA-F]+|0[0-7]+)$/,WHITESPACE:/\s/,STRING:/['"]([^'"\\]*(\\.[^"\\]*)*)['"]/g,BOOL:/^(?:true|false)$/i};g.Reflect=function(d){function g(a,k){var b=k.readVarint32(),c=b&7,b=b>>3;switch(c){case d.WIRE_TYPES.VARINT:do b=k.readUint8();while(128===(b&128));break;case d.WIRE_TYPES.BITS64:k.offset+=8;break;case d.WIRE_TYPES.LDELIM:b=k.readVarint32();k.offset+=b;break;case d.WIRE_TYPES.STARTGROUP:g(b,k);break;case d.WIRE_TYPES.ENDGROUP:if(b===a)return!1;throw Error("Illegal GROUPEND after unknown group: "+
b+" ("+a+" expected)");case d.WIRE_TYPES.BITS32:k.offset+=4;break;default:throw Error("Illegal wire type in unknown group "+a+": "+c);}return!0}function r(a,k){if(a&&"number"===typeof a.low&&"number"===typeof a.high&&"boolean"===typeof a.unsigned&&a.low===a.low&&a.high===a.high)return new d.Long(a.low,a.high,"undefined"===typeof k?a.unsigned:k);if("string"===typeof a)return d.Long.fromString(a,k||!1,10);if("number"===typeof a)return d.Long.fromNumber(a,k||!1);throw Error("not convertible to Long");
}var m={},b=function(a,k){this.parent=a;this.name=k};b.prototype.fqn=function(){var a=this.name,k=this;do{k=k.parent;if(null==k)break;a=k.name+"."+a}while(1);return a};b.prototype.toString=function(a){return(a?this.className+" ":"")+this.fqn()};b.prototype.build=function(){throw Error(this.toString(!0)+" cannot be built directly");};m.T=b;var e=function(a,k,d){b.call(this,a,k);this.className="Namespace";this.children=[];this.options=d||{}};e.prototype=Object.create(b.prototype);e.prototype.getChildren=
function(a){a=a||null;if(null==a)return this.children.slice();for(var k=[],b=0,d=this.children.length;b<d;++b)this.children[b]instanceof a&&(a===c.Field&&this.children[b]instanceof c.ExtensionField||k.push(this.children[b]));return k};e.prototype.addChild=function(a){var k;if(k=this.getChild(a.name))if(k instanceof c.Field&&k.name!==k.originalName&&!this.hasChild(k.originalName))k.name=k.originalName;else if(a instanceof c.Field&&a.name!==a.originalName&&!this.hasChild(a.originalName))a.name=a.originalName;
else throw Error("Duplicate name in namespace "+this.toString(!0)+": "+a.name);this.children.push(a)};e.prototype.hasChild=function(a){return-1<this._indexOf(a)};e.prototype.getChild=function(a){a=this._indexOf(a);return-1<a?this.children[a]:null};e.prototype._indexOf=function(a){for(var k="number"===typeof a?"id":"name",b=0;b<this.children.length;b++)if("undefined"!==typeof this.children[b][k]&&this.children[b][k]==a)return b;return-1};e.prototype.resolve=function(a,k){var b=a.split("."),d=this,
c=0;if(""==b[c]){for(;null!=d.parent;)d=d.parent;c++}do{do{d=d.getChild(b[c]);if(!(d&&d instanceof m.T)||k&&d instanceof m.Message.Field){d=null;break}c++}while(c<b.length);if(null!=d)break;if(null!==this.parent)return this.parent.resolve(a,k)}while(null!=d);return d};e.prototype.build=function(){for(var a={},k=this.getChildren(),b,d=0,c=k.length;d<c;++d)b=k[d],b instanceof e&&(a[b.name]=b.build());Object.defineProperty&&Object.defineProperty(a,"$options",{value:this.buildOpt()});return a};e.prototype.buildOpt=
function(){for(var a={},k=Object.keys(this.options),b=0;b<k.length;b++)a[k[b]]=this.options[k[b]];return a};e.prototype.getOption=function(a){return"undefined"===typeof a?this.options:"undefined"!==typeof this.options[a]?this.options[a]:null};m.Namespace=e;var c=function(a,b,c,f){e.call(this,a,b,c);this.className="Message";this.extensions=[d.ID_MIN,d.ID_MAX];this.clazz=null;this.isGroup=!!f};c.prototype=Object.create(e.prototype);c.prototype.build=function(a){if(this.clazz&&!a)return this.clazz;a=
function(a,b){function d(a,b){var k={},c;for(c in a)a.hasOwnProperty(c)&&(null===a[c]||"object"!==typeof a[c]?k[c]=a[c]:a[c]instanceof l?b&&(k[c]=a.toBuffer()):k[c]=d(a[c],b));return k}var k=b.getChildren(a.Reflect.Message.Field),c=function(d,c){a.Builder.Message.call(this);var e,n;Object.defineProperty&&Object.defineProperty(this,"$type",{get:function(){return b}});for(e=0;e<k.length;e++)n=k[e],this[n.name]=n.repeated?[]:null;for(e=0;e<k.length;e++)if(n=k[e],n.required&&"undefined"!==typeof n.options["default"])try{this.$set(n.name,
n.options["default"])}catch(f){throw Error("[INTERNAL] "+f);}if(1!=arguments.length||"object"!=typeof d||"function"==typeof d.encode||a.Util.isArray(d)||d instanceof l||d instanceof ArrayBuffer||a.Long&&d instanceof a.Long)for(e=0;e<arguments.length;e++)e<k.length&&this.$set(k[e].name,arguments[e]);else for(n=Object.keys(d),e=0;e<n.length;e++)this.$set(n[e],d[n[e]])};c.prototype=Object.create(a.Builder.Message.prototype);c.prototype.add=function(d,k,c){var e=b.getChild(d);if(!e)throw Error(this+"#"+
d+" is undefined");if(!(e instanceof a.Reflect.Message.Field))throw Error(this+"#"+d+" is not a field: "+e.toString(!0));if(!e.repeated)throw Error(this+"#"+d+" is not a repeated field");null===this[e.name]&&(this[e.name]=[]);this[e.name].push(c?k:e.verifyValue(k,!0))};c.prototype.$add=c.prototype.add;c.prototype.set=function(d,k,c){var e=b.getChild(d);if(!e)throw Error(this+"#"+d+" is not a field: undefined");if(!(e instanceof a.Reflect.Message.Field))throw Error(this+"#"+d+" is not a field: "+e.toString(!0));
this[e.name]=c?k:e.verifyValue(k)};c.prototype.$set=c.prototype.set;c.prototype.get=function(d){var k=b.getChild(d);if(!(k&&k instanceof a.Reflect.Message.Field))throw Error(this+"#"+d+" is not a field: undefined");if(!(k instanceof a.Reflect.Message.Field))throw Error(this+"#"+d+" is not a field: "+k.toString(!0));return this[k.name]};c.prototype.$get=c.prototype.get;for(var e=0;e<k.length;e++){var n=k[e];a.populateAccessors&&function(a){var d=a.originalName.replace(/(_[a-zA-Z])/g,function(a){return a.toUpperCase().replace("_",
"")}),d=d.substring(0,1).toUpperCase()+d.substring(1),k=a.originalName.replace(/([A-Z])/g,function(a){return"_"+a});b.hasChild("set"+d)||(c.prototype["set"+d]=function(b){this.$set(a.name,b)});b.hasChild("set_"+k)||(c.prototype["set_"+k]=function(b){this.$set(a.name,b)});b.hasChild("get"+d)||(c.prototype["get"+d]=function(){return this.$get(a.name)});b.hasChild("get_"+k)||(c.prototype["get_"+k]=function(){return this.$get(a.name)})}(n)}c.prototype.encode=function(a){var d=!1;a||(a=new l,d=!0);var k=
a.littleEndian;try{return b.encode(this,a.LE()),(d?a.flip():a).LE(k)}catch(c){throw a.LE(k),c;}};c.prototype.calculate=function(){return b.calculate(this)};c.prototype.encodeDelimited=function(a){var d=!1;a||(a=new l,d=!0);var k=(new l).LE();b.encode(this,k).flip();a.writeVarint32(k.remaining());a.append(k);return d?a.flip():a};c.prototype.encodeAB=function(){try{return this.encode().toArrayBuffer()}catch(a){throw a.encoded&&(a.encoded=a.encoded.toArrayBuffer()),a;}};c.prototype.toArrayBuffer=c.prototype.encodeAB;
c.prototype.encodeNB=function(){try{return this.encode().toBuffer()}catch(a){throw a.encoded&&(a.encoded=a.encoded.toBuffer()),a;}};c.prototype.toBuffer=c.prototype.encodeNB;c.prototype.encode64=function(){try{return this.encode().toBase64()}catch(a){throw a.encoded&&(a.encoded=a.encoded.toBase64()),a;}};c.prototype.toBase64=c.prototype.encode64;c.prototype.encodeHex=function(){try{return this.encode().toHex()}catch(a){throw a.encoded&&(a.encoded=a.encoded.toHex()),a;}};c.prototype.toHex=c.prototype.encodeHex;
c.prototype.toRaw=function(a){return d(this,!!a)};c.decode=function(a,d){"string"===typeof a&&(a=l.wrap(a,d?d:"base64"));a=a instanceof l?a:l.wrap(a);var k=a.littleEndian;try{var c=b.decode(a.LE());a.LE(k);return c}catch(e){throw a.LE(k),e;}};c.decodeDelimited=function(a,d){"string"===typeof a&&(a=l.wrap(a,d?d:"base64"));a=a instanceof l?a:l.wrap(a);if(1>a.remaining())return null;var k=a.offset,c=a.readVarint32();if(a.remaining()<c)return a.offset=k,null;try{var e=b.decode(a.slice(a.offset,a.offset+
c).LE());a.offset+=c;return e}catch(n){throw a.offset+=c,n;}};c.decode64=function(a){return c.decode(a,"base64")};c.decodeHex=function(a){return c.decode(a,"hex")};c.prototype.toString=function(){return b.toString()};Object.defineProperty&&Object.defineProperty(c,"$options",{value:b.buildOpt()});return c}(d,this);for(var b=this.getChildren(),e=0;e<b.length;e++)if(b[e]instanceof h)a[b[e].name]=b[e].build();else if(b[e]instanceof c)a[b[e].name]=b[e].build();else if(!(b[e]instanceof c.Field))throw Error("Illegal reflect child of "+
this.toString(!0)+": "+b[e].toString(!0));return this.clazz=a};c.prototype.encode=function(a,d){for(var b=this.getChildren(c.Field),e=null,f=0,h;f<b.length;f++)h=a.$get(b[f].name),b[f].required&&null===h?null===e&&(e=b[f]):b[f].encode(h,d);if(null!==e)throw b=Error("Missing at least one required field for "+this.toString(!0)+": "+e),b.encoded=d,b;return d};c.prototype.calculate=function(a){for(var b=this.getChildren(c.Field),d=0,e=0,f;e<b.length;e++){f=a.$get(b[e].name);if(b[e].required&&null===f)throw Error("Missing at least one required field for "+
this.toString(!0)+": "+b[e]);d+=b[e].calculate(f)}return d};c.prototype.decode=function(a,b,c){b="number"===typeof b?b:-1;for(var e=a.offset,f=new this.clazz,h,m,l;a.offset<e+b||-1==b&&0<a.remaining();){h=a.readVarint32();m=h&7;l=h>>3;if(m===d.WIRE_TYPES.ENDGROUP){if(l!==c)throw Error("Illegal group end indicator for "+this.toString(!0)+": "+l+" ("+(c?c+" expected":"not a group")+")");break}if(h=this.getChild(l))h.repeated&&!h.options.packed?f.$add(h.name,h.decode(m,a),!0):f.$set(h.name,h.decode(m,
a),!0);else switch(m){case d.WIRE_TYPES.VARINT:a.readVarint32();break;case d.WIRE_TYPES.BITS32:a.offset+=4;break;case d.WIRE_TYPES.BITS64:a.offset+=8;break;case d.WIRE_TYPES.LDELIM:h=a.readVarint32();a.offset+=h;break;case d.WIRE_TYPES.STARTGROUP:for(;g(l,a););break;default:throw Error("Illegal wire type for unknown field "+l+" in "+this.toString(!0)+"#decode: "+m);}}a=this.getChildren(d.Reflect.Field);for(b=0;b<a.length;b++)if(h=a[b],null===f[h.name]){if(h.required)throw a=Error("Missing at least one required field for "+
this.toString(!0)+": "+h.name),a.decoded=f,a;if("undefined"!==typeof h.options["default"])try{f.$set(h.name,h.options["default"])}catch(q){throw Error("[INTERNAL] "+q);}}return f};m.Message=c;var f=function(a,k,c,e,f,h){b.call(this,a,e);this.className="Message.Field";this.required="required"==k;this.repeated="repeated"==k;this.type=c;this.resolvedType=null;this.id=f;this.options=h||{};this.originalName=this.name;d.convertFieldsToCamelCase&&(this.name=this.name.replace(/_([a-zA-Z])/g,function(a,b){return b.toUpperCase()}))};
f.prototype=Object.create(b.prototype);f.prototype.verifyValue=function(a,b){b=b||!1;var c=function(a,b){throw Error("Illegal value for "+this.toString(!0)+" of type "+this.type.name+": "+a+" ("+b+")");}.bind(this);if(null===a)return this.required&&c(typeof a,"required"),null;var e;if(this.repeated&&!b){d.Util.isArray(a)||(a=[a]);c=[];for(e=0;e<a.length;e++)c.push(this.verifyValue(a[e],!0));return c}!this.repeated&&d.Util.isArray(a)&&c(typeof a,"no array expected");switch(this.type){case d.TYPES.int32:case d.TYPES.sint32:case d.TYPES.sfixed32:return("number"!==
typeof a||a===a&&0!==a%1)&&c(typeof a,"not an integer"),4294967295<a?a|0:a;case d.TYPES.uint32:case d.TYPES.fixed32:return("number"!==typeof a||a===a&&0!==a%1)&&c(typeof a,"not an integer"),0>a?a>>>0:a;case d.TYPES.int64:case d.TYPES.sint64:case d.TYPES.sfixed64:if(d.Long)try{return r(a,!1)}catch(f){c(typeof a,f.message)}else c(typeof a,"requires Long.js");case d.TYPES.uint64:case d.TYPES.fixed64:if(d.Long)try{return r(a,!0)}catch(m){c(typeof a,m.message)}else c(typeof a,"requires Long.js");case d.TYPES.bool:return"boolean"!==
typeof a&&c(typeof a,"not a boolean"),a;case d.TYPES["float"]:case d.TYPES["double"]:return"number"!==typeof a&&c(typeof a,"not a number"),a;case d.TYPES.string:return"string"===typeof a||a&&a instanceof String||c(typeof a,"not a string"),""+a;case d.TYPES.bytes:return a&&a instanceof l?a:l.wrap(a);case d.TYPES["enum"]:var g=this.resolvedType.getChildren(h.Value);for(e=0;e<g.length;e++)if(g[e].name==a||g[e].id==a)return g[e].id;c(a,"not a valid enum value");case d.TYPES.group:case d.TYPES.message:return a&&
"object"===typeof a||c(typeof a,"object expected"),a instanceof this.resolvedType.clazz?a:new this.resolvedType.clazz(a)}throw Error("[INTERNAL] Illegal value for "+this.toString(!0)+": "+a+" (undefined type "+this.type+")");};f.prototype.encode=function(a,b){a=this.verifyValue(a);if(null===this.type||"object"!==typeof this.type)throw Error("[INTERNAL] Unresolved type in "+this.toString(!0)+": "+this.type);if(null===a||this.repeated&&0==a.length)return b;try{if(this.repeated){var c;if(this.options.packed&&
0<=d.PACKABLE_WIRE_TYPES.indexOf(this.type.wireType)){b.writeVarint32(this.id<<3|d.WIRE_TYPES.LDELIM);b.ensureCapacity(b.offset+=1);var e=b.offset;for(c=0;c<a.length;c++)this.encodeValue(a[c],b);var f=b.offset-e,h=l.calculateVarint32(f);if(1<h){var m=b.slice(e,b.offset),e=e+(h-1);b.offset=e;b.append(m)}b.writeVarint32(f,e-h)}else for(c=0;c<a.length;c++)b.writeVarint32(this.id<<3|this.type.wireType),this.encodeValue(a[c],b)}else b.writeVarint32(this.id<<3|this.type.wireType),this.encodeValue(a,b)}catch(g){throw Error("Illegal value for "+
this.toString(!0)+": "+a+" ("+g+")");}return b};f.prototype.encodeValue=function(a,b){if(null===a)return b;switch(this.type){case d.TYPES.int32:0>a?b.writeVarint64(a):b.writeVarint32(a);break;case d.TYPES.uint32:b.writeVarint32(a);break;case d.TYPES.sint32:b.writeVarint32ZigZag(a);break;case d.TYPES.fixed32:b.writeUint32(a);break;case d.TYPES.sfixed32:b.writeInt32(a);break;case d.TYPES.int64:case d.TYPES.uint64:b.writeVarint64(a);break;case d.TYPES.sint64:b.writeVarint64ZigZag(a);break;case d.TYPES.fixed64:b.writeUint64(a);
break;case d.TYPES.sfixed64:b.writeInt64(a);break;case d.TYPES.bool:"string"===typeof a?b.writeVarint32("false"===a.toLowerCase()?0:!!a):b.writeVarint32(a?1:0);break;case d.TYPES["enum"]:b.writeVarint32(a);break;case d.TYPES["float"]:b.writeFloat32(a);break;case d.TYPES["double"]:b.writeFloat64(a);break;case d.TYPES.string:b.writeVString(a);break;case d.TYPES.bytes:if(0>a.remaining())throw Error("Illegal value for "+this.toString(!0)+": "+a.remaining()+" bytes remaining");var c=a.offset;b.writeVarint32(a.remaining());
b.append(a);a.offset=c;break;case d.TYPES.message:c=(new l).LE();this.resolvedType.encode(a,c);b.writeVarint32(c.offset);b.append(c.flip());break;case d.TYPES.group:this.resolvedType.encode(a,b);b.writeVarint32(this.id<<3|d.WIRE_TYPES.ENDGROUP);break;default:throw Error("[INTERNAL] Illegal value to encode in "+this.toString(!0)+": "+a+" (unknown type)");}return b};f.prototype.calculate=function(a){a=this.verifyValue(a);if(null===this.type||"object"!==typeof this.type)throw Error("[INTERNAL] Unresolved type in "+
this.toString(!0)+": "+this.type);if(null===a||this.repeated&&0==a.length)return 0;var b=0;try{if(this.repeated){var c,e;if(this.options.packed&&0<=d.PACKABLE_WIRE_TYPES.indexOf(this.type.wireType)){b+=l.calculateVarint32(this.id<<3|d.WIRE_TYPES.LDELIM);for(c=e=0;c<a.length;c++)e+=this.calculateValue(a[c]);b+=l.calculateVarint32(e);b+=e}else for(c=0;c<a.length;c++)b+=l.calculateVarint32(this.id<<3|this.type.wireType),b+=this.calculateValue(a[c])}else b+=l.calculateVarint32(this.id<<3|this.type.wireType),
b+=this.calculateValue(a)}catch(f){throw Error("Illegal value for "+this.toString(!0)+": "+a+" ("+f+")");}return b};f.prototype.calculateValue=function(a){if(null===a)return 0;switch(this.type){case d.TYPES.int32:return 0>a?l.calculateVarint64(a):l.calculateVarint32(a);case d.TYPES.uint32:return l.calculateVarint32(a);case d.TYPES.sint32:return l.calculateVarint32(l.zigZagEncode32(a));case d.TYPES.fixed32:case d.TYPES.sfixed32:case d.TYPES["float"]:return 4;case d.TYPES.int64:case d.TYPES.uint64:return l.calculateVarint64(a);
case d.TYPES.sint64:return l.calculateVarint64(l.zigZagEncode64(a));case d.TYPES.fixed64:case d.TYPES.sfixed64:return 8;case d.TYPES.bool:return 1;case d.TYPES["enum"]:return l.calculateVarint32(a);case d.TYPES["double"]:return 8;case d.TYPES.string:return a=l.calculateUTF8Bytes(a),l.calculateVarint32(a)+a;case d.TYPES.bytes:if(0>a.remaining())throw Error("Illegal value for "+this.toString(!0)+": "+a.remaining()+" bytes remaining");return l.calculateVarint32(a.remaining())+a.remaining();case d.TYPES.message:return a=
this.resolvedType.calculate(a),l.calculateVarint32(a)+a;case d.TYPES.group:return a=this.resolvedType.calculate(a),a+l.calculateVarint32(this.id<<3|d.WIRE_TYPES.ENDGROUP)}throw Error("[INTERNAL] Illegal value to encode in "+this.toString(!0)+": "+a+" (unknown type)");};f.prototype.decode=function(a,b,c){if(a!=this.type.wireType&&(c||a!=d.WIRE_TYPES.LDELIM||!this.repeated))throw Error("Illegal wire type for field "+this.toString(!0)+": "+a+" ("+this.type.wireType+" expected)");if(a==d.WIRE_TYPES.LDELIM&&
this.repeated&&this.options.packed&&0<=d.PACKABLE_WIRE_TYPES.indexOf(this.type.wireType)&&!c){a=b.readVarint32();a=b.offset+a;for(c=[];b.offset<a;)c.push(this.decode(this.type.wireType,b,!0));return c}switch(this.type){case d.TYPES.int32:return b.readVarint32()|0;case d.TYPES.uint32:return b.readVarint32()>>>0;case d.TYPES.sint32:return b.readVarint32ZigZag()|0;case d.TYPES.fixed32:return b.readUint32()>>>0;case d.TYPES.sfixed32:return b.readInt32()|0;case d.TYPES.int64:return b.readVarint64();case d.TYPES.uint64:return b.readVarint64().toUnsigned();
case d.TYPES.sint64:return b.readVarint64ZigZag();case d.TYPES.fixed64:return b.readUint64();case d.TYPES.sfixed64:return b.readInt64();case d.TYPES.bool:return!!b.readVarint32();case d.TYPES["enum"]:return b.readVarint32();case d.TYPES["float"]:return b.readFloat();case d.TYPES["double"]:return b.readDouble();case d.TYPES.string:return b.readVString();case d.TYPES.bytes:a=b.readVarint32();if(b.remaining()<a)throw Error("Illegal number of bytes for "+this.toString(!0)+": "+a+" required but got only "+
b.remaining());c=b.clone();c.limit=c.offset+a;b.offset+=a;return c;case d.TYPES.message:return a=b.readVarint32(),this.resolvedType.decode(b,a);case d.TYPES.group:return this.resolvedType.decode(b,-1,this.id)}throw Error("[INTERNAL] Illegal wire type for "+this.toString(!0)+": "+a);};m.Message.Field=f;var q=function(a,b,c,d,e,h){f.call(this,a,b,c,d,e,h)};q.prototype=Object.create(f.prototype);m.Message.ExtensionField=q;var h=function(a,b,c){e.call(this,a,b,c);this.className="Enum";this.object=null};
h.prototype=Object.create(e.prototype);h.prototype.build=function(){for(var a={},b=this.getChildren(h.Value),c=0;c<b.length;c++)a[b[c].name]=b[c].id;Object.defineProperty&&Object.defineProperty(a,"$options",{value:this.buildOpt()});return this.object=a};m.Enum=h;q=function(a,c,d){b.call(this,a,c);this.className="Enum.Value";this.id=d};q.prototype=Object.create(b.prototype);m.Enum.Value=q;q=function(a,b,c){e.call(this,a,b,c);this.className="Service";this.clazz=null};q.prototype=Object.create(e.prototype);
q.prototype.build=function(a){return this.clazz&&!a?this.clazz:this.clazz=function(a,b){var c=function(b){a.Builder.Service.call(this);this.rpcImpl=b||function(a,b,c){setTimeout(c.bind(this,Error("Not implemented, see: https://github.com/dcodeIO/ProtoBuf.js/wiki/Services")),0)}};c.prototype=Object.create(a.Builder.Service.prototype);Object.defineProperty&&(Object.defineProperty(c,"$options",{value:b.buildOpt()}),Object.defineProperty(c.prototype,"$options",{value:c.$options}));for(var d=b.getChildren(a.Reflect.Service.RPCMethod),
e=0;e<d.length;e++)(function(a){c.prototype[a.name]=function(c,d){try{c&&c instanceof a.resolvedRequestType.clazz?this.rpcImpl(a.fqn(),c,function(c,e){if(c)d(c);else{try{e=a.resolvedResponseType.clazz.decode(e)}catch(f){}e&&e instanceof a.resolvedResponseType.clazz?d(null,e):d(Error("Illegal response type received in service method "+b.name+"#"+a.name))}}):setTimeout(d.bind(this,Error("Illegal request type provided to service method "+b.name+"#"+a.name)),0)}catch(e){setTimeout(d.bind(this,e),0)}};
c[a.name]=function(b,d,e){(new c(b))[a.name](d,e)};Object.defineProperty&&(Object.defineProperty(c[a.name],"$options",{value:a.buildOpt()}),Object.defineProperty(c.prototype[a.name],"$options",{value:c[a.name].$options}))})(d[e]);return c}(d,this)};m.Service=q;var p=function(a,c,d){b.call(this,a,c);this.className="Service.Method";this.options=d||{}};p.prototype=Object.create(b.prototype);p.prototype.buildOpt=e.prototype.buildOpt;m.Service.Method=p;q=function(a,b,c,d,e){p.call(this,a,b,e);this.className=
"Service.RPCMethod";this.requestName=c;this.responseName=d;this.resolvedResponseType=this.resolvedRequestType=null};q.prototype=Object.create(p.prototype);m.Service.RPCMethod=q;return m}(g);g.Builder=function(d,g,l){var m=function(){this.ptr=this.ns=new l.Namespace(null,"");this.resolved=!1;this.result=null;this.files={};this.importRoot=null};m.prototype.reset=function(){this.ptr=this.ns};m.prototype.define=function(b,d){if("string"!==typeof b||!g.TYPEREF.test(b))throw Error("Illegal package: "+b);
var c=b.split("."),f;for(f=0;f<c.length;f++)if(!g.NAME.test(c[f]))throw Error("Illegal package: "+c[f]);for(f=0;f<c.length;f++)this.ptr.hasChild(c[f])||this.ptr.addChild(new l.Namespace(this.ptr,c[f],d)),this.ptr=this.ptr.getChild(c[f]);return this};m.isValidMessage=function(b){if("string"!==typeof b.name||!g.NAME.test(b.name)||"undefined"!==typeof b.values||"undefined"!==typeof b.rpc)return!1;var e;if("undefined"!==typeof b.fields){if(!d.Util.isArray(b.fields))return!1;var c=[],f;for(e=0;e<b.fields.length;e++){if(!m.isValidMessageField(b.fields[e]))return!1;
f=parseInt(b.fields[e].id,10);if(0<=c.indexOf(f))return!1;c.push(f)}}if("undefined"!==typeof b.enums){if(!d.Util.isArray(b.enums))return!1;for(e=0;e<b.enums.length;e++)if(!m.isValidEnum(b.enums[e]))return!1}if("undefined"!==typeof b.messages){if(!d.Util.isArray(b.messages))return!1;for(e=0;e<b.messages.length;e++)if(!m.isValidMessage(b.messages[e])&&!m.isValidExtend(b.messages[e]))return!1}return"undefined"===typeof b.extensions||d.Util.isArray(b.extensions)&&2===b.extensions.length&&"number"===typeof b.extensions[0]&&
"number"===typeof b.extensions[1]?!0:!1};m.isValidMessageField=function(b){if("string"!==typeof b.rule||"string"!==typeof b.name||"string"!==typeof b.type||"undefined"===typeof b.id||!(g.RULE.test(b.rule)&&g.NAME.test(b.name)&&g.TYPEREF.test(b.type)&&g.ID.test(""+b.id)))return!1;if("undefined"!==typeof b.options){if("object"!==typeof b.options)return!1;for(var d=Object.keys(b.options),c=0,f;c<d.length;c++)if("string"!==typeof(f=d[c])||"string"!==typeof b.options[f]&&"number"!==typeof b.options[f]&&
"boolean"!==typeof b.options[f])return!1}return!0};m.isValidEnum=function(b){if("string"!==typeof b.name||!g.NAME.test(b.name)||"undefined"===typeof b.values||!d.Util.isArray(b.values)||0==b.values.length)return!1;for(var e=0;e<b.values.length;e++)if("object"!=typeof b.values[e]||"string"!==typeof b.values[e].name||"undefined"===typeof b.values[e].id||!g.NAME.test(b.values[e].name)||!g.NEGID.test(""+b.values[e].id))return!1;return!0};m.prototype.create=function(b){if(!b)return this;d.Util.isArray(b)||
(b=[b]);if(0==b.length)return this;var e=[],c,f,g,h,p;for(e.push(b);0<e.length;){b=e.pop();if(d.Util.isArray(b))for(;0<b.length;)if(c=b.shift(),m.isValidMessage(c)){f=new l.Message(this.ptr,c.name,c.options,c.isGroup);if(c.fields&&0<c.fields.length)for(h=0;h<c.fields.length;h++){if(f.hasChild(c.fields[h].id))throw Error("Duplicate field id in message "+f.name+": "+c.fields[h].id);if(c.fields[h].options)for(g=Object.keys(c.fields[h].options),p=0;p<g.length;p++){if("string"!==typeof g[p])throw Error("Illegal field option name in message "+
f.name+"#"+c.fields[h].name+": "+g[p]);if("string"!==typeof c.fields[h].options[g[p]]&&"number"!==typeof c.fields[h].options[g[p]]&&"boolean"!==typeof c.fields[h].options[g[p]])throw Error("Illegal field option value in message "+f.name+"#"+c.fields[h].name+"#"+g[p]+": "+c.fields[h].options[g[p]]);}f.addChild(new l.Message.Field(f,c.fields[h].rule,c.fields[h].type,c.fields[h].name,c.fields[h].id,c.fields[h].options))}g=[];if("undefined"!==typeof c.enums&&0<c.enums.length)for(h=0;h<c.enums.length;h++)g.push(c.enums[h]);
if(c.messages&&0<c.messages.length)for(h=0;h<c.messages.length;h++)g.push(c.messages[h]);c.extensions&&(f.extensions=c.extensions,f.extensions[0]<d.ID_MIN&&(f.extensions[0]=d.ID_MIN),f.extensions[1]>d.ID_MAX&&(f.extensions[1]=d.ID_MAX));this.ptr.addChild(f);0<g.length&&(e.push(b),b=g,this.ptr=f)}else if(m.isValidEnum(c)){f=new l.Enum(this.ptr,c.name,c.options);for(h=0;h<c.values.length;h++)f.addChild(new l.Enum.Value(f,c.values[h].name,c.values[h].id));this.ptr.addChild(f)}else if(m.isValidService(c)){f=
new l.Service(this.ptr,c.name,c.options);for(h in c.rpc)c.rpc.hasOwnProperty(h)&&f.addChild(new l.Service.RPCMethod(f,h,c.rpc[h].request,c.rpc[h].response,c.rpc[h].options));this.ptr.addChild(f)}else if(m.isValidExtend(c))if(f=this.ptr.resolve(c.ref))for(h=0;h<c.fields.length;h++){if(f.hasChild(c.fields[h].id))throw Error("Duplicate extended field id in message "+f.name+": "+c.fields[h].id);if(c.fields[h].id<f.extensions[0]||c.fields[h].id>f.extensions[1])throw Error("Illegal extended field id in message "+
f.name+": "+c.fields[h].id+" ("+f.extensions.join(" to ")+" expected)");f.addChild(new l.Message.Field(f,c.fields[h].rule,c.fields[h].type,c.fields[h].name,c.fields[h].id,c.fields[h].options))}else{if(!/\.?google\.protobuf\./.test(c.ref))throw Error("Extended message "+c.ref+" is not defined");}else throw Error("Not a valid definition: "+JSON.stringify(c));else throw Error("Not a valid namespace: "+JSON.stringify(b));this.ptr=this.ptr.parent}this.resolved=!1;this.result=null;return this};m.prototype["import"]=
function(b,e){if("string"===typeof e){d.Util.IS_NODE&&(e=require("path").resolve(e));if(!0===this.files[e])return this.reset(),this;this.files[e]=!0}if(b.imports&&0<b.imports.length){var c,f="/",g=!1;if("object"===typeof e){if(this.importRoot=e.root,g=!0,c=this.importRoot,e=e.file,0<=c.indexOf("\\")||0<=e.indexOf("\\"))f="\\"}else"string"===typeof e?this.importRoot?c=this.importRoot:0<=e.indexOf("/")?(c=e.replace(/\/[^\/]*$/,""),""===c&&(c="/")):0<=e.indexOf("\\")?(c=e.replace(/\\[^\\]*$/,""),f="\\"):
c=".":c=null;for(var h=0;h<b.imports.length;h++)if("string"===typeof b.imports[h]){if(!c)throw Error("Cannot determine import root: File name is unknown");var m=b.imports[h];if(!/^google\/protobuf\//.test(m)&&(m=c+f+m,!0!==this.files[m])){/\.proto$/i.test(m)&&!d.DotProto&&(m=m.replace(/\.proto$/,".json"));var a=d.Util.fetch(m);if(null===a)throw Error("Failed to import '"+m+"' in '"+e+"': File not found");if(/\.json$/i.test(m))this["import"](JSON.parse(a+""),m);else this["import"]((new d.DotProto.Parser(a+
"")).parse(),m)}}else if(e)if(/\.(\w+)$/.test(e))this["import"](b.imports[h],e.replace(/^(.+)\.(\w+)$/,function(a,b,c){return b+"_import"+h+"."+c}));else this["import"](b.imports[h],e+"_import"+h);else this["import"](b.imports[h]);g&&(this.importRoot=null)}b.messages&&(b["package"]&&this.define(b["package"],b.options),this.create(b.messages),this.reset());b.enums&&(b["package"]&&this.define(b["package"],b.options),this.create(b.enums),this.reset());b.services&&(b["package"]&&this.define(b["package"],
b.options),this.create(b.services),this.reset());b["extends"]&&(b["package"]&&this.define(b["package"],b.options),this.create(b["extends"]),this.reset());return this};m.isValidService=function(b){return!("string"!==typeof b.name||!g.NAME.test(b.name)||"object"!==typeof b.rpc)};m.isValidExtend=function(b){if("string"!==typeof b.ref||!g.TYPEREF.test(b.ref))return!1;var e;if("undefined"!==typeof b.fields){if(!d.Util.isArray(b.fields))return!1;var c=[],f;for(e=0;e<b.fields.length;e++){if(!m.isValidMessageField(b.fields[e]))return!1;
f=parseInt(b.id,10);if(0<=c.indexOf(f))return!1;c.push(f)}}return!0};m.prototype.resolveAll=function(){var b;if(null!=this.ptr&&"object"!==typeof this.ptr.type){if(this.ptr instanceof l.Namespace){b=this.ptr.getChildren();for(var e=0;e<b.length;e++)this.ptr=b[e],this.resolveAll()}else if(this.ptr instanceof l.Message.Field)if(g.TYPE.test(this.ptr.type))this.ptr.type=d.TYPES[this.ptr.type];else{if(!g.TYPEREF.test(this.ptr.type))throw Error("Illegal type reference in "+this.ptr.toString(!0)+": "+this.ptr.type);
b=this.ptr.parent.resolve(this.ptr.type,!0);if(!b)throw Error("Unresolvable type reference in "+this.ptr.toString(!0)+": "+this.ptr.type);this.ptr.resolvedType=b;if(b instanceof l.Enum)this.ptr.type=d.TYPES["enum"];else if(b instanceof l.Message)this.ptr.type=b.isGroup?d.TYPES.group:d.TYPES.message;else throw Error("Illegal type reference in "+this.ptr.toString(!0)+": "+this.ptr.type);}else if(!(this.ptr instanceof d.Reflect.Enum.Value))if(this.ptr instanceof d.Reflect.Service.Method)if(this.ptr instanceof
d.Reflect.Service.RPCMethod){b=this.ptr.parent.resolve(this.ptr.requestName);if(!(b&&b instanceof d.Reflect.Message))throw Error("Illegal type reference in "+this.ptr.toString(!0)+": "+this.ptr.requestName);this.ptr.resolvedRequestType=b;b=this.ptr.parent.resolve(this.ptr.responseName);if(!(b&&b instanceof d.Reflect.Message))throw Error("Illegal type reference in "+this.ptr.toString(!0)+": "+this.ptr.responseName);this.ptr.resolvedResponseType=b}else throw Error("Illegal service type in "+this.ptr.toString(!0));
else throw Error("Illegal object in namespace: "+typeof this.ptr+":"+this.ptr);this.reset()}};m.prototype.build=function(b){this.reset();this.resolved||(this.resolveAll(),this.resolved=!0,this.result=null);null==this.result&&(this.result=this.ns.build());if(b){b=b.split(".");for(var d=this.result,c=0;c<b.length;c++)if(d[b[c]])d=d[b[c]];else{d=null;break}return d}return this.result};m.prototype.lookup=function(b){return b?this.ns.resolve(b):this.ns};m.prototype.toString=function(){return"Builder"};
m.Message=function(){};m.Service=function(){};return m}(g,g.Lang,g.Reflect);g.newBuilder=function(d,l){var r=new g.Builder;"undefined"!==typeof d&&null!==d&&r.define(d,l);return r};g.loadJson=function(d,l,r){if("string"===typeof l||l&&"string"===typeof l.file&&"string"===typeof l.root)r=l,l=null;l&&"object"===typeof l||(l=g.newBuilder());"string"===typeof d&&(d=JSON.parse(d));l["import"](d,r);l.resolveAll();l.build();return l};g.loadJsonFile=function(d,l,r){l&&"object"===typeof l?(r=l,l=null):l&&
"function"===typeof l||(l=null);if(l)return g.Util.fetch("string"===typeof d?d:d.root+"/"+d.file,function(b){if(null===b)l(Error("Failed to fetch file"));else try{l(null,g.loadJson(JSON.parse(b),r,d))}catch(e){l(e)}});var m=g.Util.fetch("object"===typeof d?d.root+"/"+d.file:d);return null===m?null:g.loadJson(JSON.parse(m),r,d)};return g}"undefined"!==typeof module&&module.exports?module.exports=t(require("bytebuffer")):"function"===typeof define&&define.amd?define(["ByteBuffer"],t):(s.dcodeIO=s.dcodeIO||
NEGID:/^\-?(?:[1-9][0-9]*|0|0x[0-9a-fA-F]+|0[0-7]+)$/,WHITESPACE:/\s/,STRING:/['"]([^'"\\]*(\\.[^"\\]*)*)['"]/g,BOOL:/^(?:true|false)$/i};h.Reflect=function(c){function h(a,f){var b=f.readVarint32(),d=b&7,b=b>>3;switch(d){case c.WIRE_TYPES.VARINT:do b=f.readUint8();while(128===(b&128));break;case c.WIRE_TYPES.BITS64:f.offset+=8;break;case c.WIRE_TYPES.LDELIM:b=f.readVarint32();f.offset+=b;break;case c.WIRE_TYPES.STARTGROUP:h(b,f);break;case c.WIRE_TYPES.ENDGROUP:if(b===a)return!1;throw Error("Illegal GROUPEND after unknown group: "+
b+" ("+a+" expected)");case c.WIRE_TYPES.BITS32:f.offset+=4;break;default:throw Error("Illegal wire type in unknown group "+a+": "+d);}return!0}function q(a,f){if(a&&"number"===typeof a.low&&"number"===typeof a.high&&"boolean"===typeof a.unsigned&&a.low===a.low&&a.high===a.high)return new c.Long(a.low,a.high,"undefined"===typeof f?a.unsigned:f);if("string"===typeof a)return c.Long.fromString(a,f||!1,10);if("number"===typeof a)return c.Long.fromNumber(a,f||!1);throw Error("not convertible to Long");
}var k={},b=function(a,f){this.parent=a;this.name=f};b.prototype.fqn=function(){var a=this.name,f=this;do{f=f.parent;if(null==f)break;a=f.name+"."+a}while(1);return a};b.prototype.toString=function(a){return(a?this.className+" ":"")+this.fqn()};b.prototype.build=function(){throw Error(this.toString(!0)+" cannot be built directly");};k.T=b;var e=function(a,f,c){b.call(this,a,f);this.className="Namespace";this.children=[];this.options=c||{}};e.prototype=Object.create(b.prototype);e.prototype.getChildren=
function(a){a=a||null;if(null==a)return this.children.slice();for(var f=[],c=0,b=this.children.length;c<b;++c)this.children[c]instanceof a&&(a===d.Field&&this.children[c]instanceof d.ExtensionField||f.push(this.children[c]));return f};e.prototype.addChild=function(a){var f;if(f=this.getChild(a.name))if(f instanceof d.Field&&f.name!==f.originalName&&!this.hasChild(f.originalName))f.name=f.originalName;else if(a instanceof d.Field&&a.name!==a.originalName&&!this.hasChild(a.originalName))a.name=a.originalName;
else throw Error("Duplicate name in namespace "+this.toString(!0)+": "+a.name);this.children.push(a)};e.prototype.hasChild=function(a){return-1<this._indexOf(a)};e.prototype.getChild=function(a){a=this._indexOf(a);return-1<a?this.children[a]:null};e.prototype._indexOf=function(a){for(var f="number"===typeof a?"id":"name",c=0;c<this.children.length;c++)if("undefined"!==typeof this.children[c][f]&&this.children[c][f]==a)return c;return-1};e.prototype.resolve=function(a,f){var c=a.split("."),b=this,
d=0;if(""==c[d]){for(;null!=b.parent;)b=b.parent;d++}do{do{b=b.getChild(c[d]);if(!(b&&b instanceof k.T)||f&&b instanceof k.Message.Field){b=null;break}d++}while(d<c.length);if(null!=b)break;if(null!==this.parent)return this.parent.resolve(a,f)}while(null!=b);return b};e.prototype.build=function(){for(var a={},f=this.getChildren(),c,b=0,d=f.length;b<d;++b)c=f[b],c instanceof e&&(a[c.name]=c.build());Object.defineProperty&&Object.defineProperty(a,"$options",{value:this.buildOpt()});return a};e.prototype.buildOpt=
function(){for(var a={},f=Object.keys(this.options),c=0;c<f.length;c++)a[f[c]]=this.options[f[c]];return a};e.prototype.getOption=function(a){return"undefined"===typeof a?this.options:"undefined"!==typeof this.options[a]?this.options[a]:null};k.Namespace=e;var d=function(a,f,b,d){e.call(this,a,f,b);this.className="Message";this.extensions=[c.ID_MIN,c.ID_MAX];this.clazz=null;this.isGroup=!!d};d.prototype=Object.create(e.prototype);d.prototype.build=function(a){if(this.clazz&&!a)return this.clazz;a=
function(a,b){function c(a,b){var f={},d;for(d in a)a.hasOwnProperty(d)&&(null===a[d]||"object"!==typeof a[d]?f[d]=a[d]:a[d]instanceof m?b&&(f[d]=a.toBuffer()):f[d]=c(a[d],b));return f}var f=b.getChildren(a.Reflect.Message.Field),d=function(c,d){a.Builder.Message.call(this);var e,n;Object.defineProperty&&Object.defineProperty(this,"$type",{get:function(){return b}});for(e=0;e<f.length;e++)n=f[e],this[n.name]=n.repeated?[]:null;for(e=0;e<f.length;e++)if(n=f[e],n.required&&"undefined"!==typeof n.options["default"])try{this.$set(n.name,
n.options["default"])}catch(g){throw Error("[INTERNAL] "+g);}if(1!==arguments.length||"object"!==typeof c||"function"===typeof c.encode||a.Util.isArray(c)||c instanceof m||c instanceof ArrayBuffer||a.Long&&c instanceof a.Long)for(e=0;e<arguments.length;e++)e<f.length&&this.$set(f[e].name,arguments[e]);else for(n=Object.keys(c),e=0;e<n.length;e++)this.$set(n[e],c[n[e]])};d.prototype=Object.create(a.Builder.Message.prototype);d.prototype.add=function(f,c,d){var e=b.getChild(f);if(!e)throw Error(this+
"#"+f+" is undefined");if(!(e instanceof a.Reflect.Message.Field))throw Error(this+"#"+f+" is not a field: "+e.toString(!0));if(!e.repeated)throw Error(this+"#"+f+" is not a repeated field");null===this[e.name]&&(this[e.name]=[]);this[e.name].push(d?c:e.verifyValue(c,!0))};d.prototype.$add=d.prototype.add;d.prototype.set=function(f,c,d){var e=b.getChild(f);if(!e)throw Error(this+"#"+f+" is not a field: undefined");if(!(e instanceof a.Reflect.Message.Field))throw Error(this+"#"+f+" is not a field: "+
e.toString(!0));this[e.name]=d?c:e.verifyValue(c)};d.prototype.$set=d.prototype.set;d.prototype.get=function(f){var c=b.getChild(f);if(!(c&&c instanceof a.Reflect.Message.Field))throw Error(this+"#"+f+" is not a field: undefined");if(!(c instanceof a.Reflect.Message.Field))throw Error(this+"#"+f+" is not a field: "+c.toString(!0));return this[c.name]};d.prototype.$get=d.prototype.get;for(var e=0;e<f.length;e++){var n=f[e];a.populateAccessors&&function(a){var f=a.originalName.replace(/(_[a-zA-Z])/g,
function(a){return a.toUpperCase().replace("_","")}),f=f.substring(0,1).toUpperCase()+f.substring(1),c=a.originalName.replace(/([A-Z])/g,function(a){return"_"+a});b.hasChild("set"+f)||(d.prototype["set"+f]=function(f){this.$set(a.name,f)});b.hasChild("set_"+c)||(d.prototype["set_"+c]=function(f){this.$set(a.name,f)});b.hasChild("get"+f)||(d.prototype["get"+f]=function(){return this.$get(a.name)});b.hasChild("get_"+c)||(d.prototype["get_"+c]=function(){return this.$get(a.name)})}(n)}d.prototype.encode=
function(a){var f=!1;a||(a=new m,f=!0);var c=a.littleEndian;try{return b.encode(this,a.LE()),(f?a.flip():a).LE(c)}catch(d){throw a.LE(c),d;}};d.prototype.calculate=function(){return b.calculate(this)};d.prototype.encodeDelimited=function(a){var f=!1;a||(a=new m,f=!0);var c=(new m).LE();b.encode(this,c).flip();a.writeVarint32(c.remaining());a.append(c);return f?a.flip():a};d.prototype.encodeAB=function(){try{return this.encode().toArrayBuffer()}catch(a){throw a.encoded&&(a.encoded=a.encoded.toArrayBuffer()),
a;}};d.prototype.toArrayBuffer=d.prototype.encodeAB;d.prototype.encodeNB=function(){try{return this.encode().toBuffer()}catch(a){throw a.encoded&&(a.encoded=a.encoded.toBuffer()),a;}};d.prototype.toBuffer=d.prototype.encodeNB;d.prototype.encode64=function(){try{return this.encode().toBase64()}catch(a){throw a.encoded&&(a.encoded=a.encoded.toBase64()),a;}};d.prototype.toBase64=d.prototype.encode64;d.prototype.encodeHex=function(){try{return this.encode().toHex()}catch(a){throw a.encoded&&(a.encoded=
a.encoded.toHex()),a;}};d.prototype.toHex=d.prototype.encodeHex;d.prototype.toRaw=function(a){return c(this,!!a)};d.decode=function(a,f){"string"===typeof a&&(a=m.wrap(a,f?f:"base64"));a=a instanceof m?a:m.wrap(a);var c=a.littleEndian;try{var d=b.decode(a.LE());a.LE(c);return d}catch(e){throw a.LE(c),e;}};d.decodeDelimited=function(a,f){"string"===typeof a&&(a=m.wrap(a,f?f:"base64"));a=a instanceof m?a:m.wrap(a);if(1>a.remaining())return null;var c=a.offset,d=a.readVarint32();if(a.remaining()<d)return a.offset=
c,null;try{var e=b.decode(a.slice(a.offset,a.offset+d).LE());a.offset+=d;return e}catch(n){throw a.offset+=d,n;}};d.decode64=function(a){return d.decode(a,"base64")};d.decodeHex=function(a){return d.decode(a,"hex")};d.prototype.toString=function(){return b.toString()};Object.defineProperty&&Object.defineProperty(d,"$options",{value:b.buildOpt()});return d}(c,this);for(var f=this.getChildren(),b=0;b<f.length;b++)if(f[b]instanceof l)a[f[b].name]=f[b].build();else if(f[b]instanceof d)a[f[b].name]=f[b].build();
else if(!(f[b]instanceof d.Field))throw Error("Illegal reflect child of "+this.toString(!0)+": "+f[b].toString(!0));return this.clazz=a};d.prototype.encode=function(a,f){for(var c=this.getChildren(d.Field),b=null,e=0,g;e<c.length;e++)g=a.$get(c[e].name),c[e].required&&null===g?null===b&&(b=c[e]):c[e].encode(g,f);if(null!==b)throw c=Error("Missing at least one required field for "+this.toString(!0)+": "+b),c.encoded=f,c;return f};d.prototype.calculate=function(a){for(var c=this.getChildren(d.Field),
b=0,e=0,g;e<c.length;e++){g=a.$get(c[e].name);if(c[e].required&&null===g)throw Error("Missing at least one required field for "+this.toString(!0)+": "+c[e]);b+=c[e].calculate(g)}return b};d.prototype.decode=function(a,f,b){f="number"===typeof f?f:-1;for(var d=a.offset,e=new this.clazz,g,l,k;a.offset<d+f||-1==f&&0<a.remaining();){g=a.readVarint32();l=g&7;k=g>>3;if(l===c.WIRE_TYPES.ENDGROUP){if(k!==b)throw Error("Illegal group end indicator for "+this.toString(!0)+": "+k+" ("+(b?b+" expected":"not a group")+
")");break}if(g=this.getChild(k))g.repeated&&!g.options.packed?e.$add(g.name,g.decode(l,a),!0):e.$set(g.name,g.decode(l,a),!0);else switch(l){case c.WIRE_TYPES.VARINT:a.readVarint32();break;case c.WIRE_TYPES.BITS32:a.offset+=4;break;case c.WIRE_TYPES.BITS64:a.offset+=8;break;case c.WIRE_TYPES.LDELIM:g=a.readVarint32();a.offset+=g;break;case c.WIRE_TYPES.STARTGROUP:for(;h(k,a););break;default:throw Error("Illegal wire type for unknown field "+k+" in "+this.toString(!0)+"#decode: "+l);}}a=this.getChildren(c.Reflect.Field);
for(f=0;f<a.length;f++)if(g=a[f],null===e[g.name]){if(g.required)throw a=Error("Missing at least one required field for "+this.toString(!0)+": "+g.name),a.decoded=e,a;if("undefined"!==typeof g.options["default"])try{e.$set(g.name,g.options["default"])}catch(m){throw Error("[INTERNAL] "+m);}}return e};k.Message=d;var g=function(a,f,d,e,g,l){b.call(this,a,e);this.className="Message.Field";this.required="required"==f;this.repeated="repeated"==f;this.type=d;this.resolvedType=null;this.id=g;this.options=
l||{};this.originalName=this.name;c.convertFieldsToCamelCase&&(this.name=this.name.replace(/_([a-zA-Z])/g,function(a,c){return c.toUpperCase()}))};g.prototype=Object.create(b.prototype);g.prototype.verifyValue=function(a,f){f=f||!1;var b=function(a,b){throw Error("Illegal value for "+this.toString(!0)+" of type "+this.type.name+": "+a+" ("+b+")");}.bind(this);if(null===a)return this.required&&b(typeof a,"required"),null;var d;if(this.repeated&&!f){c.Util.isArray(a)||(a=[a]);b=[];for(d=0;d<a.length;d++)b.push(this.verifyValue(a[d],
!0));return b}!this.repeated&&c.Util.isArray(a)&&b(typeof a,"no array expected");switch(this.type){case c.TYPES.int32:case c.TYPES.sint32:case c.TYPES.sfixed32:return("number"!==typeof a||a===a&&0!==a%1)&&b(typeof a,"not an integer"),4294967295<a?a|0:a;case c.TYPES.uint32:case c.TYPES.fixed32:return("number"!==typeof a||a===a&&0!==a%1)&&b(typeof a,"not an integer"),0>a?a>>>0:a;case c.TYPES.int64:case c.TYPES.sint64:case c.TYPES.sfixed64:if(c.Long)try{return q(a,!1)}catch(e){b(typeof a,e.message)}else b(typeof a,
"requires Long.js");case c.TYPES.uint64:case c.TYPES.fixed64:if(c.Long)try{return q(a,!0)}catch(g){b(typeof a,g.message)}else b(typeof a,"requires Long.js");case c.TYPES.bool:return"boolean"!==typeof a&&b(typeof a,"not a boolean"),a;case c.TYPES["float"]:case c.TYPES["double"]:return"number"!==typeof a&&b(typeof a,"not a number"),a;case c.TYPES.string:return"string"===typeof a||a&&a instanceof String||b(typeof a,"not a string"),""+a;case c.TYPES.bytes:return a&&a instanceof m?a:m.wrap(a);case c.TYPES["enum"]:var k=
this.resolvedType.getChildren(l.Value);for(d=0;d<k.length;d++)if(k[d].name==a||k[d].id==a)return k[d].id;b(a,"not a valid enum value");case c.TYPES.group:case c.TYPES.message:a&&"object"===typeof a||b(typeof a,"object expected");if(a instanceof this.resolvedType.clazz)return a;if(a instanceof c.Builder.Message){b={};for(d in a)a.hasOwnProperty(d)&&(b[d]=a[d]);a=b}return new this.resolvedType.clazz(a)}throw Error("[INTERNAL] Illegal value for "+this.toString(!0)+": "+a+" (undefined type "+this.type+
")");};g.prototype.encode=function(a,b){a=this.verifyValue(a);if(null===this.type||"object"!==typeof this.type)throw Error("[INTERNAL] Unresolved type in "+this.toString(!0)+": "+this.type);if(null===a||this.repeated&&0==a.length)return b;try{if(this.repeated){var d;if(this.options.packed&&0<=c.PACKABLE_WIRE_TYPES.indexOf(this.type.wireType)){b.writeVarint32(this.id<<3|c.WIRE_TYPES.LDELIM);b.ensureCapacity(b.offset+=1);var e=b.offset;for(d=0;d<a.length;d++)this.encodeValue(a[d],b);var g=b.offset-
e,l=m.calculateVarint32(g);if(1<l){var k=b.slice(e,b.offset),e=e+(l-1);b.offset=e;b.append(k)}b.writeVarint32(g,e-l)}else for(d=0;d<a.length;d++)b.writeVarint32(this.id<<3|this.type.wireType),this.encodeValue(a[d],b)}else b.writeVarint32(this.id<<3|this.type.wireType),this.encodeValue(a,b)}catch(h){throw Error("Illegal value for "+this.toString(!0)+": "+a+" ("+h+")");}return b};g.prototype.encodeValue=function(a,b){if(null===a)return b;switch(this.type){case c.TYPES.int32:0>a?b.writeVarint64(a):b.writeVarint32(a);
break;case c.TYPES.uint32:b.writeVarint32(a);break;case c.TYPES.sint32:b.writeVarint32ZigZag(a);break;case c.TYPES.fixed32:b.writeUint32(a);break;case c.TYPES.sfixed32:b.writeInt32(a);break;case c.TYPES.int64:case c.TYPES.uint64:b.writeVarint64(a);break;case c.TYPES.sint64:b.writeVarint64ZigZag(a);break;case c.TYPES.fixed64:b.writeUint64(a);break;case c.TYPES.sfixed64:b.writeInt64(a);break;case c.TYPES.bool:"string"===typeof a?b.writeVarint32("false"===a.toLowerCase()?0:!!a):b.writeVarint32(a?1:0);
break;case c.TYPES["enum"]:b.writeVarint32(a);break;case c.TYPES["float"]:b.writeFloat32(a);break;case c.TYPES["double"]:b.writeFloat64(a);break;case c.TYPES.string:b.writeVString(a);break;case c.TYPES.bytes:if(0>a.remaining())throw Error("Illegal value for "+this.toString(!0)+": "+a.remaining()+" bytes remaining");var d=a.offset;b.writeVarint32(a.remaining());b.append(a);a.offset=d;break;case c.TYPES.message:d=(new m).LE();this.resolvedType.encode(a,d);b.writeVarint32(d.offset);b.append(d.flip());
break;case c.TYPES.group:this.resolvedType.encode(a,b);b.writeVarint32(this.id<<3|c.WIRE_TYPES.ENDGROUP);break;default:throw Error("[INTERNAL] Illegal value to encode in "+this.toString(!0)+": "+a+" (unknown type)");}return b};g.prototype.calculate=function(a){a=this.verifyValue(a);if(null===this.type||"object"!==typeof this.type)throw Error("[INTERNAL] Unresolved type in "+this.toString(!0)+": "+this.type);if(null===a||this.repeated&&0==a.length)return 0;var b=0;try{if(this.repeated){var d,e;if(this.options.packed&&
0<=c.PACKABLE_WIRE_TYPES.indexOf(this.type.wireType)){b+=m.calculateVarint32(this.id<<3|c.WIRE_TYPES.LDELIM);for(d=e=0;d<a.length;d++)e+=this.calculateValue(a[d]);b+=m.calculateVarint32(e);b+=e}else for(d=0;d<a.length;d++)b+=m.calculateVarint32(this.id<<3|this.type.wireType),b+=this.calculateValue(a[d])}else b+=m.calculateVarint32(this.id<<3|this.type.wireType),b+=this.calculateValue(a)}catch(g){throw Error("Illegal value for "+this.toString(!0)+": "+a+" ("+g+")");}return b};g.prototype.calculateValue=
function(a){if(null===a)return 0;switch(this.type){case c.TYPES.int32:return 0>a?m.calculateVarint64(a):m.calculateVarint32(a);case c.TYPES.uint32:return m.calculateVarint32(a);case c.TYPES.sint32:return m.calculateVarint32(m.zigZagEncode32(a));case c.TYPES.fixed32:case c.TYPES.sfixed32:case c.TYPES["float"]:return 4;case c.TYPES.int64:case c.TYPES.uint64:return m.calculateVarint64(a);case c.TYPES.sint64:return m.calculateVarint64(m.zigZagEncode64(a));case c.TYPES.fixed64:case c.TYPES.sfixed64:return 8;
case c.TYPES.bool:return 1;case c.TYPES["enum"]:return m.calculateVarint32(a);case c.TYPES["double"]:return 8;case c.TYPES.string:return a=m.calculateUTF8Bytes(a),m.calculateVarint32(a)+a;case c.TYPES.bytes:if(0>a.remaining())throw Error("Illegal value for "+this.toString(!0)+": "+a.remaining()+" bytes remaining");return m.calculateVarint32(a.remaining())+a.remaining();case c.TYPES.message:return a=this.resolvedType.calculate(a),m.calculateVarint32(a)+a;case c.TYPES.group:return a=this.resolvedType.calculate(a),
a+m.calculateVarint32(this.id<<3|c.WIRE_TYPES.ENDGROUP)}throw Error("[INTERNAL] Illegal value to encode in "+this.toString(!0)+": "+a+" (unknown type)");};g.prototype.decode=function(a,b,d){if(a!=this.type.wireType&&(d||a!=c.WIRE_TYPES.LDELIM||!this.repeated))throw Error("Illegal wire type for field "+this.toString(!0)+": "+a+" ("+this.type.wireType+" expected)");if(a==c.WIRE_TYPES.LDELIM&&this.repeated&&this.options.packed&&0<=c.PACKABLE_WIRE_TYPES.indexOf(this.type.wireType)&&!d){a=b.readVarint32();
a=b.offset+a;for(d=[];b.offset<a;)d.push(this.decode(this.type.wireType,b,!0));return d}switch(this.type){case c.TYPES.int32:return b.readVarint32()|0;case c.TYPES.uint32:return b.readVarint32()>>>0;case c.TYPES.sint32:return b.readVarint32ZigZag()|0;case c.TYPES.fixed32:return b.readUint32()>>>0;case c.TYPES.sfixed32:return b.readInt32()|0;case c.TYPES.int64:return b.readVarint64();case c.TYPES.uint64:return b.readVarint64().toUnsigned();case c.TYPES.sint64:return b.readVarint64ZigZag();case c.TYPES.fixed64:return b.readUint64();
case c.TYPES.sfixed64:return b.readInt64();case c.TYPES.bool:return!!b.readVarint32();case c.TYPES["enum"]:return b.readVarint32();case c.TYPES["float"]:return b.readFloat();case c.TYPES["double"]:return b.readDouble();case c.TYPES.string:return b.readVString();case c.TYPES.bytes:a=b.readVarint32();if(b.remaining()<a)throw Error("Illegal number of bytes for "+this.toString(!0)+": "+a+" required but got only "+b.remaining());d=b.clone();d.limit=d.offset+a;b.offset+=a;return d;case c.TYPES.message:return a=
b.readVarint32(),this.resolvedType.decode(b,a);case c.TYPES.group:return this.resolvedType.decode(b,-1,this.id)}throw Error("[INTERNAL] Illegal wire type for "+this.toString(!0)+": "+a);};k.Message.Field=g;var r=function(a,b,c,d,e,l){g.call(this,a,b,c,d,e,l)};r.prototype=Object.create(g.prototype);k.Message.ExtensionField=r;var l=function(a,b,c){e.call(this,a,b,c);this.className="Enum";this.object=null};l.prototype=Object.create(e.prototype);l.prototype.build=function(){for(var a={},b=this.getChildren(l.Value),
c=0;c<b.length;c++)a[b[c].name]=b[c].id;Object.defineProperty&&Object.defineProperty(a,"$options",{value:this.buildOpt()});return this.object=a};k.Enum=l;r=function(a,c,d){b.call(this,a,c);this.className="Enum.Value";this.id=d};r.prototype=Object.create(b.prototype);k.Enum.Value=r;r=function(a,b,c){e.call(this,a,b,c);this.className="Service";this.clazz=null};r.prototype=Object.create(e.prototype);r.prototype.build=function(a){return this.clazz&&!a?this.clazz:this.clazz=function(a,b){var c=function(b){a.Builder.Service.call(this);
this.rpcImpl=b||function(a,b,c){setTimeout(c.bind(this,Error("Not implemented, see: https://github.com/dcodeIO/ProtoBuf.js/wiki/Services")),0)}};c.prototype=Object.create(a.Builder.Service.prototype);Object.defineProperty&&(Object.defineProperty(c,"$options",{value:b.buildOpt()}),Object.defineProperty(c.prototype,"$options",{value:c.$options}));for(var d=b.getChildren(a.Reflect.Service.RPCMethod),e=0;e<d.length;e++)(function(a){c.prototype[a.name]=function(c,d){try{c&&c instanceof a.resolvedRequestType.clazz?
this.rpcImpl(a.fqn(),c,function(c,e){if(c)d(c);else{try{e=a.resolvedResponseType.clazz.decode(e)}catch(f){}e&&e instanceof a.resolvedResponseType.clazz?d(null,e):d(Error("Illegal response type received in service method "+b.name+"#"+a.name))}}):setTimeout(d.bind(this,Error("Illegal request type provided to service method "+b.name+"#"+a.name)),0)}catch(e){setTimeout(d.bind(this,e),0)}};c[a.name]=function(b,d,e){(new c(b))[a.name](d,e)};Object.defineProperty&&(Object.defineProperty(c[a.name],"$options",
{value:a.buildOpt()}),Object.defineProperty(c.prototype[a.name],"$options",{value:c[a.name].$options}))})(d[e]);return c}(c,this)};k.Service=r;var p=function(a,c,d){b.call(this,a,c);this.className="Service.Method";this.options=d||{}};p.prototype=Object.create(b.prototype);p.prototype.buildOpt=e.prototype.buildOpt;k.Service.Method=p;r=function(a,b,c,d,e){p.call(this,a,b,e);this.className="Service.RPCMethod";this.requestName=c;this.responseName=d;this.resolvedResponseType=this.resolvedRequestType=null};
r.prototype=Object.create(p.prototype);k.Service.RPCMethod=r;return k}(h);h.Builder=function(c,h,m){var k=function(){this.ptr=this.ns=new m.Namespace(null,"");this.resolved=!1;this.result=null;this.files={};this.importRoot=null};k.prototype.reset=function(){this.ptr=this.ns};k.prototype.define=function(b,c){if("string"!==typeof b||!h.TYPEREF.test(b))throw Error("Illegal package: "+b);var d=b.split("."),g;for(g=0;g<d.length;g++)if(!h.NAME.test(d[g]))throw Error("Illegal package: "+d[g]);for(g=0;g<
d.length;g++)this.ptr.hasChild(d[g])||this.ptr.addChild(new m.Namespace(this.ptr,d[g],c)),this.ptr=this.ptr.getChild(d[g]);return this};k.isValidMessage=function(b){if("string"!==typeof b.name||!h.NAME.test(b.name)||"undefined"!==typeof b.values||"undefined"!==typeof b.rpc)return!1;var e;if("undefined"!==typeof b.fields){if(!c.Util.isArray(b.fields))return!1;var d=[],g;for(e=0;e<b.fields.length;e++){if(!k.isValidMessageField(b.fields[e]))return!1;g=parseInt(b.fields[e].id,10);if(0<=d.indexOf(g))return!1;
d.push(g)}}if("undefined"!==typeof b.enums){if(!c.Util.isArray(b.enums))return!1;for(e=0;e<b.enums.length;e++)if(!k.isValidEnum(b.enums[e]))return!1}if("undefined"!==typeof b.messages){if(!c.Util.isArray(b.messages))return!1;for(e=0;e<b.messages.length;e++)if(!k.isValidMessage(b.messages[e])&&!k.isValidExtend(b.messages[e]))return!1}return"undefined"===typeof b.extensions||c.Util.isArray(b.extensions)&&2===b.extensions.length&&"number"===typeof b.extensions[0]&&"number"===typeof b.extensions[1]?!0:
!1};k.isValidMessageField=function(b){if("string"!==typeof b.rule||"string"!==typeof b.name||"string"!==typeof b.type||"undefined"===typeof b.id||!(h.RULE.test(b.rule)&&h.NAME.test(b.name)&&h.TYPEREF.test(b.type)&&h.ID.test(""+b.id)))return!1;if("undefined"!==typeof b.options){if("object"!==typeof b.options)return!1;for(var c=Object.keys(b.options),d=0,g;d<c.length;d++)if("string"!==typeof(g=c[d])||"string"!==typeof b.options[g]&&"number"!==typeof b.options[g]&&"boolean"!==typeof b.options[g])return!1}return!0};
k.isValidEnum=function(b){if("string"!==typeof b.name||!h.NAME.test(b.name)||"undefined"===typeof b.values||!c.Util.isArray(b.values)||0==b.values.length)return!1;for(var e=0;e<b.values.length;e++)if("object"!=typeof b.values[e]||"string"!==typeof b.values[e].name||"undefined"===typeof b.values[e].id||!h.NAME.test(b.values[e].name)||!h.NEGID.test(""+b.values[e].id))return!1;return!0};k.prototype.create=function(b){if(!b)return this;c.Util.isArray(b)||(b=[b]);if(0==b.length)return this;var e=[],d,
g,h,l,p;for(e.push(b);0<e.length;){b=e.pop();if(c.Util.isArray(b))for(;0<b.length;)if(d=b.shift(),k.isValidMessage(d)){g=new m.Message(this.ptr,d.name,d.options,d.isGroup);if(d.fields&&0<d.fields.length)for(l=0;l<d.fields.length;l++){if(g.hasChild(d.fields[l].id))throw Error("Duplicate field id in message "+g.name+": "+d.fields[l].id);if(d.fields[l].options)for(h=Object.keys(d.fields[l].options),p=0;p<h.length;p++){if("string"!==typeof h[p])throw Error("Illegal field option name in message "+g.name+
"#"+d.fields[l].name+": "+h[p]);if("string"!==typeof d.fields[l].options[h[p]]&&"number"!==typeof d.fields[l].options[h[p]]&&"boolean"!==typeof d.fields[l].options[h[p]])throw Error("Illegal field option value in message "+g.name+"#"+d.fields[l].name+"#"+h[p]+": "+d.fields[l].options[h[p]]);}g.addChild(new m.Message.Field(g,d.fields[l].rule,d.fields[l].type,d.fields[l].name,d.fields[l].id,d.fields[l].options))}h=[];if("undefined"!==typeof d.enums&&0<d.enums.length)for(l=0;l<d.enums.length;l++)h.push(d.enums[l]);
if(d.messages&&0<d.messages.length)for(l=0;l<d.messages.length;l++)h.push(d.messages[l]);d.extensions&&(g.extensions=d.extensions,g.extensions[0]<c.ID_MIN&&(g.extensions[0]=c.ID_MIN),g.extensions[1]>c.ID_MAX&&(g.extensions[1]=c.ID_MAX));this.ptr.addChild(g);0<h.length&&(e.push(b),b=h,this.ptr=g)}else if(k.isValidEnum(d)){g=new m.Enum(this.ptr,d.name,d.options);for(l=0;l<d.values.length;l++)g.addChild(new m.Enum.Value(g,d.values[l].name,d.values[l].id));this.ptr.addChild(g)}else if(k.isValidService(d)){g=
new m.Service(this.ptr,d.name,d.options);for(l in d.rpc)d.rpc.hasOwnProperty(l)&&g.addChild(new m.Service.RPCMethod(g,l,d.rpc[l].request,d.rpc[l].response,d.rpc[l].options));this.ptr.addChild(g)}else if(k.isValidExtend(d))if(g=this.ptr.resolve(d.ref))for(l=0;l<d.fields.length;l++){if(g.hasChild(d.fields[l].id))throw Error("Duplicate extended field id in message "+g.name+": "+d.fields[l].id);if(d.fields[l].id<g.extensions[0]||d.fields[l].id>g.extensions[1])throw Error("Illegal extended field id in message "+
g.name+": "+d.fields[l].id+" ("+g.extensions.join(" to ")+" expected)");g.addChild(new m.Message.Field(g,d.fields[l].rule,d.fields[l].type,d.fields[l].name,d.fields[l].id,d.fields[l].options))}else{if(!/\.?google\.protobuf\./.test(d.ref))throw Error("Extended message "+d.ref+" is not defined");}else throw Error("Not a valid definition: "+JSON.stringify(d));else throw Error("Not a valid namespace: "+JSON.stringify(b));this.ptr=this.ptr.parent}this.resolved=!1;this.result=null;return this};k.prototype["import"]=
function(b,e){if("string"===typeof e){c.Util.IS_NODE&&(e=require("path").resolve(e));if(!0===this.files[e])return this.reset(),this;this.files[e]=!0}if(b.imports&&0<b.imports.length){var d,g="/",h=!1;if("object"===typeof e){if(this.importRoot=e.root,h=!0,d=this.importRoot,e=e.file,0<=d.indexOf("\\")||0<=e.indexOf("\\"))g="\\"}else"string"===typeof e?this.importRoot?d=this.importRoot:0<=e.indexOf("/")?(d=e.replace(/\/[^\/]*$/,""),""===d&&(d="/")):0<=e.indexOf("\\")?(d=e.replace(/\\[^\\]*$/,""),g="\\"):
d=".":d=null;for(var l=0;l<b.imports.length;l++)if("string"===typeof b.imports[l]){if(!d)throw Error("Cannot determine import root: File name is unknown");var k=b.imports[l];if(!/^google\/protobuf\//.test(k)&&(k=d+g+k,!0!==this.files[k])){/\.proto$/i.test(k)&&!c.DotProto&&(k=k.replace(/\.proto$/,".json"));var a=c.Util.fetch(k);if(null===a)throw Error("Failed to import '"+k+"' in '"+e+"': File not found");if(/\.json$/i.test(k))this["import"](JSON.parse(a+""),k);else this["import"]((new c.DotProto.Parser(a+
"")).parse(),k)}}else if(e)if(/\.(\w+)$/.test(e))this["import"](b.imports[l],e.replace(/^(.+)\.(\w+)$/,function(a,b,c){return b+"_import"+l+"."+c}));else this["import"](b.imports[l],e+"_import"+l);else this["import"](b.imports[l]);h&&(this.importRoot=null)}b.messages&&(b["package"]&&this.define(b["package"],b.options),this.create(b.messages),this.reset());b.enums&&(b["package"]&&this.define(b["package"],b.options),this.create(b.enums),this.reset());b.services&&(b["package"]&&this.define(b["package"],
b.options),this.create(b.services),this.reset());b["extends"]&&(b["package"]&&this.define(b["package"],b.options),this.create(b["extends"]),this.reset());return this};k.isValidService=function(b){return!("string"!==typeof b.name||!h.NAME.test(b.name)||"object"!==typeof b.rpc)};k.isValidExtend=function(b){if("string"!==typeof b.ref||!h.TYPEREF.test(b.ref))return!1;var e;if("undefined"!==typeof b.fields){if(!c.Util.isArray(b.fields))return!1;var d=[],g;for(e=0;e<b.fields.length;e++){if(!k.isValidMessageField(b.fields[e]))return!1;
g=parseInt(b.id,10);if(0<=d.indexOf(g))return!1;d.push(g)}}return!0};k.prototype.resolveAll=function(){var b;if(null!=this.ptr&&"object"!==typeof this.ptr.type){if(this.ptr instanceof m.Namespace){b=this.ptr.getChildren();for(var e=0;e<b.length;e++)this.ptr=b[e],this.resolveAll()}else if(this.ptr instanceof m.Message.Field)if(h.TYPE.test(this.ptr.type))this.ptr.type=c.TYPES[this.ptr.type];else{if(!h.TYPEREF.test(this.ptr.type))throw Error("Illegal type reference in "+this.ptr.toString(!0)+": "+this.ptr.type);
b=this.ptr.parent.resolve(this.ptr.type,!0);if(!b)throw Error("Unresolvable type reference in "+this.ptr.toString(!0)+": "+this.ptr.type);this.ptr.resolvedType=b;if(b instanceof m.Enum)this.ptr.type=c.TYPES["enum"];else if(b instanceof m.Message)this.ptr.type=b.isGroup?c.TYPES.group:c.TYPES.message;else throw Error("Illegal type reference in "+this.ptr.toString(!0)+": "+this.ptr.type);}else if(!(this.ptr instanceof c.Reflect.Enum.Value))if(this.ptr instanceof c.Reflect.Service.Method)if(this.ptr instanceof
c.Reflect.Service.RPCMethod){b=this.ptr.parent.resolve(this.ptr.requestName);if(!(b&&b instanceof c.Reflect.Message))throw Error("Illegal type reference in "+this.ptr.toString(!0)+": "+this.ptr.requestName);this.ptr.resolvedRequestType=b;b=this.ptr.parent.resolve(this.ptr.responseName);if(!(b&&b instanceof c.Reflect.Message))throw Error("Illegal type reference in "+this.ptr.toString(!0)+": "+this.ptr.responseName);this.ptr.resolvedResponseType=b}else throw Error("Illegal service type in "+this.ptr.toString(!0));
else throw Error("Illegal object in namespace: "+typeof this.ptr+":"+this.ptr);this.reset()}};k.prototype.build=function(b){this.reset();this.resolved||(this.resolveAll(),this.resolved=!0,this.result=null);null==this.result&&(this.result=this.ns.build());if(b){b=b.split(".");for(var c=this.result,d=0;d<b.length;d++)if(c[b[d]])c=c[b[d]];else{c=null;break}return c}return this.result};k.prototype.lookup=function(b){return b?this.ns.resolve(b):this.ns};k.prototype.toString=function(){return"Builder"};
k.Message=function(){};k.Service=function(){};return k}(h,h.Lang,h.Reflect);h.newBuilder=function(c,m){var q=new h.Builder;"undefined"!==typeof c&&null!==c&&q.define(c,m);return q};h.loadJson=function(c,m,q){if("string"===typeof m||m&&"string"===typeof m.file&&"string"===typeof m.root)q=m,m=null;m&&"object"===typeof m||(m=h.newBuilder());"string"===typeof c&&(c=JSON.parse(c));m["import"](c,q);m.resolveAll();m.build();return m};h.loadJsonFile=function(c,m,q){m&&"object"===typeof m?(q=m,m=null):m&&
"function"===typeof m||(m=null);if(m)return h.Util.fetch("string"===typeof c?c:c.root+"/"+c.file,function(b){if(null===b)m(Error("Failed to fetch file"));else try{m(null,h.loadJson(JSON.parse(b),q,c))}catch(e){m(e)}});var k=h.Util.fetch("object"===typeof c?c.root+"/"+c.file:c);return null===k?null:h.loadJson(JSON.parse(k),q,c)};return h}"undefined"!==typeof module&&module.exports?module.exports=t(require("bytebuffer")):"function"===typeof define&&define.amd?define(["ByteBuffer"],t):(s.dcodeIO=s.dcodeIO||
{}).ProtoBuf=t(s.dcodeIO.ByteBuffer)})(this);
{
"name": "protobufjs",
"version": "3.4.0",
"version": "3.4.1",
"description": "Protocol Buffers for JavaScript. Finally.",

@@ -5,0 +5,0 @@ "author": "Daniel Wirtz <dcode@dcode.io>",

@@ -42,4 +42,4 @@ /*?

// Set field values from a values object
if (arguments.length == 1 && typeof values == 'object' &&
/* not another Message */ typeof values.encode != 'function' &&
if (arguments.length === 1 && typeof values === 'object' &&
/* not another Message */ typeof values.encode !== 'function' &&
/* not a repeated field */ !ProtoBuf.Util.isArray(values) &&

@@ -46,0 +46,0 @@ /* not a ByteBuffer */ !(values instanceof ByteBuffer) &&

@@ -221,2 +221,10 @@ /**

return value;
if (value instanceof ProtoBuf.Builder.Message) {
// Mismatched type: Convert to object (see: https://github.com/dcodeIO/ProtoBuf.js/issues/180)
var obj = {};
for (var i in value)
if (value.hasOwnProperty(i))
obj[i] = value[i];
value = obj;
}
// Else let's try to construct one from a key-value object

@@ -223,0 +231,0 @@ return new (this.resolvedType.clazz)(value); // May throw for a hundred of reasons

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc