Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

protobufjs

Package Overview
Dependencies
Maintainers
1
Versions
168
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

protobufjs - npm Package Compare versions

Comparing version 0.12.6 to 0.12.7

tests/custom-options.proto

2

package.json
{
"name": "protobufjs",
"version": "0.12.6",
"version": "0.12.7",
"author": "Daniel Wirtz <dcode@dcode.io>",

@@ -5,0 +5,0 @@ "description": "ProtoBuf.js: protobuf for JavaScript. No compilation step required, works out of the box.",

@@ -6,8 +6,8 @@ /*

*/
(function(p){function q(n){if(!n||!n.zigZagEncode32)throw Error("ProtoBuf.js requires ByteBuffer.js >=1.1.0: Get it at https://github.com/dcodeIO/ByteBuffer.js");var f={VERSION:"0.12.6",WIRE_TYPES:{}};f.WIRE_TYPES.VARINT=0;f.WIRE_TYPES.BITS64=1;f.WIRE_TYPES.LDELIM=2;f.WIRE_TYPES.STARTGROUP=3;f.WIRE_TYPES.ENDGROUP=4;f.WIRE_TYPES.BITS32=5;f.TYPES={int32:{name:"int32",wireType:f.WIRE_TYPES.VARINT},uint32:{name:"uint32",wireType:f.WIRE_TYPES.VARINT},sint32:{name:"sint32",wireType:f.WIRE_TYPES.VARINT},
(function(p){function q(n){if(!n||!n.zigZagEncode32)throw Error("ProtoBuf.js requires ByteBuffer.js >=1.1.0: Get it at https://github.com/dcodeIO/ByteBuffer.js");var f={VERSION:"0.12.7",WIRE_TYPES:{}};f.WIRE_TYPES.VARINT=0;f.WIRE_TYPES.BITS64=1;f.WIRE_TYPES.LDELIM=2;f.WIRE_TYPES.STARTGROUP=3;f.WIRE_TYPES.ENDGROUP=4;f.WIRE_TYPES.BITS32=5;f.TYPES={int32:{name:"int32",wireType:f.WIRE_TYPES.VARINT},uint32:{name:"uint32",wireType:f.WIRE_TYPES.VARINT},sint32:{name:"sint32",wireType:f.WIRE_TYPES.VARINT},
int64:{name:"int64",wireType:f.WIRE_TYPES.VARINT},uint64:{name:"uint64",wireType:f.WIRE_TYPES.VARINT},sint64:{name:"sint64",wireType:f.WIRE_TYPES.VARINT},bool:{name:"bool",wireType:f.WIRE_TYPES.VARINT},"double":{name:"double",wireType:f.WIRE_TYPES.BITS64},string:{name:"string",wireType:f.WIRE_TYPES.LDELIM},bytes:{name:"bytes",wireType:f.WIRE_TYPES.LDELIM},fixed32:{name:"fixed32",wireType:f.WIRE_TYPES.BITS32},sfixed32:{name:"sfixed32",wireType:f.WIRE_TYPES.BITS32},fixed64:{name:"fixed64",wireType:f.WIRE_TYPES.BITS64},
sfixed64:{name:"sfixed64",wireType:f.WIRE_TYPES.BITS64},"float":{name:"float",wireType:f.WIRE_TYPES.BITS32},"enum":{name:"enum",wireType:f.WIRE_TYPES.VARINT},message:{name:"message",wireType:f.WIRE_TYPES.LDELIM}};f.Long=n.Long;f.Util=function(){Object.create||(Object.create=function(b){function c(){}if(1<arguments.length)throw Error("Object.create implementation only accepts the first parameter.");c.prototype=b;return new c});var c={};c.IS_NODE=("undefined"==typeof window||!window.window)&&"function"==
typeof require;c.XHR=function(){for(var b=[function(){return new XMLHttpRequest},function(){return new ActiveXObject("Msxml2.XMLHTTP")},function(){return new ActiveXObject("Msxml3.XMLHTTP")},function(){return new ActiveXObject("Microsoft.XMLHTTP")}],c=null,g=0;g<b.length;g++){try{c=b[g]()}catch(a){continue}break}if(!c)throw Error("XMLHttpRequest is not supported");return c};c.fetch=function(b,m){m&&"function"!=typeof m&&(m=null);if(c.IS_NODE)if(m)require("fs").readFile(b,function(a,b){a?m(null):m(""+
b)});else try{return require("fs").readFileSync(b)}catch(g){return null}else{var a=c.XHR();a.open("GET",b,m?!0:!1);a.setRequestHeader("User-Agent","XMLHTTP/1.0");a.setRequestHeader("Accept","text/plain");if(m)a.onreadystatechange=function(){4==a.readyState&&(200==a.status?m(a.responseText):m(null))},4!=a.readyState&&a.send(null);else return a.send(null),a.responseText}};return c}();f.Lang={OPEN:"{",CLOSE:"}",OPTOPEN:"[",OPTCLOSE:"]",OPTEND:",",EQUAL:"=",END:";",DELIM:/[\s\{\}=;\[\],"\(\)]/g,KEYWORD:/package|option|import|message|enum|extend/,
RULE:/required|optional|repeated/,TYPE:/double|float|int32|uint32|sint32|int64|uint64|sint64|fixed32|sfixed32|fixed64|sfixed64|bool|string|bytes/,NAME:/[a-zA-Z][a-zA-Z_0-9]*/,TYPEDEF:/[a-zA-Z](\.?[a-zA-Z_0-9])*/,TYPEREF:/\.?[a-zA-Z](\.?[a-zA-Z_0-9])*/,NUMBER:/-?([1-9][0-9]*)|0/,ID:/[0-9]+/,WHITESPACE:/\s/,STRING:/"([^"\\]*(\\.[^"\\]*)*)"/g,STRINGOPEN:'"',STRINGCLOSE:'"',COPTOPEN:"(",COPTCLOSE:")"};f.DotProto={};f.DotProto.Tokenizer=function(c){var b=function(b){this.source=""+b;this.index=0;this.stack=
typeof require;c.XHR=function(){for(var b=[function(){return new XMLHttpRequest},function(){return new ActiveXObject("Msxml2.XMLHTTP")},function(){return new ActiveXObject("Msxml3.XMLHTTP")},function(){return new ActiveXObject("Microsoft.XMLHTTP")}],c=null,h=0;h<b.length;h++){try{c=b[h]()}catch(a){continue}break}if(!c)throw Error("XMLHttpRequest is not supported");return c};c.fetch=function(b,m){m&&"function"!=typeof m&&(m=null);if(c.IS_NODE)if(m)require("fs").readFile(b,function(a,b){a?m(null):m(""+
b)});else try{return require("fs").readFileSync(b)}catch(h){return null}else{var a=c.XHR();a.open("GET",b,m?!0:!1);a.setRequestHeader("User-Agent","XMLHTTP/1.0");a.setRequestHeader("Accept","text/plain");if(m)a.onreadystatechange=function(){4==a.readyState&&(200==a.status?m(a.responseText):m(null))},4!=a.readyState&&a.send(null);else return a.send(null),a.responseText}};return c}();f.Lang={OPEN:"{",CLOSE:"}",OPTOPEN:"[",OPTCLOSE:"]",OPTEND:",",EQUAL:"=",END:";",DELIM:/[\s\{\}=;\[\],"\(\)]/g,KEYWORD:/package|option|import|message|enum|extend|service/,
RULE:/required|optional|repeated/,TYPE:/double|float|int32|uint32|sint32|int64|uint64|sint64|fixed32|sfixed32|fixed64|sfixed64|bool|string|bytes/,NAME:/[a-zA-Z][a-zA-Z_0-9]*/,TYPEDEF:/[a-zA-Z](\.?[a-zA-Z_0-9])*/,TYPEREF:/\.?[a-zA-Z](\.?[a-zA-Z_0-9])*/,NUMBER:/^-?([1-9][0-9]*)|0$/,ID:/[0-9]+/,WHITESPACE:/\s/,STRING:/"([^"\\]*(\\.[^"\\]*)*)"/g,STRINGOPEN:'"',STRINGCLOSE:'"',COPTOPEN:"(",COPTCLOSE:")"};f.DotProto={};f.DotProto.Tokenizer=function(c){var b=function(b){this.source=""+b;this.index=0;this.stack=
[];this.readingString=!1};b.prototype._readString=function(){c.STRING.lastIndex=this.index-1;var b;if(null!==(b=c.STRING.exec(this.source)))return b=b[1],this.index=c.STRING.lastIndex,this.stack.push(c.STRINGCLOSE),b;throw Error("Illegal string value at index "+this.index);};b.prototype.next=function(){if(0<this.stack.length)return this.stack.pop();if(this.index>=this.source.length)return null;if(this.readingString)return this.readingString=!1,this._readString();var b;do{for(b=!1;c.WHITESPACE.test(this.source.charAt(this.index));)if(this.index++,

@@ -17,49 +17,50 @@ this.index==this.source.length)return null;if("/"==this.source.charAt(this.index))if("/"==this.source.charAt(++this.index)){for(;"\n"!=this.source.charAt(this.index);)if(this.index++,this.index==this.source.length)return null;this.index++;b=!0}else if("*"==this.source.charAt(this.index)){for(b="";"*/"!=b+(b=this.source.charAt(this.index));)if(this.index++,this.index==this.source.length)return null;this.index++;b=!0}else throw Error("Invalid comment: /"+this.source.charAt(this.index)+" ('/' or '*' expected)");

function(){var b={name:"[ROOT]","package":null,messages:[],enums:[],imports:[],options:{}},a,d=!0;do{a=this.tn.next();if(null==a)break;if("package"==a){if(!d)throw Error("Illegal package definition: Must be declared before the first message or enum");if(null!==b["package"])throw Error("Illegal package definition: Package already declared");b["package"]=this._parsePackage(a)}else if("import"==a){if(!d)throw Error("Illegal import definition: Must be declared before the first message or enum");b.imports.push(this._parseImport(a))}else if("message"==
a)this._parseMessage(b,a),d=!1;else if("enum"==a)this._parseEnum(b,a),d=!1;else if("option"==a){if(!d)throw Error("Illegal option definition: Must be declared before the first message or enum");this._parseOption(b,a)}else if("extend"==a)this._parseExtend(b,a);else throw Error("Illegal top level declaration: "+a);}while(1);delete b.name;return b};c.prototype._parsePackage=function(c){c=this.tn.next();if(!b.TYPEDEF.test(c))throw Error("Illegal package name: "+c);var a=c;c=this.tn.next();if(c!=b.END)throw Error("Illegal end of package definition: "+
c+" ('"+b.END+"' expected)");return a};c.prototype._parseImport=function(c){c=this.tn.next();"public"==c&&(c=this.tn.next());if(c!=b.STRINGOPEN)throw Error("Illegal begin of import value: "+c+" ('"+b.STRINGOPEN+"' expected)");var a=this.tn.next();c=this.tn.next();if(c!=b.STRINGCLOSE)throw Error("Illegal end of import value: "+c+" ('"+b.STRINGCLOSE+"' expected)");c=this.tn.next();if(c!=b.END)throw Error("Illegal end of import definition: "+c+" ('"+b.END+"' expected)");return a};c.prototype._parseOption=
function(c,a){a=this.tn.next();var d=!1;a==b.COPTOPEN&&(d=!0,a=this.tn.next());if(!b.NAME.test(a))throw Error("Illegal option name in message "+c.name+": "+a);var e=a;a=this.tn.next();if(d){if(a!=b.COPTCLOSE)throw Error("Illegal custom option delimiter in message "+c.name+", option "+e+": "+a+" ('"+b.COPTCLOSE+"' expected)");a=this.tn.next()}if(a!=b.EQUAL)throw Error("Illegal option operator in message "+c.name+", option "+e+": "+a+" ('"+b.EQUAL+"' expected)");a=this.tn.next();if(a==b.STRINGOPEN){if(d=
this.tn.next(),a=this.tn.next(),a!=b.STRINGCLOSE)throw Error("Illegal end of option value in message "+c.name+", option "+e+": "+a+" ('"+b.STRINGCLOSE+"' expected)");}else if(b.NUMBER.test(a))d=parseInt(a);else if(b.NAME.test(a))d=a;else throw Error("Illegal option value in message "+c.name+", option "+e+": "+a);a=this.tn.next();if(a!=b.END)throw Error("Illegal end of option in message "+c.name+", option "+e+": "+a+" ('"+b.END+"' expected)");c.options[e]=d};c.prototype._parseExtend=function(c,a){a=
this.tn.next();if(!b.TYPEREF.test(a))throw Error("Illegal extended type in "+c.name+": "+a);var d=a;a=this.tn.next();if(a!=b.OPEN)throw Error("Illegal OPEN in "+c.name+" after extend "+d+": "+a);var e=1;do{a=this.tn.next();if(null===a)throw Error("Illegal nesting in "+c.name+", extend "+d+": EOF");if(a==b.OPEN)e++;else if(a==b.CLOSE&&(e--,0==e))break}while(1)};c.prototype._parseMessage=function(c,a){var d={};a=this.tn.next();if(!b.NAME.test(a))throw Error("Illegal message name"+(c?" in message "+
c.name:"")+": "+a);d.name=a;a=this.tn.next();if(a!=b.OPEN)throw Error("Illegal OPEN after message "+d.name+": "+a+" ('"+b.OPEN+"' expected)");d.fields=[];d.enums=[];d.messages=[];d.options={};do if(a=this.tn.next(),a==b.CLOSE)break;else if(b.RULE.test(a))this._parseMessageField(d,a);else if("enum"==a)this._parseEnum(d,a);else if("message"==a)this._parseMessage(d,a);else if("option"==a)this._parseOption(d,a);else throw Error("Illegal token in message "+d.name+": "+a+" (type or '"+b.CLOSE+"' expected)");
while(1);c.messages.push(d);return d};c.prototype._parseMessageField=function(c,a){var d={};d.rule=a;a=this.tn.next();if(!b.TYPE.test(a)&&!b.TYPEREF.test(a))throw Error("Illegal field type in message "+c.name+": "+a);d.type=a;a=this.tn.next();if(!b.NAME.test(a))throw Error("Illegal field name in message "+c.name+": "+a);d.name=a;a=this.tn.next();if(a!=b.EQUAL)throw Error("Illegal field number operator in message "+c.name+"#"+d.name+": "+a+" ('"+b.EQUAL+"' expected)");a=this.tn.next();if(!b.ID.test(a))throw Error("Illegal field number in message "+
c.name+"#"+d.name+": "+a);d.id=parseInt(a,10);d.options={};a=this.tn.next();a==b.OPTOPEN&&(this._parseMessageFieldOptions(c,d,a),a=this.tn.next());if(a!=b.END)throw Error("Illegal field delimiter in message "+c.name+"#"+d.name+": "+a+" ('"+b.END+"' expected)");c.fields.push(d)};c.prototype._parseMessageFieldOptions=function(c,a,d){var e=!0;do{d=this.tn.next();if(d==b.OPTCLOSE)break;else if(d==b.OPTEND){if(e)throw Error("Illegal start of message field options in message "+c.name+"#"+a.name+": "+d);
d=this.tn.next()}if(!b.NAME.test(d))throw Error("Illegal field option in message "+c.name+"#"+a.name+": "+d);this._parseMessageFieldOption(c,a,d);e=!1}while(1)};c.prototype._parseMessageFieldOption=function(c,a,d){var e=d;d=this.tn.next();if(d!=b.EQUAL)throw Error("Illegal field option operation in message "+c.name+"#"+a.name+": "+d+" ('=' expected)");var h;d=this.tn.next();if(d==b.STRINGOPEN){if(h=this.tn.next(),d=this.tn.next(),d!=b.STRINGCLOSE)throw Error("Illegal end of field value in message "+
c.name+"#"+a.name+", option "+e+": "+d+" ('"+b.STRINGCLOSE+"' expected)");}else if(b.NUMBER.test(d))h=parseInt(d,10);else if(b.NAME.test(d))h=d;else throw Error("Illegal field option value in message "+c.name+"#"+a.name+", option "+e+": "+d);a.options[e]=h};c.prototype._parseEnum=function(c,a){var d={};a=this.tn.next();if(!b.NAME.test(a))throw Error("Illegal enum name in message "+c.name+": "+a);d.name=a;a=this.tn.next();if(a!=b.OPEN)throw Error("Illegal OPEN after enum "+d.name+": "+a);d.values=
[];do{a=this.tn.next();if(a==b.CLOSE)break;else if(!b.NAME.test(a))throw Error("Illegal enum value name in enum "+d.name+": "+a);this._parseEnumValue(d,a)}while(1);c.enums.push(d)};c.prototype._parseEnumValue=function(c,a){var d={};d.name=a;a=this.tn.next();if(a!=b.EQUAL)throw Error("Illegal enum value operator in enum "+c.name+": "+a+" ('"+b.EQUAL+"' expected)");a=this.tn.next();if(!b.ID.test(a))throw Error("Illegal enum value value in enum "+c.name+": "+a);d.id=parseInt(a,10);c.values.push(d);a=
this.tn.next();if(a!=b.END)throw Error("Illegal enum value delimiter in enum "+c.name+": "+a+" ('"+b.END+"' expected)");};c.prototype.toString=function(){return"Parser"};return c}(f,f.Lang,f.DotProto.Tokenizer);f.Reflect=function(c){var b={},f=function(a,c){this.parent=a;this.name=c;this.resolvedType=null};f.prototype.toString=function(c){var l=this.name,k=this;do{k=k.parent;if(null==k)break;l=k.name+"."+l}while(1);c&&(this instanceof b.Message?l="Message "+l:this instanceof a.Field?l="Message.Field "+
l:this instanceof e?l="Enum "+l:this instanceof e.Value?l="Enum.Value "+l:this instanceof g&&(l="Namespace "+l));return l};f.prototype.build=function(){throw Error(this.toString(!0)+" cannot be built directly");};b.T=f;var g=function(a,c,b){f.call(this,a,c);this.children=[];this.options=b||{}};g.prototype=Object.create(f.prototype);g.prototype.getChildren=function(a){a=a||null;if(null==a)return this.children.slice();for(var c=[],b=0;b<this.children.length;b++)this.children[b]instanceof a&&c.push(this.children[b]);
return c};g.prototype.addChild=function(a){if(this.hasChild(a.name))throw Error("Duplicate name in namespace "+this.toString(!0)+": "+a.name);this.children.push(a)};g.prototype.hasChild=function(c){var b;if("number"==typeof c)for(b=0;b<this.children.length;b++){if(this.children[b]instanceof a.Field&&this.children[b].id==c)return!0}else for(b=0;b<this.children.length;b++)if(this.children[b].name==c)return!0;return!1};g.prototype.getChild=function(c){var b;if("number"==typeof c)for(b=0;b<this.children.length;b++){if(this.children[b]instanceof
a.Field&&this.children[b].id==c)return this.children[b]}else for(b=0;b<this.children.length;b++)if(this.children[b].name==c)return this.children[b];return null};g.prototype.resolve=function(a){var c=a.split("."),d=this,e=0;if(""==c[e]){for(;null!=d.parent;)d=d.parent;e++}do{do{d=d.getChild(c[e]);if(!d||!(d instanceof b.T)){d=null;break}e++}while(e<c.length);if(null!=d)break;if(null!==this.parent)return this.parent.resolve(a)}while(null!=d);return d};g.prototype.build=function(){for(var a={},c=this.getChildren(),
b,d=0;d<c.length;d++)b=c[d],b instanceof g&&(a[b.name]=b.build());Object.defineProperty&&Object.defineProperty(a,"$options",{value:this.buildOpt(),enumerable:!1,configurable:!1,writable:!1});return a};g.prototype.buildOpt=function(){for(var a={},c=Object.keys(this.options),b=0;b<c.length;b++)a[c[b]]=this.options[c[b]];return a};g.prototype.getOption=function(a){return"undefined"==typeof a?this.options:"undefined"!=typeof this.options[a]?this.options[a]:null};b.Namespace=g;var a=function(a,c,b){g.call(this,
a,c,b);this.built=null};a.prototype=Object.create(g.prototype);a.prototype.build=function(){for(var d=function(a,b){var d=b.getChildren(a.Message.Field),h=eval("(function "+b.name+"() { this.__construct.apply(this, arguments); })");h.prototype.__construct=function(a){var b,h;for(b=0;b<d.length;b++)h=d[b],this[h.name]=h.repeated?[]:null;for(b=0;b<d.length;b++)if(h=d[b],"undefined"!=typeof h.options["default"])try{this.set(h.name,h.options["default"])}catch(l){throw Error("[INTERNAL ERROR] "+l);}if(1==
arguments.length&&"object"==typeof a&&"function"!=typeof a.encode&&!(a instanceof Array)&&!(a instanceof n)&&!(a instanceof ArrayBuffer)&&!(c.Long&&a instanceof c.Long)){h=Object.keys(a);for(b=0;b<h.length;b++)this.set(h[b],a[h[b]])}else for(b=0;b<arguments.length;b++)b<d.length&&this.set(d[b].name,arguments[b])};h.prototype.add=function(c,h){var d=b.getChild(c);if(!d)throw Error(this+"#"+c+" is undefined");if(!(d instanceof a.Message.Field))throw Error(this+"#"+c+" is not a field: "+d.toString(!0));
if(!d.repeated)throw Error(this+"#"+c+" is not a repeated field");null===this[d.name]&&(this[d.name]=[]);this[d.name].push(d.verifyValue(h,!0))};h.prototype.set=function(c,h){var d=b.getChild(c);if(!d)throw Error(this+"#"+c+" is not a field: undefined");if(!(d instanceof a.Message.Field))throw Error(this+"#"+c+" is not a field: "+d.toString(!0));this[d.name]=d.verifyValue(h)};h.prototype.get=function(c){var d=b.getChild(c);if(!d||!(d instanceof a.Message.Field))throw Error(this+"#"+c+" is not a field: undefined");
if(!(d instanceof a.Message.Field))throw Error(this+"#"+c+" is not a field: "+d.toString(!0));return this[d.name]};for(var l=0;l<d.length;l++)(function(a){var c=a.name.replace(/(_[a-zA-Z])/g,function(a){return a.toUpperCase().replace("_","")}),c=c.substring(0,1).toUpperCase()+c.substring(1),d=a.name.replace(/([A-Z])/g,function(a){return"_"+a});b.hasChild("set"+c)||(h.prototype["set"+c]=function(b){this.set(a.name,b)});b.hasChild("set_"+d)||(h.prototype["set_"+d]=function(b){this.set(a.name,b)});b.hasChild("get"+
c)||(h.prototype["get"+c]=function(){return this.get(a.name)});b.hasChild("get_"+d)||(h.prototype["get_"+d]=function(){return this.get(a.name)})})(d[l]);h.prototype.encode=function(a){a=a||new n;var c=a.littleEndian,d=b.encode(this,a.LE()).flip();a.littleEndian=c;return d};h.prototype.toArrayBuffer=function(){return this.encode().toArrayBuffer()};h.decode=function(a){a=a?a instanceof n?a:n.wrap(a):new n;var c=a.littleEndian,d=b.decode(a.LE());a.littleEndian=c;return d};h.prototype.toString=function(){return b.toString()};
Object.defineProperty&&Object.defineProperty(h,"$options",{value:b.buildOpt(),enumerable:!1,configurable:!1,writable:!1});return h}(b,this),l=this.getChildren(),k=0;k<l.length;k++)if(l[k]instanceof e)d[l[k].name]=l[k].build();else if(l[k]instanceof a)d[l[k].name]=l[k].build();else if(!(l[k]instanceof a.Field))throw Error("Illegal reflect child of "+this.toString(!0)+": "+l[k].toString(!0));return this.built=d};a.prototype.encode=function(b,c){for(var d=this.getChildren(a.Field),e=0;e<d.length;e++)d[e].encode(b.get(d[e].name),
c);return c};a.prototype.decode=function(a,b){b=b||-1;for(var c=a.offset,d=new this.built;a.offset<c+b||-1==b&&0<a.remaining();){var e=a.readVarint32(),f=e&7,e=e>>3,g=this.getChild(e);if(!g)throw Error("Illegal field id in "+this.toString(!0)+"#decode: "+e);g.repeated&&!g.options.packed?d.add(g.name,g.decode(f,a)):d.set(g.name,g.decode(f,a))}return d};b.Message=a;var d=function(a,b,c,d,e,g){f.call(this,a,d);this.required="required"==b;this.repeated="repeated"==b;this.type=c;this.id=e;this.options=
g||{}};d.prototype=Object.create(f.prototype);d.prototype.verifyValue=function(a,b){b=b||!1;if(null===a){if(this.required)throw Error("Illegal value for "+this.toString(!0)+": "+a+" (required)");return null}var d,f;if(this.repeated&&!b){a instanceof Array||(a=[a]);f=[];for(d=0;d<a.length;d++)f.push(this.verifyValue(a[d],!0));return f}if(!this.repeated&&a instanceof Array)throw Error("Illegal value for "+this.toString(!0)+": "+a+" (no array expected)");if(this.type==c.TYPES.int32||this.type==c.TYPES.sint32||
this.type==c.TYPES.sfixed32)return parseInt(a,10)|0;if(this.type==c.TYPES.uint32||this.type==c.TYPES.fixed32)return parseInt(a,10)>>>0;if(c.Long){if(this.type==c.TYPES.int64||this.type==c.TYPES.sint64||this.type==c.TYPES.sfixed64)return!("object"==typeof a&&a instanceof c.Long)?c.Long.fromNumber(a,!1):a.unsigned?a.toSigned():a;if(this.type==c.TYPES.uint64||this.type==c.TYPES.fixed64)return!("object"==typeof a&&a instanceof c.Long)?c.Long.fromNumber(a,!0):a.unsigned?a:a.toUnsigned()}if(this.type==
c.TYPES.bool)return!!a;if(this.type==c.TYPES["float"]||this.type==c.TYPES["double"])return parseFloat(a);if(this.type==c.TYPES.string)return""+a;if(this.type==c.TYPES.bytes)return"object"==typeof a&&a instanceof n?a:n.wrap(a);if(this.type==c.TYPES["enum"]){f=this.resolvedType.getChildren(e.Value);for(d=0;d<f.length;d++)if(f[d].name==a||f[d].id==a)return f[d].id;throw Error("Illegal value for "+this.toString(!0)+": "+a+" (not a valid enum value)");}if(this.type==c.TYPES.message){if("object"!=typeof a)throw Error("Illegal value for "+
this.toString(!0)+": "+a+" (object expected)");return a instanceof this.resolvedType.built?a:new this.resolvedType.built(a)}throw Error("[INTERNAL ERROR] Illegal value for "+this.toString(!0)+": "+a+" (undefined type "+this.type+")");};d.prototype.encode=function(a,b){a=this.verifyValue(a);if(null==this.type||"object"!=typeof this.type)throw Error("[INTERNAL ERROR] Unresolved type in "+this.toString(!0)+": "+this.type);if(null===a||this.repeated&&0==a.length)return b;try{if(this.repeated){var d;if(this.options.packed){b.writeVarint32(this.id<<
3|c.WIRE_TYPES.LDELIM);b.ensureCapacity(b.offset+=1);var e=b.offset;for(d=0;d<a.length;d++)this.encodeValue(a[d],b);var f=b.offset-e,g=n.calculateVarint32(f);if(1<g){var m=b.slice(e,b.offset),e=e+(g-1);b.offset=e;b.append(m)}b.writeVarint32(f,e-g)}else for(d=0;d<a.length;d++)b.writeVarint32(this.id<<3|this.type.wireType),this.encodeValue(a[d],b)}else b.writeVarint32(this.id<<3|this.type.wireType),this.encodeValue(a,b)}catch(p){throw b.littleEndian=le,Error("Illegal value for "+this.toString(!0)+": "+
a+" ("+p+")");}return b};d.prototype.encodeValue=function(a,b){if(null!==a){if(this.type==c.TYPES.int32||this.type==c.TYPES.uint32)b.writeVarint32(a);else if(this.type==c.TYPES.sint32)b.writeZigZagVarint32(a);else if(this.type==c.TYPES.fixed32)b.writeUint32(a);else if(this.type==c.TYPES.sfixed32)b.writeInt32(a);else if(this.type==c.TYPES.int64||this.type==c.TYPES.uint64)b.writeVarint64(a);else if(this.type==c.TYPES.sint64)b.writeZigZagVarint64(a);else if(this.type==c.TYPES.fixed64)b.writeUint64(a);
else if(this.type==c.TYPES.sfixed64)b.writeInt64(a);else if(this.type==c.TYPES.bool)b.writeVarint32(a?1:0);else if(this.type==c.TYPES["enum"])b.writeVarint32(a);else if(this.type==c.TYPES["float"])b.writeFloat32(a);else if(this.type==c.TYPES["double"])b.writeFloat64(a);else if(this.type==c.TYPES.string)b.writeVString(a);else if(this.type==c.TYPES.bytes)a.offset>a.length&&(b=b.clone().flip()),b.writeVarint32(a.remaining()),b.append(a);else if(this.type==c.TYPES.message){var d=b.offset;b.writeUint8(0);
this.resolvedType.encode(a,b);var e=b.offset-d-1,f=n.calculateVarint32(e);if(1<f){var g=b.clone();g.offset-=e;b.append(g.flip(),d-1+f)}b.writeVarint32(e,d)}else throw Error("[INTERNAL ERROR] Illegal value to encode in "+this.toString(!0)+": "+a+" (unknown type)");return b}};d.prototype.decode=function(a,b,d){if(a!=this.type.wireType&&(d||a!=c.WIRE_TYPES.LDELIM||!this.repeated))throw Error("Illegal wire type for field "+this.toString(!0)+": "+a+" ("+this.type.wireType+" expected)");if(a==c.WIRE_TYPES.LDELIM&&
(this.repeated&&this.options.packed)&&!d){a=b.readVarint32();a=b.offset+a;for(d=[];b.offset<a;)d.push(this.decode(this.type.wireType,b,!0));return d}if(this.type==c.TYPES.int32)return b.readVarint32()|0;if(this.type==c.TYPES.uint32)return b.readVarint32()>>>0;if(this.type==c.TYPES.sint32)return b.readZigZagVarint32()|0;if(this.type==c.TYPES.fixed32)return b.readUint32()>>>0;if(this.type==c.TYPES.sfixed32)return b.readInt32()|0;if(this.type==c.TYPES.int64)return b.readVarint64();if(this.type==c.TYPES.uint64)return b.readVarint64().toUnsigned();
if(this.type==c.TYPES.sint64)return b.readZigZagVarint64();if(this.type==c.TYPES.fixed64)return b.readUint64();if(this.type==c.TYPES.sfixed64)return b.readInt64();if(this.type==c.TYPES.bool)return!!b.readVarint32();if(this.type==c.TYPES["enum"])return b.readVarint32();if(this.type==c.TYPES["float"])return b.readFloat();if(this.type==c.TYPES["double"])return b.readDouble();if(this.type==c.TYPES.string)return b.readVString();if(this.type==c.TYPES.bytes)return a=b.readVarint32(),d=b.clone(),d.length=
d.offset+a,b.offset+=a,d;if(this.type==c.TYPES.message)return a=b.readVarint32(),this.resolvedType.decode(b,a);throw Error("[INTERNAL ERROR] Illegal wire type for "+this.toString(!0)+": "+a);};b.Message.Field=d;var e=function(a,b,c){g.call(this,a,b,c);this.built=null};e.prototype=Object.create(g.prototype);e.prototype.build=function(){for(var a={},b=this.getChildren(e.Value),c=0;c<b.length;c++)a[b[c].name]=b[c].id;Object.defineProperty&&Object.defineProperty(a,"$options",{value:this.buildOpt(),enumerable:!1,
configurable:!1,writable:!1});return this.built=a};b.Enum=e;d=function(a,b,c){f.call(this,a,b);this.id=c};d.prototype=Object.create(f.prototype);b.Enum.Value=d;return b}(f);f.Builder=function(c,b,f){var g=function(){this.ptr=this.ns=new f.Namespace(null,"");this.resolved=!1;this.result=null};g.prototype.reset=function(){this.ptr=this.ns};g.prototype.define=function(a,c){if("string"!=typeof a||!b.TYPEDEF.test(a))throw Error("Illegal package name: "+a);var e=a.split("."),h;for(h=0;h<e.length;h++)if(!b.NAME.test(e[h]))throw Error("Illegal package name: "+
e[h]);for(h=0;h<e.length;h++)this.ptr.hasChild(e[h])||this.ptr.addChild(new f.Namespace(this.ptr,e[h],c)),this.ptr=this.ptr.getChild(e[h]);return this};g.isValidMessage=function(a){if("string"!=typeof a.name||!b.NAME.test(a.name)||"undefined"!=typeof a.values)return!1;var c;if("undefined"!=typeof a.fields){if(!(a.fields instanceof Array))return!1;var e=[],f;for(c=0;c<a.fields.length;c++){if(!g.isValidMessageField(a.fields[c]))return!1;f=parseInt(a.id,10);if(0<=e.indexOf(f))return!1;e.push(f)}}if("undefined"!=
typeof a.enums){if(!(a.enums instanceof Array))return!1;for(c=0;c<a.enums.length;c++)if(!g.isValidEnum(a.enums[c]))return!1}if("undefined"!=typeof a.messages){if(!(a.messages instanceof Array))return!1;for(c=0;c<a.messages.length;c++)if(!g.isValidMessage(a.messages[c]))return!1}return!0};g.isValidMessageField=function(a){if("string"!=typeof a.rule||"string"!=typeof a.name||"string"!=typeof a.type||"undefined"==typeof a.id||!b.RULE.test(a.rule)||!b.NAME.test(a.name)||!b.TYPEREF.test(a.type)||!b.ID.test(""+
a.id))return!1;if("undefined"!=typeof a.options){if("object"!=typeof a.options)return!1;for(var c=Object.keys(a.options),e=0;e<c.length;e++)if(!b.NAME.test(c[e])||!b.ID.test(""+a.options[c[e]])&&!b.TYPEREF.test(a.options[c[e]]))return!1}return!0};g.isValidEnum=function(a){if("string"!=typeof a.name||!b.NAME.test(a.name)||"undefined"==typeof a.values||!(a.values instanceof Array)||0==a.values.length)return!1;for(var c=0;c<a.values.length;c++)if("object"!=typeof a.values[c]||"string"!=typeof a.values[c].name||
"undefined"==typeof a.values[c].id||!b.NAME.test(a.values[c].name)||!b.ID.test(""+a.values[c].id))return!1;return!0};g.prototype.create=function(a){if(a&&(a instanceof Array||(a=[a]),0!=a.length)){var c=[],e,h,l,k,n;for(c.push(a);0<c.length;){a=c.pop();if(a instanceof Array)for(;0<a.length;)if(e=a.shift(),g.isValidMessage(e)){h=new f.Message(this.ptr,e.name,e.options);if(e.fields&&0<e.fields.length)for(k=0;k<e.fields.length;k++){if(!g.isValidMessageField(e.fields[k]))throw Error("Not a valid message field definition in message "+
h.name+": "+JSON.stringify(e.fields[k]));if(h.hasChild(e.fields[k].id))throw Error("Duplicate field id in message "+h.name+": "+e.fields[k].id);if(e.fields[k].options){l=Object.keys(e.fields[k].options);for(n=0;n<l.length;n++){if(!b.NAME.test(l[n]))throw Error("Illegal field option name in message "+h.name+"#"+e.fields[k].name+": "+l[n]);if(!b.ID.test(""+e.fields[k].options[l[n]])&&!b.TYPEREF.test(e.fields[k].options[l[n]]))throw Error("Illegal field option value in message "+h.name+"#"+e.fields[k].name+
"#"+l[n]+": "+e.fields[k].options[l[n]]);}}h.addChild(new f.Message.Field(h,e.fields[k].rule,e.fields[k].type,e.fields[k].name,e.fields[k].id,e.fields[k].options))}l=[];if("undefined"!=typeof e.enums&&0<e.enums.length)for(k=0;k<e.enums.length;k++)l.push(e.enums[k]);if(e.messages&&0<e.messages.length)for(k=0;k<e.messages.length;k++)l.push(e.messages[k]);this.ptr.addChild(h);0<l.length&&(c.push(a),a=l,this.ptr=h)}else if(g.isValidEnum(e)){h=new f.Enum(this.ptr,e.name,e.options);for(k=0;k<e.values.length;k++)h.addChild(new f.Enum.Value(h,
e.values[k].name,e.values[k].id));this.ptr.addChild(h)}else throw Error("Not a valid message or enum definition: "+JSON.stringify(e));else throw Error("Not a valid namespace definition: "+JSON.stringify(a));this.ptr=this.ptr.parent}this.resolved=!1;this.result=null;return this}};g.prototype["import"]=function(a,b){a["package"]&&this.define(a["package"],a.options);a.messages&&this.create(a.messages);this.reset();if(a.imports&&0<a.imports.length){if(!b)throw Error("Cannot determine import root: File name is unknown");
for(var e=b.replace(/[\/\\][^\/\\]*$/,""),f=0;f<a.imports.length;f++){var g=e+"/"+a.imports[f];if(/\.json$/i.test(g)){var k=c.Util.fetch(g);if(null===k)throw Error("Failed to import '"+g+"' in '"+b+"': File not found");this["import"](JSON.parse(k),g)}else if(!/google\/protobuf\//.test(g)){k=c.Util.fetch(g);if(null===k)throw Error("Failed to import '"+g+"' in '"+b+"': File not found");k=new c.DotProto.Parser(k+"");this["import"](k.parse(),g)}}}return this};g.prototype.resolveAll=function(){if(!(null==
this.ptr||"object"==typeof this.ptr.type)){if(this.ptr instanceof f.Namespace)for(var a=this.ptr.getChildren(),d=0;d<a.length;d++)this.ptr=a[d],this.resolveAll();else if(this.ptr instanceof f.Message.Field)if(b.TYPE.test(this.ptr.type))this.ptr.type=c.TYPES[this.ptr.type];else{if(!b.TYPEREF.test(this.ptr.type))throw Error("Illegal type reference in "+this.ptr.toString(!0)+": "+this.ptr.type);a=this.ptr.parent.resolve(this.ptr.type);if(!a)throw Error("Unresolvable type reference in "+this.ptr.toString(!0)+
": "+this.ptr.type);this.ptr.resolvedType=a;if(a instanceof f.Enum)this.ptr.type=c.TYPES["enum"];else if(a instanceof f.Message)this.ptr.type=c.TYPES.message;else throw Error("Illegal type reference in "+this.ptr.toString(!0)+": "+this.ptr.type);}else if(!(this.ptr instanceof c.Reflect.Enum.Value))throw Error("Illegal object type in namespace: "+typeof this.ptr+":"+this.ptr);this.reset()}};g.prototype.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){a=a.split(".");for(var b=this.result,c=0;c<a.length;c++)if(b[a[c]])b=b[a[c]];else{b=null;break}return b}return this.result};g.prototype.toString=function(){return"Builder"};return g}(f,f.Lang,f.Reflect);f.protoFromString=function(c,b,m){"string"==typeof b&&(m=b,b=null);c=(new f.DotProto.Parser(c+"")).parse();b="object"==typeof b?b:new f.Builder;null!==c["package"]&&b.define(c["package"],c.options);b.create(c.messages);b.reset();null!==c["package"]&&
b.define(c["package"],c.options);b.create(c.enums);b.reset();if(m&&0<c.imports.length)b["import"]({imports:c.imports},m);b.resolveAll();b.build();return b};f.protoFromFile=function(c,b,m){if(b&&"object"==typeof b)m=b,b=null;else if(!b||"function"!=typeof b)b=null;if(b)f.Util.fetch(c,function(a){b(f.protoFromString(a,m,c))});else{var g=f.Util.fetch(c);return null!==g?f.protoFromString(g,m,c):null}};f.newBuilder=function(c,b){var m=new f.Builder;"undefined"!=typeof c&&m.define(c,b);return m};return f}
"undefined"!=typeof module&&module.exports?module.exports=q(require("bytebuffer")):"undefined"!=typeof define&&define.amd?define("ProtoBuf",["ByteBuffer"],q):(p.dcodeIO||(p.dcodeIO={}),p.dcodeIO.ProtoBuf=q(p.dcodeIO.ByteBuffer))})(this);
a)this._parseMessage(b,a),d=!1;else if("enum"==a)this._parseEnum(b,a),d=!1;else if("option"==a){if(!d)throw Error("Illegal option definition: Must be declared before the first message or enum");this._parseOption(b,a)}else if("extend"==a||"service"==a)this._parseIgnored(b,a);else throw Error("Illegal top level declaration: "+a);}while(1);delete b.name;return b};c.prototype._parsePackage=function(c){c=this.tn.next();if(!b.TYPEDEF.test(c))throw Error("Illegal package name: "+c);var a=c;c=this.tn.next();
if(c!=b.END)throw Error("Illegal end of package definition: "+c+" ('"+b.END+"' expected)");return a};c.prototype._parseImport=function(c){c=this.tn.next();"public"==c&&(c=this.tn.next());if(c!=b.STRINGOPEN)throw Error("Illegal begin of import value: "+c+" ('"+b.STRINGOPEN+"' expected)");var a=this.tn.next();c=this.tn.next();if(c!=b.STRINGCLOSE)throw Error("Illegal end of import value: "+c+" ('"+b.STRINGCLOSE+"' expected)");c=this.tn.next();if(c!=b.END)throw Error("Illegal end of import definition: "+
c+" ('"+b.END+"' expected)");return a};c.prototype._parseOption=function(c,a){a=this.tn.next();var d=!1;a==b.COPTOPEN&&(d=!0,a=this.tn.next());if(!b.NAME.test(a))throw Error("Illegal option name in message "+c.name+": "+a);var e=a;a=this.tn.next();if(d){if(a!=b.COPTCLOSE)throw Error("Illegal custom option name delimiter in message "+c.name+", option "+e+": "+a+" ('"+b.COPTCLOSE+"' expected)");a=this.tn.next()}if(a!=b.EQUAL)throw Error("Illegal option operator in message "+c.name+", option "+e+": "+
a+" ('"+b.EQUAL+"' expected)");a=this.tn.next();if(a==b.STRINGOPEN){if(d=this.tn.next(),a=this.tn.next(),a!=b.STRINGCLOSE)throw Error("Illegal end of option value in message "+c.name+", option "+e+": "+a+" ('"+b.STRINGCLOSE+"' expected)");}else if(b.NUMBER.test(a))d=parseInt(a);else if(b.NAME.test(a))d=a;else throw Error("Illegal option value in message "+c.name+", option "+e+": "+a);a=this.tn.next();if(a!=b.END)throw Error("Illegal end of option in message "+c.name+", option "+e+": "+a+" ('"+b.END+
"' expected)");c.options[e]=d};c.prototype._parseIgnored=function(c,a){var d=this.tn.next();if(!b.TYPEREF.test(d))throw Error("Illegal "+a+" type in "+c.name+": "+d);var e=d,d=this.tn.next();if(d!=b.OPEN)throw Error("Illegal OPEN in "+c.name+" after "+a+" "+e+": "+d);var g=1;do{d=this.tn.next();if(null===d)throw Error("Illegal nesting in "+c.name+", "+a+" "+e+": EOF");if(d==b.OPEN)g++;else if(d==b.CLOSE&&(g--,0==g))break}while(1)};c.prototype._parseMessage=function(c,a){var d={};a=this.tn.next();
if(!b.NAME.test(a))throw Error("Illegal message name"+(c?" in message "+c.name:"")+": "+a);d.name=a;a=this.tn.next();if(a!=b.OPEN)throw Error("Illegal OPEN after message "+d.name+": "+a+" ('"+b.OPEN+"' expected)");d.fields=[];d.enums=[];d.messages=[];d.options={};do if(a=this.tn.next(),a==b.CLOSE)break;else if(b.RULE.test(a))this._parseMessageField(d,a);else if("enum"==a)this._parseEnum(d,a);else if("message"==a)this._parseMessage(d,a);else if("option"==a)this._parseOption(d,a);else throw Error("Illegal token in message "+
d.name+": "+a+" (type or '"+b.CLOSE+"' expected)");while(1);c.messages.push(d);return d};c.prototype._parseMessageField=function(c,a){var d={};d.rule=a;a=this.tn.next();if(!b.TYPE.test(a)&&!b.TYPEREF.test(a))throw Error("Illegal field type in message "+c.name+": "+a);d.type=a;a=this.tn.next();if(!b.NAME.test(a))throw Error("Illegal field name in message "+c.name+": "+a);d.name=a;a=this.tn.next();if(a!=b.EQUAL)throw Error("Illegal field number operator in message "+c.name+"#"+d.name+": "+a+" ('"+b.EQUAL+
"' expected)");a=this.tn.next();if(!b.ID.test(a))throw Error("Illegal field number in message "+c.name+"#"+d.name+": "+a);d.id=parseInt(a,10);d.options={};a=this.tn.next();a==b.OPTOPEN&&(this._parseFieldOptions(c,d,a),a=this.tn.next());if(a!=b.END)throw Error("Illegal field delimiter in message "+c.name+"#"+d.name+": "+a+" ('"+b.END+"' expected)");c.fields.push(d)};c.prototype._parseFieldOptions=function(c,a,d){var e=!0;do{d=this.tn.next();if(d==b.OPTCLOSE)break;else if(d==b.OPTEND){if(e)throw Error("Illegal start of message field options in message "+
c.name+"#"+a.name+": "+d);d=this.tn.next()}this._parseFieldOption(c,a,d);e=!1}while(1)};c.prototype._parseFieldOption=function(c,a,d){var e=!1;d==b.COPTOPEN&&(d=this.tn.next(),e=!0);if(!b.NAME.test(d))throw Error("Illegal field option in message "+c.name+"#"+a.name+": "+d);var g=d;d=this.tn.next();if(e){if(d!=b.COPTCLOSE)throw Error("Illegal custom field option name delimiter in message "+c.name+"#"+a.name+": "+d+" (')' expected)");d=this.tn.next()}if(d!=b.EQUAL)throw Error("Illegal field option operation in message "+
c.name+"#"+a.name+": "+d+" ('=' expected)");d=this.tn.next();if(d==b.STRINGOPEN){if(e=this.tn.next(),d=this.tn.next(),d!=b.STRINGCLOSE)throw Error("Illegal end of field value in message "+c.name+"#"+a.name+", option "+g+": "+d+" ('"+b.STRINGCLOSE+"' expected)");}else if(b.NUMBER.test(d))e=parseFloat(d);else if(b.TYPEREF.test(d))e=d;else throw Error("Illegal field option value in message "+c.name+"#"+a.name+", option "+g+": "+d);a.options[g]=e};c.prototype._parseEnum=function(c,a){var d={};a=this.tn.next();
if(!b.NAME.test(a))throw Error("Illegal enum name in message "+c.name+": "+a);d.name=a;a=this.tn.next();if(a!=b.OPEN)throw Error("Illegal OPEN after enum "+d.name+": "+a);d.values=[];d.options={};do{a=this.tn.next();if(a==b.CLOSE)break;if("option"==a)this._parseOption(d,a);else{if(!b.NAME.test(a))throw Error("Illegal enum value name in enum "+d.name+": "+a);this._parseEnumValue(d,a)}}while(1);c.enums.push(d)};c.prototype._parseEnumValue=function(c,a){var d={};d.name=a;a=this.tn.next();if(a!=b.EQUAL)throw Error("Illegal enum value operator in enum "+
c.name+": "+a+" ('"+b.EQUAL+"' expected)");a=this.tn.next();if(!b.ID.test(a))throw Error("Illegal enum value value in enum "+c.name+": "+a);d.id=parseInt(a,10);c.values.push(d);a=this.tn.next();a==b.OPTOPEN&&(this._parseFieldOptions(c,{options:{}},a),a=this.tn.next());if(a!=b.END)throw Error("Illegal enum value delimiter in enum "+c.name+": "+a+" ('"+b.END+"' expected)");};c.prototype.toString=function(){return"Parser"};return c}(f,f.Lang,f.DotProto.Tokenizer);f.Reflect=function(c){var b={},f=function(a,
c){this.parent=a;this.name=c;this.resolvedType=null};f.prototype.toString=function(c){var k=this.name,d=this;do{d=d.parent;if(null==d)break;k=d.name+"."+k}while(1);c&&(this instanceof b.Message?k="Message "+k:this instanceof a.Field?k="Message.Field "+k:this instanceof e?k="Enum "+k:this instanceof e.Value?k="Enum.Value "+k:this instanceof h&&(k="Namespace "+k));return k};f.prototype.build=function(){throw Error(this.toString(!0)+" cannot be built directly");};b.T=f;var h=function(a,c,b){f.call(this,
a,c);this.children=[];this.options=b||{}};h.prototype=Object.create(f.prototype);h.prototype.getChildren=function(a){a=a||null;if(null==a)return this.children.slice();for(var c=[],b=0;b<this.children.length;b++)this.children[b]instanceof a&&c.push(this.children[b]);return c};h.prototype.addChild=function(a){if(this.hasChild(a.name))throw Error("Duplicate name in namespace "+this.toString(!0)+": "+a.name);this.children.push(a)};h.prototype.hasChild=function(c){var b;if("number"==typeof c)for(b=0;b<
this.children.length;b++){if(this.children[b]instanceof a.Field&&this.children[b].id==c)return!0}else for(b=0;b<this.children.length;b++)if(this.children[b].name==c)return!0;return!1};h.prototype.getChild=function(c){var b;if("number"==typeof c)for(b=0;b<this.children.length;b++){if(this.children[b]instanceof a.Field&&this.children[b].id==c)return this.children[b]}else for(b=0;b<this.children.length;b++)if(this.children[b].name==c)return this.children[b];return null};h.prototype.resolve=function(a){var c=
a.split("."),d=this,e=0;if(""==c[e]){for(;null!=d.parent;)d=d.parent;e++}do{do{d=d.getChild(c[e]);if(!d||!(d instanceof b.T)){d=null;break}e++}while(e<c.length);if(null!=d)break;if(null!==this.parent)return this.parent.resolve(a)}while(null!=d);return d};h.prototype.build=function(){for(var a={},c=this.getChildren(),b,d=0;d<c.length;d++)b=c[d],b instanceof h&&(a[b.name]=b.build());Object.defineProperty&&Object.defineProperty(a,"$options",{value:this.buildOpt(),enumerable:!1,configurable:!1,writable:!1});
return a};h.prototype.buildOpt=function(){for(var a={},c=Object.keys(this.options),b=0;b<c.length;b++)a[c[b]]=this.options[c[b]];return a};h.prototype.getOption=function(a){return"undefined"==typeof a?this.options:"undefined"!=typeof this.options[a]?this.options[a]:null};b.Namespace=h;var a=function(a,c,b){h.call(this,a,c,b);this.built=null};a.prototype=Object.create(h.prototype);a.prototype.build=function(){for(var d=function(a,b){var d=b.getChildren(a.Message.Field),g=eval("(function "+b.name+"() { this.__construct.apply(this, arguments); })");
g.prototype.__construct=function(a){var b,g;for(b=0;b<d.length;b++)g=d[b],this[g.name]=g.repeated?[]:null;for(b=0;b<d.length;b++)if(g=d[b],"undefined"!=typeof g.options["default"])try{this.set(g.name,g.options["default"])}catch(k){throw Error("[INTERNAL ERROR] "+k);}if(1==arguments.length&&"object"==typeof a&&"function"!=typeof a.encode&&!(a instanceof Array)&&!(a instanceof n)&&!(a instanceof ArrayBuffer)&&!(c.Long&&a instanceof c.Long)){g=Object.keys(a);for(b=0;b<g.length;b++)this.set(g[b],a[g[b]])}else for(b=
0;b<arguments.length;b++)b<d.length&&this.set(d[b].name,arguments[b])};g.prototype.add=function(c,d){var g=b.getChild(c);if(!g)throw Error(this+"#"+c+" is undefined");if(!(g instanceof a.Message.Field))throw Error(this+"#"+c+" is not a field: "+g.toString(!0));if(!g.repeated)throw Error(this+"#"+c+" is not a repeated field");null===this[g.name]&&(this[g.name]=[]);this[g.name].push(g.verifyValue(d,!0))};g.prototype.set=function(c,d){var g=b.getChild(c);if(!g)throw Error(this+"#"+c+" is not a field: undefined");
if(!(g instanceof a.Message.Field))throw Error(this+"#"+c+" is not a field: "+g.toString(!0));this[g.name]=g.verifyValue(d)};g.prototype.get=function(c){var g=b.getChild(c);if(!g||!(g instanceof a.Message.Field))throw Error(this+"#"+c+" is not a field: undefined");if(!(g instanceof a.Message.Field))throw Error(this+"#"+c+" is not a field: "+g.toString(!0));return this[g.name]};for(var k=0;k<d.length;k++)(function(a){var c=a.name.replace(/(_[a-zA-Z])/g,function(a){return a.toUpperCase().replace("_",
"")}),c=c.substring(0,1).toUpperCase()+c.substring(1),d=a.name.replace(/([A-Z])/g,function(a){return"_"+a});b.hasChild("set"+c)||(g.prototype["set"+c]=function(b){this.set(a.name,b)});b.hasChild("set_"+d)||(g.prototype["set_"+d]=function(b){this.set(a.name,b)});b.hasChild("get"+c)||(g.prototype["get"+c]=function(){return this.get(a.name)});b.hasChild("get_"+d)||(g.prototype["get_"+d]=function(){return this.get(a.name)})})(d[k]);g.prototype.encode=function(a){a=a||new n;var c=a.littleEndian,g=b.encode(this,
a.LE()).flip();a.littleEndian=c;return g};g.prototype.toArrayBuffer=function(){return this.encode().toArrayBuffer()};g.decode=function(a){a=a?a instanceof n?a:n.wrap(a):new n;var c=a.littleEndian,g=b.decode(a.LE());a.littleEndian=c;return g};g.prototype.toString=function(){return b.toString()};Object.defineProperty&&Object.defineProperty(g,"$options",{value:b.buildOpt(),enumerable:!1,configurable:!1,writable:!1});return g}(b,this),k=this.getChildren(),l=0;l<k.length;l++)if(k[l]instanceof e)d[k[l].name]=
k[l].build();else if(k[l]instanceof a)d[k[l].name]=k[l].build();else if(!(k[l]instanceof a.Field))throw Error("Illegal reflect child of "+this.toString(!0)+": "+k[l].toString(!0));return this.built=d};a.prototype.encode=function(b,c){for(var d=this.getChildren(a.Field),e=0;e<d.length;e++)d[e].encode(b.get(d[e].name),c);return c};a.prototype.decode=function(a,b){b=b||-1;for(var c=a.offset,d=new this.built;a.offset<c+b||-1==b&&0<a.remaining();){var e=a.readVarint32(),f=e&7,e=e>>3,h=this.getChild(e);
if(!h)throw Error("Illegal field id in "+this.toString(!0)+"#decode: "+e);h.repeated&&!h.options.packed?d.add(h.name,h.decode(f,a)):d.set(h.name,h.decode(f,a))}return d};b.Message=a;var d=function(a,b,c,d,e,h){f.call(this,a,d);this.required="required"==b;this.repeated="repeated"==b;this.type=c;this.id=e;this.options=h||{}};d.prototype=Object.create(f.prototype);d.prototype.verifyValue=function(a,b){b=b||!1;if(null===a){if(this.required)throw Error("Illegal value for "+this.toString(!0)+": "+a+" (required)");
return null}var d,f;if(this.repeated&&!b){a instanceof Array||(a=[a]);f=[];for(d=0;d<a.length;d++)f.push(this.verifyValue(a[d],!0));return f}if(!this.repeated&&a instanceof Array)throw Error("Illegal value for "+this.toString(!0)+": "+a+" (no array expected)");if(this.type==c.TYPES.int32||this.type==c.TYPES.sint32||this.type==c.TYPES.sfixed32)return parseInt(a,10)|0;if(this.type==c.TYPES.uint32||this.type==c.TYPES.fixed32)return parseInt(a,10)>>>0;if(c.Long){if(this.type==c.TYPES.int64||this.type==
c.TYPES.sint64||this.type==c.TYPES.sfixed64)return!("object"==typeof a&&a instanceof c.Long)?c.Long.fromNumber(a,!1):a.unsigned?a.toSigned():a;if(this.type==c.TYPES.uint64||this.type==c.TYPES.fixed64)return!("object"==typeof a&&a instanceof c.Long)?c.Long.fromNumber(a,!0):a.unsigned?a:a.toUnsigned()}if(this.type==c.TYPES.bool)return!!a;if(this.type==c.TYPES["float"]||this.type==c.TYPES["double"])return parseFloat(a);if(this.type==c.TYPES.string)return""+a;if(this.type==c.TYPES.bytes)return"object"==
typeof a&&a instanceof n?a:n.wrap(a);if(this.type==c.TYPES["enum"]){f=this.resolvedType.getChildren(e.Value);for(d=0;d<f.length;d++)if(f[d].name==a||f[d].id==a)return f[d].id;throw Error("Illegal value for "+this.toString(!0)+": "+a+" (not a valid enum value)");}if(this.type==c.TYPES.message){if("object"!=typeof a)throw Error("Illegal value for "+this.toString(!0)+": "+a+" (object expected)");return a instanceof this.resolvedType.built?a:new this.resolvedType.built(a)}throw Error("[INTERNAL ERROR] Illegal value for "+
this.toString(!0)+": "+a+" (undefined type "+this.type+")");};d.prototype.encode=function(a,b){a=this.verifyValue(a);if(null==this.type||"object"!=typeof this.type)throw Error("[INTERNAL ERROR] Unresolved type in "+this.toString(!0)+": "+this.type);if(null===a||this.repeated&&0==a.length)return b;try{if(this.repeated){var d;if(this.options.packed){b.writeVarint32(this.id<<3|c.WIRE_TYPES.LDELIM);b.ensureCapacity(b.offset+=1);var e=b.offset;for(d=0;d<a.length;d++)this.encodeValue(a[d],b);var f=b.offset-
e,h=n.calculateVarint32(f);if(1<h){var m=b.slice(e,b.offset),e=e+(h-1);b.offset=e;b.append(m)}b.writeVarint32(f,e-h)}else for(d=0;d<a.length;d++)b.writeVarint32(this.id<<3|this.type.wireType),this.encodeValue(a[d],b)}else b.writeVarint32(this.id<<3|this.type.wireType),this.encodeValue(a,b)}catch(p){throw b.littleEndian=le,Error("Illegal value for "+this.toString(!0)+": "+a+" ("+p+")");}return b};d.prototype.encodeValue=function(a,b){if(null!==a){if(this.type==c.TYPES.int32||this.type==c.TYPES.uint32)b.writeVarint32(a);
else if(this.type==c.TYPES.sint32)b.writeZigZagVarint32(a);else if(this.type==c.TYPES.fixed32)b.writeUint32(a);else if(this.type==c.TYPES.sfixed32)b.writeInt32(a);else if(this.type==c.TYPES.int64||this.type==c.TYPES.uint64)b.writeVarint64(a);else if(this.type==c.TYPES.sint64)b.writeZigZagVarint64(a);else if(this.type==c.TYPES.fixed64)b.writeUint64(a);else if(this.type==c.TYPES.sfixed64)b.writeInt64(a);else if(this.type==c.TYPES.bool)b.writeVarint32(a?1:0);else if(this.type==c.TYPES["enum"])b.writeVarint32(a);
else if(this.type==c.TYPES["float"])b.writeFloat32(a);else if(this.type==c.TYPES["double"])b.writeFloat64(a);else if(this.type==c.TYPES.string)b.writeVString(a);else if(this.type==c.TYPES.bytes)a.offset>a.length&&(b=b.clone().flip()),b.writeVarint32(a.remaining()),b.append(a);else if(this.type==c.TYPES.message){var d=b.offset;b.writeUint8(0);this.resolvedType.encode(a,b);var e=b.offset-d-1,f=n.calculateVarint32(e);if(1<f){var h=b.clone();h.offset-=e;b.append(h.flip(),d-1+f)}b.writeVarint32(e,d)}else throw Error("[INTERNAL ERROR] Illegal value to encode in "+
this.toString(!0)+": "+a+" (unknown type)");return b}};d.prototype.decode=function(a,b,d){if(a!=this.type.wireType&&(d||a!=c.WIRE_TYPES.LDELIM||!this.repeated))throw Error("Illegal wire type for field "+this.toString(!0)+": "+a+" ("+this.type.wireType+" expected)");if(a==c.WIRE_TYPES.LDELIM&&(this.repeated&&this.options.packed)&&!d){a=b.readVarint32();a=b.offset+a;for(d=[];b.offset<a;)d.push(this.decode(this.type.wireType,b,!0));return d}if(this.type==c.TYPES.int32)return b.readVarint32()|0;if(this.type==
c.TYPES.uint32)return b.readVarint32()>>>0;if(this.type==c.TYPES.sint32)return b.readZigZagVarint32()|0;if(this.type==c.TYPES.fixed32)return b.readUint32()>>>0;if(this.type==c.TYPES.sfixed32)return b.readInt32()|0;if(this.type==c.TYPES.int64)return b.readVarint64();if(this.type==c.TYPES.uint64)return b.readVarint64().toUnsigned();if(this.type==c.TYPES.sint64)return b.readZigZagVarint64();if(this.type==c.TYPES.fixed64)return b.readUint64();if(this.type==c.TYPES.sfixed64)return b.readInt64();if(this.type==
c.TYPES.bool)return!!b.readVarint32();if(this.type==c.TYPES["enum"])return b.readVarint32();if(this.type==c.TYPES["float"])return b.readFloat();if(this.type==c.TYPES["double"])return b.readDouble();if(this.type==c.TYPES.string)return b.readVString();if(this.type==c.TYPES.bytes)return a=b.readVarint32(),d=b.clone(),d.length=d.offset+a,b.offset+=a,d;if(this.type==c.TYPES.message)return a=b.readVarint32(),this.resolvedType.decode(b,a);throw Error("[INTERNAL ERROR] Illegal wire type for "+this.toString(!0)+
": "+a);};b.Message.Field=d;var e=function(a,b,c){h.call(this,a,b,c);this.built=null};e.prototype=Object.create(h.prototype);e.prototype.build=function(){for(var a={},b=this.getChildren(e.Value),c=0;c<b.length;c++)a[b[c].name]=b[c].id;Object.defineProperty&&Object.defineProperty(a,"$options",{value:this.buildOpt(),enumerable:!1,configurable:!1,writable:!1});return this.built=a};b.Enum=e;d=function(a,b,c){f.call(this,a,b);this.id=c};d.prototype=Object.create(f.prototype);b.Enum.Value=d;return b}(f);
f.Builder=function(c,b,f){var h=function(){this.ptr=this.ns=new f.Namespace(null,"");this.resolved=!1;this.result=null};h.prototype.reset=function(){this.ptr=this.ns};h.prototype.define=function(a,c){if("string"!=typeof a||!b.TYPEDEF.test(a))throw Error("Illegal package name: "+a);var e=a.split("."),g;for(g=0;g<e.length;g++)if(!b.NAME.test(e[g]))throw Error("Illegal package name: "+e[g]);for(g=0;g<e.length;g++)this.ptr.hasChild(e[g])||this.ptr.addChild(new f.Namespace(this.ptr,e[g],c)),this.ptr=this.ptr.getChild(e[g]);
return this};h.isValidMessage=function(a){if("string"!=typeof a.name||!b.NAME.test(a.name)||"undefined"!=typeof a.values)return!1;var c;if("undefined"!=typeof a.fields){if(!(a.fields instanceof Array))return!1;var e=[],g;for(c=0;c<a.fields.length;c++){if(!h.isValidMessageField(a.fields[c]))return!1;g=parseInt(a.id,10);if(0<=e.indexOf(g))return!1;e.push(g)}}if("undefined"!=typeof a.enums){if(!(a.enums instanceof Array))return!1;for(c=0;c<a.enums.length;c++)if(!h.isValidEnum(a.enums[c]))return!1}if("undefined"!=
typeof a.messages){if(!(a.messages instanceof Array))return!1;for(c=0;c<a.messages.length;c++)if(!h.isValidMessage(a.messages[c]))return!1}return!0};h.isValidMessageField=function(a){if("string"!=typeof a.rule||"string"!=typeof a.name||"string"!=typeof a.type||"undefined"==typeof a.id||!b.RULE.test(a.rule)||!b.NAME.test(a.name)||!b.TYPEREF.test(a.type)||!b.ID.test(""+a.id))return!1;if("undefined"!=typeof a.options){if("object"!=typeof a.options)return!1;for(var c=Object.keys(a.options),e=0;e<c.length;e++)if(!b.NAME.test(c[e])||
!b.ID.test(""+a.options[c[e]])&&!b.TYPEREF.test(a.options[c[e]]))return!1}return!0};h.isValidEnum=function(a){if("string"!=typeof a.name||!b.NAME.test(a.name)||"undefined"==typeof a.values||!(a.values instanceof Array)||0==a.values.length)return!1;for(var c=0;c<a.values.length;c++)if("object"!=typeof a.values[c]||"string"!=typeof a.values[c].name||"undefined"==typeof a.values[c].id||!b.NAME.test(a.values[c].name)||!b.ID.test(""+a.values[c].id))return!1;return!0};h.prototype.create=function(a){if(a&&
(a instanceof Array||(a=[a]),0!=a.length)){var c=[],e,g,k,l,n;for(c.push(a);0<c.length;){a=c.pop();if(a instanceof Array)for(;0<a.length;)if(e=a.shift(),h.isValidMessage(e)){g=new f.Message(this.ptr,e.name,e.options);if(e.fields&&0<e.fields.length)for(l=0;l<e.fields.length;l++){if(!h.isValidMessageField(e.fields[l]))throw Error("Not a valid message field definition in message "+g.name+": "+JSON.stringify(e.fields[l]));if(g.hasChild(e.fields[l].id))throw Error("Duplicate field id in message "+g.name+
": "+e.fields[l].id);if(e.fields[l].options){k=Object.keys(e.fields[l].options);for(n=0;n<k.length;n++){if(!b.NAME.test(k[n]))throw Error("Illegal field option name in message "+g.name+"#"+e.fields[l].name+": "+k[n]);if(!b.ID.test(""+e.fields[l].options[k[n]])&&!b.TYPEREF.test(e.fields[l].options[k[n]]))throw Error("Illegal field option value in message "+g.name+"#"+e.fields[l].name+"#"+k[n]+": "+e.fields[l].options[k[n]]);}}g.addChild(new f.Message.Field(g,e.fields[l].rule,e.fields[l].type,e.fields[l].name,
e.fields[l].id,e.fields[l].options))}k=[];if("undefined"!=typeof e.enums&&0<e.enums.length)for(l=0;l<e.enums.length;l++)k.push(e.enums[l]);if(e.messages&&0<e.messages.length)for(l=0;l<e.messages.length;l++)k.push(e.messages[l]);this.ptr.addChild(g);0<k.length&&(c.push(a),a=k,this.ptr=g)}else if(h.isValidEnum(e)){g=new f.Enum(this.ptr,e.name,e.options);for(l=0;l<e.values.length;l++)g.addChild(new f.Enum.Value(g,e.values[l].name,e.values[l].id));this.ptr.addChild(g)}else throw Error("Not a valid message or enum definition: "+
JSON.stringify(e));else throw Error("Not a valid namespace definition: "+JSON.stringify(a));this.ptr=this.ptr.parent}this.resolved=!1;this.result=null;return this}};h.prototype["import"]=function(a,b){a["package"]&&this.define(a["package"],a.options);a.messages&&this.create(a.messages);this.reset();if(a.imports&&0<a.imports.length){if(!b)throw Error("Cannot determine import root: File name is unknown");for(var e=b.replace(/[\/\\][^\/\\]*$/,""),g=0;g<a.imports.length;g++){var f=e+"/"+a.imports[g];
if(/\.json$/i.test(f)){var h=c.Util.fetch(f);if(null===h)throw Error("Failed to import '"+f+"' in '"+b+"': File not found");this["import"](JSON.parse(h),f)}else if(!/google\/protobuf\//.test(f)){h=c.Util.fetch(f);if(null===h)throw Error("Failed to import '"+f+"' in '"+b+"': File not found");h=new c.DotProto.Parser(h+"");this["import"](h.parse(),f)}}}return this};h.prototype.resolveAll=function(){if(!(null==this.ptr||"object"==typeof this.ptr.type)){if(this.ptr instanceof f.Namespace)for(var a=this.ptr.getChildren(),
d=0;d<a.length;d++)this.ptr=a[d],this.resolveAll();else if(this.ptr instanceof f.Message.Field)if(b.TYPE.test(this.ptr.type))this.ptr.type=c.TYPES[this.ptr.type];else{if(!b.TYPEREF.test(this.ptr.type))throw Error("Illegal type reference in "+this.ptr.toString(!0)+": "+this.ptr.type);a=this.ptr.parent.resolve(this.ptr.type);if(!a)throw Error("Unresolvable type reference in "+this.ptr.toString(!0)+": "+this.ptr.type);this.ptr.resolvedType=a;if(a instanceof f.Enum)this.ptr.type=c.TYPES["enum"];else if(a instanceof
f.Message)this.ptr.type=c.TYPES.message;else throw Error("Illegal type reference in "+this.ptr.toString(!0)+": "+this.ptr.type);}else if(!(this.ptr instanceof c.Reflect.Enum.Value))throw Error("Illegal object type in namespace: "+typeof this.ptr+":"+this.ptr);this.reset()}};h.prototype.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){a=a.split(".");for(var b=this.result,c=0;c<a.length;c++)if(b[a[c]])b=
b[a[c]];else{b=null;break}return b}return this.result};h.prototype.toString=function(){return"Builder"};return h}(f,f.Lang,f.Reflect);f.protoFromString=function(c,b,m){"string"==typeof b&&(m=b,b=null);c=(new f.DotProto.Parser(c+"")).parse();b="object"==typeof b?b:new f.Builder;null!==c["package"]&&b.define(c["package"],c.options);b.create(c.messages);b.reset();null!==c["package"]&&b.define(c["package"],c.options);b.create(c.enums);b.reset();if(m&&0<c.imports.length)b["import"]({imports:c.imports},
m);b.resolveAll();b.build();return b};f.protoFromFile=function(c,b,m){if(b&&"object"==typeof b)m=b,b=null;else if(!b||"function"!=typeof b)b=null;if(b)f.Util.fetch(c,function(a){b(f.protoFromString(a,m,c))});else{var h=f.Util.fetch(c);return null!==h?f.protoFromString(h,m,c):null}};f.newBuilder=function(c,b){var m=new f.Builder;"undefined"!=typeof c&&m.define(c,b);return m};return f}"undefined"!=typeof module&&module.exports?module.exports=q(require("bytebuffer")):"undefined"!=typeof define&&define.amd?
define("ProtoBuf",["ByteBuffer"],q):(p.dcodeIO||(p.dcodeIO={}),p.dcodeIO.ProtoBuf=q(p.dcodeIO.ByteBuffer))})(this);

@@ -6,8 +6,8 @@ /*

*/
(function(n){function p(l){if(!l||!l.zigZagEncode32)throw Error("ProtoBuf.js requires ByteBuffer.js >=1.1.0: Get it at https://github.com/dcodeIO/ByteBuffer.js");var f={VERSION:"0.12.6",WIRE_TYPES:{}};f.WIRE_TYPES.VARINT=0;f.WIRE_TYPES.BITS64=1;f.WIRE_TYPES.LDELIM=2;f.WIRE_TYPES.STARTGROUP=3;f.WIRE_TYPES.ENDGROUP=4;f.WIRE_TYPES.BITS32=5;f.TYPES={int32:{name:"int32",wireType:f.WIRE_TYPES.VARINT},uint32:{name:"uint32",wireType:f.WIRE_TYPES.VARINT},sint32:{name:"sint32",wireType:f.WIRE_TYPES.VARINT},
(function(n){function p(l){if(!l||!l.zigZagEncode32)throw Error("ProtoBuf.js requires ByteBuffer.js >=1.1.0: Get it at https://github.com/dcodeIO/ByteBuffer.js");var f={VERSION:"0.12.7",WIRE_TYPES:{}};f.WIRE_TYPES.VARINT=0;f.WIRE_TYPES.BITS64=1;f.WIRE_TYPES.LDELIM=2;f.WIRE_TYPES.STARTGROUP=3;f.WIRE_TYPES.ENDGROUP=4;f.WIRE_TYPES.BITS32=5;f.TYPES={int32:{name:"int32",wireType:f.WIRE_TYPES.VARINT},uint32:{name:"uint32",wireType:f.WIRE_TYPES.VARINT},sint32:{name:"sint32",wireType:f.WIRE_TYPES.VARINT},
int64:{name:"int64",wireType:f.WIRE_TYPES.VARINT},uint64:{name:"uint64",wireType:f.WIRE_TYPES.VARINT},sint64:{name:"sint64",wireType:f.WIRE_TYPES.VARINT},bool:{name:"bool",wireType:f.WIRE_TYPES.VARINT},"double":{name:"double",wireType:f.WIRE_TYPES.BITS64},string:{name:"string",wireType:f.WIRE_TYPES.LDELIM},bytes:{name:"bytes",wireType:f.WIRE_TYPES.LDELIM},fixed32:{name:"fixed32",wireType:f.WIRE_TYPES.BITS32},sfixed32:{name:"sfixed32",wireType:f.WIRE_TYPES.BITS32},fixed64:{name:"fixed64",wireType:f.WIRE_TYPES.BITS64},
sfixed64:{name:"sfixed64",wireType:f.WIRE_TYPES.BITS64},"float":{name:"float",wireType:f.WIRE_TYPES.BITS32},"enum":{name:"enum",wireType:f.WIRE_TYPES.VARINT},message:{name:"message",wireType:f.WIRE_TYPES.LDELIM}};f.Long=l.Long;f.Util=function(){Object.create||(Object.create=function(d){function h(){}if(1<arguments.length)throw Error("Object.create implementation only accepts the first parameter.");h.prototype=d;return new h});var d={};d.IS_NODE=("undefined"==typeof window||!window.window)&&"function"==
typeof require;d.XHR=function(){for(var d=[function(){return new XMLHttpRequest},function(){return new ActiveXObject("Msxml2.XMLHTTP")},function(){return new ActiveXObject("Msxml3.XMLHTTP")},function(){return new ActiveXObject("Microsoft.XMLHTTP")}],h=null,f=0;f<d.length;f++){try{h=d[f]()}catch(b){continue}break}if(!h)throw Error("XMLHttpRequest is not supported");return h};d.fetch=function(f,h){h&&"function"!=typeof h&&(h=null);if(d.IS_NODE)if(h)require("fs").readFile(f,function(b,d){b?h(null):h(""+
d)});else try{return require("fs").readFileSync(f)}catch(k){return null}else{var b=d.XHR();b.open("GET",f,h?!0:!1);b.setRequestHeader("User-Agent","XMLHTTP/1.0");b.setRequestHeader("Accept","text/plain");if(h)b.onreadystatechange=function(){4==b.readyState&&(200==b.status?h(b.responseText):h(null))},4!=b.readyState&&b.send(null);else return b.send(null),b.responseText}};return d}();f.Lang={OPEN:"{",CLOSE:"}",OPTOPEN:"[",OPTCLOSE:"]",OPTEND:",",EQUAL:"=",END:";",DELIM:/[\s\{\}=;\[\],"\(\)]/g,KEYWORD:/package|option|import|message|enum|extend/,
RULE:/required|optional|repeated/,TYPE:/double|float|int32|uint32|sint32|int64|uint64|sint64|fixed32|sfixed32|fixed64|sfixed64|bool|string|bytes/,NAME:/[a-zA-Z][a-zA-Z_0-9]*/,TYPEDEF:/[a-zA-Z](\.?[a-zA-Z_0-9])*/,TYPEREF:/\.?[a-zA-Z](\.?[a-zA-Z_0-9])*/,NUMBER:/-?([1-9][0-9]*)|0/,ID:/[0-9]+/,WHITESPACE:/\s/,STRING:/"([^"\\]*(\\.[^"\\]*)*)"/g,STRINGOPEN:'"',STRINGCLOSE:'"',COPTOPEN:"(",COPTCLOSE:")"};f.Reflect=function(d){var f={},h=function(a,c){this.parent=a;this.name=c;this.resolvedType=null};h.prototype.toString=
d)});else try{return require("fs").readFileSync(f)}catch(k){return null}else{var b=d.XHR();b.open("GET",f,h?!0:!1);b.setRequestHeader("User-Agent","XMLHTTP/1.0");b.setRequestHeader("Accept","text/plain");if(h)b.onreadystatechange=function(){4==b.readyState&&(200==b.status?h(b.responseText):h(null))},4!=b.readyState&&b.send(null);else return b.send(null),b.responseText}};return d}();f.Lang={OPEN:"{",CLOSE:"}",OPTOPEN:"[",OPTCLOSE:"]",OPTEND:",",EQUAL:"=",END:";",DELIM:/[\s\{\}=;\[\],"\(\)]/g,KEYWORD:/package|option|import|message|enum|extend|service/,
RULE:/required|optional|repeated/,TYPE:/double|float|int32|uint32|sint32|int64|uint64|sint64|fixed32|sfixed32|fixed64|sfixed64|bool|string|bytes/,NAME:/[a-zA-Z][a-zA-Z_0-9]*/,TYPEDEF:/[a-zA-Z](\.?[a-zA-Z_0-9])*/,TYPEREF:/\.?[a-zA-Z](\.?[a-zA-Z_0-9])*/,NUMBER:/^-?([1-9][0-9]*)|0$/,ID:/[0-9]+/,WHITESPACE:/\s/,STRING:/"([^"\\]*(\\.[^"\\]*)*)"/g,STRINGOPEN:'"',STRINGCLOSE:'"',COPTOPEN:"(",COPTCLOSE:")"};f.Reflect=function(d){var f={},h=function(a,c){this.parent=a;this.name=c;this.resolvedType=null};h.prototype.toString=
function(a){var c=this.name,e=this;do{e=e.parent;if(null==e)break;c=e.name+"."+c}while(1);a&&(this instanceof f.Message?c="Message "+c:this instanceof b.Field?c="Message.Field "+c:this instanceof g?c="Enum "+c:this instanceof g.Value?c="Enum.Value "+c:this instanceof k&&(c="Namespace "+c));return c};h.prototype.build=function(){throw Error(this.toString(!0)+" cannot be built directly");};f.T=h;var k=function(a,c,e){h.call(this,a,c);this.children=[];this.options=e||{}};k.prototype=Object.create(h.prototype);

@@ -14,0 +14,0 @@ k.prototype.getChildren=function(a){a=a||null;if(null==a)return this.children.slice();for(var c=[],e=0;e<this.children.length;e++)this.children[e]instanceof a&&c.push(this.children[e]);return c};k.prototype.addChild=function(a){if(this.hasChild(a.name))throw Error("Duplicate name in namespace "+this.toString(!0)+": "+a.name);this.children.push(a)};k.prototype.hasChild=function(a){var c;if("number"==typeof a)for(c=0;c<this.children.length;c++){if(this.children[c]instanceof b.Field&&this.children[c].id==

@@ -87,4 +87,4 @@ // #ifdef UNDEFINED

this._parseOption(topLevel, token);
} else if (token == 'extend') {
this._parseExtend(topLevel, token);
} else if (token == 'extend' || token == 'service') {
this._parseIgnored(topLevel, token);
} else {

@@ -146,6 +146,5 @@ throw(new Error("Illegal top level declaration: "+token));

/**
* Parses a top level option.
* Parses a namespace option.
* @param {Object} parent Parent definition
* @param {string} token Initial token
* @return {Object}
* @throws {Error} If the option cannot be parsed

@@ -168,3 +167,3 @@ * @private

if (token != Lang.COPTCLOSE) {
throw(new Error("Illegal custom option delimiter in message "+parent.name+", option "+name+": "+token+" ('"+Lang.COPTCLOSE+"' expected)"));
throw(new Error("Illegal custom option name delimiter in message "+parent.name+", option "+name+": "+token+" ('"+Lang.COPTCLOSE+"' expected)"));
}

@@ -201,13 +200,13 @@ token = this.tn.next();

/**
* Parses an extend directive which is actually ignored.
* Parses an ignored directive of the form ['keyword', 'typeref', '{' ... '}'].
* @param {Object} parent Parent definition
* @param {string} token Initial token
* @param {string} keyword Initial token
* @return {Object}
* @throws {Error} If the extend directive cannot be parsed
* @throws {Error} If the directive cannot be parsed
* @private
*/
Parser.prototype._parseExtend = function(parent, token) {
token = this.tn.next();
Parser.prototype._parseIgnored = function(parent, keyword) {
var token = this.tn.next();
if (!Lang.TYPEREF.test(token)) {
throw(new Error("Illegal extended type in "+parent.name+": "+token));
throw(new Error("Illegal "+keyword+" type in "+parent.name+": "+token));
}

@@ -217,3 +216,3 @@ var name = token;

if (token != Lang.OPEN) {
throw(new Error("Illegal OPEN in "+parent.name+" after extend "+name+": "+token));
throw(new Error("Illegal OPEN in "+parent.name+" after "+keyword+" "+name+": "+token));
}

@@ -224,3 +223,3 @@ var depth = 1;

if (token === null) {
throw(new Error("Illegal nesting in "+parent.name+", extend "+name+": EOF"));
throw(new Error("Illegal nesting in "+parent.name+", "+keyword+" "+name+": EOF"));
}

@@ -316,3 +315,3 @@ if (token == Lang.OPEN) {

if (token == Lang.OPTOPEN) {
this._parseMessageFieldOptions(msg, fld, token);
this._parseFieldOptions(msg, fld, token);
token = this.tn.next();

@@ -327,3 +326,3 @@ }

/**
* Parses a message field options defintion.
* Parses a set of field option defintions.
* @param {Object} msg Message definition

@@ -335,3 +334,3 @@ * @param {Object} fld Field definition

*/
Parser.prototype._parseMessageFieldOptions = function(msg, fld, token) {
Parser.prototype._parseFieldOptions = function(msg, fld, token) {
var first = true;

@@ -348,6 +347,3 @@ do {

}
if (!Lang.NAME.test(token)) {
throw(new Error("Illegal field option in message "+msg.name+"#"+fld.name+": "+token));
}
this._parseMessageFieldOption(msg, fld, token);
this._parseFieldOption(msg, fld, token);
first = false;

@@ -358,3 +354,3 @@ } while (true);

/**
* Parses a message field directive
* Parses a single field option.
* @param {Object} msg Message definition

@@ -366,5 +362,19 @@ * @param {Object} fld Field definition

*/
Parser.prototype._parseMessageFieldOption = function(msg, fld, token) {
Parser.prototype._parseFieldOption = function(msg, fld, token) {
var custom = false;
if (token == Lang.COPTOPEN) {
token = this.tn.next();
custom = true;
}
if (!Lang.NAME.test(token)) {
throw(new Error("Illegal field option in message "+msg.name+"#"+fld.name+": "+token));
}
var name = token;
token = this.tn.next();
if (custom) {
if (token != Lang.COPTCLOSE) {
throw(new Error("Illegal custom field option name delimiter in message "+msg.name+"#"+fld.name+": "+token+" (')' expected)"));
}
token = this.tn.next();
}
if (token != Lang.EQUAL) {

@@ -382,5 +392,5 @@ throw(new Error("Illegal field option operation in message "+msg.name+"#"+fld.name+": "+token+" ('=' expected)"));

} else if (Lang.NUMBER.test(token)) {
value = parseInt(token, 10);
} else if (Lang.NAME.test(token)) {
value = token;
value = parseFloat(token);
} else if (Lang.TYPEREF.test(token)) {
value = token; // TODO: Resolve?
} else {

@@ -412,2 +422,3 @@ throw(new Error("Illegal field option value in message "+msg.name+"#"+fld.name+", option "+name+": "+token));

enm["values"] = [];
enm["options"] = {};
do {

@@ -417,6 +428,11 @@ token = this.tn.next();

break;
} else if (!Lang.NAME.test(token)) {
throw(new Error("Illegal enum value name in enum "+enm.name+": "+token));
}
this._parseEnumValue(enm, token);
if (token == 'option') {
this._parseOption(enm, token);
} else {
if (!Lang.NAME.test(token)) {
throw(new Error("Illegal enum value name in enum "+enm.name+": "+token));
}
this._parseEnumValue(enm, token);
}
} while (true);

@@ -448,2 +464,7 @@ msg["enums"].push(enm);

token = this.tn.next();
if (token == Lang.OPTOPEN) {
var opt = { 'options' : {} }; // TODO: Actually expose them somehow.
this._parseFieldOptions(enm, opt, token);
token = this.tn.next();
}
if (token != Lang.END) {

@@ -450,0 +471,0 @@ throw(new Error("Illegal enum value delimiter in enum "+enm.name+": "+token+" ('"+Lang.END+"' expected)"));

@@ -43,3 +43,3 @@ // #ifdef UNDEFINED

DELIM: /[\s\{\}=;\[\],"\(\)]/g,
KEYWORD: /package|option|import|message|enum|extend/,
KEYWORD: /package|option|import|message|enum|extend|service/,
RULE: /required|optional|repeated/,

@@ -50,3 +50,3 @@ TYPE: /double|float|int32|uint32|sint32|int64|uint64|sint64|fixed32|sfixed32|fixed64|sfixed64|bool|string|bytes/,

TYPEREF: /\.?[a-zA-Z](\.?[a-zA-Z_0-9])*/,
NUMBER: /-?([1-9][0-9]*)|0/,
NUMBER: /^-?([1-9][0-9]*)|0$/,
ID: /[0-9]+/,

@@ -53,0 +53,0 @@ WHITESPACE: /\s/,

@@ -624,2 +624,18 @@ /*

},
// Custom options on all levels
// victorr (https://github.com/victorr)
"customOptions": function(test) {
try {
var parser = new ProtoBuf.DotProto.Parser(ProtoBuf.Util.fetch(__dirname+"/custom-options.proto"));
var root = parser.parse();
test.equal(root["options"]["my_file_option"], "Hello world!");
test.equal(root["messages"][0]["options"]["my_message_option"], 1234)
test.equal(root["messages"][0]["fields"][0]["options"]["my_field_option"], 4.5);
// TODO: add tests for my_enum_option, my_enum_value_option
} catch (e) {
fail(e);
}
test.done();
},

@@ -626,0 +642,0 @@ // Node.js only

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

Sorry, the diff of this file is not supported yet

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

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc