UNPKG

protobufjs-no-cli

Version:

Protocol Buffers for JavaScript. Finally.

89 lines (88 loc) 42.4 kB
/* protobuf.js (c) 2013 Daniel Wirtz <dcode@dcode.io> Released under the Apache License, Version 2.0 see: https://github.com/dcodeIO/protobuf.js for details */ (function(h,y){"function"===typeof define&&define.amd?define(["bytebuffer"],y):"function"===typeof require&&"object"===typeof module&&module&&module.exports?module.exports=y(require("bytebuffer"),!0):(h.dcodeIO=h.dcodeIO||{}).ProtoBuf=y(h.dcodeIO.ByteBuffer)})(this,function(h,y){var d={};d.ByteBuffer=h;d.Long=h.Long||null;d.VERSION="5.0.1";d.WIRE_TYPES={};d.WIRE_TYPES.VARINT=0;d.WIRE_TYPES.BITS64=1;d.WIRE_TYPES.LDELIM=2;d.WIRE_TYPES.STARTGROUP=3;d.WIRE_TYPES.ENDGROUP=4;d.WIRE_TYPES.BITS32=5;d.PACKABLE_WIRE_TYPES= [d.WIRE_TYPES.VARINT,d.WIRE_TYPES.BITS64,d.WIRE_TYPES.BITS32];d.TYPES={int32:{name:"int32",wireType:d.WIRE_TYPES.VARINT,defaultValue:0},uint32:{name:"uint32",wireType:d.WIRE_TYPES.VARINT,defaultValue:0},sint32:{name:"sint32",wireType:d.WIRE_TYPES.VARINT,defaultValue:0},int64:{name:"int64",wireType:d.WIRE_TYPES.VARINT,defaultValue:d.Long?d.Long.ZERO:void 0},uint64:{name:"uint64",wireType:d.WIRE_TYPES.VARINT,defaultValue:d.Long?d.Long.UZERO:void 0},sint64:{name:"sint64",wireType:d.WIRE_TYPES.VARINT, defaultValue:d.Long?d.Long.ZERO:void 0},bool:{name:"bool",wireType:d.WIRE_TYPES.VARINT,defaultValue:!1},"double":{name:"double",wireType:d.WIRE_TYPES.BITS64,defaultValue:0},string:{name:"string",wireType:d.WIRE_TYPES.LDELIM,defaultValue:""},bytes:{name:"bytes",wireType:d.WIRE_TYPES.LDELIM,defaultValue:null},fixed32:{name:"fixed32",wireType:d.WIRE_TYPES.BITS32,defaultValue:0},sfixed32:{name:"sfixed32",wireType:d.WIRE_TYPES.BITS32,defaultValue:0},fixed64:{name:"fixed64",wireType:d.WIRE_TYPES.BITS64, defaultValue:d.Long?d.Long.UZERO:void 0},sfixed64:{name:"sfixed64",wireType:d.WIRE_TYPES.BITS64,defaultValue:d.Long?d.Long.ZERO:void 0},"float":{name:"float",wireType:d.WIRE_TYPES.BITS32,defaultValue:0},"enum":{name:"enum",wireType:d.WIRE_TYPES.VARINT,defaultValue:0},message:{name:"message",wireType:d.WIRE_TYPES.LDELIM,defaultValue:null},group:{name:"group",wireType:d.WIRE_TYPES.STARTGROUP,defaultValue:null}};d.MAP_KEY_TYPES=[d.TYPES.int32,d.TYPES.sint32,d.TYPES.sfixed32,d.TYPES.uint32,d.TYPES.fixed32, d.TYPES.int64,d.TYPES.sint64,d.TYPES.sfixed64,d.TYPES.uint64,d.TYPES.fixed64,d.TYPES.bool,d.TYPES.string,d.TYPES.bytes];d.ID_MIN=1;d.ID_MAX=536870911;d.convertFieldsToCamelCase=!1;d.populateAccessors=!0;d.populateDefaults=!0;d.Util=function(){var c={};c.IS_NODE=!("object"!==typeof process||"[object process]"!==process+""||process.browser);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")}],d=null,h=0;h<c.length;h++){try{d=c[h]()}catch(k){continue}break}if(!d)throw Error("XMLHttpRequest is not supported");return d};c.fetch=function(d,h){h&&"function"!=typeof h&&(h=null);if(c.IS_NODE){var n=require("fs");if(h)n.readFile(d,function(c,d){c?h(null):h(""+d)});else try{return n.readFileSync(d)}catch(k){return null}}else{var f=c.XHR();f.open("GET",d,h?!0:!1);f.setRequestHeader("Accept","text/plain");"function"===typeof f.overrideMimeType&& f.overrideMimeType("text/plain");if(h)f.onreadystatechange=function(){4==f.readyState&&(200==f.status||0==f.status&&"string"===typeof f.responseText?h(f.responseText):h(null))},4!=f.readyState&&f.send(null);else return f.send(null),200==f.status||0==f.status&&"string"===typeof f.responseText?f.responseText:null}};c.toCamelCase=function(c){return c.replace(/_([a-zA-Z])/g,function(c,d){return d.toUpperCase()})};return c}();d.Lang={DELIM:/[\s\{\}=;:\[\],'"\(\)<>]/g,RULE:/^(?:required|optional|repeated|map)$/, 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|0[xX][0-9a-fA-F]+|0[0-7]+|([0-9]*(\.[0-9]*)?([Ee][+-]?[0-9]+)?)|inf|nan)$/,NUMBER_DEC:/^(?:[1-9][0-9]*|0)$/,NUMBER_HEX:/^0[xX][0-9a-fA-F]+$/,NUMBER_OCT:/^0[0-7]+$/,NUMBER_FLT:/^([0-9]*(\.[0-9]*)?([Ee][+-]?[0-9]+)?|inf|nan)$/, BOOL:/^(?:true|false)$/i,ID:/^(?:[1-9][0-9]*|0|0[xX][0-9a-fA-F]+|0[0-7]+)$/,NEGID:/^\-?(?:[1-9][0-9]*|0|0[xX][0-9a-fA-F]+|0[0-7]+)$/,WHITESPACE:/\s/,STRING:/(?:"([^"\\]*(?:\\.[^"\\]*)*)")|(?:'([^'\\]*(?:\\.[^'\\]*)*)')/g,STRING_DQ:/(?:"([^"\\]*(?:\\.[^"\\]*)*)")/g,STRING_SQ:/(?:'([^'\\]*(?:\\.[^'\\]*)*)')/g};d.Reflect=function(c){function d(a,g){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 g?a.unsigned:g);if("string"===typeof a)return c.Long.fromString(a,g||!1,10);if("number"===typeof a)return c.Long.fromNumber(a,g||!1);throw Error("not convertible to Long");}function s(a,g){var m=g.readVarint32(),b=m&7,m=m>>>3;switch(b){case c.WIRE_TYPES.VARINT:do m=g.readUint8();while(128===(m&128));break;case c.WIRE_TYPES.BITS64:g.offset+=8;break;case c.WIRE_TYPES.LDELIM:m=g.readVarint32();g.offset+=m;break;case c.WIRE_TYPES.STARTGROUP:s(m,g);break;case c.WIRE_TYPES.ENDGROUP:if(m===a)return!1; throw Error("Illegal GROUPEND after unknown group: "+m+" ("+a+" expected)");case c.WIRE_TYPES.BITS32:g.offset+=4;break;default:throw Error("Illegal wire type in unknown group "+a+": "+b);}return!0}var n={},k=function(a,g,c){this.builder=a;this.parent=g;this.name=c},f=k.prototype;f.fqn=function(){var a=this.name,g=this;do{g=g.parent;if(null==g)break;a=g.name+"."+a}while(1);return a};f.toString=function(a){return(a?this.className+" ":"")+this.fqn()};f.build=function(){throw Error(this.toString(!0)+ " cannot be built directly");};n.T=k;var b=function(a,g,c,b,r){k.call(this,a,g,c);this.className="Namespace";this.children=[];this.options=b||{};this.syntax=r||"proto2"},f=b.prototype=Object.create(k.prototype);f.getChildren=function(a){a=a||null;if(null==a)return this.children.slice();for(var g=[],c=0,b=this.children.length;c<b;++c)this.children[c]instanceof a&&g.push(this.children[c]);return g};f.addChild=function(a){var g;if(g=this.getChild(a.name))if(g instanceof t.Field&&g.name!==g.originalName&& null===this.getChild(g.originalName))g.name=g.originalName;else if(a instanceof t.Field&&a.name!==a.originalName&&null===this.getChild(a.originalName))a.name=a.originalName;else throw Error("Duplicate name in namespace "+this.toString(!0)+": "+a.name);this.children.push(a)};f.getChild=function(a){for(var g="number"===typeof a?"id":"name",c=0,b=this.children.length;c<b;++c)if(this.children[c][g]===a)return this.children[c];return null};f.resolve=function(a,g){var c="string"===typeof a?a.split("."): a,b=this,r=0;if(""===c[r]){for(;null!==b.parent;)b=b.parent;r++}do{do{if(!(b instanceof n.Namespace)){b=null;break}b=b.getChild(c[r]);if(!(b&&b instanceof n.T)||g&&!(b instanceof n.Namespace)){b=null;break}r++}while(r<c.length);if(null!=b)break;if(null!==this.parent)return this.parent.resolve(a,g)}while(null!=b);return b};f.qn=function(a){var g=[],c=a;do g.unshift(c.name),c=c.parent;while(null!==c);for(c=1;c<=g.length;c++){var b=g.slice(g.length-c);if(a===this.resolve(b,a instanceof n.Namespace))return b.join(".")}return a.fqn()}; f.build=function(){for(var a={},c=this.children,m=0,d=c.length,r;m<d;++m)r=c[m],r instanceof b&&(a[r.name]=r.build());Object.defineProperty&&Object.defineProperty(a,"$options",{value:this.buildOpt()});return a};f.buildOpt=function(){for(var a={},c=Object.keys(this.options),b=0,d=c.length;b<d;++b)a[c[b]]=this.options[c[b]];return a};f.getOption=function(a){return"undefined"===typeof a?this.options:"undefined"!==typeof this.options[a]?this.options[a]:null};n.Namespace=b;var l=function(a,g,b,d,r){this.type= a;this.resolvedType=g;this.isMapKey=b;this.syntax=d;this.name=r;if(b&&0>c.MAP_KEY_TYPES.indexOf(a))throw Error("Invalid map key type: "+a.name);},e=l.prototype;l.defaultFieldValue=function(a){"string"===typeof a&&(a=c.TYPES[a]);if("undefined"===typeof a.defaultValue)throw Error("default value for type "+a.name+" is not supported");return a==c.TYPES.bytes?new h(0):a.defaultValue};e.toString=function(){return(this.name||"")+(this.isMapKey?"map":"value")+" element"};e.verifyValue=function(a){function g(a, c){throw Error("Illegal value for "+b.toString(!0)+" of type "+b.type.name+": "+a+" ("+c+")");}var b=this;switch(this.type){case c.TYPES.int32:case c.TYPES.sint32:case c.TYPES.sfixed32:return("number"!==typeof a||a===a&&0!==a%1)&&g(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)&&g(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 d(a,!1)}catch(e){g(typeof a, e.message)}else g(typeof a,"requires Long.js");case c.TYPES.uint64:case c.TYPES.fixed64:if(c.Long)try{return d(a,!0)}catch(r){g(typeof a,r.message)}else g(typeof a,"requires Long.js");case c.TYPES.bool:return"boolean"!==typeof a&&g(typeof a,"not a boolean"),a;case c.TYPES["float"]:case c.TYPES["double"]:return"number"!==typeof a&&g(typeof a,"not a number"),a;case c.TYPES.string:return"string"===typeof a||a&&a instanceof String||g(typeof a,"not a string"),""+a;case c.TYPES.bytes:return h.isByteBuffer(a)? a:h.wrap(a,"base64");case c.TYPES["enum"]:for(var w=this.resolvedType.getChildren(c.Reflect.Enum.Value),f=0;f<w.length;f++)if(w[f].name==a||w[f].id==a)return w[f].id;if("proto3"===this.syntax)return("number"!==typeof a||a===a&&0!==a%1)&&g(typeof a,"not an integer"),(4294967295<a||0>a)&&g(typeof a,"not in range for uint32"),a;g(a,"not a valid enum value");case c.TYPES.group:case c.TYPES.message:a&&"object"===typeof a||g(typeof a,"object expected");if(a instanceof this.resolvedType.clazz)return a;if(a instanceof c.Builder.Message){var w={},f;for(f in a)a.hasOwnProperty(f)&&(w[f]=a[f]);a=w}return new this.resolvedType.clazz(a)}throw Error("[INTERNAL] Illegal value for "+this.toString(!0)+": "+a+" (undefined type "+this.type+")");};e.calculateLength=function(a,g){if(null===g)return 0;var b;switch(this.type){case c.TYPES.int32:return 0>g?h.calculateVarint64(g):h.calculateVarint32(g);case c.TYPES.uint32:return h.calculateVarint32(g);case c.TYPES.sint32:return h.calculateVarint32(h.zigZagEncode32(g));case c.TYPES.fixed32:case c.TYPES.sfixed32:case c.TYPES["float"]:return 4; case c.TYPES.int64:case c.TYPES.uint64:return h.calculateVarint64(g);case c.TYPES.sint64:return h.calculateVarint64(h.zigZagEncode64(g));case c.TYPES.fixed64:case c.TYPES.sfixed64:return 8;case c.TYPES.bool:return 1;case c.TYPES["enum"]:return h.calculateVarint32(g);case c.TYPES["double"]:return 8;case c.TYPES.string:return b=h.calculateUTF8Bytes(g),h.calculateVarint32(b)+b;case c.TYPES.bytes:if(0>g.remaining())throw Error("Illegal value for "+this.toString(!0)+": "+g.remaining()+" bytes remaining"); return h.calculateVarint32(g.remaining())+g.remaining();case c.TYPES.message:return b=this.resolvedType.calculate(g),h.calculateVarint32(b)+b;case c.TYPES.group:return b=this.resolvedType.calculate(g),b+h.calculateVarint32(a<<3|c.WIRE_TYPES.ENDGROUP)}throw Error("[INTERNAL] Illegal value to encode in "+this.toString(!0)+": "+g+" (unknown type)");};e.encodeValue=function(a,g,b){if(null===g)return b;switch(this.type){case c.TYPES.int32:0>g?b.writeVarint64(g):b.writeVarint32(g);break;case c.TYPES.uint32:b.writeVarint32(g); break;case c.TYPES.sint32:b.writeVarint32ZigZag(g);break;case c.TYPES.fixed32:b.writeUint32(g);break;case c.TYPES.sfixed32:b.writeInt32(g);break;case c.TYPES.int64:case c.TYPES.uint64:b.writeVarint64(g);break;case c.TYPES.sint64:b.writeVarint64ZigZag(g);break;case c.TYPES.fixed64:b.writeUint64(g);break;case c.TYPES.sfixed64:b.writeInt64(g);break;case c.TYPES.bool:"string"===typeof g?b.writeVarint32("false"===g.toLowerCase()?0:!!g):b.writeVarint32(g?1:0);break;case c.TYPES["enum"]:b.writeVarint32(g); break;case c.TYPES["float"]:b.writeFloat32(g);break;case c.TYPES["double"]:b.writeFloat64(g);break;case c.TYPES.string:b.writeVString(g);break;case c.TYPES.bytes:if(0>g.remaining())throw Error("Illegal value for "+this.toString(!0)+": "+g.remaining()+" bytes remaining");a=g.offset;b.writeVarint32(g.remaining());b.append(g);g.offset=a;break;case c.TYPES.message:a=(new h).LE();this.resolvedType.encode(g,a);b.writeVarint32(a.offset);b.append(a.flip());break;case c.TYPES.group:this.resolvedType.encode(g, b);b.writeVarint32(a<<3|c.WIRE_TYPES.ENDGROUP);break;default:throw Error("[INTERNAL] Illegal value to encode in "+this.toString(!0)+": "+g+" (unknown type)");}return b};e.decode=function(a,g,b){if(g!=this.type.wireType)throw Error("Unexpected wire type for element");switch(this.type){case c.TYPES.int32:return a.readVarint32()|0;case c.TYPES.uint32:return a.readVarint32()>>>0;case c.TYPES.sint32:return a.readVarint32ZigZag()|0;case c.TYPES.fixed32:return a.readUint32()>>>0;case c.TYPES.sfixed32:return a.readInt32()| 0;case c.TYPES.int64:return a.readVarint64();case c.TYPES.uint64:return a.readVarint64().toUnsigned();case c.TYPES.sint64:return a.readVarint64ZigZag();case c.TYPES.fixed64:return a.readUint64();case c.TYPES.sfixed64:return a.readInt64();case c.TYPES.bool:return!!a.readVarint32();case c.TYPES["enum"]:return a.readVarint32();case c.TYPES["float"]:return a.readFloat();case c.TYPES["double"]:return a.readDouble();case c.TYPES.string:return a.readVString();case c.TYPES.bytes:b=a.readVarint32();if(a.remaining()< b)throw Error("Illegal number of bytes for "+this.toString(!0)+": "+b+" required but got only "+a.remaining());g=a.clone();g.limit=g.offset+b;a.offset+=b;return g;case c.TYPES.message:return b=a.readVarint32(),this.resolvedType.decode(a,b);case c.TYPES.group:return this.resolvedType.decode(a,-1,b)}throw Error("[INTERNAL] Illegal decode type");};e.valueFromString=function(a){if(!this.isMapKey)throw Error("valueFromString() called on non-map-key element");switch(this.type){case c.TYPES.int32:case c.TYPES.sint32:case c.TYPES.sfixed32:case c.TYPES.uint32:case c.TYPES.fixed32:return this.verifyValue(parseInt(a)); case c.TYPES.int64:case c.TYPES.sint64:case c.TYPES.sfixed64:case c.TYPES.uint64:case c.TYPES.fixed64:return this.verifyValue(a);case c.TYPES.bool:return"true"===a;case c.TYPES.string:return this.verifyValue(a);case c.TYPES.bytes:return h.fromBinary(a)}};e.valueToString=function(a){if(!this.isMapKey)throw Error("valueToString() called on non-map-key element");return this.type===c.TYPES.bytes?a.toString("binary"):a.toString()};n.Element=l;var t=function(a,c,d,e,r,f){b.call(this,a,c,d,e,f);this.className= "Message";this.extensions=void 0;this.clazz=null;this.isGroup=!!r;this._fieldsByName=this._fieldsById=this._fields=null},e=t.prototype=Object.create(b.prototype);e.build=function(a){if(this.clazz&&!a)return this.clazz;a=function(a,c){function g(c,b,d,e){if(null===c||"object"!==typeof c){if(e&&e instanceof a.Reflect.Enum){var m=a.Reflect.Enum.getName(e.object,c);if(null!==m)return m}return c}if(h.isByteBuffer(c))return b?c.toBase64():c.toBuffer();if(a.Long.isLong(c))return d?c.toString():a.Long.fromValue(c); var f;if(Array.isArray(c))return f=[],c.forEach(function(a,c){f[c]=g(a,b,d,e)}),f;f={};if(c instanceof a.Map){for(var m=c.entries(),l=m.next();!l.done;l=m.next())f[c.keyElem.valueToString(l.value[0])]=g(l.value[1],b,d,c.valueElem.resolvedType);return f}var m=c.$type,l=void 0,q;for(q in c)c.hasOwnProperty(q)&&(m&&(l=m.getChild(q))?f[q]=g(c[q],b,d,l.resolvedType):f[q]=g(c[q],b,d));return f}var b=c.getChildren(a.Reflect.Message.Field),d=c.getChildren(a.Reflect.Message.OneOf),m=function(g,e){a.Builder.Message.call(this); for(var f=0,l=d.length;f<l;++f)this[d[f].name]=null;f=0;for(l=b.length;f<l;++f){var q=b[f];this[q.name]=q.repeated?[]:q.map?new a.Map(q):null;!q.required&&"proto3"!==c.syntax||null===q.defaultValue||(this[q.name]=q.defaultValue)}if(0<arguments.length)if(1!==arguments.length||null===g||"object"!==typeof g||!("function"!==typeof g.encode||g instanceof m)||Array.isArray(g)||g instanceof a.Map||h.isByteBuffer(g)||g instanceof ArrayBuffer||a.Long&&g instanceof a.Long)for(f=0,l=arguments.length;f<l;++f)"undefined"!== typeof(q=arguments[f])&&this.$set(b[f].name,q);else this.$set(g)},e=m.prototype=Object.create(a.Builder.Message.prototype);e.add=function(g,b,d){var e=c._fieldsByName[g];if(!d){if(!e)throw Error(this+"#"+g+" is undefined");if(!(e instanceof a.Reflect.Message.Field))throw Error(this+"#"+g+" is not a field: "+e.toString(!0));if(!e.repeated)throw Error(this+"#"+g+" is not a repeated field");b=e.verifyValue(b,!0)}null===this[g]&&(this[g]=[]);this[g].push(b);return this};e.$add=e.add;e.set=function(g, b,e){if(g&&"object"===typeof g){e=b;for(var d in g)g.hasOwnProperty(d)&&"undefined"!==typeof(b=g[d])&&this.$set(d,b,e);return this}d=c._fieldsByName[g];if(e)this[g]=b;else{if(!d)throw Error(this+"#"+g+" is not a field: undefined");if(!(d instanceof a.Reflect.Message.Field))throw Error(this+"#"+g+" is not a field: "+d.toString(!0));this[d.name]=b=d.verifyValue(b)}d&&d.oneof&&(e=this[d.oneof.name],null!==b?(null!==e&&e!==d.name&&(this[e]=null),this[d.oneof.name]=d.name):e===g&&(this[d.oneof.name]=null)); return this};e.$set=e.set;e.get=function(g,b){if(b)return this[g];var d=c._fieldsByName[g];if(!(d&&d instanceof a.Reflect.Message.Field))throw Error(this+"#"+g+" is not a field: undefined");if(!(d instanceof a.Reflect.Message.Field))throw Error(this+"#"+g+" is not a field: "+d.toString(!0));return this[d.name]};e.$get=e.get;for(var f=0;f<b.length;f++){var l=b[f];l instanceof a.Reflect.Message.ExtensionField||c.builder.options.populateAccessors&&function(a){var g=a.originalName.replace(/(_[a-zA-Z])/g, function(a){return a.toUpperCase().replace("_","")}),g=g.substring(0,1).toUpperCase()+g.substring(1),b=a.originalName.replace(/([A-Z])/g,function(a){return"_"+a}),d=function(c,g){this[a.name]=g?c:a.verifyValue(c);return this},m=function(){return this[a.name]};null===c.getChild("set"+g)&&(e["set"+g]=d);null===c.getChild("set_"+b)&&(e["set_"+b]=d);null===c.getChild("get"+g)&&(e["get"+g]=m);null===c.getChild("get_"+b)&&(e["get_"+b]=m)}(l)}e.encode=function(a,g){"boolean"===typeof a&&(g=a,a=void 0);var b= !1;a||(a=new h,b=!0);var d=a.littleEndian;try{return c.encode(this,a.LE(),g),(b?a.flip():a).LE(d)}catch(e){throw a.LE(d),e;}};m.encode=function(a,c,g){return(new m(a)).encode(c,g)};e.calculate=function(){return c.calculate(this)};e.encodeDelimited=function(a,g){var b=!1;a||(a=new h,b=!0);var d=(new h).LE();c.encode(this,d,g).flip();a.writeVarint32(d.remaining());a.append(d);return b?a.flip():a};e.encodeAB=function(){try{return this.encode().toArrayBuffer()}catch(a){throw a.encoded&&(a.encoded=a.encoded.toArrayBuffer()), a;}};e.toArrayBuffer=e.encodeAB;e.encodeNB=function(){try{return this.encode().toBuffer()}catch(a){throw a.encoded&&(a.encoded=a.encoded.toBuffer()),a;}};e.toBuffer=e.encodeNB;e.encode64=function(){try{return this.encode().toBase64()}catch(a){throw a.encoded&&(a.encoded=a.encoded.toBase64()),a;}};e.toBase64=e.encode64;e.encodeHex=function(){try{return this.encode().toHex()}catch(a){throw a.encoded&&(a.encoded=a.encoded.toHex()),a;}};e.toHex=e.encodeHex;e.toRaw=function(a,c){return g(this,!!a,!!c, this.$type)};e.encodeJSON=function(){return JSON.stringify(g(this,!0,!0,this.$type))};m.decode=function(a,g,b){"string"===typeof g&&(b=g,g=-1);"string"===typeof a?a=h.wrap(a,b?b:"base64"):h.isByteBuffer(a)||(a=h.wrap(a));b=a.littleEndian;try{var d=c.decode(a.LE(),g);a.LE(b);return d}catch(e){throw a.LE(b),e;}};m.decodeDelimited=function(a,g){"string"===typeof a?a=h.wrap(a,g?g:"base64"):h.isByteBuffer(a)||(a=h.wrap(a));if(1>a.remaining())return null;var b=a.offset,d=a.readVarint32();if(a.remaining()< d)return a.offset=b,null;try{var e=c.decode(a.slice(a.offset,a.offset+d).LE());a.offset+=d;return e}catch(m){throw a.offset+=d,m;}};m.decode64=function(a){return m.decode(a,"base64")};m.decodeHex=function(a){return m.decode(a,"hex")};m.decodeJSON=function(a){return new m(JSON.parse(a))};e.toString=function(){return c.toString()};Object.defineProperty&&(Object.defineProperty(m,"$options",{value:c.buildOpt()}),Object.defineProperty(e,"$options",{value:m.$options}),Object.defineProperty(m,"$type",{value:c}), Object.defineProperty(e,"$type",{value:c}));return m}(c,this);this._fields=[];this._fieldsById={};this._fieldsByName={};for(var g=0,b=this.children.length,d;g<b;g++)if(d=this.children[g],d instanceof x||d instanceof t||d instanceof A){if(a.hasOwnProperty(d.name))throw Error("Illegal reflect child of "+this.toString(!0)+": "+d.toString(!0)+" cannot override static property '"+d.name+"'");a[d.name]=d.build()}else if(d instanceof t.Field)d.build(),this._fields.push(d),this._fieldsById[d.id]=d,this._fieldsByName[d.name]= d;else if(!(d instanceof t.OneOf||d instanceof u))throw Error("Illegal reflect child of "+this.toString(!0)+": "+this.children[g].toString(!0));return this.clazz=a};e.encode=function(a,c,b){for(var d=null,e,f=0,l=this._fields.length,h;f<l;++f)e=this._fields[f],h=a[e.name],e.required&&null===h?null===d&&(d=e):e.encode(b?h:e.verifyValue(h),c,a);if(null!==d)throw a=Error("Missing at least one required field for "+this.toString(!0)+": "+d),a.encoded=c,a;return c};e.calculate=function(a){for(var c=0,b= 0,d=this._fields.length,e,f;b<d;++b){e=this._fields[b];f=a[e.name];if(e.required&&null===f)throw Error("Missing at least one required field for "+this.toString(!0)+": "+e);c+=e.calculate(f,a)}return c};e.decode=function(a,g,b){"number"!==typeof g&&(g=-1);for(var d=a.offset,e=new this.clazz,f,l,h;a.offset<d+g||-1===g&&0<a.remaining();){f=a.readVarint32();l=f&7;h=f>>>3;if(l===c.WIRE_TYPES.ENDGROUP){if(h!==b)throw Error("Illegal group end indicator for "+this.toString(!0)+": "+h+" ("+(b?b+" expected": "not a group")+")");break}if(f=this._fieldsById[h])f.repeated&&!f.options.packed?e[f.name].push(f.decode(l,a)):f.map?(l=f.decode(l,a),e[f.name].set(l[0],l[1])):(e[f.name]=f.decode(l,a),f.oneof&&(l=e[f.oneof.name],null!==l&&l!==f.name&&(e[l]=null),e[f.oneof.name]=f.name));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:f=a.readVarint32();a.offset+=f;break;case c.WIRE_TYPES.STARTGROUP:for(;s(h, a););break;default:throw Error("Illegal wire type for unknown field "+h+" in "+this.toString(!0)+"#decode: "+l);}}a=0;for(g=this._fields.length;a<g;++a)if(f=this._fields[a],null===e[f.name])if("proto3"===this.syntax)e[f.name]=f.defaultValue;else{if(f.required)throw a=Error("Missing at least one required field for "+this.toString(!0)+": "+f.name),a.decoded=e,a;c.populateDefaults&&null!==f.defaultValue&&(e[f.name]=f.defaultValue)}return e};n.Message=t;var z=function(a,g,b,d,e,f,l,h,u,p){k.call(this, a,g,f);this.className="Message.Field";this.required="required"===b;this.repeated="repeated"===b;this.map="map"===b;this.keyType=d||null;this.type=e;this.resolvedType=null;this.id=l;this.options=h||{};this.defaultValue=null;this.oneof=u||null;this.syntax=p||"proto2";this.originalName=this.name;this.keyElement=this.element=null;!this.builder.options.convertFieldsToCamelCase||this instanceof t.ExtensionField||(this.name=c.Util.toCamelCase(this.name))},e=z.prototype=Object.create(k.prototype);e.build= function(){this.element=new l(this.type,this.resolvedType,!1,this.syntax,this.name);this.map&&(this.keyElement=new l(this.keyType,void 0,!0,this.syntax,this.name));"proto3"!==this.syntax||this.repeated||this.map?"undefined"!==typeof this.options["default"]&&(this.defaultValue=this.verifyValue(this.options["default"])):this.defaultValue=l.defaultFieldValue(this.type)};e.verifyValue=function(a,g){function b(a,c){throw Error("Illegal value for "+d.toString(!0)+" of type "+d.type.name+": "+a+" ("+c+")"); }g=g||!1;var d=this;if(null===a)return this.required&&b(typeof a,"required"),"proto3"===this.syntax&&this.type!==c.TYPES.message&&b(typeof a,"proto3 field without field presence cannot be null"),null;var e;if(this.repeated&&!g){Array.isArray(a)||(a=[a]);var f=[];for(e=0;e<a.length;e++)f.push(this.element.verifyValue(a[e]));return f}if(this.map&&!g){if(a instanceof c.Map)return a;a instanceof Object||b(typeof a,"expected ProtoBuf.Map or raw object for map field");return new c.Map(this,a)}!this.repeated&& Array.isArray(a)&&b(typeof a,"no array expected");return this.element.verifyValue(a)};e.hasWirePresence=function(a,b){if("proto3"!==this.syntax)return null!==a;if(this.oneof&&b[this.oneof.name]===this.name)return!0;switch(this.type){case c.TYPES.int32:case c.TYPES.sint32:case c.TYPES.sfixed32:case c.TYPES.uint32:case c.TYPES.fixed32:return 0!==a;case c.TYPES.int64:case c.TYPES.sint64:case c.TYPES.sfixed64:case c.TYPES.uint64:case c.TYPES.fixed64:return 0!==a.low||0!==a.high;case c.TYPES.bool:return a; case c.TYPES["float"]:case c.TYPES["double"]:return 0!==a;case c.TYPES.string:return 0<a.length;case c.TYPES.bytes:return 0<a.remaining();case c.TYPES["enum"]:return 0!==a;case c.TYPES.message:return null!==a;default:return!0}};e.encode=function(a,b,d){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 e;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 f=b.offset;for(e=0;e<a.length;e++)this.element.encodeValue(this.id,a[e],b);var l=b.offset-f,u=h.calculateVarint32(l);if(1<u){var t=b.slice(f,b.offset),f=f+(u-1);b.offset=f;b.append(t)}b.writeVarint32(l,f-u)}else for(e=0;e<a.length;e++)b.writeVarint32(this.id<<3|this.type.wireType),this.element.encodeValue(this.id,a[e],b)}else this.map?a.forEach(function(a,e,d){d=h.calculateVarint32(8|this.keyType.wireType)+this.keyElement.calculateLength(1, e)+h.calculateVarint32(16|this.type.wireType)+this.element.calculateLength(2,a);b.writeVarint32(this.id<<3|c.WIRE_TYPES.LDELIM);b.writeVarint32(d);b.writeVarint32(8|this.keyType.wireType);this.keyElement.encodeValue(1,e,b);b.writeVarint32(16|this.type.wireType);this.element.encodeValue(2,a,b)},this):this.hasWirePresence(a,d)&&(b.writeVarint32(this.id<<3|this.type.wireType),this.element.encodeValue(this.id,a,b))}catch(k){throw Error("Illegal value for "+this.toString(!0)+": "+a+" ("+k+")");}return b}; e.calculate=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 0;var e=0;try{if(this.repeated){var d,f;if(this.options.packed&&0<=c.PACKABLE_WIRE_TYPES.indexOf(this.type.wireType)){e+=h.calculateVarint32(this.id<<3|c.WIRE_TYPES.LDELIM);for(d=f=0;d<a.length;d++)f+=this.element.calculateLength(this.id,a[d]);e+=h.calculateVarint32(f);e+=f}else for(d= 0;d<a.length;d++)e+=h.calculateVarint32(this.id<<3|this.type.wireType),e+=this.element.calculateLength(this.id,a[d])}else this.map?a.forEach(function(a,b,g){a=h.calculateVarint32(8|this.keyType.wireType)+this.keyElement.calculateLength(1,b)+h.calculateVarint32(16|this.type.wireType)+this.element.calculateLength(2,a);e+=h.calculateVarint32(this.id<<3|c.WIRE_TYPES.LDELIM);e+=h.calculateVarint32(a);e+=a},this):this.hasWirePresence(a,b)&&(e+=h.calculateVarint32(this.id<<3|this.type.wireType),e+=this.element.calculateLength(this.id, a))}catch(l){throw Error("Illegal value for "+this.toString(!0)+": "+a+" ("+l+")");}return e};e.decode=function(a,b,e){if(!(!this.map&&a==this.type.wireType||!e&&this.repeated&&this.options.packed&&a==c.WIRE_TYPES.LDELIM||this.map&&a==c.WIRE_TYPES.LDELIM))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)&&!e){a=b.readVarint32(); a=b.offset+a;for(e=[];b.offset<a;)e.push(this.decode(this.type.wireType,b,!0));return e}if(this.map){var d=l.defaultFieldValue(this.keyType);e=l.defaultFieldValue(this.type);a=b.readVarint32();if(b.remaining()<a)throw Error("Illegal number of bytes for "+this.toString(!0)+": "+a+" required but got only "+b.remaining());var f=b.clone();f.limit=f.offset+a;for(b.offset+=a;0<f.remaining();)if(b=f.readVarint32(),a=b&7,b>>>=3,1===b)d=this.keyElement.decode(f,a,b);else if(2===b)e=this.element.decode(f,a, b);else throw Error("Unexpected tag in map field key/value submessage");return[d,e]}return this.element.decode(b,a,this.id)};n.Message.Field=z;e=function(a,b,c,e,d,f,l){z.call(this,a,b,c,null,e,d,f,l)};e.prototype=Object.create(z.prototype);n.Message.ExtensionField=e;n.Message.OneOf=function(a,b,c){k.call(this,a,b,c);this.fields=[]};var x=function(a,c,e,d,f){b.call(this,a,c,e,d,f);this.className="Enum";this.object=null};x.getName=function(a,b){for(var c=Object.keys(a),e=0,d;e<c.length;++e)if(a[d= c[e]]===b)return d;return null};(x.prototype=Object.create(b.prototype)).build=function(a){if(this.object&&!a)return this.object;a=new c.Builder.Enum;for(var b=this.getChildren(x.Value),e=0,d=b.length;e<d;++e)a[b[e].name]=b[e].id;Object.defineProperty&&Object.defineProperty(a,"$options",{value:this.buildOpt(),enumerable:!1});return this.object=a};n.Enum=x;e=function(a,b,c,e){k.call(this,a,b,c);this.className="Enum.Value";this.id=e};e.prototype=Object.create(k.prototype);n.Enum.Value=e;var u=function(a, b,c,e){k.call(this,a,b,c);this.field=e};u.prototype=Object.create(k.prototype);n.Extension=u;var A=function(a,c,e,d){b.call(this,a,c,e,d);this.className="Service";this.clazz=null};(A.prototype=Object.create(b.prototype)).build=function(a){return this.clazz&&!a?this.clazz:this.clazz=function(a,b){for(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)}},e=c.prototype= Object.create(a.Builder.Service.prototype),d=b.getChildren(a.Reflect.Service.RPCMethod),f=0;f<d.length;f++)(function(a){e[a.name]=function(c,e){try{try{c=a.resolvedRequestType.clazz.decode(h.wrap(c))}catch(d){if(!(d instanceof TypeError))throw d;}if(null===c||"object"!==typeof c)throw Error("Illegal arguments");c instanceof a.resolvedRequestType.clazz||(c=new a.resolvedRequestType.clazz(c));this.rpcImpl(a.fqn(),c,function(c,d){if(c)e(c);else{null===d&&(d="");try{d=a.resolvedResponseType.clazz.decode(d)}catch(g){}d&& d instanceof a.resolvedResponseType.clazz?e(null,d):e(Error("Illegal response type received in service method "+b.name+"#"+a.name))}})}catch(g){setTimeout(e.bind(this,g),0)}};c[a.name]=function(b,e,d){(new c(b))[a.name](e,d)};Object.defineProperty&&(Object.defineProperty(c[a.name],"$options",{value:a.buildOpt()}),Object.defineProperty(e[a.name],"$options",{value:c[a.name].$options}))})(d[f]);Object.defineProperty&&(Object.defineProperty(c,"$options",{value:b.buildOpt()}),Object.defineProperty(e,"$options", {value:c.$options}),Object.defineProperty(c,"$type",{value:b}),Object.defineProperty(e,"$type",{value:b}));return c}(c,this)};n.Service=A;var v=function(a,b,c,e){k.call(this,a,b,c);this.className="Service.Method";this.options=e||{}};(v.prototype=Object.create(k.prototype)).buildOpt=f.buildOpt;n.Service.Method=v;f=function(a,b,c,e,d,f,l,h){v.call(this,a,b,c,h);this.className="Service.RPCMethod";this.requestName=e;this.responseName=d;this.requestStream=f;this.responseStream=l;this.resolvedResponseType= this.resolvedRequestType=null};f.prototype=Object.create(v.prototype);n.Service.RPCMethod=f;return n}(d);d.Builder=function(c,d,h){function n(b){b.messages&&b.messages.forEach(function(c){c.syntax=b.syntax;n(c)});b.enums&&b.enums.forEach(function(c){c.syntax=b.syntax})}var k=function(b){this.ptr=this.ns=new h.Namespace(this,null,"");this.resolved=!1;this.result=null;this.files={};this.importRoot=null;this.options=b||{}},f=k.prototype;k.isMessage=function(b){return"string"!==typeof b.name||"undefined"!== typeof b.values||"undefined"!==typeof b.rpc?!1:!0};k.isMessageField=function(b){return"string"!==typeof b.rule||"string"!==typeof b.name||"string"!==typeof b.type||"undefined"===typeof b.id?!1:!0};k.isEnum=function(b){return"string"===typeof b.name&&"undefined"!==typeof b.values&&Array.isArray(b.values)&&0!==b.values.length?!0:!1};k.isService=function(b){return"string"===typeof b.name&&"object"===typeof b.rpc&&b.rpc?!0:!1};k.isExtend=function(b){return"string"!==typeof b.ref?!1:!0};f.reset=function(){this.ptr= this.ns;return this};f.define=function(b){if("string"!==typeof b||!d.TYPEREF.test(b))throw Error("illegal namespace: "+b);b.split(".").forEach(function(b){var c=this.ptr.getChild(b);null===c&&this.ptr.addChild(c=new h.Namespace(this,this.ptr,b));this.ptr=c},this);return this};f.create=function(b){if(!b)return this;if(Array.isArray(b)){if(0===b.length)return this;b=b.slice()}else b=[b];for(var d=[b];0<d.length;){b=d.pop();if(!Array.isArray(b))throw Error("not a valid namespace: "+JSON.stringify(b)); for(;0<b.length;){var e=b.shift();if(k.isMessage(e)){var f=new h.Message(this,this.ptr,e.name,e.options,e.isGroup,e.syntax),n={};e.oneofs&&Object.keys(e.oneofs).forEach(function(b){f.addChild(n[b]=new h.Message.OneOf(this,f,b))},this);e.fields&&e.fields.forEach(function(b){if(null!==f.getChild(b.id|0))throw Error("duplicate or invalid field id in "+f.name+": "+b.id);if(b.options&&"object"!==typeof b.options)throw Error("illegal field options in "+f.name+"#"+b.name);var c=null;if("string"===typeof b.oneof&& !(c=n[b.oneof]))throw Error("illegal oneof in "+f.name+"#"+b.name+": "+b.oneof);b=new h.Message.Field(this,f,b.rule,b.keytype,b.type,b.name,b.id,b.options,c,e.syntax);c&&c.fields.push(b);f.addChild(b)},this);var p=[];e.enums&&e.enums.forEach(function(b){p.push(b)});e.messages&&e.messages.forEach(function(b){p.push(b)});e.services&&e.services.forEach(function(b){p.push(b)});e.extensions&&(f.extensions="number"===typeof e.extensions[0]?[e.extensions]:e.extensions);this.ptr.addChild(f);if(0<p.length){d.push(b); b=p;p=null;this.ptr=f;f=null;continue}p=null}else if(k.isEnum(e))f=new h.Enum(this,this.ptr,e.name,e.options,e.syntax),e.values.forEach(function(b){f.addChild(new h.Enum.Value(this,f,b.name,b.id))},this),this.ptr.addChild(f);else if(k.isService(e))f=new h.Service(this,this.ptr,e.name,e.options),Object.keys(e.rpc).forEach(function(b){var c=e.rpc[b];f.addChild(new h.Service.RPCMethod(this,f,b,c.request,c.response,!!c.request_stream,!!c.response_stream,c.options))},this),this.ptr.addChild(f);else if(k.isExtend(e))if(f= this.ptr.resolve(e.ref,!0))e.fields.forEach(function(b){if(null!==f.getChild(b.id|0))throw Error("duplicate extended field id in "+f.name+": "+b.id);if(f.extensions){var e=!1;f.extensions.forEach(function(a){b.id>=a[0]&&b.id<=a[1]&&(e=!0)});if(!e)throw Error("illegal extended field id in "+f.name+": "+b.id+" (not within valid ranges)");}var d=b.name;this.options.convertFieldsToCamelCase&&(d=c.Util.toCamelCase(d));var d=new h.Message.ExtensionField(this,f,b.rule,b.type,this.ptr.fqn()+"."+d,b.id,b.options), a=new h.Extension(this,this.ptr,b.name,d);d.extension=a;this.ptr.addChild(a);f.addChild(d)},this);else{if(!/\.?google\.protobuf\./.test(e.ref))throw Error("extended message "+e.ref+" is not defined");}else throw Error("not a valid definition: "+JSON.stringify(e));f=e=null}b=null;this.ptr=this.ptr.parent}this.resolved=!1;this.result=null;return this};f["import"]=function(b,d){var e="/";if("string"===typeof d){c.Util.IS_NODE&&(d=require("path").resolve(d));if(!0===this.files[d])return this.reset(); this.files[d]=!0}else if("object"===typeof d){var f=d.root;c.Util.IS_NODE&&(f=require("path").resolve(f));if(0<=f.indexOf("\\")||0<=d.file.indexOf("\\"))e="\\";f=f+e+d.file;if(!0===this.files[f])return this.reset();this.files[f]=!0}if(b.imports&&0<b.imports.length){var h=!1;if("object"===typeof d){if(this.importRoot=d.root,h=!0,f=this.importRoot,d=d.file,0<=f.indexOf("\\")||0<=d.indexOf("\\"))e="\\"}else"string"===typeof d?this.importRoot?f=this.importRoot:0<=d.indexOf("/")?(f=d.replace(/\/[^\/]*$/, ""),""===f&&(f="/")):0<=d.indexOf("\\")?(f=d.replace(/\\[^\\]*$/,""),e="\\"):f=".":f=null;for(var k=0;k<b.imports.length;k++)if("string"===typeof b.imports[k]){if(!f)throw Error("cannot determine import root");var p=b.imports[k];if("google/protobuf/descriptor.proto"!==p&&(p=f+e+p,!0!==this.files[p])){/\.proto$/i.test(p)&&!c.DotProto&&(p=p.replace(/\.proto$/,".json"));var s=c.Util.fetch(p);if(null===s)throw Error("failed to import '"+p+"' in '"+d+"': file not found");if(/\.json$/i.test(p))this["import"](JSON.parse(s+ ""),p);else this["import"](c.DotProto.Parser.parse(s),p)}}else if(d)if(/\.(\w+)$/.test(d))this["import"](b.imports[k],d.replace(/^(.+)\.(\w+)$/,function(a,b,c){return b+"_import"+k+"."+c}));else this["import"](b.imports[k],d+"_import"+k);else this["import"](b.imports[k]);h&&(this.importRoot=null)}b["package"]&&this.define(b["package"]);b.syntax&&n(b);var v=this.ptr;b.options&&Object.keys(b.options).forEach(function(a){v.options[a]=b.options[a]});b.messages&&(this.create(b.messages),this.ptr=v);b.enums&& (this.create(b.enums),this.ptr=v);b.services&&(this.create(b.services),this.ptr=v);b["extends"]&&this.create(b["extends"]);return this.reset()};f.resolveAll=function(){var b;if(null==this.ptr||"object"===typeof this.ptr.type)return this;if(this.ptr instanceof h.Namespace)this.ptr.children.forEach(function(b){this.ptr=b;this.resolveAll()},this);else if(this.ptr instanceof h.Message.Field){if(d.TYPE.test(this.ptr.type))this.ptr.type=c.TYPES[this.ptr.type];else{if(!d.TYPEREF.test(this.ptr.type))throw Error("illegal type reference in "+ this.ptr.toString(!0)+": "+this.ptr.type);b=(this.ptr instanceof h.Message.ExtensionField?this.ptr.extension.parent: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 h.Enum){if(this.ptr.type=c.TYPES["enum"],"proto3"===this.ptr.syntax&&"proto3"!==b.syntax)throw Error("proto3 message cannot reference proto2 enum");}else if(b instanceof h.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);}if(this.ptr.map){if(!d.TYPE.test(this.ptr.keyType))throw Error("illegal key type for map field in "+this.ptr.toString(!0)+": "+this.ptr.keyType);this.ptr.keyType=c.TYPES[this.ptr.keyType]}}else if(this.ptr instanceof c.Reflect.Service.Method)if(this.ptr instanceof c.Reflect.Service.RPCMethod){b=this.ptr.parent.resolve(this.ptr.requestName,!0);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,!0);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 if(!(this.ptr instanceof c.Reflect.Message.OneOf||this.ptr instanceof c.Reflect.Extension||this.ptr instanceof c.Reflect.Enum.Value))throw Error("illegal object in namespace: "+ typeof this.ptr+": "+this.ptr);return this.reset()};f.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)return this.result;b="string"===typeof b?b.split("."):b;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};f.lookup=function(b,c){return b?this.ns.resolve(b,c):this.ns};f.toString=function(){return"Builder"};k.Message=function(){};k.Enum=function(){};k.Service= function(){};return k}(d,d.Lang,d.Reflect);d.Map=function(c,d){function h(c){var b=0;return{next:function(){return b<c.length?{done:!1,value:c[b++]}:{done:!0}}}}var n=function(c,b){if(!c.map)throw Error("field is not a map");this.field=c;this.keyElem=new d.Element(c.keyType,null,!0,c.syntax);this.valueElem=new d.Element(c.type,c.resolvedType,!1,c.syntax);this.map={};Object.defineProperty(this,"size",{get:function(){return Object.keys(this.map).length}});if(b)for(var h=Object.keys(b),e=0;e<h.length;e++){var k= this.keyElem.valueFromString(h[e]),n=this.valueElem.verifyValue(b[h[e]]);this.map[this.keyElem.valueToString(k)]={key:k,value:n}}},k=n.prototype;k.clear=function(){this.map={}};k["delete"]=function(c){c=this.keyElem.valueToString(this.keyElem.verifyValue(c));var b=c in this.map;delete this.map[c];return b};k.entries=function(){for(var c=[],b=Object.keys(this.map),d=0,e;d<b.length;d++)c.push([(e=this.map[b[d]]).key,e.value]);return h(c)};k.keys=function(){for(var c=[],b=Object.keys(this.map),d=0;d< b.length;d++)c.push(this.map[b[d]].key);return h(c)};k.values=function(){for(var c=[],b=Object.keys(this.map),d=0;d<b.length;d++)c.push(this.map[b[d]].value);return h(c)};k.forEach=function(c,b){for(var d=Object.keys(this.map),e=0,h;e<d.length;e++)c.call(b,(h=this.map[d[e]]).value,h.key,this)};k.set=function(c,b){var d=this.keyElem.verifyValue(c),e=this.valueElem.verifyValue(b);this.map[this.keyElem.valueToString(d)]={key:d,value:e};return this};k.get=function(c){c=this.keyElem.valueToString(this.keyElem.verifyValue(c)); return c in this.map?this.map[c].value:void 0};k.has=function(c){return this.keyElem.valueToString(this.keyElem.verifyValue(c))in this.map};return n}(d,d.Reflect);d.newBuilder=function(c){c=c||{};"undefined"===typeof c.convertFieldsToCamelCase&&(c.convertFieldsToCamelCase=d.convertFieldsToCamelCase);"undefined"===typeof c.populateAccessors&&(c.populateAccessors=d.populateAccessors);return new d.Builder(c)};d.loadJson=function(c,h,s){if("string"===typeof h||h&&"string"===typeof h.file&&"string"=== typeof h.root)s=h,h=null;h&&"object"===typeof h||(h=d.newBuilder());"string"===typeof c&&(c=JSON.parse(c));h["import"](c,s);h.resolveAll();return h};d.loadJsonFile=function(c,h,s){h&&"object"===typeof h?(s=h,h=null):h&&"function"===typeof h||(h=null);if(h)return d.Util.fetch("string"===typeof c?c:c.root+"/"+c.file,function(k){if(null===k)h(Error("Failed to fetch file"));else try{h(null,d.loadJson(JSON.parse(k),s,c))}catch(f){h(f)}});var n=d.Util.fetch("object"===typeof c?c.root+"/"+c.file:c);return null=== n?null:d.loadJson(JSON.parse(n),s,c)};return d});