diff --git a/dist/protobuf-light.js b/dist/protobuf-light.js index a8843426f..94a5640cb 100644 --- a/dist/protobuf-light.js +++ b/dist/protobuf-light.js @@ -3791,18 +3791,28 @@ var importFilename = json['imports'][i]; if (importFilename === "google/protobuf/descriptor.proto") continue; // Not needed and therefore not used - importFilename = importRoot + delim + importFilename; - if (this.files[importFilename] === true) - continue; // Already imported - if (/\.proto$/i.test(importFilename) && !ProtoBuf.DotProto) // If this is a light build - importFilename = importFilename.replace(/\.proto$/, ".json"); // always load the JSON file - var contents = ProtoBuf.Util.fetch(importFilename); - if (contents === null) - throw Error("failed to import '"+importFilename+"' in '"+filename+"': file not found"); - if (/\.json$/i.test(importFilename)) // Always possible - this["import"](JSON.parse(contents+""), importFilename); // May throw - else - this["import"](ProtoBuf.DotProto.Parser.parse(contents), importFilename); // May throw + var tmpImportRoot = importRoot; + var tmpImportPathIndex = 0; + while (true) { + var tmpImportFilename = tmpImportRoot + delim + importFilename; + if (this.files[tmpImportFilename] === true) + break; // Already imported + if (/\.proto$/i.test(tmpImportFilename) && !ProtoBuf.DotProto) // If this is a light build + tmpImportFilename = tmpImportFilename.replace(/\.proto$/, ".json"); // always load the JSON file + var contents = ProtoBuf.Util.fetch(tmpImportFilename); + if (contents === null) { + if (this.options.includePath && this.options.includePath.length > tmpImportPathIndex) { + tmpImportRoot = this.options.includePath[tmpImportPathIndex++]; + continue; + } + throw Error("failed to import '"+(importRoot + delim + importFilename)+"' in '"+filename+"': file not found"); + } + if (/\.json$/i.test(tmpImportFilename)) // Always possible + this["import"](JSON.parse(contents+""), tmpImportFilename); // May throw + else + this["import"](ProtoBuf.DotProto.Parser.parse(contents), tmpImportFilename); // May throw + break; + } } else // Import structure if (!filename) this["import"](json['imports'][i]); diff --git a/dist/protobuf-light.min.js b/dist/protobuf-light.min.js index 5f6306a1f..cb289fa98 100644 --- a/dist/protobuf-light.min.js +++ b/dist/protobuf-light.min.js @@ -3,86 +3,92 @@ 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= +var $jscomp={scope:{}};$jscomp.defineProperty="function"==typeof Object.defineProperties?Object.defineProperty:function(e,n,d){if(d.get||d.set)throw new TypeError("ES3 does not support getters and setters.");e!=Array.prototype&&e!=Object.prototype&&(e[n]=d.value)};$jscomp.getGlobal=function(e){return"undefined"!=typeof window&&window===e?e:"undefined"!=typeof global&&null!=global?global:e};$jscomp.global=$jscomp.getGlobal(this);$jscomp.SYMBOL_PREFIX="jscomp_symbol_"; +$jscomp.initSymbol=function(){$jscomp.initSymbol=function(){};$jscomp.global.Symbol||($jscomp.global.Symbol=$jscomp.Symbol)};$jscomp.symbolCounter_=0;$jscomp.Symbol=function(e){return $jscomp.SYMBOL_PREFIX+(e||"")+$jscomp.symbolCounter_++}; +$jscomp.initSymbolIterator=function(){$jscomp.initSymbol();var e=$jscomp.global.Symbol.iterator;e||(e=$jscomp.global.Symbol.iterator=$jscomp.global.Symbol("iterator"));"function"!=typeof Array.prototype[e]&&$jscomp.defineProperty(Array.prototype,e,{configurable:!0,writable:!0,value:function(){return $jscomp.arrayIterator(this)}});$jscomp.initSymbolIterator=function(){}};$jscomp.arrayIterator=function(e){var n=0;return $jscomp.iteratorPrototype(function(){return n]/g,RULE:/^(?:required|optional|repeated|map)$/, +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,e=0;e]/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(b){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 b.Long(a.low,a.high,"undefined"=== -typeof g?a.unsigned:g);if("string"===typeof a)return b.Long.fromString(a,g||!1,10);if("number"===typeof a)return b.Long.fromNumber(a,g||!1);throw Error("not convertible to Long");}function t(a,g){var m=g.readVarint32(),c=m&7,m=m>>>3;switch(c){case b.WIRE_TYPES.VARINT:do m=g.readUint8();while(128===(m&128));break;case b.WIRE_TYPES.BITS64:g.offset+=8;break;case b.WIRE_TYPES.LDELIM:m=g.readVarint32();g.offset+=m;break;case b.WIRE_TYPES.STARTGROUP:t(m,g);break;case b.WIRE_TYPES.ENDGROUP:if(m===a)return!1; -throw Error("Illegal GROUPEND after unknown group: "+m+" ("+a+" expected)");case b.WIRE_TYPES.BITS32:g.offset+=4;break;default:throw Error("Illegal wire type in unknown group "+a+": "+c);}return!0}var n={},k=function(a,g,b){this.builder=a;this.parent=g;this.name=b},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 c=function(a,g,b,c,s){k.call(this,a,g,b);this.className="Namespace";this.children=[];this.options=c||{};this.syntax=s||"proto2"},f=c.prototype=Object.create(k.prototype);f.getChildren=function(a){a=a||null;if(null==a)return this.children.slice();for(var g=[],b=0,c=this.children.length;bb.MAP_KEY_TYPES.indexOf(a))throw Error("Invalid map key type: "+a.name);},e=l.prototype;l.defaultFieldValue=function(a){"string"===typeof a&&(a=b.TYPES[a]);if("undefined"===typeof a.defaultValue)throw Error("default value for type "+a.name+" is not supported");return a==b.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, -b){throw Error("Illegal value for "+c.toString(!0)+" of type "+c.type.name+": "+a+" ("+b+")");}var c=this;switch(this.type){case b.TYPES.int32:case b.TYPES.sint32:case b.TYPES.sfixed32:return("number"!==typeof a||a===a&&0!==a%1)&&g(typeof a,"not an integer"),4294967295a?a>>>0:a;case b.TYPES.int64:case b.TYPES.sint64:case b.TYPES.sfixed64:if(b.Long)try{return d(a,!1)}catch(e){g(typeof a, -e.message)}else g(typeof a,"requires Long.js");case b.TYPES.uint64:case b.TYPES.fixed64:if(b.Long)try{return d(a,!0)}catch(s){g(typeof a,s.message)}else g(typeof a,"requires Long.js");case b.TYPES.bool:return"boolean"!==typeof a&&g(typeof a,"not a boolean"),a;case b.TYPES["float"]:case b.TYPES["double"]:return"number"!==typeof a&&g(typeof a,"not a number"),a;case b.TYPES.string:return"string"===typeof a||a&&a instanceof String||g(typeof a,"not a string"),""+a;case b.TYPES.bytes:return h.isByteBuffer(a)? -a:h.wrap(a,"base64");case b.TYPES["enum"]:for(var v=this.resolvedType.getChildren(b.Reflect.Enum.Value),f=0;fa)&&g(typeof a,"not in range for uint32"),a;g(a,"not a valid enum value");case b.TYPES.group:case b.TYPES.message:a&&"object"===typeof a||g(typeof a,"object expected");if(a instanceof this.resolvedType.clazz)return a;if(a instanceof -b.Builder.Message){var v={},f;for(f in a)a.hasOwnProperty(f)&&(v[f]=a[f]);a=v}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 c;switch(this.type){case b.TYPES.int32:return 0>g?h.calculateVarint64(g):h.calculateVarint32(g);case b.TYPES.uint32:return h.calculateVarint32(g);case b.TYPES.sint32:return h.calculateVarint32(h.zigZagEncode32(g));case b.TYPES.fixed32:case b.TYPES.sfixed32:case b.TYPES["float"]:return 4; -case b.TYPES.int64:case b.TYPES.uint64:return h.calculateVarint64(g);case b.TYPES.sint64:return h.calculateVarint64(h.zigZagEncode64(g));case b.TYPES.fixed64:case b.TYPES.sfixed64:return 8;case b.TYPES.bool:return 1;case b.TYPES["enum"]:return h.calculateVarint32(g);case b.TYPES["double"]:return 8;case b.TYPES.string:return c=h.calculateUTF8Bytes(g),h.calculateVarint32(c)+c;case b.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 b.TYPES.message:return c=this.resolvedType.calculate(g),h.calculateVarint32(c)+c;case b.TYPES.group:return c=this.resolvedType.calculate(g),c+h.calculateVarint32(a<<3|b.WIRE_TYPES.ENDGROUP)}throw Error("[INTERNAL] Illegal value to encode in "+this.toString(!0)+": "+g+" (unknown type)");};e.encodeValue=function(a,g,c){if(null===g)return c;switch(this.type){case b.TYPES.int32:0>g?c.writeVarint64(g):c.writeVarint32(g);break;case b.TYPES.uint32:c.writeVarint32(g); -break;case b.TYPES.sint32:c.writeVarint32ZigZag(g);break;case b.TYPES.fixed32:c.writeUint32(g);break;case b.TYPES.sfixed32:c.writeInt32(g);break;case b.TYPES.int64:case b.TYPES.uint64:c.writeVarint64(g);break;case b.TYPES.sint64:c.writeVarint64ZigZag(g);break;case b.TYPES.fixed64:c.writeUint64(g);break;case b.TYPES.sfixed64:c.writeInt64(g);break;case b.TYPES.bool:"string"===typeof g?c.writeVarint32("false"===g.toLowerCase()?0:!!g):c.writeVarint32(g?1:0);break;case b.TYPES["enum"]:c.writeVarint32(g); -break;case b.TYPES["float"]:c.writeFloat32(g);break;case b.TYPES["double"]:c.writeFloat64(g);break;case b.TYPES.string:c.writeVString(g);break;case b.TYPES.bytes:if(0>g.remaining())throw Error("Illegal value for "+this.toString(!0)+": "+g.remaining()+" bytes remaining");a=g.offset;c.writeVarint32(g.remaining());c.append(g);g.offset=a;break;case b.TYPES.message:a=(new h).LE();this.resolvedType.encode(g,a);c.writeVarint32(a.offset);c.append(a.flip());break;case b.TYPES.group:this.resolvedType.encode(g, -c);c.writeVarint32(a<<3|b.WIRE_TYPES.ENDGROUP);break;default:throw Error("[INTERNAL] Illegal value to encode in "+this.toString(!0)+": "+g+" (unknown type)");}return c};e.decode=function(a,g,c){if(g!=this.type.wireType)throw Error("Unexpected wire type for element");switch(this.type){case b.TYPES.int32:return a.readVarint32()|0;case b.TYPES.uint32:return a.readVarint32()>>>0;case b.TYPES.sint32:return a.readVarint32ZigZag()|0;case b.TYPES.fixed32:return a.readUint32()>>>0;case b.TYPES.sfixed32:return a.readInt32()| -0;case b.TYPES.int64:return a.readVarint64();case b.TYPES.uint64:return a.readVarint64().toUnsigned();case b.TYPES.sint64:return a.readVarint64ZigZag();case b.TYPES.fixed64:return a.readUint64();case b.TYPES.sfixed64:return a.readInt64();case b.TYPES.bool:return!!a.readVarint32();case b.TYPES["enum"]:return a.readVarint32();case b.TYPES["float"]:return a.readFloat();case b.TYPES["double"]:return a.readDouble();case b.TYPES.string:return a.readVString();case b.TYPES.bytes:c=a.readVarint32();if(a.remaining()< -c)throw Error("Illegal number of bytes for "+this.toString(!0)+": "+c+" required but got only "+a.remaining());g=a.clone();g.limit=g.offset+c;a.offset+=c;return g;case b.TYPES.message:return c=a.readVarint32(),this.resolvedType.decode(a,c);case b.TYPES.group:return this.resolvedType.decode(a,-1,c)}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 b.TYPES.int32:case b.TYPES.sint32:case b.TYPES.sfixed32:case b.TYPES.uint32:case b.TYPES.fixed32:return this.verifyValue(parseInt(a)); -case b.TYPES.int64:case b.TYPES.sint64:case b.TYPES.sfixed64:case b.TYPES.uint64:case b.TYPES.fixed64:return this.verifyValue(a);case b.TYPES.bool:return"true"===a;case b.TYPES.string:return this.verifyValue(a);case b.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===b.TYPES.bytes?a.toString("binary"):a.toString()};n.Element=l;var p=function(a,b,d,e,s,f){c.call(this,a,b,d,e,f);this.className= -"Message";this.extensions=void 0;this.clazz=null;this.isGroup=!!s;this._fieldsByName=this._fieldsById=this._fields=null},e=p.prototype=Object.create(c.prototype);e.build=function(a){if(this.clazz&&!a)return this.clazz;a=function(a,b){function g(b,c,d,e){if(null===b||"object"!==typeof b){if(e&&e instanceof a.Reflect.Enum){var m=a.Reflect.Enum.getName(e.object,b);if(null!==m)return m}return b}if(h.isByteBuffer(b))return c?b.toBase64():b.toBuffer();if(a.Long.isLong(b))return d?b.toString():a.Long.fromValue(b); -var f;if(Array.isArray(b))return f=[],b.forEach(function(a,b){f[b]=g(a,c,d,e)}),f;f={};if(b instanceof a.Map){for(var m=b.entries(),l=m.next();!l.done;l=m.next())f[b.keyElem.valueToString(l.value[0])]=g(l.value[1],c,d,b.valueElem.resolvedType);return f}var m=b.$type,l=void 0,r;for(r in b)b.hasOwnProperty(r)&&(m&&(l=m.getChild(r))?f[r]=g(b[r],c,d,l.resolvedType):f[r]=g(b[r],c,d));return f}var c=b.getChildren(a.Reflect.Message.Field),d=b.getChildren(a.Reflect.Message.OneOf),m=function(g,e){a.Builder.Message.call(this); -for(var f=0,l=d.length;fa.remaining())return null;var c=a.offset, -d=a.readVarint32();if(a.remaining()>>3;if(l===b.WIRE_TYPES.ENDGROUP){if(p!==c)throw Error("Illegal group end indicator for "+ -this.toString(!0)+": "+p+" ("+(c?c+" expected":"not a group")+")");break}if(f=this._fieldsById[p])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 b.WIRE_TYPES.VARINT:a.readVarint32();break;case b.WIRE_TYPES.BITS32:a.offset+=4;break;case b.WIRE_TYPES.BITS64:a.offset+=8;break;case b.WIRE_TYPES.LDELIM:f=a.readVarint32(); -a.offset+=f;break;case b.WIRE_TYPES.STARTGROUP:for(;t(p,a););break;default:throw Error("Illegal wire type for unknown field "+p+" in "+this.toString(!0)+"#decode: "+l);}}a=0;for(g=this._fields.length;a>>=3,1===c)e=this.keyElement.decode(f,a,c);else if(2===c)d= -this.element.decode(f,a,c);else throw Error("Unexpected tag in map field key/value submessage");return[e,d]}return this.element.decode(c,a,this.id)};n.Message.Field=z;e=function(a,c,b,d,e,f,l){z.call(this,a,c,b,null,d,e,f,l)};e.prototype=Object.create(z.prototype);n.Message.ExtensionField=e;n.Message.OneOf=function(a,c,b){k.call(this,a,c,b);this.fields=[]};var x=function(a,b,d,e,f){c.call(this,a,b,d,e,f);this.className="Enum";this.object=null};x.getName=function(a,c){for(var b=Object.keys(a),d=0, -e;d=a[0]&&c.id<=a[1]&&(d=!0)});if(!d)throw Error("illegal extended field id in "+f.name+": "+c.id+" (not within valid ranges)");}var e=c.name;this.options.convertFieldsToCamelCase&&(e=b.Util.toCamelCase(e));var e=new h.Message.ExtensionField(this,f,c.rule,c.type,this.ptr.fqn()+"."+e,c.id,c.options), -a=new h.Extension(this,this.ptr,c.name,e);e.extension=a;this.ptr.addChild(a);f.addChild(e)},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}c=null;this.ptr=this.ptr.parent}this.resolved=!1;this.result=null;return this};f["import"]=function(c,d){var e="/";if("string"===typeof d){b.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;b.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(c.imports&&0>>3;switch(b){case c.WIRE_TYPES.VARINT:do m=f.readUint8();while(128===(m&128));break;case c.WIRE_TYPES.BITS64:f.offset+=8;break;case c.WIRE_TYPES.LDELIM:m=f.readVarint32();f.offset+=m;break;case c.WIRE_TYPES.STARTGROUP:w(m,f);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:f.offset+=4;break;default:throw Error("Illegal wire type in unknown group "+a+": "+b);}return!0}var t={},k=function(a,f,c){this.builder=a;this.parent=f;this.name=c},h=k.prototype;h.fqn=function(){var a=this.name,f=this;do{f=f.parent;if(null==f)break;a=f.name+"."+a}while(1);return a};h.toString=function(a){return(a?this.className+" ":"")+this.fqn()};h.build=function(){throw Error(this.toString(!0)+ +" cannot be built directly");};t.T=k;var b=function(a,f,c,b,e){k.call(this,a,f,c);this.className="Namespace";this.children=[];this.options=b||{};this.syntax=e||"proto2"},h=b.prototype=Object.create(k.prototype);h.getChildren=function(a){a=a||null;if(null==a)return this.children.slice();for(var f=[],c=0,b=this.children.length;cc.MAP_KEY_TYPES.indexOf(a))throw Error("Invalid map key type: "+a.name);},g=q.prototype;q.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 e(0):a.defaultValue};g.toString=function(){return(this.name||"")+(this.isMapKey?"map":"value")+" element"};g.verifyValue=function(a){function f(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)&&f(typeof a,"not an integer"),4294967295a?a>>>0:a;case c.TYPES.int64:case c.TYPES.sint64:case c.TYPES.sfixed64:if(c.Long)try{return d(a,!1)}catch(x){f(typeof a, +x.message)}else f(typeof a,"requires Long.js");case c.TYPES.uint64:case c.TYPES.fixed64:if(c.Long)try{return d(a,!0)}catch(x){f(typeof a,x.message)}else f(typeof a,"requires Long.js");case c.TYPES.bool:return"boolean"!==typeof a&&f(typeof a,"not a boolean"),a;case c.TYPES["float"]:case c.TYPES["double"]:return"number"!==typeof a&&f(typeof a,"not a number"),a;case c.TYPES.string:return"string"===typeof a||a&&a instanceof String||f(typeof a,"not a string"),""+a;case c.TYPES.bytes:return e.isByteBuffer(a)? +a:e.wrap(a,"base64");case c.TYPES["enum"]:for(var l=this.resolvedType.getChildren(c.Reflect.Enum.Value),r=0;ra)&&f(typeof a,"not in range for uint32"),a;f(a,"not a valid enum value");case c.TYPES.group:case c.TYPES.message:a&&"object"===typeof a||f(typeof a,"object expected");if(a instanceof this.resolvedType.clazz)return a;if(a instanceof +c.Builder.Message){var l={},r;for(r in a)a.hasOwnProperty(r)&&(l[r]=a[r]);a=l}return new this.resolvedType.clazz(a)}throw Error("[INTERNAL] Illegal value for "+this.toString(!0)+": "+a+" (undefined type "+this.type+")");};g.calculateLength=function(a,f){if(null===f)return 0;var b;switch(this.type){case c.TYPES.int32:return 0>f?e.calculateVarint64(f):e.calculateVarint32(f);case c.TYPES.uint32:return e.calculateVarint32(f);case c.TYPES.sint32:return e.calculateVarint32(e.zigZagEncode32(f));case c.TYPES.fixed32:case c.TYPES.sfixed32:case c.TYPES["float"]:return 4; +case c.TYPES.int64:case c.TYPES.uint64:return e.calculateVarint64(f);case c.TYPES.sint64:return e.calculateVarint64(e.zigZagEncode64(f));case c.TYPES.fixed64:case c.TYPES.sfixed64:return 8;case c.TYPES.bool:return 1;case c.TYPES["enum"]:return e.calculateVarint32(f);case c.TYPES["double"]:return 8;case c.TYPES.string:return b=e.calculateUTF8Bytes(f),e.calculateVarint32(b)+b;case c.TYPES.bytes:if(0>f.remaining())throw Error("Illegal value for "+this.toString(!0)+": "+f.remaining()+" bytes remaining"); +return e.calculateVarint32(f.remaining())+f.remaining();case c.TYPES.message:return b=this.resolvedType.calculate(f),e.calculateVarint32(b)+b;case c.TYPES.group:return b=this.resolvedType.calculate(f),b+e.calculateVarint32(a<<3|c.WIRE_TYPES.ENDGROUP)}throw Error("[INTERNAL] Illegal value to encode in "+this.toString(!0)+": "+f+" (unknown type)");};g.encodeValue=function(a,f,b){if(null===f)return b;switch(this.type){case c.TYPES.int32:0>f?b.writeVarint64(f):b.writeVarint32(f);break;case c.TYPES.uint32:b.writeVarint32(f); +break;case c.TYPES.sint32:b.writeVarint32ZigZag(f);break;case c.TYPES.fixed32:b.writeUint32(f);break;case c.TYPES.sfixed32:b.writeInt32(f);break;case c.TYPES.int64:case c.TYPES.uint64:b.writeVarint64(f);break;case c.TYPES.sint64:b.writeVarint64ZigZag(f);break;case c.TYPES.fixed64:b.writeUint64(f);break;case c.TYPES.sfixed64:b.writeInt64(f);break;case c.TYPES.bool:"string"===typeof f?b.writeVarint32("false"===f.toLowerCase()?0:!!f):b.writeVarint32(f?1:0);break;case c.TYPES["enum"]:b.writeVarint32(f); +break;case c.TYPES["float"]:b.writeFloat32(f);break;case c.TYPES["double"]:b.writeFloat64(f);break;case c.TYPES.string:b.writeVString(f);break;case c.TYPES.bytes:if(0>f.remaining())throw Error("Illegal value for "+this.toString(!0)+": "+f.remaining()+" bytes remaining");a=f.offset;b.writeVarint32(f.remaining());b.append(f);f.offset=a;break;case c.TYPES.message:a=(new e).LE();this.resolvedType.encode(f,a);b.writeVarint32(a.offset);b.append(a.flip());break;case c.TYPES.group:this.resolvedType.encode(f, +b);b.writeVarint32(a<<3|c.WIRE_TYPES.ENDGROUP);break;default:throw Error("[INTERNAL] Illegal value to encode in "+this.toString(!0)+": "+f+" (unknown type)");}return b};g.decode=function(a,f,b){if(f!=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());f=a.clone();f.limit=f.offset+b;a.offset+=b;return f;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");};g.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 e.fromBinary(a)}};g.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()};t.Element=q;var v=function(a,c,e,d,r,g){b.call(this,a,c,e,d,g);this.className= +"Message";this.extensions=void 0;this.clazz=null;this.isGroup=!!r;this._fieldsByName=this._fieldsById=this._fields=null},g=v.prototype=Object.create(b.prototype);g.build=function(a){if(this.clazz&&!a)return this.clazz;a=function(a,c){function b(c,f,d,g){if(null===c||"object"!==typeof c){if(g&&g instanceof a.Reflect.Enum){var p=a.Reflect.Enum.getName(g.object,c);if(null!==p)return p}return c}if(e.isByteBuffer(c))return f?c.toBase64():c.toBuffer();if(a.Long.isLong(c))return d?c.toString():a.Long.fromValue(c); +var l;if(Array.isArray(c))return l=[],c.forEach(function(a,c){l[c]=b(a,f,d,g)}),l;l={};if(c instanceof a.Map){for(var p=c.entries(),m=p.next();!m.done;m=p.next())l[c.keyElem.valueToString(m.value[0])]=b(m.value[1],f,d,c.valueElem.resolvedType);return l}var p=c.$type,m=void 0,r;for(r in c)c.hasOwnProperty(r)&&(p&&(m=p.getChild(r))?l[r]=b(c[r],f,d,m.resolvedType):l[r]=b(c[r],f,d));return l}var f=c.getChildren(a.Reflect.Message.Field),d=c.getChildren(a.Reflect.Message.OneOf),l=function(b,g){a.Builder.Message.call(this); +for(var p=0,m=d.length;pa.remaining())return null;var f=a.offset, +d=a.readVarint32();if(a.remaining()>>3;if(m===c.WIRE_TYPES.ENDGROUP){if(q!==d)throw Error("Illegal group end indicator for "+ +this.toString(!0)+": "+q+" ("+(d?d+" expected":"not a group")+")");break}if(g=this._fieldsById[q])g.repeated&&!g.options.packed?e[g.name].push(g.decode(m,a)):g.map?(m=g.decode(m,a),e[g.name].set(m[0],m[1])):(e[g.name]=g.decode(m,a),g.oneof&&(m=e[g.oneof.name],null!==m&&m!==g.name&&(e[m]=null),e[g.oneof.name]=g.name));else switch(m){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(;w(q,a););break;default:throw Error("Illegal wire type for unknown field "+q+" in "+this.toString(!0)+"#decode: "+m);}}a=0;for(b=this._fields.length;a>>=3,1===b)f=this.keyElement.decode(e,a,b);else if(2===b)d= +this.element.decode(e,a,b);else throw Error("Unexpected tag in map field key/value submessage");return[f,d]}return this.element.decode(b,a,this.id)};t.Message.Field=n;g=function(a,b,c,d,e,g,q){n.call(this,a,b,c,null,d,e,g,q)};g.prototype=Object.create(n.prototype);t.Message.ExtensionField=g;t.Message.OneOf=function(a,b,c){k.call(this,a,b,c);this.fields=[]};var y=function(a,c,d,e,g){b.call(this,a,c,d,e,g);this.className="Enum";this.object=null};y.getName=function(a,b){for(var c=Object.keys(a),f=0, +d;f=a[0]&&b.id<=a[1]&&(d=!0)});if(!d)throw Error("illegal extended field id in "+h.name+": "+b.id+" (not within valid ranges)");}var g=b.name;this.options.convertFieldsToCamelCase&&(g=c.Util.toCamelCase(g));var g=new e.Message.ExtensionField(this,h,b.rule,b.type,this.ptr.fqn()+"."+g,b.id,b.options), +a=new e.Extension(this,this.ptr,b.name,g);g.extension=a;this.ptr.addChild(a);h.addChild(g)},this);else{if(!/\.?google\.protobuf\./.test(g.ref))throw Error("extended message "+g.ref+" is not defined");}else throw Error("not a valid definition: "+JSON.stringify(g));h=g=null}b=null;this.ptr=this.ptr.parent}this.resolved=!1;this.result=null;return this};h["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 h=d.root;c.Util.IS_NODE&&(h=require("path").resolve(h));if(0<=h.indexOf("\\")||0<=d.file.indexOf("\\"))e="\\";h=h+e+d.file;if(!0===this.files[h])return this.reset();this.files[h]=!0}if(b.imports&&0w){n=this.options.includePath[w++]; +continue}throw Error("failed to import '"+(h+e+t)+"' in '"+d+"': file not found");}if(/\.json$/i.test(n))this["import"](JSON.parse(a+""),n);else this["import"](c.DotProto.Parser.parse(a),n);break}}else if(d)if(/\.(\w+)$/.test(d))this["import"](b.imports[q],d.replace(/^(.+)\.(\w+)$/,function(a,b,c){return b+"_import"+q+"."+c}));else this["import"](b.imports[q],d+"_import"+q);else this["import"](b.imports[q]);k&&(this.importRoot=null)}b["package"]&&this.define(b["package"]);b.syntax&&u(b);var f=this.ptr; +b.options&&Object.keys(b.options).forEach(function(a){f.options[a]=b.options[a]});b.messages&&(this.create(b.messages),this.ptr=f);b.enums&&(this.create(b.enums),this.ptr=f);b.services&&(this.create(b.services),this.ptr=f);b["extends"]&&this.create(b["extends"]);return this.reset()};h.resolveAll=function(){var b;if(null==this.ptr||"object"===typeof this.ptr.type)return this;if(this.ptr instanceof e.Namespace)this.ptr.children.forEach(function(b){this.ptr=b;this.resolveAll()},this);else if(this.ptr instanceof +e.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 e.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 e.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 e.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]}"proto3"===this.ptr.syntax&&this.ptr.repeated&& +void 0===this.ptr.options.packed&&-1!==c.PACKABLE_WIRE_TYPES.indexOf(this.ptr.type.wireType)&&(this.ptr.options.packed=!0)}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()};h.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 tmpImportPathIndex) { + tmpImportRoot = this.options.includePath[tmpImportPathIndex++]; + continue; + } + throw Error("failed to import '"+(importRoot + delim + importFilename)+"' in '"+filename+"': file not found"); + } + if (/\.json$/i.test(tmpImportFilename)) // Always possible + this["import"](JSON.parse(contents+""), tmpImportFilename); // May throw + else + this["import"](ProtoBuf.DotProto.Parser.parse(contents), tmpImportFilename); // May throw + break; + } } else // Import structure if (!filename) this["import"](json['imports'][i]); diff --git a/dist/protobuf.min.js b/dist/protobuf.min.js index 3b94e8656..46d2cd139 100644 --- a/dist/protobuf.min.js +++ b/dist/protobuf.min.js @@ -3,108 +3,114 @@ Released under the Apache License, Version 2.0 see: https://github.com/dcodeIO/protobuf.js for details */ -(function(g,u){"function"===typeof define&&define.amd?define(["bytebuffer"],u):"function"===typeof require&&"object"===typeof module&&module&&module.exports?module.exports=u(require("bytebuffer"),!0):(g.dcodeIO=g.dcodeIO||{}).ProtoBuf=u(g.dcodeIO.ByteBuffer)})(this,function(g,u){var d={};d.ByteBuffer=g;d.Long=g.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= +var $jscomp={scope:{}};$jscomp.defineProperty="function"==typeof Object.defineProperties?Object.defineProperty:function(f,p,d){if(d.get||d.set)throw new TypeError("ES3 does not support getters and setters.");f!=Array.prototype&&f!=Object.prototype&&(f[p]=d.value)};$jscomp.getGlobal=function(f){return"undefined"!=typeof window&&window===f?f:"undefined"!=typeof global&&null!=global?global:f};$jscomp.global=$jscomp.getGlobal(this);$jscomp.SYMBOL_PREFIX="jscomp_symbol_"; +$jscomp.initSymbol=function(){$jscomp.initSymbol=function(){};$jscomp.global.Symbol||($jscomp.global.Symbol=$jscomp.Symbol)};$jscomp.symbolCounter_=0;$jscomp.Symbol=function(f){return $jscomp.SYMBOL_PREFIX+(f||"")+$jscomp.symbolCounter_++}; +$jscomp.initSymbolIterator=function(){$jscomp.initSymbol();var f=$jscomp.global.Symbol.iterator;f||(f=$jscomp.global.Symbol.iterator=$jscomp.global.Symbol("iterator"));"function"!=typeof Array.prototype[f]&&$jscomp.defineProperty(Array.prototype,f,{configurable:!0,writable:!0,value:function(){return $jscomp.arrayIterator(this)}});$jscomp.initSymbolIterator=function(){}};$jscomp.arrayIterator=function(f){var p=0;return $jscomp.iteratorPrototype(function(){return p]/g,RULE:/^(?:required|optional|repeated|map)$/, +function(){return new ActiveXObject("Microsoft.XMLHTTP")}],d=null,f=0;f]/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.DotProto=function(b,d){function g(b,c){var a=-1,k=1;"-"==b.charAt(0)&&(k=-1,b=b.substring(1));if(d.NUMBER_DEC.test(b))a=parseInt(b);else if(d.NUMBER_HEX.test(b))a=parseInt(b.substring(2),16); -else if(d.NUMBER_OCT.test(b))a=parseInt(b.substring(1),8);else throw Error("illegal id value: "+(0>k?"-":"")+b);a=k*a|0;if(!c&&0>a)throw Error("illegal id value: "+(0>k?"-":"")+b);return a}function q(b){var c=1;"-"==b.charAt(0)&&(c=-1,b=b.substring(1));if(d.NUMBER_DEC.test(b))return c*parseInt(b,10);if(d.NUMBER_HEX.test(b))return c*parseInt(b.substring(2),16);if(d.NUMBER_OCT.test(b))return c*parseInt(b.substring(1),8);if("inf"===b)return Infinity*c;if("nan"===b)return NaN;if(d.NUMBER_FLT.test(b))return c* -parseFloat(b);throw Error("illegal number value: "+(0>c?"-":"")+b);}function n(b,c,d){"undefined"===typeof b[c]?b[c]=d:(Array.isArray(b[c])||(b[c]=[b[c]]),b[c].push(d))}var h={},a=function(b){this.source=b+"";this.index=0;this.line=1;this.stack=[];this._stringOpen=null},e=a.prototype;e._readString=function(){var b='"'===this._stringOpen?d.STRING_DQ:d.STRING_SQ;b.lastIndex=this.index-1;var c=b.exec(this.source);if(!c)throw Error("unterminated string");this.index=b.lastIndex;this.stack.push(this._stringOpen); -this._stringOpen=null;return c[1]};e.next=function(){if(0=this.source.length)return null;if(null!==this._stringOpen)return this._readString();var b,c;do{for(b=!1;d.WHITESPACE.test(c=this.source.charAt(this.index));)if("\n"===c&&++this.line,++this.index===this.source.length)return null;if("/"===this.source.charAt(this.index))if(++this.index,"/"===this.source.charAt(this.index)){for(;"\n"!==this.source.charAt(++this.index);)if(this.index==this.source.length)return null; -++this.index;++this.line;b=!0}else if("*"===(c=this.source.charAt(this.index))){do{"\n"===c&&++this.line;if(++this.index===this.source.length)return null;b=c;c=this.source.charAt(this.index)}while("*"!==b||"/"!==c);++this.index;b=!0}else return"/"}while(b);if(this.index===this.source.length)return null;c=this.index;d.DELIM.lastIndex=0;if(!d.DELIM.test(this.source.charAt(c++)))for(;c");c=this.tn.next(); -if(!d.NAME.test(c))throw Error("illegal message field name: "+c);e.name=c;this.tn.skip("=");e.id=g(this.tn.next());c=this.tn.peek();"["===c&&this._parseFieldOptions(e);this.tn.skip(";")}else if(a="undefined"!==typeof a?a:this.tn.next(),"group"===a){c=this._parseMessage(b,e);if(!/^[A-Z]/.test(c.name))throw Error("illegal group name: "+c.name);e.type=c.name;e.name=c.name.toLowerCase();this.tn.omit(";")}else{if(!d.TYPE.test(a)&&!d.TYPEREF.test(a))throw Error("illegal message field type: "+a);e.type= -a;c=this.tn.next();if(!d.NAME.test(c))throw Error("illegal message field name: "+c);e.name=c;this.tn.skip("=");e.id=g(this.tn.next());c=this.tn.peek();"["===c&&this._parseFieldOptions(e);this.tn.skip(";")}b.fields.push(e);return e};e._parseMessageOneOf=function(b){var c=this.tn.next();if(!d.NAME.test(c))throw Error("illegal oneof name: "+c);var a=c,e=[];for(this.tn.skip("{");"}"!==(c=this.tn.next());)c=this._parseMessageField(b,"optional",c),c.oneof=a,e.push(c.id);this.tn.omit(";");b.oneofs[a]=e}; -e._parseFieldOptions=function(b){this.tn.skip("[");for(var c=!0;"]"!==this.tn.peek();)c||this.tn.skip(","),this._parseOption(b,!0),c=!1;this.tn.next()};e._parseEnum=function(b){var c={name:"",values:[],options:{}},a=this.tn.next();if(!d.NAME.test(a))throw Error("illegal name: "+a);c.name=a;for(this.tn.skip("{");"}"!==(a=this.tn.next());)if("option"===a)this._parseOption(c);else{if(!d.NAME.test(a))throw Error("illegal name: "+a);this.tn.skip("=");var e={name:a,id:g(this.tn.next(),!0)},a=this.tn.peek(); -"["===a&&this._parseFieldOptions({options:{}});this.tn.skip(";");c.values.push(e)}this.tn.omit(";");b.enums.push(c)};e._parseExtensionRanges=function(){var a=[],c,d;do{for(d=[];;){c=this.tn.next();switch(c){case "min":c=b.ID_MIN;break;case "max":c=b.ID_MAX;break;default:c=q(c)}d.push(c);if(2===d.length)break;if("to"!==this.tn.peek()){d.push(c);break}this.tn.next()}a.push(d)}while(this.tn.omit(","));this.tn.skip(";");return a};e._parseExtend=function(b){var a=this.tn.next();if(!d.TYPEREF.test(a))throw Error("illegal extend reference: "+ -a);var e={ref:a,fields:[]};for(this.tn.skip("{");"}"!==(a=this.tn.next());)if(d.RULE.test(a))this._parseMessageField(e,a);else if(d.TYPEREF.test(a)){if(!this.proto3)throw Error("illegal field rule: "+a);this._parseMessageField(e,"optional",a)}else throw Error("illegal extend token: "+a);this.tn.omit(";");b.messages.push(e);return e};e.toString=function(){return"Parser at line "+this.tn.line};h.Parser=l;return h}(d,d.Lang);d.Reflect=function(b){function d(f,m){if(f&&"number"===typeof f.low&&"number"=== -typeof f.high&&"boolean"===typeof f.unsigned&&f.low===f.low&&f.high===f.high)return new b.Long(f.low,f.high,"undefined"===typeof m?f.unsigned:m);if("string"===typeof f)return b.Long.fromString(f,m||!1,10);if("number"===typeof f)return b.Long.fromNumber(f,m||!1);throw Error("not convertible to Long");}function p(f,m){var a=m.readVarint32(),c=a&7,a=a>>>3;switch(c){case b.WIRE_TYPES.VARINT:do a=m.readUint8();while(128===(a&128));break;case b.WIRE_TYPES.BITS64:m.offset+=8;break;case b.WIRE_TYPES.LDELIM:a= -m.readVarint32();m.offset+=a;break;case b.WIRE_TYPES.STARTGROUP:p(a,m);break;case b.WIRE_TYPES.ENDGROUP:if(a===f)return!1;throw Error("Illegal GROUPEND after unknown group: "+a+" ("+f+" expected)");case b.WIRE_TYPES.BITS32:m.offset+=4;break;default:throw Error("Illegal wire type in unknown group "+f+": "+c);}return!0}var q={},n=function(f,b,a){this.builder=f;this.parent=b;this.name=a},h=n.prototype;h.fqn=function(){var f=this.name,b=this;do{b=b.parent;if(null==b)break;f=b.name+"."+f}while(1);return f}; -h.toString=function(f){return(f?this.className+" ":"")+this.fqn()};h.build=function(){throw Error(this.toString(!0)+" cannot be built directly");};q.T=n;var a=function(f,b,a,c,d){n.call(this,f,b,a);this.className="Namespace";this.children=[];this.options=c||{};this.syntax=d||"proto2"},h=a.prototype=Object.create(n.prototype);h.getChildren=function(b){b=b||null;if(null==b)return this.children.slice();for(var a=[],c=0,d=this.children.length;cb.MAP_KEY_TYPES.indexOf(f))throw Error("Invalid map key type: "+f.name);},l=e.prototype;e.defaultFieldValue=function(f){"string"===typeof f&&(f=b.TYPES[f]);if("undefined"===typeof f.defaultValue)throw Error("default value for type "+f.name+" is not supported");return f==b.TYPES.bytes?new g(0):f.defaultValue}; -l.toString=function(){return(this.name||"")+(this.isMapKey?"map":"value")+" element"};l.verifyValue=function(f){function a(b,f){throw Error("Illegal value for "+c.toString(!0)+" of type "+c.type.name+": "+b+" ("+f+")");}var c=this;switch(this.type){case b.TYPES.int32:case b.TYPES.sint32:case b.TYPES.sfixed32:return("number"!==typeof f||f===f&&0!==f%1)&&a(typeof f,"not an integer"),4294967295f?f>>>0:f;case b.TYPES.int64:case b.TYPES.sint64:case b.TYPES.sfixed64:if(b.Long)try{return d(f,!1)}catch(e){a(typeof f,e.message)}else a(typeof f,"requires Long.js");case b.TYPES.uint64:case b.TYPES.fixed64:if(b.Long)try{return d(f,!0)}catch(k){a(typeof f,k.message)}else a(typeof f,"requires Long.js");case b.TYPES.bool:return"boolean"!==typeof f&&a(typeof f,"not a boolean"),f;case b.TYPES["float"]:case b.TYPES["double"]:return"number"!==typeof f&&a(typeof f,"not a number"),f;case b.TYPES.string:return"string"=== -typeof f||f&&f instanceof String||a(typeof f,"not a string"),""+f;case b.TYPES.bytes:return g.isByteBuffer(f)?f:g.wrap(f,"base64");case b.TYPES["enum"]:for(var l=this.resolvedType.getChildren(b.Reflect.Enum.Value),h=0;hf)&&a(typeof f,"not in range for uint32"),f;a(f,"not a valid enum value");case b.TYPES.group:case b.TYPES.message:f&& -"object"===typeof f||a(typeof f,"object expected");if(f instanceof this.resolvedType.clazz)return f;if(f instanceof b.Builder.Message){var l={},h;for(h in f)f.hasOwnProperty(h)&&(l[h]=f[h]);f=l}return new this.resolvedType.clazz(f)}throw Error("[INTERNAL] Illegal value for "+this.toString(!0)+": "+f+" (undefined type "+this.type+")");};l.calculateLength=function(f,a){if(null===a)return 0;var c;switch(this.type){case b.TYPES.int32:return 0>a?g.calculateVarint64(a):g.calculateVarint32(a);case b.TYPES.uint32:return g.calculateVarint32(a); -case b.TYPES.sint32:return g.calculateVarint32(g.zigZagEncode32(a));case b.TYPES.fixed32:case b.TYPES.sfixed32:case b.TYPES["float"]:return 4;case b.TYPES.int64:case b.TYPES.uint64:return g.calculateVarint64(a);case b.TYPES.sint64:return g.calculateVarint64(g.zigZagEncode64(a));case b.TYPES.fixed64:case b.TYPES.sfixed64:return 8;case b.TYPES.bool:return 1;case b.TYPES["enum"]:return g.calculateVarint32(a);case b.TYPES["double"]:return 8;case b.TYPES.string:return c=g.calculateUTF8Bytes(a),g.calculateVarint32(c)+ -c;case b.TYPES.bytes:if(0>a.remaining())throw Error("Illegal value for "+this.toString(!0)+": "+a.remaining()+" bytes remaining");return g.calculateVarint32(a.remaining())+a.remaining();case b.TYPES.message:return c=this.resolvedType.calculate(a),g.calculateVarint32(c)+c;case b.TYPES.group:return c=this.resolvedType.calculate(a),c+g.calculateVarint32(f<<3|b.WIRE_TYPES.ENDGROUP)}throw Error("[INTERNAL] Illegal value to encode in "+this.toString(!0)+": "+a+" (unknown type)");};l.encodeValue=function(f, +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.DotProto=function(b,d){function f(b,c){var n,a=1;"-"==b.charAt(0)&&(a=-1,b=b.substring(1));if(d.NUMBER_DEC.test(b))n=parseInt(b);else if(d.NUMBER_HEX.test(b))n=parseInt(b.substring(2),16);else if(d.NUMBER_OCT.test(b))n= +parseInt(b.substring(1),8);else throw Error("illegal id value: "+(0>a?"-":"")+b);n=a*n|0;if(!c&&0>n)throw Error("illegal id value: "+(0>a?"-":"")+b);return n}function t(b){var c=1;"-"==b.charAt(0)&&(c=-1,b=b.substring(1));if(d.NUMBER_DEC.test(b))return c*parseInt(b,10);if(d.NUMBER_HEX.test(b))return c*parseInt(b.substring(2),16);if(d.NUMBER_OCT.test(b))return c*parseInt(b.substring(1),8);if("inf"===b)return Infinity*c;if("nan"===b)return NaN;if(d.NUMBER_FLT.test(b))return c*parseFloat(b);throw Error("illegal number value: "+ +(0>c?"-":"")+b);}function l(b,c,d){"undefined"===typeof b[c]?b[c]=d:(Array.isArray(b[c])||(b[c]=[b[c]]),b[c].push(d))}var m={},a=function(b){this.source=b+"";this.index=0;this.line=1;this.stack=[];this._stringOpen=null},g=a.prototype;g._readString=function(){var b='"'===this._stringOpen?d.STRING_DQ:d.STRING_SQ;b.lastIndex=this.index-1;var c=b.exec(this.source);if(!c)throw Error("unterminated string");this.index=b.lastIndex;this.stack.push(this._stringOpen);this._stringOpen=null;return c[1]};g.next= +function(){if(0=this.source.length)return null;if(null!==this._stringOpen)return this._readString();var b,c;do{for(b=!1;d.WHITESPACE.test(c=this.source.charAt(this.index));)if("\n"===c&&++this.line,++this.index===this.source.length)return null;if("/"===this.source.charAt(this.index))if(++this.index,"/"===this.source.charAt(this.index)){for(;"\n"!==this.source.charAt(++this.index);)if(this.index==this.source.length)return null;++this.index; +++this.line;b=!0}else if("*"===(c=this.source.charAt(this.index))){do{"\n"===c&&++this.line;if(++this.index===this.source.length)return null;b=c;c=this.source.charAt(this.index)}while("*"!==b||"/"!==c);++this.index;b=!0}else return"/"}while(b);if(this.index===this.source.length)return null;c=this.index;d.DELIM.lastIndex=0;if(!d.DELIM.test(this.source.charAt(c++)))for(;c");c=this.tn.next(); +if(!d.NAME.test(c))throw Error("illegal message field name: "+c);g.name=c;this.tn.skip("=");g.id=f(this.tn.next());c=this.tn.peek();"["===c&&this._parseFieldOptions(g);this.tn.skip(";")}else if(a="undefined"!==typeof a?a:this.tn.next(),"group"===a){c=this._parseMessage(b,g);if(!/^[A-Z]/.test(c.name))throw Error("illegal group name: "+c.name);g.type=c.name;g.name=c.name.toLowerCase();this.tn.omit(";")}else{if(!d.TYPE.test(a)&&!d.TYPEREF.test(a))throw Error("illegal message field type: "+a);g.type= +a;c=this.tn.next();if(!d.NAME.test(c))throw Error("illegal message field name: "+c);g.name=c;this.tn.skip("=");g.id=f(this.tn.next());c=this.tn.peek();"["===c&&this._parseFieldOptions(g);this.tn.skip(";")}b.fields.push(g);return g};g._parseMessageOneOf=function(b){var c=this.tn.next();if(!d.NAME.test(c))throw Error("illegal oneof name: "+c);var a=c,g=[];for(this.tn.skip("{");"}"!==(c=this.tn.next());)c=this._parseMessageField(b,"optional",c),c.oneof=a,g.push(c.id);this.tn.omit(";");b.oneofs[a]=g}; +g._parseFieldOptions=function(b){this.tn.skip("[");for(var c=!0;"]"!==this.tn.peek();)c||this.tn.skip(","),this._parseOption(b,!0),c=!1;this.tn.next()};g._parseEnum=function(b){var c={name:"",values:[],options:{}},a=this.tn.next();if(!d.NAME.test(a))throw Error("illegal name: "+a);c.name=a;for(this.tn.skip("{");"}"!==(a=this.tn.next());)if("option"===a)this._parseOption(c);else{if(!d.NAME.test(a))throw Error("illegal name: "+a);this.tn.skip("=");var g={name:a,id:f(this.tn.next(),!0)},a=this.tn.peek(); +"["===a&&this._parseFieldOptions({options:{}});this.tn.skip(";");c.values.push(g)}this.tn.omit(";");b.enums.push(c)};g._parseExtensionRanges=function(){var a=[],c,d;do{for(d=[];;){c=this.tn.next();switch(c){case "min":c=b.ID_MIN;break;case "max":c=b.ID_MAX;break;default:c=t(c)}d.push(c);if(2===d.length)break;if("to"!==this.tn.peek()){d.push(c);break}this.tn.next()}a.push(d)}while(this.tn.omit(","));this.tn.skip(";");return a};g._parseExtend=function(b){var a=this.tn.next();if(!d.TYPEREF.test(a))throw Error("illegal extend reference: "+ +a);var g={ref:a,fields:[]};for(this.tn.skip("{");"}"!==(a=this.tn.next());)if(d.RULE.test(a))this._parseMessageField(g,a);else if(d.TYPEREF.test(a)){if(!this.proto3)throw Error("illegal field rule: "+a);this._parseMessageField(g,"optional",a)}else throw Error("illegal extend token: "+a);this.tn.omit(";");b.messages.push(g);return g};g.toString=function(){return"Parser at line "+this.tn.line};m.Parser=h;return m}(d,d.Lang);d.Reflect=function(b){function d(e,k){if(e&&"number"===typeof e.low&&"number"=== +typeof e.high&&"boolean"===typeof e.unsigned&&e.low===e.low&&e.high===e.high)return new b.Long(e.low,e.high,"undefined"===typeof k?e.unsigned:k);if("string"===typeof e)return b.Long.fromString(e,k||!1,10);if("number"===typeof e)return b.Long.fromNumber(e,k||!1);throw Error("not convertible to Long");}function z(e,k){var a=k.readVarint32(),c=a&7,a=a>>>3;switch(c){case b.WIRE_TYPES.VARINT:do a=k.readUint8();while(128===(a&128));break;case b.WIRE_TYPES.BITS64:k.offset+=8;break;case b.WIRE_TYPES.LDELIM:a= +k.readVarint32();k.offset+=a;break;case b.WIRE_TYPES.STARTGROUP:z(a,k);break;case b.WIRE_TYPES.ENDGROUP:if(a===e)return!1;throw Error("Illegal GROUPEND after unknown group: "+a+" ("+e+" expected)");case b.WIRE_TYPES.BITS32:k.offset+=4;break;default:throw Error("Illegal wire type in unknown group "+e+": "+c);}return!0}var q={},l=function(b,k,a){this.builder=b;this.parent=k;this.name=a},m=l.prototype;m.fqn=function(){var b=this.name,k=this;do{k=k.parent;if(null==k)break;b=k.name+"."+b}while(1);return b}; +m.toString=function(b){return(b?this.className+" ":"")+this.fqn()};m.build=function(){throw Error(this.toString(!0)+" cannot be built directly");};q.T=l;var a=function(b,k,a,c,d){l.call(this,b,k,a);this.className="Namespace";this.children=[];this.options=c||{};this.syntax=d||"proto2"},m=a.prototype=Object.create(l.prototype);m.getChildren=function(b){b=b||null;if(null==b)return this.children.slice();for(var e=[],a=0,c=this.children.length;ab.MAP_KEY_TYPES.indexOf(e))throw Error("Invalid map key type: "+e.name);},h=g.prototype;g.defaultFieldValue=function(e){"string"===typeof e&&(e=b.TYPES[e]);if("undefined"===typeof e.defaultValue)throw Error("default value for type "+e.name+" is not supported");return e==b.TYPES.bytes?new f(0):e.defaultValue}; +h.toString=function(){return(this.name||"")+(this.isMapKey?"map":"value")+" element"};h.verifyValue=function(e){function a(b,e){throw Error("Illegal value for "+c.toString(!0)+" of type "+c.type.name+": "+b+" ("+e+")");}var c=this;switch(this.type){case b.TYPES.int32:case b.TYPES.sint32:case b.TYPES.sfixed32:return("number"!==typeof e||e===e&&0!==e%1)&&a(typeof e,"not an integer"),4294967295e?e>>>0:e;case b.TYPES.int64:case b.TYPES.sint64:case b.TYPES.sfixed64:if(b.Long)try{return d(e,!1)}catch(y){a(typeof e,y.message)}else a(typeof e,"requires Long.js");case b.TYPES.uint64:case b.TYPES.fixed64:if(b.Long)try{return d(e,!0)}catch(y){a(typeof e,y.message)}else a(typeof e,"requires Long.js");case b.TYPES.bool:return"boolean"!==typeof e&&a(typeof e,"not a boolean"),e;case b.TYPES["float"]:case b.TYPES["double"]:return"number"!==typeof e&&a(typeof e,"not a number"),e;case b.TYPES.string:return"string"=== +typeof e||e&&e instanceof String||a(typeof e,"not a string"),""+e;case b.TYPES.bytes:return f.isByteBuffer(e)?e:f.wrap(e,"base64");case b.TYPES["enum"]:for(var g=this.resolvedType.getChildren(b.Reflect.Enum.Value),h=0;he)&&a(typeof e,"not in range for uint32"),e;a(e,"not a valid enum value");case b.TYPES.group:case b.TYPES.message:e&& +"object"===typeof e||a(typeof e,"object expected");if(e instanceof this.resolvedType.clazz)return e;if(e instanceof b.Builder.Message){var g={},h;for(h in e)e.hasOwnProperty(h)&&(g[h]=e[h]);e=g}return new this.resolvedType.clazz(e)}throw Error("[INTERNAL] Illegal value for "+this.toString(!0)+": "+e+" (undefined type "+this.type+")");};h.calculateLength=function(e,a){if(null===a)return 0;var c;switch(this.type){case b.TYPES.int32:return 0>a?f.calculateVarint64(a):f.calculateVarint32(a);case b.TYPES.uint32:return f.calculateVarint32(a); +case b.TYPES.sint32:return f.calculateVarint32(f.zigZagEncode32(a));case b.TYPES.fixed32:case b.TYPES.sfixed32:case b.TYPES["float"]:return 4;case b.TYPES.int64:case b.TYPES.uint64:return f.calculateVarint64(a);case b.TYPES.sint64:return f.calculateVarint64(f.zigZagEncode64(a));case b.TYPES.fixed64:case b.TYPES.sfixed64:return 8;case b.TYPES.bool:return 1;case b.TYPES["enum"]:return f.calculateVarint32(a);case b.TYPES["double"]:return 8;case b.TYPES.string:return c=f.calculateUTF8Bytes(a),f.calculateVarint32(c)+ +c;case b.TYPES.bytes:if(0>a.remaining())throw Error("Illegal value for "+this.toString(!0)+": "+a.remaining()+" bytes remaining");return f.calculateVarint32(a.remaining())+a.remaining();case b.TYPES.message:return c=this.resolvedType.calculate(a),f.calculateVarint32(c)+c;case b.TYPES.group:return c=this.resolvedType.calculate(a),c+f.calculateVarint32(e<<3|b.WIRE_TYPES.ENDGROUP)}throw Error("[INTERNAL] Illegal value to encode in "+this.toString(!0)+": "+a+" (unknown type)");};h.encodeValue=function(e, a,c){if(null===a)return c;switch(this.type){case b.TYPES.int32:0>a?c.writeVarint64(a):c.writeVarint32(a);break;case b.TYPES.uint32:c.writeVarint32(a);break;case b.TYPES.sint32:c.writeVarint32ZigZag(a);break;case b.TYPES.fixed32:c.writeUint32(a);break;case b.TYPES.sfixed32:c.writeInt32(a);break;case b.TYPES.int64:case b.TYPES.uint64:c.writeVarint64(a);break;case b.TYPES.sint64:c.writeVarint64ZigZag(a);break;case b.TYPES.fixed64:c.writeUint64(a);break;case b.TYPES.sfixed64:c.writeInt64(a);break;case b.TYPES.bool:"string"=== -typeof a?c.writeVarint32("false"===a.toLowerCase()?0:!!a):c.writeVarint32(a?1:0);break;case b.TYPES["enum"]:c.writeVarint32(a);break;case b.TYPES["float"]:c.writeFloat32(a);break;case b.TYPES["double"]:c.writeFloat64(a);break;case b.TYPES.string:c.writeVString(a);break;case b.TYPES.bytes:if(0>a.remaining())throw Error("Illegal value for "+this.toString(!0)+": "+a.remaining()+" bytes remaining");f=a.offset;c.writeVarint32(a.remaining());c.append(a);a.offset=f;break;case b.TYPES.message:f=(new g).LE(); -this.resolvedType.encode(a,f);c.writeVarint32(f.offset);c.append(f.flip());break;case b.TYPES.group:this.resolvedType.encode(a,c);c.writeVarint32(f<<3|b.WIRE_TYPES.ENDGROUP);break;default:throw Error("[INTERNAL] Illegal value to encode in "+this.toString(!0)+": "+a+" (unknown type)");}return c};l.decode=function(a,c,d){if(c!=this.type.wireType)throw Error("Unexpected wire type for element");switch(this.type){case b.TYPES.int32:return a.readVarint32()|0;case b.TYPES.uint32:return a.readVarint32()>>> +typeof a?c.writeVarint32("false"===a.toLowerCase()?0:!!a):c.writeVarint32(a?1:0);break;case b.TYPES["enum"]:c.writeVarint32(a);break;case b.TYPES["float"]:c.writeFloat32(a);break;case b.TYPES["double"]:c.writeFloat64(a);break;case b.TYPES.string:c.writeVString(a);break;case b.TYPES.bytes:if(0>a.remaining())throw Error("Illegal value for "+this.toString(!0)+": "+a.remaining()+" bytes remaining");e=a.offset;c.writeVarint32(a.remaining());c.append(a);a.offset=e;break;case b.TYPES.message:e=(new f).LE(); +this.resolvedType.encode(a,e);c.writeVarint32(e.offset);c.append(e.flip());break;case b.TYPES.group:this.resolvedType.encode(a,c);c.writeVarint32(e<<3|b.WIRE_TYPES.ENDGROUP);break;default:throw Error("[INTERNAL] Illegal value to encode in "+this.toString(!0)+": "+a+" (unknown type)");}return c};h.decode=function(a,c,d){if(c!=this.type.wireType)throw Error("Unexpected wire type for element");switch(this.type){case b.TYPES.int32:return a.readVarint32()|0;case b.TYPES.uint32:return a.readVarint32()>>> 0;case b.TYPES.sint32:return a.readVarint32ZigZag()|0;case b.TYPES.fixed32:return a.readUint32()>>>0;case b.TYPES.sfixed32:return a.readInt32()|0;case b.TYPES.int64:return a.readVarint64();case b.TYPES.uint64:return a.readVarint64().toUnsigned();case b.TYPES.sint64:return a.readVarint64ZigZag();case b.TYPES.fixed64:return a.readUint64();case b.TYPES.sfixed64:return a.readInt64();case b.TYPES.bool:return!!a.readVarint32();case b.TYPES["enum"]:return a.readVarint32();case b.TYPES["float"]:return a.readFloat(); -case b.TYPES["double"]:return a.readDouble();case b.TYPES.string:return a.readVString();case b.TYPES.bytes:d=a.readVarint32();if(a.remaining()b.remaining())return null;var f=b.offset,e=b.readVarint32();if(b.remaining()>>3;if(h===b.WIRE_TYPES.ENDGROUP){if(s!==e)throw Error("Illegal group end indicator for "+this.toString(!0)+": "+s+" ("+(e?e+" expected":"not a group")+")");break}if(l=this._fieldsById[s])l.repeated&&!l.options.packed?k[l.name].push(l.decode(h, -a)):l.map?(h=l.decode(h,a),k[l.name].set(h[0],h[1])):(k[l.name]=l.decode(h,a),l.oneof&&(h=k[l.oneof.name],null!==h&&h!==l.name&&(k[h]=null),k[l.oneof.name]=l.name));else switch(h){case b.WIRE_TYPES.VARINT:a.readVarint32();break;case b.WIRE_TYPES.BITS32:a.offset+=4;break;case b.WIRE_TYPES.BITS64:a.offset+=8;break;case b.WIRE_TYPES.LDELIM:l=a.readVarint32();a.offset+=l;break;case b.WIRE_TYPES.STARTGROUP:for(;p(s,a););break;default:throw Error("Illegal wire type for unknown field "+s+" in "+this.toString(!0)+ -"#decode: "+h);}}a=0;for(c=this._fields.length;ab.remaining())return null;var c=b.offset,d=b.readVarint32();if(b.remaining()>>3;if(h===b.WIRE_TYPES.ENDGROUP){if(f!==d)throw Error("Illegal group end indicator for "+this.toString(!0)+": "+f+" ("+(d?d+" expected":"not a group")+")");break}if(k=this._fieldsById[f])k.repeated&&!k.options.packed?g[k.name].push(k.decode(h, +a)):k.map?(h=k.decode(h,a),g[k.name].set(h[0],h[1])):(g[k.name]=k.decode(h,a),k.oneof&&(h=g[k.oneof.name],null!==h&&h!==k.name&&(g[h]=null),g[k.oneof.name]=k.name));else switch(h){case b.WIRE_TYPES.VARINT:a.readVarint32();break;case b.WIRE_TYPES.BITS32:a.offset+=4;break;case b.WIRE_TYPES.BITS64:a.offset+=8;break;case b.WIRE_TYPES.LDELIM:k=a.readVarint32();a.offset+=k;break;case b.WIRE_TYPES.STARTGROUP:for(;z(f,a););break;default:throw Error("Illegal wire type for unknown field "+f+" in "+this.toString(!0)+ +"#decode: "+h);}}a=0;for(c=this._fields.length;a>>=3,1===c)k=this.keyElement.decode(l,a,c);else if(2===c)d=this.element.decode(l,a,c);else throw Error("Unexpected tag in map field key/value submessage"); -return[k,d]}return this.element.decode(c,a,this.id)};q.Message.Field=c;l=function(a,b,e,d,k,l,h){c.call(this,a,b,e,null,d,k,l,h)};l.prototype=Object.create(c.prototype);q.Message.ExtensionField=l;q.Message.OneOf=function(a,b,c){n.call(this,a,b,c);this.fields=[]};var t=function(b,c,e,d,k){a.call(this,b,c,e,d,k);this.className="Enum";this.object=null};t.getName=function(a,b){for(var c=Object.keys(a),e=0,d;e=b[0]&&a.id<=b[1]&&(c=!0)});if(!c)throw Error("illegal extended field id in "+h.name+": "+a.id+" (not within valid ranges)");}var d=a.name;this.options.convertFieldsToCamelCase&&(d=b.Util.toCamelCase(d));var d=new g.Message.ExtensionField(this,h,a.rule,a.type,this.ptr.fqn()+"."+d,a.id,a.options),e=new g.Extension(this,this.ptr,a.name,d);d.extension=e;this.ptr.addChild(e);h.addChild(d)},this);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));h=d=null}a=null;this.ptr=this.ptr.parent}this.resolved=!1;this.result=null;return this};h["import"]=function(a,d){var h="/";if("string"===typeof d){b.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 g=d.root;b.Util.IS_NODE&&(g=require("path").resolve(g));if(0<=g.indexOf("\\")||0<=d.file.indexOf("\\"))h="\\";g=g+h+d.file;if(!0=== -this.files[g])return this.reset();this.files[g]=!0}if(a.imports&&0>>=3,1===c)e=this.keyElement.decode(h,a,c);else if(2===c)d=this.element.decode(h,a,c);else throw Error("Unexpected tag in map field key/value submessage"); +return[e,d]}return this.element.decode(c,a,this.id)};q.Message.Field=c;h=function(a,b,d,g,h,f,n){c.call(this,a,b,d,null,g,h,f,n)};h.prototype=Object.create(c.prototype);q.Message.ExtensionField=h;q.Message.OneOf=function(a,b,c){l.call(this,a,b,c);this.fields=[]};var w=function(b,c,d,g,h){a.call(this,b,c,d,g,h);this.className="Enum";this.object=null};w.getName=function(a,b){for(var c=Object.keys(a),d=0,e;d=b[0]&&a.id<=b[1]&&(c=!0)});if(!c)throw Error("illegal extended field id in "+n.name+": "+a.id+" (not within valid ranges)");}var d=a.name;this.options.convertFieldsToCamelCase&&(d=b.Util.toCamelCase(d));var d=new f.Message.ExtensionField(this,n,a.rule,a.type,this.ptr.fqn()+"."+d,a.id,a.options),g=new f.Extension(this,this.ptr,a.name,d);d.extension=g;this.ptr.addChild(g);n.addChild(d)},this);else{if(!/\.?google\.protobuf\./.test(h.ref))throw Error("extended message "+ +h.ref+" is not defined");}else throw Error("not a valid definition: "+JSON.stringify(h));n=h=null}a=null;this.ptr=this.ptr.parent}this.resolved=!1;this.result=null;return this};m["import"]=function(a,d){var g="/";if("string"===typeof d){b.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;b.Util.IS_NODE&&(f=require("path").resolve(f));if(0<=f.indexOf("\\")||0<=d.file.indexOf("\\"))g="\\";f=f+g+d.file;if(!0=== +this.files[f])return this.reset();this.files[f]=!0}if(a.imports&&0p){q=this.options.includePath[p++];continue}throw Error("failed to import '"+(f+g+l)+"' in '"+d+"': file not found");}if(/\.json$/i.test(q))this["import"](JSON.parse(e+""),q);else this["import"](b.DotProto.Parser.parse(e), +q);break}}else if(d)if(/\.(\w+)$/.test(d))this["import"](a.imports[m],d.replace(/^(.+)\.(\w+)$/,function(a,b,c){return b+"_import"+m+"."+c}));else this["import"](a.imports[m],d+"_import"+m);else this["import"](a.imports[m]);c&&(this.importRoot=null)}a["package"]&&this.define(a["package"]);a.syntax&&t(a);var k=this.ptr;a.options&&Object.keys(a.options).forEach(function(b){k.options[b]=a.options[b]});a.messages&&(this.create(a.messages),this.ptr=k);a.enums&&(this.create(a.enums),this.ptr=k);a.services&& +(this.create(a.services),this.ptr=k);a["extends"]&&this.create(a["extends"]);return this.reset()};m.resolveAll=function(){var a;if(null==this.ptr||"object"===typeof this.ptr.type)return this;if(this.ptr instanceof f.Namespace)this.ptr.children.forEach(function(a){this.ptr=a;this.resolveAll()},this);else if(this.ptr instanceof f.Message.Field){if(d.TYPE.test(this.ptr.type))this.ptr.type=b.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);a=(this.ptr instanceof f.Message.ExtensionField?this.ptr.extension.parent:this.ptr.parent).resolve(this.ptr.type,!0);if(!a)throw Error("unresolvable type reference in "+this.ptr.toString(!0)+": "+this.ptr.type);this.ptr.resolvedType=a;if(a instanceof f.Enum){if(this.ptr.type=b.TYPES["enum"],"proto3"===this.ptr.syntax&&"proto3"!==a.syntax)throw Error("proto3 message cannot reference proto2 enum");}else if(a instanceof f.Message)this.ptr.type=a.isGroup?b.TYPES.group:b.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=b.TYPES[this.ptr.keyType]}"proto3"===this.ptr.syntax&&this.ptr.repeated&&void 0===this.ptr.options.packed&&-1!==b.PACKABLE_WIRE_TYPES.indexOf(this.ptr.type.wireType)&&(this.ptr.options.packed=!0)}else if(this.ptr instanceof b.Reflect.Service.Method)if(this.ptr instanceof +b.Reflect.Service.RPCMethod){a=this.ptr.parent.resolve(this.ptr.requestName,!0);if(!(a&&a instanceof b.Reflect.Message))throw Error("Illegal type reference in "+this.ptr.toString(!0)+": "+this.ptr.requestName);this.ptr.resolvedRequestType=a;a=this.ptr.parent.resolve(this.ptr.responseName,!0);if(!(a&&a instanceof b.Reflect.Message))throw Error("Illegal type reference in "+this.ptr.toString(!0)+": "+this.ptr.responseName);this.ptr.resolvedResponseType=a}else throw Error("illegal service type in "+this.ptr.toString(!0)); +else if(!(this.ptr instanceof b.Reflect.Message.OneOf||this.ptr instanceof b.Reflect.Extension||this.ptr instanceof b.Reflect.Enum.Value))throw Error("illegal object in namespace: "+typeof this.ptr+": "+this.ptr);return this.reset()};m.build=function(a){this.reset();this.resolved||(this.resolveAll(),this.resolved=!0,this.result=null);null===this.result&&(this.result=this.ns.build());if(!a)return this.result;a="string"===typeof a?a.split("."):a;for(var b=this.result,d=0;d tmpImportPathIndex) { + tmpImportRoot = this.options.includePath[tmpImportPathIndex++]; + continue; + } + throw Error("failed to import '"+(importRoot + delim + importFilename)+"' in '"+filename+"': file not found"); + } + if (/\.json$/i.test(tmpImportFilename)) // Always possible + this["import"](JSON.parse(contents+""), tmpImportFilename); // May throw + else + this["import"](ProtoBuf.DotProto.Parser.parse(contents), tmpImportFilename); // May throw + break; + } } else // Import structure if (!filename) this["import"](json['imports'][i]);