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.9.3 to 0.9.4

externs/ByteBuffer.js

4

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

@@ -23,3 +23,3 @@ "description": "protobuf for JavaScript",

"nodeunit": ">=0.7",
"preprocessor": ">=0.9.6"
"preprocessor": ">=0.9.7"
},

@@ -26,0 +26,0 @@ "license": "Apache License, Version 2.0",

@@ -7,48 +7,49 @@ /*

(function(s){function t(k){if(!k||!k.calculateUTF8String||!k.zigZagEncode32)if("undefined"!=typeof dcodeIO&&dcodeIO.ByteBuffer&&(k=dcodeIO.ByteBuffer),!k&&"function"==typeof require&&(k=require("ByteBuffer")),!k)throw Error("ProtoBuf.js requires ByteBuffer.js >=1.1.0: Get it at https://github.com/dcodeIO/ByteBuffer.js");Object.create||(Object.create=function(b){function a(){}if(1<arguments.length)throw Error("Object.create implementation only accepts the first parameter.");a.prototype=b;return new a});
var e={VERSION:"0.9.2",WIRE_TYPES:{}};e.WIRE_TYPES.VARINT=0;e.WIRE_TYPES.BITS64=1;e.WIRE_TYPES.LDELIM=2;e.WIRE_TYPES.STARTGROUP=3;e.WIRE_TYPES.ENDGROUP=4;e.WIRE_TYPES.BITS32=5;e.TYPES={int32:{name:"int32",wireType:e.WIRE_TYPES.VARINT},uint32:{name:"uint32",wireType:e.WIRE_TYPES.VARINT},sint32:{name:"sint32",wireType:e.WIRE_TYPES.VARINT},bool:{name:"bool",wireType:e.WIRE_TYPES.VARINT},"double":{name:"double",wireType:e.WIRE_TYPES.BITS64},string:{name:"string",wireType:e.WIRE_TYPES.LDELIM},bytes:{name:"bytes",
var e={VERSION:"0.9.4",WIRE_TYPES:{}};e.WIRE_TYPES.VARINT=0;e.WIRE_TYPES.BITS64=1;e.WIRE_TYPES.LDELIM=2;e.WIRE_TYPES.STARTGROUP=3;e.WIRE_TYPES.ENDGROUP=4;e.WIRE_TYPES.BITS32=5;e.TYPES={int32:{name:"int32",wireType:e.WIRE_TYPES.VARINT},uint32:{name:"uint32",wireType:e.WIRE_TYPES.VARINT},sint32:{name:"sint32",wireType:e.WIRE_TYPES.VARINT},bool:{name:"bool",wireType:e.WIRE_TYPES.VARINT},"double":{name:"double",wireType:e.WIRE_TYPES.BITS64},string:{name:"string",wireType:e.WIRE_TYPES.LDELIM},bytes:{name:"bytes",
wireType:e.WIRE_TYPES.LDELIM},fixed32:{name:"fixed32",wireType:e.WIRE_TYPES.BITS32},sfixed32:{name:"sfixed32",wireType:e.WIRE_TYPES.BITS32},"float":{name:"float",wireType:e.WIRE_TYPES.BITS32},"enum":{name:"enum",wireType:e.WIRE_TYPES.VARINT},message:{name:"message",wireType:e.WIRE_TYPES.LDELIM}};e.Lang={OPEN:"{",CLOSE:"}",OPTOPEN:"[",OPTCLOSE:"]",OPTEND:",",EQUAL:"=",END:";",DELIM:/[\s\{\}=;\[\],"]/g,KEYWORD:/package|option|message|enum/,RULE:/required|optional|repeated/,TYPE:/double|float|int32|uint32|sint32|fixed32|sfixed32|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]+/,COMMENT:"//",WHITESPACE:/\s/,STRING:/"([^"\\]*(\\.[^"\\]*)*)"/g,STRINGOPEN:'"',STRINGCLOSE:'"'};e.DotProto={};var s=e.DotProto,p=e.Lang,n=function(b){this.source=""+b;this.index=0;this.stack=[];this.readingString=!1};n.prototype._readString=function(){p.STRING.lastIndex=this.index-1;var b;if(null!==(b=p.STRING.exec(this.source)))return b=b[1],this.index=
p.STRING.lastIndex,this.stack.push(p.STRINGCLOSE),b;throw Error("Illegal string value at index "+this.index);};n.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;p.WHITESPACE.test(this.source.charAt(this.index));)if(this.index++,this.index==this.source.length)return null;if(this.source.charAt(this.index)==p.COMMENT.charAt(0)){if(this.source.charAt(++this.index)!=
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]+/,COMMENT:"//",WHITESPACE:/\s/,STRING:/"([^"\\]*(\\.[^"\\]*)*)"/g,STRINGOPEN:'"',STRINGCLOSE:'"'};e.DotProto={};var s=e.DotProto,p=e.Lang,l=function(b){this.source=""+b;this.index=0;this.stack=[];this.readingString=!1};l.prototype._readString=function(){p.STRING.lastIndex=this.index-1;var b;if(null!==(b=p.STRING.exec(this.source)))return b=b[1],this.index=
p.STRING.lastIndex,this.stack.push(p.STRINGCLOSE),b;throw Error("Illegal string value at index "+this.index);};l.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;p.WHITESPACE.test(this.source.charAt(this.index));)if(this.index++,this.index==this.source.length)return null;if(this.source.charAt(this.index)==p.COMMENT.charAt(0)){if(this.source.charAt(++this.index)!=
p.COMMENT.charAt(1))throw Error("Invalid comment: /"+this.source.charAt(this.index)+" ('"+p.COMMENT.charAt(1)+"' expected)");for(;"\n"!=this.source.charAt(this.index);)if(this.index++,this.index==this.source.length)return null;this.index++;b=!0}}while(b);if(this.index==this.source.length)return null;b=this.index;p.DELIM.lastIndex=0;if(p.DELIM.test(this.source.charAt(b)))b++;else for(b++;b<this.source.length&&!p.DELIM.test(this.source.charAt(b));)b++;b=this.source.substring(this.index,this.index=b);
b==p.STRINGOPEN&&(this.readingString=!0);return b};n.prototype.toString=function(){return"Tokenizer("+this.index+"/"+this.source.length+")"};s.Tokenizer=n;var s=e.DotProto,f=e.Lang,t=e.DotProto.Tokenizer,n=function(b){this.tn=new t(b)};n.prototype.parse=function(){var b=[],a=null,c={name:"[ROOT]",options:{}},d,e=!0;do{d=this.tn.next();if(null==d)break;if("package"==d){if(!e)throw Error("Illegal package definition: Must be declared before the first message");if(null!==a)throw Error("Illegal package definition: Package already declared");
a=this._parsePackage(d)}else if("message"==d)d=this._parseMessage(null,d),b.push(d),e=!1;else if("option"==d){if(!e)throw Error("Illegal option definition: Must be declared before the first message");this._parseOption(c,d)}else throw Error("Illegal top level declaration: "+d);}while(1);return{"package":a,options:c.options,messages:b}};n.prototype._parsePackage=function(b){b=this.tn.next();if(!f.TYPEDEF.test(b))throw Error("Illegal package name: "+b);var a=b;b=this.tn.next();if(b!=f.END)throw Error("Illegal end of package definition: "+
b+" ('"+f.END+"' expected)");return a};n.prototype._parseOption=function(b,a){a=this.tn.next();if(!f.NAME.test(a))throw Error("Illegal option name in message "+b.name+": "+a);var c=a;a=this.tn.next();if(a!=f.EQUAL)throw Error("Illegal option operator in message "+b.name+", option "+c+": "+a+" ('"+f.EQUAL+"' expected)");var d;a=this.tn.next();if(a==f.STRINGOPEN){if(d=this.tn.next(),a=this.tn.next(),a!=f.STRINGCLOSE)throw Error("Illegal end of option value in message "+b.name+", option "+c+": "+a+" ('"+
f.STRINGCLOSE+"' expected)");}else if(f.NUMBER.test(a))d=parseInt(a);else if(f.NAME.test(a))d=a;else throw Error("Illegal option value in message "+b.name+", option "+c+": "+a);a=this.tn.next();if(a!=f.END)throw Error("Illegal end of option in message "+b.name+", option "+c+": "+a+" ('"+f.END+"' expected)");b.options[c]=d};n.prototype._parseMessage=function(b,a){var c={};a=this.tn.next();if(!f.NAME.test(a))throw Error("Illegal message name"+(b?" in message "+b.name:"")+": "+a);c.name=a;a=this.tn.next();
if(a!=f.OPEN)throw Error("Illegal OPEN after message "+c.name+": "+a);c.fields=[];c.enums=[];c.messages=[];c.options={};do if(a=this.tn.next(),"}"==a)break;else if(f.RULE.test(a))this._parseMessageField(c,a);else if("enum"==a)this._parseEnum(c,a);else if("message"==a)this._parseMessage(c,a);else if("option"==a)this._parseOption(c,a);else throw Error("Illegal token in message "+c.name+": "+a);while(1);null!=b&&b.messages.push(c);return c};n.prototype._parseMessageField=function(b,a){var c={};c.rule=
b==p.STRINGOPEN&&(this.readingString=!0);return b};l.prototype.toString=function(){return"Tokenizer("+this.index+"/"+this.source.length+")"};s.Tokenizer=l;var s=e.DotProto,f=e.Lang,t=e.DotProto.Tokenizer,l=function(b){this.tn=new t(b)};l.prototype.parse=function(){var b=[],a=null,c={name:"[ROOT]",options:{}},d,e=!0;do{d=this.tn.next();if(null==d)break;if("package"==d){if(!e)throw Error("Illegal package definition: Must be declared before the first message");if(null!==a)throw Error("Illegal package definition: Package already declared");
a=this._parsePackage(d)}else if("message"==d)d=this._parseMessage(null,d),b.push(d),e=!1;else if("option"==d){if(!e)throw Error("Illegal option definition: Must be declared before the first message");this._parseOption(c,d)}else throw Error("Illegal top level declaration: "+d);}while(1);return{"package":a,options:c.options,messages:b}};l.prototype._parsePackage=function(b){b=this.tn.next();if(!f.TYPEDEF.test(b))throw Error("Illegal package name: "+b);var a=b;b=this.tn.next();if(b!=f.END)throw Error("Illegal end of package definition: "+
b+" ('"+f.END+"' expected)");return a};l.prototype._parseOption=function(b,a){a=this.tn.next();if(!f.NAME.test(a))throw Error("Illegal option name in message "+b.name+": "+a);var c=a;a=this.tn.next();if(a!=f.EQUAL)throw Error("Illegal option operator in message "+b.name+", option "+c+": "+a+" ('"+f.EQUAL+"' expected)");var d;a=this.tn.next();if(a==f.STRINGOPEN){if(d=this.tn.next(),a=this.tn.next(),a!=f.STRINGCLOSE)throw Error("Illegal end of option value in message "+b.name+", option "+c+": "+a+" ('"+
f.STRINGCLOSE+"' expected)");}else if(f.NUMBER.test(a))d=parseInt(a);else if(f.NAME.test(a))d=a;else throw Error("Illegal option value in message "+b.name+", option "+c+": "+a);a=this.tn.next();if(a!=f.END)throw Error("Illegal end of option in message "+b.name+", option "+c+": "+a+" ('"+f.END+"' expected)");b.options[c]=d};l.prototype._parseMessage=function(b,a){var c={};a=this.tn.next();if(!f.NAME.test(a))throw Error("Illegal message name"+(b?" in message "+b.name:"")+": "+a);c.name=a;a=this.tn.next();
if(a!=f.OPEN)throw Error("Illegal OPEN after message "+c.name+": "+a);c.fields=[];c.enums=[];c.messages=[];c.options={};do if(a=this.tn.next(),"}"==a)break;else if(f.RULE.test(a))this._parseMessageField(c,a);else if("enum"==a)this._parseEnum(c,a);else if("message"==a)this._parseMessage(c,a);else if("option"==a)this._parseOption(c,a);else throw Error("Illegal token in message "+c.name+": "+a);while(1);null!=b&&b.messages.push(c);return c};l.prototype._parseMessageField=function(b,a){var c={};c.rule=
a;a=this.tn.next();if(!f.TYPE.test(a)&&!f.TYPEREF.test(a))throw Error("Illegal field type in message "+b.name+": "+a);c.type=a;a=this.tn.next();if(!f.NAME.test(a))throw Error("Illegal field name in message "+b.name+": "+a);c.name=a;a=this.tn.next();if(a!=f.EQUAL)throw Error("Illegal field number operator in message "+b.name+"#"+c.name+": "+a+" ('"+f.EQUAL+"' expected)");a=this.tn.next();if(!f.ID.test(a))throw Error("Illegal field number in message "+b.name+"#"+c.name+": "+a);c.id=parseInt(a,10);c.options=
{};a=this.tn.next();a==f.OPTOPEN&&(this._parseMessageFieldOptions(b,c,a),a=this.tn.next());if(a!=f.END)throw Error("Illegal field delimiter in message "+b.name+"#"+c.name+": "+a+" ('"+f.END+"' expected)");b.fields.push(c)};n.prototype._parseMessageFieldOptions=function(b,a,c){var d=!0;do{c=this.tn.next();if(c==f.OPTCLOSE)break;else if(c==f.OPTEND){if(d)throw Error("Illegal start of message field options in message "+b.name+"#"+a.name+": "+c);c=this.tn.next()}if(!f.NAME.test(c))throw Error("Illegal field option in message "+
b.name+"#"+a.name+": "+c);this._parseMessageFieldOption(b,a,c);d=!1}while(1)};n.prototype._parseMessageFieldOption=function(b,a,c){var d=c;c=this.tn.next();if(c!=f.EQUAL)throw Error("Illegal field option operation in message "+b.name+"#"+a.name+": "+c+" ('=' expected)");var e;c=this.tn.next();if(c==f.STRINGOPEN){if(e=this.tn.next(),c=this.tn.next(),c!=f.STRINGCLOSE)throw Error("Illegal end of field value in message "+b.name+"#"+a.name+", option "+d+": "+c+" ('"+f.STRINGCLOSE+"' expected)");}else if(f.NUMBER.test(c))e=
parseInt(c,10);else if(f.NAME.test(c))e=c;else throw Error("Illegal field option value in message "+b.name+"#"+a.name+", option "+d+": "+c);a.options[d]=e};n.prototype._parseEnum=function(b,a){var c={};a=this.tn.next();if(!f.NAME.test(a))throw Error("Illegal enum name in message "+b.name+": "+a);c.name=a;a=this.tn.next();if(a!=f.OPEN)throw Error("Illegal OPEN after enum "+c.name+": "+a);c.values=[];do{a=this.tn.next();if(a==f.CLOSE)break;else if(!f.NAME.test(a))throw Error("Illegal enum value name in enum "+
c.name+": "+a);this._parseEnumValue(c,a)}while(1);b.enums.push(c)};n.prototype._parseEnumValue=function(b,a){var c={};c.name=a;a=this.tn.next();if(a!=f.EQUAL)throw Error("Illegal enum value operator in enum "+b.name+": "+a+" ('"+f.EQUAL+"' expected)");a=this.tn.next();if(!f.ID.test(a))throw Error("Illegal enum value value in enum "+b.name+": "+a);c.id=parseInt(a,10);b.values.push(c);a=this.tn.next();if(a!=f.END)throw Error("Illegal enum value delimiter in enum "+b.name+": "+a+" ('"+f.END+"' expected)");
};s.Parser=n;e.Reflect=function(b){var a={},c=function(b,a){this.parent=b;this.name=a;this.resolvedType=null};c.prototype.toString=function(b){var c=this.name,l=this;do{l=l.parent;if(null==l)break;c=l.name+"."+c}while(1);b&&(this instanceof a.Message?c="Message "+c:this instanceof e.Field?c="Message.Field "+c:this instanceof j?c="Enum "+c:this instanceof j.Value?c="Enum.Value "+c:this instanceof d&&(c="Namespace "+c));return c};c.prototype.build=function(){throw this.toString(!0)+" cannot be built directly";
};a.T=c;var d=function(b,a){c.call(this,b,a);this.children=[]};d.prototype=Object.create(c.prototype);d.prototype.getChildren=function(b){b=b||null;if(null==b)return this.children.slice();for(var a=[],c=0;c<this.children.length;c++)this.children[c]instanceof b&&a.push(this.children[c]);return a};d.prototype.addChild=function(b){if(this.hasChild(b.name))throw Error("Duplicate name in namespace "+this.toString(!0)+": "+b.name);this.children.push(b)};d.prototype.hasChild=function(b){var a;if("number"==
typeof b)for(a=0;a<this.children.length;a++){if(this.children[a]instanceof e.Field&&this.children[a].id==b)return!0}else for(a=0;a<this.children.length;a++)if(this.children[a].name==b)return!0;return!1};d.prototype.getChild=function(b){var a;if("number"==typeof b)for(a=0;a<this.children.length;a++){if(this.children[a]instanceof e.Field&&this.children[a].id==b)return this.children[a]}else for(a=0;a<this.children.length;a++)if(this.children[a].name==b)return this.children[a];return null};d.prototype.resolve=
function(b){var c=b.split("."),l=this,d=0;if(""==c[d]){for(;null!=l.parent;)l=l.parent;d++}do{do{l=l.getChild(c[d]);if(!l||!(l instanceof a.T)){l=null;break}d++}while(d<c.length);if(null!=l)break;if(null!==this.parent)return this.parent.resolve(b)}while(null!=l);return l};d.prototype.build=function(){for(var b={},a=this.getChildren(),c,e=0;e<a.length;e++)c=a[e],c instanceof d&&(b[c.name]=c.build());return b};a.Namespace=d;var e=function(b,a){d.call(this,b,a);this.built=null};e.prototype=Object.create(d.prototype);
e.prototype.build=function(){for(var b=function(b,a){var c=a.getChildren(b.Message.Field),d=eval("(function "+a.name+"() { this.__construct.apply(this, arguments); })");d.prototype.__construct=function(b){var a,d;for(a=0;a<c.length;a++)d=c[a],this[d.name]=d.repeated?[]:null;for(a=0;a<c.length;a++)if(d=c[a],"undefined"!=typeof d.options["default"])try{this.set(d.name,d.options["default"])}catch(g){throw Error("[INTERNAL ERROR] "+g);}if("object"==typeof b&&"function"!=typeof b.encode){d=Object.keys(b);
for(a=0;a<d.length;a++)this.set(d[a],b[d[a]])}else for(a=0;a<arguments.length;a++)a<c.length&&this.set(c[a].name,arguments[a])};d.prototype.add=function(c,d){var g=a.getChild(c);if(!g)throw this+"#"+c+" is undefined";if(!(g instanceof b.Message.Field))throw this+"#"+c+" is not a field: "+g.toString(!0);if(!g.repeated)throw this+"#"+c+" is not a repeated field";null===this[g.name]&&(this[g.name]=[]);this[g.name].push(g.verifyValue(d))};d.prototype.set=function(c,d){var g=a.getChild(c);if(!g)throw this+
"#"+c+" is not a field: undefined";if(!(g instanceof b.Message.Field))throw this+"#"+c+" is not a field: "+g.toString(!0);this[g.name]=g.verifyValue(d)};d.prototype.get=function(c){var d=a.getChild(c);if(!d||!(d instanceof b.Message.Field))throw this+"#"+c+" is not a field: undefined";if(!(d instanceof b.Message.Field))throw this+"#"+c+" is not a field: "+d.toString(!0);return this[d.name]};for(var g=0;g<c.length;g++)(function(b){var c=b.name.replace(/(_[a-zA-Z])/g,function(b){return b.toUpperCase().replace("_",
"")}),c=c.substring(0,1).toUpperCase()+c.substring(1),g=b.name.replace(/([A-Z])/g,function(b){return"_"+b});a.hasChild("set"+c)||(d.prototype["set"+c]=function(a){this.set(b.name,a)});a.hasChild("set_"+g)||(d.prototype["set_"+g]=function(a){this.set(b.name,a)});a.hasChild("get"+c)||(d.prototype["get"+c]=function(){return this.get(b.name)});a.hasChild("get_"+g)||(d.prototype["get_"+g]=function(){return this.get(b.name)})})(c[g]);d.prototype.encode=function(b){b=b||new k;a.encode(this,b);return b.flip()};
d.prototype.toArrayBuffer=function(){return this.encode().toArrayBuffer()};d.decode=function(b){b=b?b instanceof k?b:k.wrap(b):new k;return a.decode(b)};d.prototype.toString=function(){return a.toString()};return d}(a,this),c=this.getChildren(),d=0;d<c.length;d++)if(c[d]instanceof j)b[c[d].name]=c[d].build();else if(c[d]instanceof e)b[c[d].name]=c[d].build();else if(!(c[d]instanceof e.Field))throw Error("Illegal reflect child of "+this.toString(!0)+": "+c[d].toString(!0));return this.built=b};e.prototype.encode=
function(b,a){for(var c=this.getChildren(e.Field),d=0;d<c.length;d++)c[d].encode(b.get(c[d].name),a)};e.prototype.decode=function(b,a){a=a||-1;for(var c=b.offset,d=new this.built;b.offset<c+a||-1==a&&0<b.remaining();){var e=b.readVarint32(),f=e&7,e=e>>3,r=this.getChild(e);if(!r)throw Error("Illegal field id in "+this.toString(!0)+"#decode: "+e);d.set(r.name,r.decode(f,b))}return d};a.Message=e;var f=function(b,a,d,e,f,r){c.call(this,b,e);this.required="required"==a;this.repeated="repeated"==a;this.type=
d;this.id=f;this.options=r||{}};f.prototype=Object.create(c.prototype);f.prototype.verifyValue=function(a,c){c=c||!1;if(null===a){if(this.required)throw Error("Illegal value for "+this.toString(!0)+": "+a+" (required)");return null}var d,e;if(this.repeated&&!c){if(!(a instanceof Array))throw Error("Illegal value for "+this.toString(!0)+": "+a+" (not an array)");e=[];for(d=0;d<a.length;d++)e.push(this.verifyValue(a[d],!0));return e}if(!this.repeated&&a instanceof Array)throw Error("Illegal value for "+
this.toString(!0)+": "+a+" (is array)");if(this.type!=b.TYPES.message&&a instanceof Object)throw Error("Illegal value for "+this.toString(!0)+": "+a+" (is object)");if(this.type==b.TYPES.int32||this.type==b.TYPES.sint32||this.type==b.TYPES.fixed32||this.type==b.TYPES.sfixed32)return parseInt(a,10);if(this.type==b.TYPES.uint32){a=parseInt(a,10);if(0>a)throw Error("Illegal value for "+this.toString(!0)+": "+a+" (must not be negative)");return a}if(this.type==b.TYPES.bool)return!!a;if(this.type==b.TYPES["float"]||
this.type==b.TYPES["double"])return parseFloat(a);if(this.type==b.TYPES.string)return""+a;if(this.type==b.TYPES.bytes)return k.wrap(a);if(this.type==b.TYPES["enum"]){e=this.resolvedType.getChildren(j.Value);for(d=0;d<e.length;d++)if(e[d].name==a||e[d].id==a)return e[d].id;throw Error("Illegal value for "+this.toString(!0)+": "+a+" (not a valid enum value)");}if(this.type==b.TYPES.message){if(a instanceof this.resolvedType.built)return a;if("object"==typeof a)return new this.resolvedType.built(a);
throw Error("Illegal value for "+this.toString(!0)+": "+a+" (not an instance of "+this.resolvedType+")");}throw Error("[INTERNAL ERROR] Illegal value for "+this.toString(!0)+": "+a+" (undefined type "+this.type+")");};f.prototype.encode=function(a,c){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)try{if(this.repeated){var d;if(this.options.packed){c.writeVarint32(this.id<<3|b.WIRE_TYPES.LDELIM);
for(d=0;d<a.length;d++)this.encodeValue(a[d],c)}else for(d=0;d<a.length;d++)c.writeVarint32(this.id<<3|this.type.wireType),this.encodeValue(a[d],c)}else c.writeVarint32(this.id<<3|this.type.wireType),this.encodeValue(a,c)}catch(e){throw Error("Illegal value for "+this.toString(!0)+": "+a+" ("+e+")");}};f.prototype.decode=function(a,c){var d,e;if(a!=this.type.wireType)throw Error("Illegal wire type for field "+this.toString(!0)+": "+a+" ("+this.type.wireType+" expected)");if(this.type==b.TYPES.int32)return c.readVarint32();
if(this.type==b.TYPES.uint32)return d=c.readVarint32(),UINT32[0]=d,UINT32[0];if(this.type==b.TYPES.sint32)return c.readZigZagVarint32();if(this.type==b.TYPES.bool)return!!c.readVarint32();if(this.type==b.TYPES["enum"])return c.readVarint32();if(this.type==b.TYPES["double"])return c.readDouble();if(this.type==b.TYPES.string)return c.readVString();if(this.type==b.TYPES.bytes)return e=c.readVarint32(),d=c.clone(),d.length=d.offset+e,d;if(this.type==b.TYPES.message)return e=c.readVarint32(),this.resolvedType.decode(c,
e);if(a==b.WIRE_TYPES.LDELIM&&this.repeated){e=c.readVarint32();for(e=c.offset+e;c.offset<e;)this.decode(this.type.wireType,c);return[]}if(this.type==b.TYPES.fixed32)return c.readInt32();if(this.type==b.TYPES.sfixed32)return k.zigZagDecode32(c.readUint32());if(this.type==b.TYPES["float"])return c.readFloat();throw Error("[INTERNAL ERROR] Illegal wire type for "+this.toString(!0)+": "+a);};f.prototype.encodeValue=function(a,c){if(null!==a)if(this.type==b.TYPES.int32||this.type==b.TYPES.uint32)c.writeVarint32(a);
else if(this.type==b.TYPES.sint32)c.writeVarint32(k.zigZagEncode32(a));else if(this.type==b.TYPES.fixed32)c.writeUint32(a);else if(this.type==b.TYPES.sfixed32)c.writeUint32(k.zigZagEncode32(a));else if(this.type==b.TYPES.bool)c.writeVarint32(a?1:0);else if(this.type==b.TYPES["enum"])c.writeVarint32(a);else if(this.type==b.TYPES["float"])c.writeFloat32(a);else if(this.type==b.TYPES["double"])c.writeFloat64(a);else if(this.type==b.TYPES.string)c.writeVString(a);else if(this.type==b.TYPES.bytes)a.offset>
a.length&&(c=c.clone().flip()),c.writeVarint32(a.remaining()),c.append(a);else if(this.type==b.TYPES.message){var d=c.offset;c.writeUint8(0);this.resolvedType.encode(a,c);var e=c.offset-d-1,f=k.calculateVarint32(e);if(1<f){var r=c.clone();r.offset-=e;c.append(r.flip(),d-1+f)}c.writeVarint32(e,d)}else throw Error("[INTERNAL ERROR] Illegal value to encode in "+this.toString(!0)+": "+a+" (unknown type)");};a.Message.Field=f;var j=function(a,b){d.call(this,a,b);this.built=null};j.prototype=Object.create(d.prototype);
j.prototype.build=function(){for(var a={},b=this.getChildren(j.Value),c=0;c<b.length;c++)a[b[c].name]=b[c].id;return this.built=a};a.Enum=j;f=function(a,b,d){c.call(this,a,b);this.id=d};f.prototype=Object.create(c.prototype);a.Enum.Value=f;return a}(e);var h=e.Lang,q=e.Reflect,m=function(){this.ptr=this.ns=new q.Namespace(null,"");this.resolved=!1;this.result=null};m.prototype.reset=function(){this.ptr=this.ns};m.prototype.define=function(b){if("string"!=typeof b||!h.TYPEDEF.test(b))throw Error("Illegal package name: "+
b);b=b.split(".");var a;for(a=0;a<b.length;a++)if(!h.NAME.test(b[a]))throw Error("Illegal package name: "+b[a]);for(a=0;a<b.length;a++)this.ptr.hasChild(b[a])||this.ptr.addChild(new q.Namespace(this.ptr,b[a])),this.ptr=this.ptr.getChild(b[a]);return this};m.isValidMessage=function(b){if("string"!=typeof b.name||!h.NAME.test(b.name)||"undefined"!=typeof b.values)return!1;var a;if("undefined"!=typeof b.fields){if(!(b.fields instanceof Array))return!1;var c=[],d;for(a=0;a<b.fields.length;a++){if(!m.isValidMessageField(b.fields[a]))return!1;
d=parseInt(b.id,10);if(0<=c.indexOf(d))return!1;c.push(d)}}if("undefined"!=typeof b.enums){if(!(b.enums instanceof Array))return!1;for(a=0;a<b.enums.length;a++)if(!m.isValidEnum(b.enums[a]))return!1}if("undefined"!=typeof b.messages){if(!(b.messages instanceof Array))return!1;for(a=0;a<b.messages.length;a++)if(!m.isValidMessage(b.messages[a]))return!1}return!0};m.isValidMessageField=function(b){if("string"!=typeof b.rule||"string"!=typeof b.name||"string"!=typeof b.type||"undefined"==typeof b.id||
!h.RULE.test(b.rule)||!h.NAME.test(b.name)||!h.TYPEREF.test(b.type)||!h.ID.test(""+b.id))return!1;if("undefined"!=typeof b.options){if("object"!=typeof b.options)return!1;for(var a=Object.keys(b.options),c=0;c<a.length;c++)if(!h.NAME.test(a[c])||!h.ID.test(""+b.options[a[c]])&&!h.TYPEREF.test(b.options[a[c]]))return!1}return!0};m.isValidEnum=function(b){if("string"!=typeof b.name||!h.NAME.test(b.name)||"undefined"==typeof b.values||!(b.values instanceof Array)||0==b.values.length)return!1;for(var a=
0;a<b.values.length;a++)if("object"!=typeof b.values[a]||"string"!=typeof b.values[a].name||"undefined"==typeof b.values[a].id||!h.NAME.test(b.values[a].name)||!h.ID.test(""+b.values[a].id))return!1;return!0};m.prototype.create=function(b){if(b&&(b instanceof Array||(b=[b]),0!=b.length)){var a=[],c,d,e,f,j;for(a.push(b);0<a.length;){b=a.pop();if(b instanceof Array)for(;0<b.length;)if(c=b.shift(),m.isValidMessage(c)){d=new q.Message(this.ptr,c.name);if(c.fields&&0<c.fields.length)for(f=0;f<c.fields.length;f++){if(!m.isValidMessageField(c.fields[f]))throw Error("Not a valid message field definition in message "+
d.name+": "+JSON.stringify(c.fields[f]));if(c.fields[f].options){e=Object.keys(c.fields[f].options);for(j=0;j<e.length;j++){if(!h.NAME.test(e[j]))throw Error("Illegal field option name in message "+d.name+"#"+c.fields[f].name+": "+e[j]);if(!h.ID.test(""+c.fields[f].options[e[j]])&&!h.TYPEREF.test(c.fields[f].options[e[j]]))throw Error("Illegal field option value in message "+d.name+"#"+c.fields[f].name+"#"+e[j]+": "+c.fields[f].options[e[j]]);}}d.addChild(new q.Message.Field(d,c.fields[f].rule,c.fields[f].type,
c.fields[f].name,c.fields[f].id,c.fields[f].options))}e=[];if("undefined"!=typeof c.enums&&0<c.enums.length)for(f=0;f<c.enums.length;f++)e.push(c.enums[f]);if(c.messages&&0<c.messages.length)for(f=0;f<c.messages.length;f++)e.push(c.messages[f]);this.ptr.addChild(d);0<e.length&&(a.push(b),b=e,this.ptr=d)}else if(m.isValidEnum(c)){d=new q.Enum(this.ptr,c.name);for(f=0;f<c.values.length;f++)d.addChild(new q.Enum.Value(d,c.values[f].name,c.values[f].id));this.ptr.addChild(d)}else throw Error("Not a valid message or enum definition: "+
JSON.stringify(c));else throw Error("Not a valid namespace definition: "+JSON.stringify(b));this.ptr=this.ptr.parent}this.resolved=!1;this.result=null;return this}};m.prototype.resolveAll=function(){if(!(null==this.ptr||"object"==typeof this.ptr.type)){if(this.ptr instanceof q.Namespace)for(var b=this.ptr.getChildren(),a=0;a<b.length;a++)this.ptr=b[a],this.resolveAll();else if(this.ptr instanceof q.Message.Field)if(h.TYPE.test(this.ptr.type))this.ptr.type=e.TYPES[this.ptr.type];else{if(!h.TYPEREF.test(this.ptr.type))throw Error("Illegal type reference in "+
this.ptr.toString(!0)+": "+this.ptr.type);b=this.ptr.parent.resolve(this.ptr.type);if(!b)throw Error("Unresolvable type reference in "+this.ptr.toString(!0)+": "+this.ptr.type);this.ptr.resolvedType=b;if(b instanceof q.Enum)this.ptr.type=e.TYPES["enum"];else if(b instanceof q.Message)this.ptr.type=e.TYPES.message;else throw Error("Illegal type reference in "+this.ptr.toString(!0)+": "+this.ptr.type);}else if(!(this.ptr instanceof e.Reflect.Enum.Value))throw Error("Illegal object type in namespace: "+
typeof this.ptr+":"+this.ptr);this.reset()}};m.prototype.build=function(b){this.reset();this.resolved||(this.resolveAll(),this.resolved=!0,this.result=null);null==this.result&&(this.result=this.ns.build());if(b){b=b.split(".");for(var a=this.result,c=0;c<b.length;c++)if(a[b[c]])a=a[b[c]];else{a=null;break}return a}return this.result};m.prototype.toString=function(){return"Builder"};e.Builder=m;e.protoFromString=function(b){b=(new e.DotProto.Parser(b+"")).parse();var a=new e.Builder;null!==b["package"]&&
a.define(b["package"]);a.create(b.messages);a.reset();a.resolveAll();a.build();return a};e.protoFromFile=function(b,a){if(("undefined"==typeof window||!window.window)&&"function"==typeof require){var c=require("fs");if("function"==typeof a)c.readFile(b,function(b,c){a(e.protoFromString(c))});else return e.protoFromString(require("fs").readFileSync(b))}else{if("function"!=typeof a)throw Error("Cannot read '"+b+"': ProtoBuf.protoFromFile requires a callback");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=!1,f=0;f<c.length;f++){try{d=c[f]()}catch(h){continue}break}if(!d)throw Error("Cannot read '"+b+"': Your browser does not support XMLHttpRequest");d.open("GET",b,!0);d.setRequestHeader("User-Agent","XMLHTTP/1.0");d.onreadystatechange=function(){if(4==d.readyState){if(200!=d.status&&304!=d.status)throw Error("Failed to read '"+b+
"': Server returned status code "+d.status);a(e.protoFromString(d.responseText))}};4!=d.readyState&&d.send()}};e.newBuilder=function(b){var a=new e.Builder;"undefined"!=typeof b&&a.define(b);return a};return e}"undefined"!=typeof module&&module.exports?module.exports=t(require("bytebuffer")):"undefined"!=typeof define&&define.amd?define("ProtoBuf",["ByteBuffer"],t):(s.dcodeIO||(s.dcodeIO={}),s.dcodeIO.ProtoBuf=t(s.dcodeIO.ByteBuffer))})(this);
{};a=this.tn.next();a==f.OPTOPEN&&(this._parseMessageFieldOptions(b,c,a),a=this.tn.next());if(a!=f.END)throw Error("Illegal field delimiter in message "+b.name+"#"+c.name+": "+a+" ('"+f.END+"' expected)");b.fields.push(c)};l.prototype._parseMessageFieldOptions=function(b,a,c){var d=!0;do{c=this.tn.next();if(c==f.OPTCLOSE)break;else if(c==f.OPTEND){if(d)throw Error("Illegal start of message field options in message "+b.name+"#"+a.name+": "+c);c=this.tn.next()}if(!f.NAME.test(c))throw Error("Illegal field option in message "+
b.name+"#"+a.name+": "+c);this._parseMessageFieldOption(b,a,c);d=!1}while(1)};l.prototype._parseMessageFieldOption=function(b,a,c){var d=c;c=this.tn.next();if(c!=f.EQUAL)throw Error("Illegal field option operation in message "+b.name+"#"+a.name+": "+c+" ('=' expected)");var e;c=this.tn.next();if(c==f.STRINGOPEN){if(e=this.tn.next(),c=this.tn.next(),c!=f.STRINGCLOSE)throw Error("Illegal end of field value in message "+b.name+"#"+a.name+", option "+d+": "+c+" ('"+f.STRINGCLOSE+"' expected)");}else if(f.NUMBER.test(c))e=
parseInt(c,10);else if(f.NAME.test(c))e=c;else throw Error("Illegal field option value in message "+b.name+"#"+a.name+", option "+d+": "+c);a.options[d]=e};l.prototype._parseEnum=function(b,a){var c={};a=this.tn.next();if(!f.NAME.test(a))throw Error("Illegal enum name in message "+b.name+": "+a);c.name=a;a=this.tn.next();if(a!=f.OPEN)throw Error("Illegal OPEN after enum "+c.name+": "+a);c.values=[];do{a=this.tn.next();if(a==f.CLOSE)break;else if(!f.NAME.test(a))throw Error("Illegal enum value name in enum "+
c.name+": "+a);this._parseEnumValue(c,a)}while(1);b.enums.push(c)};l.prototype._parseEnumValue=function(b,a){var c={};c.name=a;a=this.tn.next();if(a!=f.EQUAL)throw Error("Illegal enum value operator in enum "+b.name+": "+a+" ('"+f.EQUAL+"' expected)");a=this.tn.next();if(!f.ID.test(a))throw Error("Illegal enum value value in enum "+b.name+": "+a);c.id=parseInt(a,10);b.values.push(c);a=this.tn.next();if(a!=f.END)throw Error("Illegal enum value delimiter in enum "+b.name+": "+a+" ('"+f.END+"' expected)");
};l.prototype.toString=function(){return"Parser"};s.Parser=l;e.Reflect=function(b){var a={},c=function(b,a){this.parent=b;this.name=a;this.resolvedType=null};c.prototype.toString=function(b){var c=this.name,m=this;do{m=m.parent;if(null==m)break;c=m.name+"."+c}while(1);b&&(this instanceof a.Message?c="Message "+c:this instanceof e.Field?c="Message.Field "+c:this instanceof j?c="Enum "+c:this instanceof j.Value?c="Enum.Value "+c:this instanceof d&&(c="Namespace "+c));return c};c.prototype.build=function(){throw Error(this.toString(!0)+
" cannot be built directly");};a.T=c;var d=function(b,a){c.call(this,b,a);this.children=[]};d.prototype=Object.create(c.prototype);d.prototype.getChildren=function(b){b=b||null;if(null==b)return this.children.slice();for(var a=[],c=0;c<this.children.length;c++)this.children[c]instanceof b&&a.push(this.children[c]);return a};d.prototype.addChild=function(b){if(this.hasChild(b.name))throw Error("Duplicate name in namespace "+this.toString(!0)+": "+b.name);this.children.push(b)};d.prototype.hasChild=
function(b){var a;if("number"==typeof b)for(a=0;a<this.children.length;a++){if(this.children[a]instanceof e.Field&&this.children[a].id==b)return!0}else for(a=0;a<this.children.length;a++)if(this.children[a].name==b)return!0;return!1};d.prototype.getChild=function(b){var a;if("number"==typeof b)for(a=0;a<this.children.length;a++){if(this.children[a]instanceof e.Field&&this.children[a].id==b)return this.children[a]}else for(a=0;a<this.children.length;a++)if(this.children[a].name==b)return this.children[a];
return null};d.prototype.resolve=function(b){var c=b.split("."),m=this,d=0;if(""==c[d]){for(;null!=m.parent;)m=m.parent;d++}do{do{m=m.getChild(c[d]);if(!m||!(m instanceof a.T)){m=null;break}d++}while(d<c.length);if(null!=m)break;if(null!==this.parent)return this.parent.resolve(b)}while(null!=m);return m};d.prototype.build=function(){for(var b={},a=this.getChildren(),c,e=0;e<a.length;e++)c=a[e],c instanceof d&&(b[c.name]=c.build());return b};a.Namespace=d;var e=function(b,a){d.call(this,b,a);this.built=
null};e.prototype=Object.create(d.prototype);e.prototype.build=function(){for(var b=function(b,a){var c=a.getChildren(b.Message.Field),d=eval("(function "+a.name+"() { this.__construct.apply(this, arguments); })");d.prototype.__construct=function(b){var a,d;for(a=0;a<c.length;a++)d=c[a],this[d.name]=d.repeated?[]:null;for(a=0;a<c.length;a++)if(d=c[a],"undefined"!=typeof d.options["default"])try{this.set(d.name,d.options["default"])}catch(g){throw Error("[INTERNAL ERROR] "+g);}if("object"==typeof b&&
"function"!=typeof b.encode){d=Object.keys(b);for(a=0;a<d.length;a++)this.set(d[a],b[d[a]])}else for(a=0;a<arguments.length;a++)a<c.length&&this.set(c[a].name,arguments[a])};d.prototype.add=function(c,d){var g=a.getChild(c);if(!g)throw Error(this+"#"+c+" is undefined");if(!(g instanceof b.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))};
d.prototype.set=function(c,d){var g=a.getChild(c);if(!g)throw Error(this+"#"+c+" is not a field: undefined");if(!(g instanceof b.Message.Field))throw Error(this+"#"+c+" is not a field: "+g.toString(!0));this[g.name]=g.verifyValue(d)};d.prototype.get=function(c){var d=a.getChild(c);if(!d||!(d instanceof b.Message.Field))throw Error(this+"#"+c+" is not a field: undefined");if(!(d instanceof b.Message.Field))throw Error(this+"#"+c+" is not a field: "+d.toString(!0));return this[d.name]};for(var g=0;g<
c.length;g++)(function(b){var c=b.name.replace(/(_[a-zA-Z])/g,function(b){return b.toUpperCase().replace("_","")}),c=c.substring(0,1).toUpperCase()+c.substring(1),g=b.name.replace(/([A-Z])/g,function(b){return"_"+b});a.hasChild("set"+c)||(d.prototype["set"+c]=function(a){this.set(b.name,a)});a.hasChild("set_"+g)||(d.prototype["set_"+g]=function(a){this.set(b.name,a)});a.hasChild("get"+c)||(d.prototype["get"+c]=function(){return this.get(b.name)});a.hasChild("get_"+g)||(d.prototype["get_"+g]=function(){return this.get(b.name)})})(c[g]);
d.prototype.encode=function(b){b=b||new k;a.encode(this,b);return b.flip()};d.prototype.toArrayBuffer=function(){return this.encode().toArrayBuffer()};d.decode=function(b){b=b?b instanceof k?b:k.wrap(b):new k;return a.decode(b)};d.prototype.toString=function(){return a.toString()};return d}(a,this),c=this.getChildren(),d=0;d<c.length;d++)if(c[d]instanceof j)b[c[d].name]=c[d].build();else if(c[d]instanceof e)b[c[d].name]=c[d].build();else if(!(c[d]instanceof e.Field))throw Error("Illegal reflect child of "+
this.toString(!0)+": "+c[d].toString(!0));return this.built=b};e.prototype.encode=function(b,a){for(var c=this.getChildren(e.Field),d=0;d<c.length;d++)c[d].encode(b.get(c[d].name),a)};e.prototype.decode=function(b,a){a=a||-1;for(var c=b.offset,d=new this.built;b.offset<c+a||-1==a&&0<b.remaining();){var e=b.readVarint32(),f=e&7,e=e>>3,r=this.getChild(e);if(!r)throw Error("Illegal field id in "+this.toString(!0)+"#decode: "+e);d.set(r.name,r.decode(f,b))}return d};a.Message=e;var f=function(b,a,d,e,
f,r){c.call(this,b,e);this.required="required"==a;this.repeated="repeated"==a;this.type=d;this.id=f;this.options=r||{}};f.prototype=Object.create(c.prototype);f.prototype.verifyValue=function(a,c){c=c||!1;if(null===a){if(this.required)throw Error("Illegal value for "+this.toString(!0)+": "+a+" (required)");return null}var d,e;if(this.repeated&&!c){if(!(a instanceof Array))throw Error("Illegal value for "+this.toString(!0)+": "+a+" (not an array)");e=[];for(d=0;d<a.length;d++)e.push(this.verifyValue(a[d],
!0));return e}if(!this.repeated&&a instanceof Array)throw Error("Illegal value for "+this.toString(!0)+": "+a+" (is array)");if(this.type!=b.TYPES.message&&a instanceof Object)throw Error("Illegal value for "+this.toString(!0)+": "+a+" (is object)");if(this.type==b.TYPES.int32||this.type==b.TYPES.sint32||this.type==b.TYPES.fixed32||this.type==b.TYPES.sfixed32)return parseInt(a,10);if(this.type==b.TYPES.uint32){a=parseInt(a,10);if(0>a)throw Error("Illegal value for "+this.toString(!0)+": "+a+" (must not be negative)");
return a}if(this.type==b.TYPES.bool)return!!a;if(this.type==b.TYPES["float"]||this.type==b.TYPES["double"])return parseFloat(a);if(this.type==b.TYPES.string)return""+a;if(this.type==b.TYPES.bytes)return k.wrap(a);if(this.type==b.TYPES["enum"]){e=this.resolvedType.getChildren(j.Value);for(d=0;d<e.length;d++)if(e[d].name==a||e[d].id==a)return e[d].id;throw Error("Illegal value for "+this.toString(!0)+": "+a+" (not a valid enum value)");}if(this.type==b.TYPES.message){if(a instanceof this.resolvedType.built)return a;
if("object"==typeof a)return new this.resolvedType.built(a);throw Error("Illegal value for "+this.toString(!0)+": "+a+" (not an instance of "+this.resolvedType+")");}throw Error("[INTERNAL ERROR] Illegal value for "+this.toString(!0)+": "+a+" (undefined type "+this.type+")");};f.prototype.encode=function(a,c){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)try{if(this.repeated){var d;
if(this.options.packed){c.writeVarint32(this.id<<3|b.WIRE_TYPES.LDELIM);for(d=0;d<a.length;d++)this.encodeValue(a[d],c)}else for(d=0;d<a.length;d++)c.writeVarint32(this.id<<3|this.type.wireType),this.encodeValue(a[d],c)}else c.writeVarint32(this.id<<3|this.type.wireType),this.encodeValue(a,c)}catch(e){throw Error("Illegal value for "+this.toString(!0)+": "+a+" ("+e+")");}};f.prototype.decode=function(a,c){var d,e;if(a!=this.type.wireType)throw Error("Illegal wire type for field "+this.toString(!0)+
": "+a+" ("+this.type.wireType+" expected)");if(this.type==b.TYPES.int32)return c.readVarint32();if(this.type==b.TYPES.uint32)return d=c.readVarint32(),UINT32[0]=d,UINT32[0];if(this.type==b.TYPES.sint32)return c.readZigZagVarint32();if(this.type==b.TYPES.bool)return!!c.readVarint32();if(this.type==b.TYPES["enum"])return c.readVarint32();if(this.type==b.TYPES["double"])return c.readDouble();if(this.type==b.TYPES.string)return c.readVString();if(this.type==b.TYPES.bytes)return e=c.readVarint32(),d=
c.clone(),d.length=d.offset+e,d;if(this.type==b.TYPES.message)return e=c.readVarint32(),this.resolvedType.decode(c,e);if(a==b.WIRE_TYPES.LDELIM&&this.repeated){e=c.readVarint32();for(e=c.offset+e;c.offset<e;)this.decode(this.type.wireType,c);return[]}if(this.type==b.TYPES.fixed32)return c.readInt32();if(this.type==b.TYPES.sfixed32)return k.zigZagDecode32(c.readUint32());if(this.type==b.TYPES["float"])return c.readFloat();throw Error("[INTERNAL ERROR] Illegal wire type for "+this.toString(!0)+": "+
a);};f.prototype.encodeValue=function(a,c){if(null!==a)if(this.type==b.TYPES.int32||this.type==b.TYPES.uint32)c.writeVarint32(a);else if(this.type==b.TYPES.sint32)c.writeVarint32(k.zigZagEncode32(a));else if(this.type==b.TYPES.fixed32)c.writeUint32(a);else if(this.type==b.TYPES.sfixed32)c.writeUint32(k.zigZagEncode32(a));else if(this.type==b.TYPES.bool)c.writeVarint32(a?1:0);else if(this.type==b.TYPES["enum"])c.writeVarint32(a);else if(this.type==b.TYPES["float"])c.writeFloat32(a);else if(this.type==
b.TYPES["double"])c.writeFloat64(a);else if(this.type==b.TYPES.string)c.writeVString(a);else if(this.type==b.TYPES.bytes)a.offset>a.length&&(c=c.clone().flip()),c.writeVarint32(a.remaining()),c.append(a);else if(this.type==b.TYPES.message){var d=c.offset;c.writeUint8(0);this.resolvedType.encode(a,c);var e=c.offset-d-1,f=k.calculateVarint32(e);if(1<f){var r=c.clone();r.offset-=e;c.append(r.flip(),d-1+f)}c.writeVarint32(e,d)}else throw Error("[INTERNAL ERROR] Illegal value to encode in "+this.toString(!0)+
": "+a+" (unknown type)");};a.Message.Field=f;var j=function(a,b){d.call(this,a,b);this.built=null};j.prototype=Object.create(d.prototype);j.prototype.build=function(){for(var a={},b=this.getChildren(j.Value),c=0;c<b.length;c++)a[b[c].name]=b[c].id;return this.built=a};a.Enum=j;f=function(a,b,d){c.call(this,a,b);this.id=d};f.prototype=Object.create(c.prototype);a.Enum.Value=f;return a}(e);var h=e.Lang,q=e.Reflect,n=function(){this.ptr=this.ns=new q.Namespace(null,"");this.resolved=!1;this.result=
null};n.prototype.reset=function(){this.ptr=this.ns};n.prototype.define=function(b){if("string"!=typeof b||!h.TYPEDEF.test(b))throw Error("Illegal package name: "+b);b=b.split(".");var a;for(a=0;a<b.length;a++)if(!h.NAME.test(b[a]))throw Error("Illegal package name: "+b[a]);for(a=0;a<b.length;a++)this.ptr.hasChild(b[a])||this.ptr.addChild(new q.Namespace(this.ptr,b[a])),this.ptr=this.ptr.getChild(b[a]);return this};n.isValidMessage=function(b){if("string"!=typeof b.name||!h.NAME.test(b.name)||"undefined"!=
typeof b.values)return!1;var a;if("undefined"!=typeof b.fields){if(!(b.fields instanceof Array))return!1;var c=[],d;for(a=0;a<b.fields.length;a++){if(!n.isValidMessageField(b.fields[a]))return!1;d=parseInt(b.id,10);if(0<=c.indexOf(d))return!1;c.push(d)}}if("undefined"!=typeof b.enums){if(!(b.enums instanceof Array))return!1;for(a=0;a<b.enums.length;a++)if(!n.isValidEnum(b.enums[a]))return!1}if("undefined"!=typeof b.messages){if(!(b.messages instanceof Array))return!1;for(a=0;a<b.messages.length;a++)if(!n.isValidMessage(b.messages[a]))return!1}return!0};
n.isValidMessageField=function(b){if("string"!=typeof b.rule||"string"!=typeof b.name||"string"!=typeof b.type||"undefined"==typeof b.id||!h.RULE.test(b.rule)||!h.NAME.test(b.name)||!h.TYPEREF.test(b.type)||!h.ID.test(""+b.id))return!1;if("undefined"!=typeof b.options){if("object"!=typeof b.options)return!1;for(var a=Object.keys(b.options),c=0;c<a.length;c++)if(!h.NAME.test(a[c])||!h.ID.test(""+b.options[a[c]])&&!h.TYPEREF.test(b.options[a[c]]))return!1}return!0};n.isValidEnum=function(b){if("string"!=
typeof b.name||!h.NAME.test(b.name)||"undefined"==typeof b.values||!(b.values instanceof Array)||0==b.values.length)return!1;for(var a=0;a<b.values.length;a++)if("object"!=typeof b.values[a]||"string"!=typeof b.values[a].name||"undefined"==typeof b.values[a].id||!h.NAME.test(b.values[a].name)||!h.ID.test(""+b.values[a].id))return!1;return!0};n.prototype.create=function(b){if(b&&(b instanceof Array||(b=[b]),0!=b.length)){var a=[],c,d,e,f,j;for(a.push(b);0<a.length;){b=a.pop();if(b instanceof Array)for(;0<
b.length;)if(c=b.shift(),n.isValidMessage(c)){d=new q.Message(this.ptr,c.name);if(c.fields&&0<c.fields.length)for(f=0;f<c.fields.length;f++){if(!n.isValidMessageField(c.fields[f]))throw Error("Not a valid message field definition in message "+d.name+": "+JSON.stringify(c.fields[f]));if(c.fields[f].options){e=Object.keys(c.fields[f].options);for(j=0;j<e.length;j++){if(!h.NAME.test(e[j]))throw Error("Illegal field option name in message "+d.name+"#"+c.fields[f].name+": "+e[j]);if(!h.ID.test(""+c.fields[f].options[e[j]])&&
!h.TYPEREF.test(c.fields[f].options[e[j]]))throw Error("Illegal field option value in message "+d.name+"#"+c.fields[f].name+"#"+e[j]+": "+c.fields[f].options[e[j]]);}}d.addChild(new q.Message.Field(d,c.fields[f].rule,c.fields[f].type,c.fields[f].name,c.fields[f].id,c.fields[f].options))}e=[];if("undefined"!=typeof c.enums&&0<c.enums.length)for(f=0;f<c.enums.length;f++)e.push(c.enums[f]);if(c.messages&&0<c.messages.length)for(f=0;f<c.messages.length;f++)e.push(c.messages[f]);this.ptr.addChild(d);0<
e.length&&(a.push(b),b=e,this.ptr=d)}else if(n.isValidEnum(c)){d=new q.Enum(this.ptr,c.name);for(f=0;f<c.values.length;f++)d.addChild(new q.Enum.Value(d,c.values[f].name,c.values[f].id));this.ptr.addChild(d)}else throw Error("Not a valid message or enum definition: "+JSON.stringify(c));else throw Error("Not a valid namespace definition: "+JSON.stringify(b));this.ptr=this.ptr.parent}this.resolved=!1;this.result=null;return this}};n.prototype.resolveAll=function(){if(!(null==this.ptr||"object"==typeof this.ptr.type)){if(this.ptr instanceof
q.Namespace)for(var b=this.ptr.getChildren(),a=0;a<b.length;a++)this.ptr=b[a],this.resolveAll();else if(this.ptr instanceof q.Message.Field)if(h.TYPE.test(this.ptr.type))this.ptr.type=e.TYPES[this.ptr.type];else{if(!h.TYPEREF.test(this.ptr.type))throw Error("Illegal type reference in "+this.ptr.toString(!0)+": "+this.ptr.type);b=this.ptr.parent.resolve(this.ptr.type);if(!b)throw Error("Unresolvable type reference in "+this.ptr.toString(!0)+": "+this.ptr.type);this.ptr.resolvedType=b;if(b instanceof
q.Enum)this.ptr.type=e.TYPES["enum"];else if(b instanceof q.Message)this.ptr.type=e.TYPES.message;else throw Error("Illegal type reference in "+this.ptr.toString(!0)+": "+this.ptr.type);}else if(!(this.ptr instanceof e.Reflect.Enum.Value))throw Error("Illegal object type in namespace: "+typeof this.ptr+":"+this.ptr);this.reset()}};n.prototype.build=function(b){this.reset();this.resolved||(this.resolveAll(),this.resolved=!0,this.result=null);null==this.result&&(this.result=this.ns.build());if(b){b=
b.split(".");for(var a=this.result,c=0;c<b.length;c++)if(a[b[c]])a=a[b[c]];else{a=null;break}return a}return this.result};n.prototype.toString=function(){return"Builder"};e.Builder=n;e.protoFromString=function(b){b=(new e.DotProto.Parser(b+"")).parse();var a=new e.Builder;null!==b["package"]&&a.define(b["package"]);a.create(b.messages);a.reset();a.resolveAll();a.build();return a};e.protoFromFile=function(b,a){if(("undefined"==typeof window||!window.window)&&"function"==typeof require){var c=require("fs");
if("function"==typeof a)c.readFile(b,function(b,c){a(e.protoFromString(c))});else return e.protoFromString(require("fs").readFileSync(b))}else{if("function"!=typeof a)throw Error("Cannot read '"+b+"': ProtoBuf.protoFromFile requires a callback");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=!1,f=0;f<c.length;f++){try{d=c[f]()}catch(h){continue}break}if(!d)throw Error("Cannot read '"+
b+"': Your browser does not support XMLHttpRequest");d.open("GET",b,!0);d.setRequestHeader("User-Agent","XMLHTTP/1.0");d.onreadystatechange=function(){if(4==d.readyState){if(200!=d.status&&304!=d.status)throw Error("Failed to read '"+b+"': Server returned status code "+d.status);a(e.protoFromString(d.responseText))}};4!=d.readyState&&d.send()}};e.newBuilder=function(b){var a=new e.Builder;"undefined"!=typeof b&&a.define(b);return a};return e}"undefined"!=typeof module&&module.exports?module.exports=
t(require("bytebuffer")):"undefined"!=typeof define&&define.amd?define("ProtoBuf",["ByteBuffer"],t):(s.dcodeIO||(s.dcodeIO={}),s.dcodeIO.ProtoBuf=t(s.dcodeIO.ByteBuffer))})(this);

@@ -7,18 +7,18 @@ /*

(function(p){function q(k){if(!k||!k.calculateUTF8String||!k.zigZagEncode32)if("undefined"!=typeof dcodeIO&&dcodeIO.ByteBuffer&&(k=dcodeIO.ByteBuffer),!k&&"function"==typeof require&&(k=require("ByteBuffer")),!k)throw Error("ProtoBuf.js requires ByteBuffer.js >=1.1.0: Get it at https://github.com/dcodeIO/ByteBuffer.js");Object.create||(Object.create=function(a){function b(){}if(1<arguments.length)throw Error("Object.create implementation only accepts the first parameter.");b.prototype=a;return new b});
var f={VERSION:"0.9.2",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},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",
var f={VERSION:"0.9.4",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},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},"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.Lang={OPEN:"{",CLOSE:"}",OPTOPEN:"[",OPTCLOSE:"]",OPTEND:",",EQUAL:"=",END:";",DELIM:/[\s\{\}=;\[\],"]/g,KEYWORD:/package|option|message|enum/,RULE:/required|optional|repeated/,TYPE:/double|float|int32|uint32|sint32|fixed32|sfixed32|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]+/,COMMENT:"//",WHITESPACE:/\s/,STRING:/"([^"\\]*(\\.[^"\\]*)*)"/g,STRINGOPEN:'"',STRINGCLOSE:'"'};f.Reflect=function(a){var b={},e=function(a,c){this.parent=a;this.name=c;this.resolvedType=null};e.prototype.toString=function(a){var c=this.name,d=this;do{d=d.parent;if(null==d)break;c=d.name+"."+c}while(1);a&&(this instanceof b.Message?c="Message "+c:this instanceof
l.Field?c="Message.Field "+c:this instanceof j?c="Enum "+c:this instanceof j.Value?c="Enum.Value "+c:this instanceof f&&(c="Namespace "+c));return c};e.prototype.build=function(){throw this.toString(!0)+" cannot be built directly";};b.T=e;var f=function(a,c){e.call(this,a,c);this.children=[]};f.prototype=Object.create(e.prototype);f.prototype.getChildren=function(a){a=a||null;if(null==a)return this.children.slice();for(var c=[],d=0;d<this.children.length;d++)this.children[d]instanceof a&&c.push(this.children[d]);
l.Field?c="Message.Field "+c:this instanceof j?c="Enum "+c:this instanceof j.Value?c="Enum.Value "+c:this instanceof f&&(c="Namespace "+c));return c};e.prototype.build=function(){throw Error(this.toString(!0)+" cannot be built directly");};b.T=e;var f=function(a,c){e.call(this,a,c);this.children=[]};f.prototype=Object.create(e.prototype);f.prototype.getChildren=function(a){a=a||null;if(null==a)return this.children.slice();for(var c=[],d=0;d<this.children.length;d++)this.children[d]instanceof a&&c.push(this.children[d]);
return c};f.prototype.addChild=function(a){if(this.hasChild(a.name))throw Error("Duplicate name in namespace "+this.toString(!0)+": "+a.name);this.children.push(a)};f.prototype.hasChild=function(a){var c;if("number"==typeof a)for(c=0;c<this.children.length;c++){if(this.children[c]instanceof l.Field&&this.children[c].id==a)return!0}else for(c=0;c<this.children.length;c++)if(this.children[c].name==a)return!0;return!1};f.prototype.getChild=function(a){var c;if("number"==typeof a)for(c=0;c<this.children.length;c++){if(this.children[c]instanceof
l.Field&&this.children[c].id==a)return this.children[c]}else for(c=0;c<this.children.length;c++)if(this.children[c].name==a)return this.children[c];return null};f.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};f.prototype.build=function(){for(var a={},c=this.getChildren(),
d,b=0;b<c.length;b++)d=c[b],d instanceof f&&(a[d.name]=d.build());return a};b.Namespace=f;var l=function(a,c){f.call(this,a,c);this.built=null};l.prototype=Object.create(f.prototype);l.prototype.build=function(){for(var a=function(a,c){var d=c.getChildren(a.Message.Field),h=eval("(function "+c.name+"() { this.__construct.apply(this, arguments); })");h.prototype.__construct=function(a){var c,h;for(c=0;c<d.length;c++)h=d[c],this[h.name]=h.repeated?[]:null;for(c=0;c<d.length;c++)if(h=d[c],"undefined"!=
typeof h.options["default"])try{this.set(h.name,h.options["default"])}catch(b){throw Error("[INTERNAL ERROR] "+b);}if("object"==typeof a&&"function"!=typeof a.encode){h=Object.keys(a);for(c=0;c<h.length;c++)this.set(h[c],a[h[c]])}else for(c=0;c<arguments.length;c++)c<d.length&&this.set(d[c].name,arguments[c])};h.prototype.add=function(h,d){var b=c.getChild(h);if(!b)throw this+"#"+h+" is undefined";if(!(b instanceof a.Message.Field))throw this+"#"+h+" is not a field: "+b.toString(!0);if(!b.repeated)throw this+
"#"+h+" is not a repeated field";null===this[b.name]&&(this[b.name]=[]);this[b.name].push(b.verifyValue(d))};h.prototype.set=function(h,d){var b=c.getChild(h);if(!b)throw this+"#"+h+" is not a field: undefined";if(!(b instanceof a.Message.Field))throw this+"#"+h+" is not a field: "+b.toString(!0);this[b.name]=b.verifyValue(d)};h.prototype.get=function(h){var d=c.getChild(h);if(!d||!(d instanceof a.Message.Field))throw this+"#"+h+" is not a field: undefined";if(!(d instanceof a.Message.Field))throw this+
"#"+h+" is not a field: "+d.toString(!0);return this[d.name]};for(var b=0;b<d.length;b++)(function(a){var d=a.name.replace(/(_[a-zA-Z])/g,function(a){return a.toUpperCase().replace("_","")}),d=d.substring(0,1).toUpperCase()+d.substring(1),b=a.name.replace(/([A-Z])/g,function(a){return"_"+a});c.hasChild("set"+d)||(h.prototype["set"+d]=function(c){this.set(a.name,c)});c.hasChild("set_"+b)||(h.prototype["set_"+b]=function(c){this.set(a.name,c)});c.hasChild("get"+d)||(h.prototype["get"+d]=function(){return this.get(a.name)});
c.hasChild("get_"+b)||(h.prototype["get_"+b]=function(){return this.get(a.name)})})(d[b]);h.prototype.encode=function(a){a=a||new k;c.encode(this,a);return a.flip()};h.prototype.toArrayBuffer=function(){return this.encode().toArrayBuffer()};h.decode=function(a){a=a?a instanceof k?a:k.wrap(a):new k;return c.decode(a)};h.prototype.toString=function(){return c.toString()};return h}(b,this),c=this.getChildren(),d=0;d<c.length;d++)if(c[d]instanceof j)a[c[d].name]=c[d].build();else if(c[d]instanceof l)a[c[d].name]=
c[d].build();else if(!(c[d]instanceof l.Field))throw Error("Illegal reflect child of "+this.toString(!0)+": "+c[d].toString(!0));return this.built=a};l.prototype.encode=function(a,c){for(var d=this.getChildren(l.Field),b=0;b<d.length;b++)d[b].encode(a.get(d[b].name),c)};l.prototype.decode=function(a,c){c=c||-1;for(var d=a.offset,b=new this.built;a.offset<d+c||-1==c&&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);b.set(g.name,g.decode(f,a))}return b};b.Message=l;var g=function(a,c,d,b,f,g){e.call(this,a,b);this.required="required"==c;this.repeated="repeated"==c;this.type=d;this.id=f;this.options=g||{}};g.prototype=Object.create(e.prototype);g.prototype.verifyValue=function(b,c){c=c||!1;if(null===b){if(this.required)throw Error("Illegal value for "+this.toString(!0)+": "+b+" (required)");return null}var d,e;if(this.repeated&&!c){if(!(b instanceof Array))throw Error("Illegal value for "+this.toString(!0)+
": "+b+" (not an array)");e=[];for(d=0;d<b.length;d++)e.push(this.verifyValue(b[d],!0));return e}if(!this.repeated&&b instanceof Array)throw Error("Illegal value for "+this.toString(!0)+": "+b+" (is array)");if(this.type!=a.TYPES.message&&b instanceof Object)throw Error("Illegal value for "+this.toString(!0)+": "+b+" (is object)");if(this.type==a.TYPES.int32||this.type==a.TYPES.sint32||this.type==a.TYPES.fixed32||this.type==a.TYPES.sfixed32)return parseInt(b,10);if(this.type==a.TYPES.uint32){b=parseInt(b,
10);if(0>b)throw Error("Illegal value for "+this.toString(!0)+": "+b+" (must not be negative)");return b}if(this.type==a.TYPES.bool)return!!b;if(this.type==a.TYPES["float"]||this.type==a.TYPES["double"])return parseFloat(b);if(this.type==a.TYPES.string)return""+b;if(this.type==a.TYPES.bytes)return k.wrap(b);if(this.type==a.TYPES["enum"]){e=this.resolvedType.getChildren(j.Value);for(d=0;d<e.length;d++)if(e[d].name==b||e[d].id==b)return e[d].id;throw Error("Illegal value for "+this.toString(!0)+": "+
b+" (not a valid enum value)");}if(this.type==a.TYPES.message){if(b instanceof this.resolvedType.built)return b;if("object"==typeof b)return new this.resolvedType.built(b);throw Error("Illegal value for "+this.toString(!0)+": "+b+" (not an instance of "+this.resolvedType+")");}throw Error("[INTERNAL ERROR] Illegal value for "+this.toString(!0)+": "+b+" (undefined type "+this.type+")");};g.prototype.encode=function(b,c){b=this.verifyValue(b);if(null==this.type||"object"!=typeof this.type)throw Error("[INTERNAL ERROR] Unresolved type in "+
typeof h.options["default"])try{this.set(h.name,h.options["default"])}catch(b){throw Error("[INTERNAL ERROR] "+b);}if("object"==typeof a&&"function"!=typeof a.encode){h=Object.keys(a);for(c=0;c<h.length;c++)this.set(h[c],a[h[c]])}else for(c=0;c<arguments.length;c++)c<d.length&&this.set(d[c].name,arguments[c])};h.prototype.add=function(h,d){var b=c.getChild(h);if(!b)throw Error(this+"#"+h+" is undefined");if(!(b instanceof a.Message.Field))throw Error(this+"#"+h+" is not a field: "+b.toString(!0));
if(!b.repeated)throw Error(this+"#"+h+" is not a repeated field");null===this[b.name]&&(this[b.name]=[]);this[b.name].push(b.verifyValue(d))};h.prototype.set=function(h,d){var b=c.getChild(h);if(!b)throw Error(this+"#"+h+" is not a field: undefined");if(!(b instanceof a.Message.Field))throw Error(this+"#"+h+" is not a field: "+b.toString(!0));this[b.name]=b.verifyValue(d)};h.prototype.get=function(h){var d=c.getChild(h);if(!d||!(d instanceof a.Message.Field))throw Error(this+"#"+h+" is not a field: undefined");
if(!(d instanceof a.Message.Field))throw Error(this+"#"+h+" is not a field: "+d.toString(!0));return this[d.name]};for(var b=0;b<d.length;b++)(function(a){var d=a.name.replace(/(_[a-zA-Z])/g,function(a){return a.toUpperCase().replace("_","")}),d=d.substring(0,1).toUpperCase()+d.substring(1),b=a.name.replace(/([A-Z])/g,function(a){return"_"+a});c.hasChild("set"+d)||(h.prototype["set"+d]=function(c){this.set(a.name,c)});c.hasChild("set_"+b)||(h.prototype["set_"+b]=function(c){this.set(a.name,c)});c.hasChild("get"+
d)||(h.prototype["get"+d]=function(){return this.get(a.name)});c.hasChild("get_"+b)||(h.prototype["get_"+b]=function(){return this.get(a.name)})})(d[b]);h.prototype.encode=function(a){a=a||new k;c.encode(this,a);return a.flip()};h.prototype.toArrayBuffer=function(){return this.encode().toArrayBuffer()};h.decode=function(a){a=a?a instanceof k?a:k.wrap(a):new k;return c.decode(a)};h.prototype.toString=function(){return c.toString()};return h}(b,this),c=this.getChildren(),d=0;d<c.length;d++)if(c[d]instanceof
j)a[c[d].name]=c[d].build();else if(c[d]instanceof l)a[c[d].name]=c[d].build();else if(!(c[d]instanceof l.Field))throw Error("Illegal reflect child of "+this.toString(!0)+": "+c[d].toString(!0));return this.built=a};l.prototype.encode=function(a,c){for(var d=this.getChildren(l.Field),b=0;b<d.length;b++)d[b].encode(a.get(d[b].name),c)};l.prototype.decode=function(a,c){c=c||-1;for(var d=a.offset,b=new this.built;a.offset<d+c||-1==c&&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);b.set(g.name,g.decode(f,a))}return b};b.Message=l;var g=function(a,c,d,b,f,g){e.call(this,a,b);this.required="required"==c;this.repeated="repeated"==c;this.type=d;this.id=f;this.options=g||{}};g.prototype=Object.create(e.prototype);g.prototype.verifyValue=function(b,c){c=c||!1;if(null===b){if(this.required)throw Error("Illegal value for "+this.toString(!0)+": "+b+" (required)");return null}var d,e;if(this.repeated&&!c){if(!(b instanceof
Array))throw Error("Illegal value for "+this.toString(!0)+": "+b+" (not an array)");e=[];for(d=0;d<b.length;d++)e.push(this.verifyValue(b[d],!0));return e}if(!this.repeated&&b instanceof Array)throw Error("Illegal value for "+this.toString(!0)+": "+b+" (is array)");if(this.type!=a.TYPES.message&&b instanceof Object)throw Error("Illegal value for "+this.toString(!0)+": "+b+" (is object)");if(this.type==a.TYPES.int32||this.type==a.TYPES.sint32||this.type==a.TYPES.fixed32||this.type==a.TYPES.sfixed32)return parseInt(b,
10);if(this.type==a.TYPES.uint32){b=parseInt(b,10);if(0>b)throw Error("Illegal value for "+this.toString(!0)+": "+b+" (must not be negative)");return b}if(this.type==a.TYPES.bool)return!!b;if(this.type==a.TYPES["float"]||this.type==a.TYPES["double"])return parseFloat(b);if(this.type==a.TYPES.string)return""+b;if(this.type==a.TYPES.bytes)return k.wrap(b);if(this.type==a.TYPES["enum"]){e=this.resolvedType.getChildren(j.Value);for(d=0;d<e.length;d++)if(e[d].name==b||e[d].id==b)return e[d].id;throw Error("Illegal value for "+
this.toString(!0)+": "+b+" (not a valid enum value)");}if(this.type==a.TYPES.message){if(b instanceof this.resolvedType.built)return b;if("object"==typeof b)return new this.resolvedType.built(b);throw Error("Illegal value for "+this.toString(!0)+": "+b+" (not an instance of "+this.resolvedType+")");}throw Error("[INTERNAL ERROR] Illegal value for "+this.toString(!0)+": "+b+" (undefined type "+this.type+")");};g.prototype.encode=function(b,c){b=this.verifyValue(b);if(null==this.type||"object"!=typeof this.type)throw Error("[INTERNAL ERROR] Unresolved type in "+
this.toString(!0)+": "+this.type);if(null!==b)try{if(this.repeated){var d;if(this.options.packed){c.writeVarint32(this.id<<3|a.WIRE_TYPES.LDELIM);for(d=0;d<b.length;d++)this.encodeValue(b[d],c)}else for(d=0;d<b.length;d++)c.writeVarint32(this.id<<3|this.type.wireType),this.encodeValue(b[d],c)}else c.writeVarint32(this.id<<3|this.type.wireType),this.encodeValue(b,c)}catch(e){throw Error("Illegal value for "+this.toString(!0)+": "+b+" ("+e+")");}};g.prototype.decode=function(b,c){var d,e;if(b!=this.type.wireType)throw Error("Illegal wire type for field "+

@@ -25,0 +25,0 @@ this.toString(!0)+": "+b+" ("+this.type.wireType+" expected)");if(this.type==a.TYPES.int32)return c.readVarint32();if(this.type==a.TYPES.uint32)return d=c.readVarint32(),UINT32[0]=d,UINT32[0];if(this.type==a.TYPES.sint32)return c.readZigZagVarint32();if(this.type==a.TYPES.bool)return!!c.readVarint32();if(this.type==a.TYPES["enum"])return c.readVarint32();if(this.type==a.TYPES["double"])return c.readDouble();if(this.type==a.TYPES.string)return c.readVString();if(this.type==a.TYPES.bytes)return e=c.readVarint32(),

@@ -6,3 +6,4 @@ ProtoBuf.js - protobuf for JavaScript [![Build Status](https://travis-ci.org/dcodeIO/ProtoBuf.js.png?branch=master)](https://travis-ci.org/dcodeIO/ProtoBuf.js)

reflection, message class building and simple encoding and decoding in plain JavaScript. No compilation step required,
works out of the box on .proto files.
works out of the box on .proto files. It's also used for the cross-platform multiplayer component in
[eSoccer](http://www.esoccer.me), an HTML5 game developed at [University of Applied Sciences Bonn](http://www.h-brs.de).

@@ -231,4 +232,5 @@ Builder

#### Not (yet) supported ####
* Extensions (what for?), imports (put everything into one builder instead) and services (you roll your own, don't you?).
* Extensions (what for?), imports (put everything into one builder instead by calling `Builder#define(package)` and
`Builder#create([messages])` multiple times) and services (you roll your own, don't you?).
However, if you need anything of the above, please drop me a note how you'd like to see it implemented. It's just that

@@ -278,2 +280,34 @@ I have no idea how to benefit from that and therefore I am not sure how to design it.

CommonJS, AMD and browser (shim)
--------------------------------
#### node.js / CommonJS ####
```bash
npm install protobufjs
```
```javascript
var ProtoBuf = require("protobufjs");
...
```
#### RequireJS / AMD ####
```javascript
var ProtoBuf = require("/path/to/ProtoBuf.js");
...
```
#### Browser (shim) ####
```html
<script src="//raw.github.com/dcodeIO/ProtoBuf.js/master/ProtoBuf.min.js"></script>
```
```javascript
var ProtoBuf = dcodeIO.ProtoBuf;
...
```
Downloads

@@ -299,7 +333,7 @@ ---------

* [node.js](http://nodejs.org) compatible, also available via [npm](https://npmjs.org/package/protobufjs)
* [Closure Compiler](https://developers.google.com/closure/compiler/) ADVANCED_OPTIMIZATIONS compatible (fully annotated)
* [Closure Compiler](https://developers.google.com/closure/compiler/) compatible (fully annotated, [externs](https://github.com/dcodeIO/ProtoBuf.js/tree/master/externs))
* Fully documented using [jsdoc3](https://github.com/jsdoc3/jsdoc)
* Well tested through [nodeunit](https://github.com/caolan/nodeunit)
* [ByteBuffer.js](https://github.com/dcodeIO/ByteBuffer.js) is the only production dependency
* Small footprint (even smaller if you use JSON definitions instead of .proto files, because no parser is required)
* Small footprint (even smaller if you use a noparse build)

@@ -306,0 +340,0 @@ License

@@ -60,3 +60,5 @@ /*

* ProtoBuf.js version.
* @type {Object.<string, string>}
* @type {string}
* @const
* @expose
*/

@@ -83,2 +85,3 @@ ProtoBuf.VERSION = // #put '"'+VERSION+'";'

* @type {number}
* @const
* @expose

@@ -91,2 +94,3 @@ */

* @type {number}
* @const
* @expose

@@ -99,3 +103,4 @@ */

* @type {number}
* @deprecated
* @const
* @deprecated Not supported.
* @expose

@@ -108,3 +113,4 @@ */

* @type {number}
* @deprecated
* @const
* @deprecated Not supported.
* @expose

@@ -117,2 +123,3 @@ */

* @type {number}
* @const
* @expose

@@ -123,3 +130,3 @@ */

/**
* Native types.
* Types.
* @dict

@@ -126,0 +133,0 @@ * @type {Object.<string,{name: string, wireType: number}>}

@@ -35,4 +35,3 @@ // #ifdef UNDEFINED

* Namespace.
* @type {Object.<string,ProtoBuf.Reflect.Message>}
* @dict
* @type {ProtoBuf.Reflect.Namespace}
* @expose

@@ -44,4 +43,3 @@ */

* Namespace pointer.
* @type {Object.<string, *>}
* @dict
* @type {ProtoBuf.Reflect.T}
* @expose

@@ -60,3 +58,3 @@ */

* The current building result.
* @type {*|null}
* @type {Object.<string,ProtoBuf.Builder.Message|Object>|null}
* @expose

@@ -77,2 +75,3 @@ */

* Defines a package on top of the current pointer position and places the pointer on it.
* @param {string} pkg
* @return {ProtoBuf.Builder} this

@@ -103,3 +102,3 @@ * @throws {Error} If the package name is invalid

* Tests if a definition is a valid message definition.
* @param {Object} def Definition
* @param {Object.<string,*>} def Definition
* @return {boolean} true if valid, else false

@@ -223,2 +222,3 @@ * @expose

* Creates ths specified protocol types at the current pointer position.
* @param {Array.<Object.<string,*>>} messages Messages to create
* @return {ProtoBuf.Builder} this

@@ -314,3 +314,3 @@ * @throws {Error} If a message definition is invalid

/**
* Resolves the namespace.
* Resolves all namespace objects.
* @throws {Error} If a type cannot be resolved

@@ -394,3 +394,3 @@ * @expose

* Returns a string representation of this object.
* @returns {string} String representation as of "Builder"
* @return {string} String representation as of "Builder"
* @expose

@@ -397,0 +397,0 @@ */

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

* Runs the parser.
* @return {{package: string, messages: Array.<Object>}}
* @return {{package: string|null, messages: Array.<object>, options: object<string,*>}}
* @throws {Error} If the source cannot be parsed

@@ -358,2 +358,10 @@ * @expose

};
/**
* Returns a string representation of this object.
* @returns {string} String representation as of "Parser"
*/
Parser.prototype.toString = function() {
return "Parser";
};

@@ -360,0 +368,0 @@ return Parser;

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

* Returns a string representation of this object.
* @returns {string} String representation as of "Tokenizer(index/length)"
* @return {string} String representation as of "Tokenizer(index/length)"
* @expose

@@ -144,0 +144,0 @@ */

@@ -93,7 +93,7 @@ // #ifdef UNDEFINED

* Builds this type.
* @throws {string} Exception if this type cannot be built directly
* @throws {Error} If this type cannot be built directly
* @expose
*/
T.prototype.build = function() {
throw(this.toString(true)+" cannot be built directly");
throw(new Error(this.toString(true)+" cannot be built directly"));
};

@@ -110,3 +110,3 @@

* @exports ProtoBuf.Reflect.Namespace
* @param {?Reflect.Reflect.Namespace} parent Parent
* @param {ProtoBuf.Reflect.Namespace|null} parent Parent
* @param {string} name

@@ -255,3 +255,3 @@ * @constructor

* @exports ProtoBuf.Reflect.Message
* @param {!ProtoBuf.Reflect.Message|!ProtoBuf.Reflect.Namespace} parent Parent message or namespace
* @param {ProtoBuf.Reflect.Namespace} parent Parent message or namespace
* @param {string} name Message name

@@ -278,3 +278,3 @@ * @constructor

* @see ProtoBuf.Builder.Message
* @return {Function} Message class
* @return {ProtoBuf.Reflect.Message} Message class
* @throws {Error} If the message cannot be built

@@ -348,3 +348,3 @@ * @expose

* @param {*} value Value to add
* @throws {string} If the value cannot be added
* @throws {Error} If the value cannot be added
* @expose

@@ -355,9 +355,9 @@ */

if (!field) {
throw(this+"#"+key+" is undefined");
throw(new Error(this+"#"+key+" is undefined"));
}
if (!(field instanceof Reflect.Message.Field)) {
throw(this+"#"+key+" is not a field: "+field.toString(true)); // May throw if it's an enum or embedded message
throw(new Error(this+"#"+key+" is not a field: "+field.toString(true))); // May throw if it's an enum or embedded message
}
if (!field.repeated) {
throw(this+"#"+key+" is not a repeated field");
throw(new Error(this+"#"+key+" is not a repeated field"));
}

@@ -374,3 +374,3 @@ if (this[field.name] === null) this[field.name] = [];

* @param {*} value Value to set
* @throws {string} If the value cannot be set
* @throws {Error} If the value cannot be set
* @expose

@@ -381,6 +381,6 @@ */

if (!field) {
throw(this+"#"+key+" is not a field: undefined");
throw(new Error(this+"#"+key+" is not a field: undefined"));
}
if (!(field instanceof Reflect.Message.Field)) {
throw(this+"#"+key+" is not a field: "+field.toString(true));
throw(new Error(this+"#"+key+" is not a field: "+field.toString(true)));
}

@@ -396,3 +396,3 @@ this[field.name] = field.verifyValue(value); // May throw

* @return {*} Value
* @throws {string} If there is no such field
* @throws {Error} If there is no such field
* @expose

@@ -403,6 +403,6 @@ */

if (!field || !(field instanceof Reflect.Message.Field)) {
throw(this+"#"+key+" is not a field: undefined");
throw(new Error(this+"#"+key+" is not a field: undefined"));
}
if (!(field instanceof Reflect.Message.Field)) {
throw(this+"#"+key+" is not a field: "+field.toString(true));
throw(new Error(this+"#"+key+" is not a field: "+field.toString(true)));
}

@@ -440,3 +440,3 @@ return this[field.name];

* @abstract
* @throws {string} If the value cannot be set
* @throws {Error} If the value cannot be set
*/

@@ -456,3 +456,3 @@ if (!T.hasChild("set"+Name)) {

* @abstract
* @throws {string} If the value cannot be set
* @throws {Error} If the value cannot be set
*/

@@ -475,3 +475,3 @@ if (!T.hasChild("set_"+name)) {

Message.prototype["get"+Name] = function() {
return this.get(field.name);
return this.get(field.name); // Does not throw, field exists
}

@@ -490,3 +490,3 @@ }

Message.prototype["get_"+name] = function() {
return this.get(field.name);
return this.get(field.name); // Does not throw, field exists
};

@@ -506,3 +506,3 @@ }

* @return {ByteBuffer} Encoded message
* @throws {string} If the message cannot be encoded
* @throws {Error} If the message cannot be encoded
* @expose

@@ -521,3 +521,3 @@ */

* @return {ArrayBuffer} Encoded message as ArrayBuffer
* @throws {string} If the message cannot be encoded
* @throws {Error} If the message cannot be encoded
* @expose

@@ -535,3 +535,3 @@ */

* @return {ProtoBuf.Builder.Message} Decoded message
* @throws {string} If the message cannot be decoded
* @throws {Error} If the message cannot be decoded
* @expose

@@ -629,3 +629,3 @@ */

* @param {string} name Field name
* @param {string} id Unique field id
* @param {number} id Unique field id
* @param {Object.<string.*>=} options Options

@@ -632,0 +632,0 @@ * @constructor

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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

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