protobufjs
Advanced tools
Comparing version 0.9.4 to 0.9.5
@@ -47,3 +47,3 @@ /* | ||
/** | ||
* @type {length} | ||
* @type {number} | ||
*/ | ||
@@ -94,2 +94,12 @@ ByteBuffer.prototype.length; | ||
/** | ||
* @return {ByteBuffer} | ||
*/ | ||
ByteBuffer.prototype.LE = function() {}; | ||
/** | ||
* @return {ByteBuffer} | ||
*/ | ||
ByteBuffer.prototype.BE = function() {}; | ||
/** | ||
* @param {number} capacity | ||
@@ -105,2 +115,3 @@ * @return {boolean} | ||
* @throws {Error} | ||
* @nosideeffects | ||
*/ | ||
@@ -114,2 +125,3 @@ ByteBuffer.prototype.slice = function(begin, end) {}; | ||
* @throws {Error} | ||
* @nosideeffects | ||
*/ | ||
@@ -136,2 +148,3 @@ ByteBuffer.prototype.sliceAndCompact = function(begin, end) {}; | ||
* @return {!ByteBuffer} | ||
* @nosideeffects | ||
*/ | ||
@@ -142,2 +155,3 @@ ByteBuffer.prototype.clone = function() {}; | ||
* @return {!ByteBuffer} | ||
* @nosideeffects | ||
*/ | ||
@@ -148,2 +162,3 @@ ByteBuffer.prototype.copy = function() {}; | ||
* @return {number} | ||
* @nosideeffects | ||
*/ | ||
@@ -154,2 +169,3 @@ ByteBuffer.prototype.remaining = function() {}; | ||
* @return {number} | ||
* @nosideeffects | ||
*/ | ||
@@ -388,12 +404,3 @@ ByteBuffer.prototype.capacity = function() {}; | ||
/** | ||
* @param {Int8Array|Uint8Array|Int16Array|Uint16Array|Int32Array|Uint32Array|Float32Array|Float64Array} fromType | ||
* @param {Int8Array|Uint8Array|Int16Array|Uint16Array|Int32Array|Uint32Array|Float32Array|Float64Array} toType | ||
* @param {number} value | ||
* @return {number} | ||
* @nosideeffects | ||
*/ | ||
ByteBuffer.cast = function(fromType, toType, value) {}; | ||
/** | ||
* @param {number} value | ||
* @param {number=} offset | ||
@@ -534,5 +541,6 @@ * @return {!ByteBuffer|number} | ||
/** | ||
* @param {function(string)=} out | ||
* @nosideeffects | ||
*/ | ||
ByteBuffer.prototype.printDebug = function() {}; | ||
ByteBuffer.prototype.printDebug = function(out) {}; | ||
@@ -572,2 +580,3 @@ /** | ||
* @return {!{char: number, length: number}} | ||
* @nosideeffects | ||
*/ | ||
@@ -574,0 +583,0 @@ ByteBuffer.decodeUTF8Char = function(src, offset) {}; |
{ | ||
"name": "protobufjs", | ||
"version": "0.9.4", | ||
"version": "0.9.5", | ||
"author": "Daniel Wirtz <dcode@dcode.io>", | ||
"description": "protobuf for JavaScript", | ||
"contributors": [ | ||
{ "name": "Daniel Wirtz", "email": "dcode@dcode.io" } | ||
], | ||
"main": "ProtoBuf.js", | ||
@@ -17,9 +14,13 @@ "bin": { | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/dcodeIO/ProtoBuf.js/issues" | ||
}, | ||
"keywords": ["net", "buffer", "protobuf", "serialization", "bytebuffer", "websocket", "webrtc"], | ||
"dependencies": { | ||
"bytebuffer": ">=1.1.0" | ||
"bytebuffer": ">=1.1.2" | ||
}, | ||
"devDependencies": { | ||
"nodeunit": ">=0.7", | ||
"preprocessor": ">=0.9.7" | ||
"preprocessor": ">=1.0.2", | ||
"closurecompiler": ">=1.1" | ||
}, | ||
@@ -36,5 +37,7 @@ "license": "Apache License, Version 2.0", | ||
"build": "node build.js", | ||
"compile": "java -jar closure-compiler/compiler.jar --create_source_map ProtoBuf.min.map --compilation_level SIMPLE_OPTIMIZATIONS --js ProtoBuf.js --js_output_file ProtoBuf.min.js && java -jar closure-compiler/compiler.jar --create_source_map ProtoBuf.noparse.min.map --compilation_level SIMPLE_OPTIMIZATIONS --js ProtoBuf.noparse.js --js_output_file ProtoBuf.noparse.min.js", | ||
"compile": "npm run-script compile-full && npm run-script compile-noparse", | ||
"compile-full": "ccjs ProtoBuf.js --create_source_map=ProtoBuf.min.map --compilation_level=SIMPLE_OPTIMIZATIONS > ProtoBuf.min.js", | ||
"compile-noparse": "ccjs ProtoBuf.noparse.js --create_source_map=ProtoBuf.noparse.min.map --compilation_level=SIMPLE_OPTIMIZATIONS > ProtoBuf.noparse.min.js", | ||
"jsdoc": "jsdoc -c jsdoc.json" | ||
} | ||
} |
@@ -6,50 +6,50 @@ /* | ||
*/ | ||
(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.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,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};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)};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); | ||
(function(p){function q(l){if(!l||!l.calculateUTF8String||!l.zigZagEncode32)if("undefined"!=typeof dcodeIO&&dcodeIO.ByteBuffer&&(l=dcodeIO.ByteBuffer),!l&&"function"==typeof require&&(l=require("ByteBuffer")),!l)throw Error("ProtoBuf.js requires ByteBuffer.js >=1.1.0: Get it at https://github.com/dcodeIO/ByteBuffer.js");var e={VERSION:"0.9.5",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.Util=function(){Object.create||(Object.create=function(d){function c(){}if(1<arguments.length)throw Error("Object.create implementation only accepts the first parameter.");c.prototype=d;return new c});var c={};c.IS_NODE=("undefined"==typeof window||!window.window)&&"function"==typeof require;c.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")}],c=null,h=0;h<d.length;h++){try{c=d[h]()}catch(a){continue}break}if(!c)throw Error("XMLHttpRequest is not supported");return c};c.fetch=function(d,n){n&&"function"!=typeof n&&(n=null);if(c.IS_NODE)if(n)require("fs").readFile(d,function(a,d){a?n(null):n(""+d)});else try{return require("fs").readFileSync(d)}catch(h){return null}else{var a=c.XHR();a.open("GET",d,n?!0:!1);a.setRequestHeader("User-Agent", | ||
"XMLHTTP/1.0");if(n)a.onreadystatechange=function(){4==a.readyState&&(200==a.status?n(a.responseText):n(null))},4!=a.readyState&&a.send(null);else return 200==a.status?a.responseText:null}};return c}();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={};e.DotProto.Tokenizer=function(c){var d=function(d){this.source=""+d;this.index=0;this.stack=[];this.readingString=!1};d.prototype._readString=function(){c.STRING.lastIndex=this.index-1;var d;if(null!==(d=c.STRING.exec(this.source)))return d=d[1],this.index=c.STRING.lastIndex,this.stack.push(c.STRINGCLOSE),d;throw Error("Illegal string value at index "+ | ||
this.index);};d.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 d;do{for(d=!1;c.WHITESPACE.test(this.source.charAt(this.index));)if(this.index++,this.index==this.source.length)return null;if(this.source.charAt(this.index)==c.COMMENT.charAt(0)){if(this.source.charAt(++this.index)!=c.COMMENT.charAt(1))throw Error("Invalid comment: /"+this.source.charAt(this.index)+ | ||
" ('"+c.COMMENT.charAt(1)+"' expected)");for(;"\n"!=this.source.charAt(this.index);)if(this.index++,this.index==this.source.length)return null;this.index++;d=!0}}while(d);if(this.index==this.source.length)return null;d=this.index;c.DELIM.lastIndex=0;if(c.DELIM.test(this.source.charAt(d)))d++;else for(d++;d<this.source.length&&!c.DELIM.test(this.source.charAt(d));)d++;d=this.source.substring(this.index,this.index=d);d==c.STRINGOPEN&&(this.readingString=!0);return d};d.prototype.toString=function(){return"Tokenizer("+ | ||
this.index+"/"+this.source.length+")"};return d}(e.Lang);e.DotProto.Parser=function(c,d,e){c=function(d){this.tn=new e(d)};c.prototype.parse=function(){var d=[],a=null,b={name:"[ROOT]",options:{}},c,g=!0;do{c=this.tn.next();if(null==c)break;if("package"==c){if(!g)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(c)}else if("message"==c)c=this._parseMessage(null,c), | ||
d.push(c),g=!1;else if("option"==c){if(!g)throw Error("Illegal option definition: Must be declared before the first message");this._parseOption(b,c)}else throw Error("Illegal top level declaration: "+c);}while(1);return{"package":a,options:b.options,messages:d}};c.prototype._parsePackage=function(c){c=this.tn.next();if(!d.TYPEDEF.test(c))throw Error("Illegal package name: "+c);var a=c;c=this.tn.next();if(c!=d.END)throw Error("Illegal end of package definition: "+c+" ('"+d.END+"' expected)");return a}; | ||
c.prototype._parseOption=function(c,a){a=this.tn.next();if(!d.NAME.test(a))throw Error("Illegal option name in message "+c.name+": "+a);var b=a;a=this.tn.next();if(a!=d.EQUAL)throw Error("Illegal option operator in message "+c.name+", option "+b+": "+a+" ('"+d.EQUAL+"' expected)");var f;a=this.tn.next();if(a==d.STRINGOPEN){if(f=this.tn.next(),a=this.tn.next(),a!=d.STRINGCLOSE)throw Error("Illegal end of option value in message "+c.name+", option "+b+": "+a+" ('"+d.STRINGCLOSE+"' expected)");}else if(d.NUMBER.test(a))f= | ||
parseInt(a);else if(d.NAME.test(a))f=a;else throw Error("Illegal option value in message "+c.name+", option "+b+": "+a);a=this.tn.next();if(a!=d.END)throw Error("Illegal end of option in message "+c.name+", option "+b+": "+a+" ('"+d.END+"' expected)");c.options[b]=f};c.prototype._parseMessage=function(c,a){var b={};a=this.tn.next();if(!d.NAME.test(a))throw Error("Illegal message name"+(c?" in message "+c.name:"")+": "+a);b.name=a;a=this.tn.next();if(a!=d.OPEN)throw Error("Illegal OPEN after message "+ | ||
b.name+": "+a);b.fields=[];b.enums=[];b.messages=[];b.options={};do if(a=this.tn.next(),"}"==a)break;else if(d.RULE.test(a))this._parseMessageField(b,a);else if("enum"==a)this._parseEnum(b,a);else if("message"==a)this._parseMessage(b,a);else if("option"==a)this._parseOption(b,a);else throw Error("Illegal token in message "+b.name+": "+a);while(1);null!=c&&c.messages.push(b);return b};c.prototype._parseMessageField=function(c,a){var b={};b.rule=a;a=this.tn.next();if(!d.TYPE.test(a)&&!d.TYPEREF.test(a))throw Error("Illegal field type in message "+ | ||
c.name+": "+a);b.type=a;a=this.tn.next();if(!d.NAME.test(a))throw Error("Illegal field name in message "+c.name+": "+a);b.name=a;a=this.tn.next();if(a!=d.EQUAL)throw Error("Illegal field number operator in message "+c.name+"#"+b.name+": "+a+" ('"+d.EQUAL+"' expected)");a=this.tn.next();if(!d.ID.test(a))throw Error("Illegal field number in message "+c.name+"#"+b.name+": "+a);b.id=parseInt(a,10);b.options={};a=this.tn.next();a==d.OPTOPEN&&(this._parseMessageFieldOptions(c,b,a),a=this.tn.next());if(a!= | ||
d.END)throw Error("Illegal field delimiter in message "+c.name+"#"+b.name+": "+a+" ('"+d.END+"' expected)");c.fields.push(b)};c.prototype._parseMessageFieldOptions=function(c,a,b){var f=!0;do{b=this.tn.next();if(b==d.OPTCLOSE)break;else if(b==d.OPTEND){if(f)throw Error("Illegal start of message field options in message "+c.name+"#"+a.name+": "+b);b=this.tn.next()}if(!d.NAME.test(b))throw Error("Illegal field option in message "+c.name+"#"+a.name+": "+b);this._parseMessageFieldOption(c,a,b);f=!1}while(1)}; | ||
c.prototype._parseMessageFieldOption=function(c,a,b){var f=b;b=this.tn.next();if(b!=d.EQUAL)throw Error("Illegal field option operation in message "+c.name+"#"+a.name+": "+b+" ('=' expected)");var g;b=this.tn.next();if(b==d.STRINGOPEN){if(g=this.tn.next(),b=this.tn.next(),b!=d.STRINGCLOSE)throw Error("Illegal end of field value in message "+c.name+"#"+a.name+", option "+f+": "+b+" ('"+d.STRINGCLOSE+"' expected)");}else if(d.NUMBER.test(b))g=parseInt(b,10);else if(d.NAME.test(b))g=b;else throw Error("Illegal field option value in message "+ | ||
c.name+"#"+a.name+", option "+f+": "+b);a.options[f]=g};c.prototype._parseEnum=function(c,a){var b={};a=this.tn.next();if(!d.NAME.test(a))throw Error("Illegal enum name in message "+c.name+": "+a);b.name=a;a=this.tn.next();if(a!=d.OPEN)throw Error("Illegal OPEN after enum "+b.name+": "+a);b.values=[];do{a=this.tn.next();if(a==d.CLOSE)break;else if(!d.NAME.test(a))throw Error("Illegal enum value name in enum "+b.name+": "+a);this._parseEnumValue(b,a)}while(1);c.enums.push(b)};c.prototype._parseEnumValue= | ||
function(c,a){var b={};b.name=a;a=this.tn.next();if(a!=d.EQUAL)throw Error("Illegal enum value operator in enum "+c.name+": "+a+" ('"+d.EQUAL+"' expected)");a=this.tn.next();if(!d.ID.test(a))throw Error("Illegal enum value value in enum "+c.name+": "+a);b.id=parseInt(a,10);c.values.push(b);a=this.tn.next();if(a!=d.END)throw Error("Illegal enum value delimiter in enum "+c.name+": "+a+" ('"+d.END+"' expected)");};c.prototype.toString=function(){return"Parser"};return c}(e,e.Lang,e.DotProto.Tokenizer); | ||
e.Reflect=function(c){var d={},e=function(a,c){this.parent=a;this.name=c;this.resolvedType=null};e.prototype.toString=function(c){var m=this.name,b=this;do{b=b.parent;if(null==b)break;m=b.name+"."+m}while(1);c&&(this instanceof d.Message?m="Message "+m:this instanceof a.Field?m="Message.Field "+m:this instanceof f?m="Enum "+m:this instanceof f.Value?m="Enum.Value "+m:this instanceof h&&(m="Namespace "+m));return m};e.prototype.build=function(){throw Error(this.toString(!0)+" cannot be built directly"); | ||
};d.T=e;var h=function(a,c){e.call(this,a,c);this.children=[]};h.prototype=Object.create(e.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("."),b=this,f=0;if(""==c[f]){for(;null!=b.parent;)b=b.parent;f++}do{do{b=b.getChild(c[f]);if(!b||!(b instanceof d.T)){b=null;break}f++}while(f<c.length);if(null!=b)break;if(null!==this.parent)return this.parent.resolve(a)}while(null!=b);return b};h.prototype.build=function(){for(var a={},b=this.getChildren(),c,d=0;d<b.length;d++)c=b[d],c instanceof h&&(a[c.name]=c.build());return a};d.Namespace=h;var a=function(a,c){h.call(this,a,c);this.built=null};a.prototype=Object.create(h.prototype); | ||
a.prototype.build=function(){for(var c=function(a,b){var c=b.getChildren(a.Message.Field),d=eval("(function "+b.name+"() { this.__construct.apply(this, arguments); })");d.prototype.__construct=function(a){var b,d;for(b=0;b<c.length;b++)d=c[b],this[d.name]=d.repeated?[]:null;for(b=0;b<c.length;b++)if(d=c[b],"undefined"!=typeof d.options["default"])try{this.set(d.name,d.options["default"])}catch(g){throw Error("[INTERNAL ERROR] "+g);}if("object"==typeof a&&"function"!=typeof a.encode){d=Object.keys(a); | ||
for(b=0;b<d.length;b++)this.set(d[b],a[d[b]])}else for(b=0;b<arguments.length;b++)b<c.length&&this.set(c[b].name,arguments[b])};d.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))};d.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)};d.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 g=0;g<c.length;g++)(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),g=a.name.replace(/([A-Z])/g,function(a){return"_"+a});b.hasChild("set"+c)||(d.prototype["set"+c]=function(b){this.set(a.name,b)});b.hasChild("set_"+g)||(d.prototype["set_"+g]=function(b){this.set(a.name,b)});b.hasChild("get"+c)||(d.prototype["get"+c]=function(){return this.get(a.name)});b.hasChild("get_"+g)||(d.prototype["get_"+g]=function(){return this.get(a.name)})})(c[g]);d.prototype.encode=function(a){a= | ||
a||new l;b.encode(this,a);return a.flip()};d.prototype.toArrayBuffer=function(){return this.encode().toArrayBuffer()};d.decode=function(a){a=a?a instanceof l?a:l.wrap(a):new l;return b.decode(a)};d.prototype.toString=function(){return b.toString()};return d}(d,this),b=this.getChildren(),k=0;k<b.length;k++)if(b[k]instanceof f)c[b[k].name]=b[k].build();else if(b[k]instanceof a)c[b[k].name]=b[k].build();else if(!(b[k]instanceof a.Field))throw Error("Illegal reflect child of "+this.toString(!0)+": "+ | ||
b[k].toString(!0));return this.built=c};a.prototype.encode=function(b,c){for(var d=this.getChildren(a.Field),f=0;f<d.length;f++)d[f].encode(b.get(d[f].name),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 f=a.readVarint32(),e=f&7,f=f>>3,h=this.getChild(f);if(!h)throw Error("Illegal field id in "+this.toString(!0)+"#decode: "+f);d.set(h.name,h.decode(e,a))}return d};d.Message=a;var b=function(a,b,c,d,f,h){e.call(this,a,d); | ||
this.required="required"==b;this.repeated="repeated"==b;this.type=c;this.id=f;this.options=h||{}};b.prototype=Object.create(e.prototype);b.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,e;if(this.repeated&&!b){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!=c.TYPES.message&&a instanceof Object)throw Error("Illegal value for "+this.toString(!0)+": "+a+" (is object)");if(this.type==c.TYPES.int32||this.type==c.TYPES.sint32||this.type==c.TYPES.fixed32||this.type==c.TYPES.sfixed32)return parseInt(a,10);if(this.type==c.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== | ||
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 l.wrap(a);if(this.type==c.TYPES["enum"]){e=this.resolvedType.getChildren(f.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==c.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+")");};b.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)try{if(this.repeated){var d;if(this.options.packed){b.writeVarint32(this.id<< | ||
3|c.WIRE_TYPES.LDELIM);for(d=0;d<a.length;d++)this.encodeValue(a[d],b)}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(f){throw Error("Illegal value for "+this.toString(!0)+": "+a+" ("+f+")");}};b.prototype.decode=function(a,b){var d,f;if(a!=this.type.wireType)throw Error("Illegal wire type for field "+this.toString(!0)+": "+a+" ("+this.type.wireType+" expected)");if(this.type== | ||
c.TYPES.int32)return b.readVarint32();if(this.type==c.TYPES.uint32)return d=b.readVarint32(),UINT32[0]=d,UINT32[0];if(this.type==c.TYPES.sint32)return b.readZigZagVarint32();if(this.type==c.TYPES.bool)return!!b.readVarint32();if(this.type==c.TYPES["enum"])return b.readVarint32();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 f=b.readVarint32(),d=b.clone(),d.length=d.offset+f,d;if(this.type==c.TYPES.message)return f= | ||
b.readVarint32(),this.resolvedType.decode(b,f);if(a==c.WIRE_TYPES.LDELIM&&this.repeated){f=b.readVarint32();for(f=b.offset+f;b.offset<f;)this.decode(this.type.wireType,b);return[]}if(this.type==c.TYPES.fixed32)return b.readInt32();if(this.type==c.TYPES.sfixed32)return l.zigZagDecode32(b.readUint32());if(this.type==c.TYPES["float"])return b.readFloat();throw Error("[INTERNAL ERROR] Illegal wire type for "+this.toString(!0)+": "+a);};b.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.writeVarint32(l.zigZagEncode32(a));else if(this.type==c.TYPES.fixed32)b.writeUint32(a);else if(this.type==c.TYPES.sfixed32)b.writeUint32(l.zigZagEncode32(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 f=b.offset-d-1,e=l.calculateVarint32(f);if(1<e){var h=b.clone();h.offset-=f;b.append(h.flip(),d-1+e)}b.writeVarint32(f,d)}else throw Error("[INTERNAL ERROR] Illegal value to encode in "+this.toString(!0)+": "+a+" (unknown type)");};d.Message.Field=b;var f=function(a,b){h.call(this,a, | ||
b);this.built=null};f.prototype=Object.create(h.prototype);f.prototype.build=function(){for(var a={},b=this.getChildren(f.Value),c=0;c<b.length;c++)a[b[c].name]=b[c].id;return this.built=a};d.Enum=f;b=function(a,b,c){e.call(this,a,b);this.id=c};b.prototype=Object.create(e.prototype);d.Enum.Value=b;return d}(e);e.Builder=function(c,d,e){var h=function(){this.ptr=this.ns=new e.Namespace(null,"");this.resolved=!1;this.result=null};h.prototype.reset=function(){this.ptr=this.ns};h.prototype.define=function(a){if("string"!= | ||
typeof a||!d.TYPEDEF.test(a))throw Error("Illegal package name: "+a);a=a.split(".");var b;for(b=0;b<a.length;b++)if(!d.NAME.test(a[b]))throw Error("Illegal package name: "+a[b]);for(b=0;b<a.length;b++)this.ptr.hasChild(a[b])||this.ptr.addChild(new e.Namespace(this.ptr,a[b])),this.ptr=this.ptr.getChild(a[b]);return this};h.isValidMessage=function(a){if("string"!=typeof a.name||!d.NAME.test(a.name)||"undefined"!=typeof a.values)return!1;var b;if("undefined"!=typeof a.fields){if(!(a.fields instanceof | ||
Array))return!1;var c=[],e;for(b=0;b<a.fields.length;b++){if(!h.isValidMessageField(a.fields[b]))return!1;e=parseInt(a.id,10);if(0<=c.indexOf(e))return!1;c.push(e)}}if("undefined"!=typeof a.enums){if(!(a.enums instanceof Array))return!1;for(b=0;b<a.enums.length;b++)if(!h.isValidEnum(a.enums[b]))return!1}if("undefined"!=typeof a.messages){if(!(a.messages instanceof Array))return!1;for(b=0;b<a.messages.length;b++)if(!h.isValidMessage(a.messages[b]))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||!d.RULE.test(a.rule)||!d.NAME.test(a.name)||!d.TYPEREF.test(a.type)||!d.ID.test(""+a.id))return!1;if("undefined"!=typeof a.options){if("object"!=typeof a.options)return!1;for(var b=Object.keys(a.options),c=0;c<b.length;c++)if(!d.NAME.test(b[c])||!d.ID.test(""+a.options[b[c]])&&!d.TYPEREF.test(a.options[b[c]]))return!1}return!0};h.isValidEnum=function(a){if("string"!=typeof a.name||!d.NAME.test(a.name)||"undefined"== | ||
typeof a.values||!(a.values instanceof Array)||0==a.values.length)return!1;for(var b=0;b<a.values.length;b++)if("object"!=typeof a.values[b]||"string"!=typeof a.values[b].name||"undefined"==typeof a.values[b].id||!d.NAME.test(a.values[b].name)||!d.ID.test(""+a.values[b].id))return!1;return!0};h.prototype.create=function(a){if(a&&(a instanceof Array||(a=[a]),0!=a.length)){var b=[],c,g,m,k,l;for(b.push(a);0<b.length;){a=b.pop();if(a instanceof Array)for(;0<a.length;)if(c=a.shift(),h.isValidMessage(c)){g= | ||
new e.Message(this.ptr,c.name);if(c.fields&&0<c.fields.length)for(k=0;k<c.fields.length;k++){if(!h.isValidMessageField(c.fields[k]))throw Error("Not a valid message field definition in message "+g.name+": "+JSON.stringify(c.fields[k]));if(c.fields[k].options){m=Object.keys(c.fields[k].options);for(l=0;l<m.length;l++){if(!d.NAME.test(m[l]))throw Error("Illegal field option name in message "+g.name+"#"+c.fields[k].name+": "+m[l]);if(!d.ID.test(""+c.fields[k].options[m[l]])&&!d.TYPEREF.test(c.fields[k].options[m[l]]))throw Error("Illegal field option value in message "+ | ||
g.name+"#"+c.fields[k].name+"#"+m[l]+": "+c.fields[k].options[m[l]]);}}g.addChild(new e.Message.Field(g,c.fields[k].rule,c.fields[k].type,c.fields[k].name,c.fields[k].id,c.fields[k].options))}m=[];if("undefined"!=typeof c.enums&&0<c.enums.length)for(k=0;k<c.enums.length;k++)m.push(c.enums[k]);if(c.messages&&0<c.messages.length)for(k=0;k<c.messages.length;k++)m.push(c.messages[k]);this.ptr.addChild(g);0<m.length&&(b.push(a),a=m,this.ptr=g)}else if(h.isValidEnum(c)){g=new e.Enum(this.ptr,c.name);for(k= | ||
0;k<c.values.length;k++)g.addChild(new e.Enum.Value(g,c.values[k].name,c.values[k].id));this.ptr.addChild(g)}else throw Error("Not a valid message or enum definition: "+JSON.stringify(c));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.resolveAll=function(){if(!(null==this.ptr||"object"==typeof this.ptr.type)){if(this.ptr instanceof e.Namespace)for(var a=this.ptr.getChildren(),b=0;b<a.length;b++)this.ptr= | ||
a[b],this.resolveAll();else if(this.ptr instanceof e.Message.Field)if(d.TYPE.test(this.ptr.type))this.ptr.type=c.TYPES[this.ptr.type];else{if(!d.TYPEREF.test(this.ptr.type))throw Error("Illegal type reference in "+this.ptr.toString(!0)+": "+this.ptr.type);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 e.Enum)this.ptr.type=c.TYPES["enum"];else if(a instanceof e.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}(e,e.Lang,e.Reflect);e.protoFromString=function(c){c=(new e.DotProto.Parser(c+"")).parse();var d=new e.Builder;null!==c["package"]&&d.define(c["package"]);d.create(c.messages);d.reset();d.resolveAll();d.build();return d};e.protoFromFile=function(c,d){d&&"function"!=typeof d&&(d=null);if(d)e.Util.fetch(c,function(c){d(e.protoFromString(c))});else{var l=e.Util.fetch(c);return null!==l?e.protoFromString(l): | ||
null}};e.newBuilder=function(c){var d=new e.Builder;"undefined"!=typeof c&&d.define(c);return d};return e}"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,35 +6,37 @@ /* | ||
*/ | ||
(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.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 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 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 "+ | ||
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(), | ||
d=c.clone(),d.length=d.offset+e,d;if(this.type==a.TYPES.message)return e=c.readVarint32(),this.resolvedType.decode(c,e);if(b==a.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==a.TYPES.fixed32)return c.readInt32();if(this.type==a.TYPES.sfixed32)return k.zigZagDecode32(c.readUint32());if(this.type==a.TYPES["float"])return c.readFloat();throw Error("[INTERNAL ERROR] Illegal wire type for "+this.toString(!0)+": "+ | ||
b);};g.prototype.encodeValue=function(b,c){if(null!==b)if(this.type==a.TYPES.int32||this.type==a.TYPES.uint32)c.writeVarint32(b);else if(this.type==a.TYPES.sint32)c.writeVarint32(k.zigZagEncode32(b));else if(this.type==a.TYPES.fixed32)c.writeUint32(b);else if(this.type==a.TYPES.sfixed32)c.writeUint32(k.zigZagEncode32(b));else if(this.type==a.TYPES.bool)c.writeVarint32(b?1:0);else if(this.type==a.TYPES["enum"])c.writeVarint32(b);else if(this.type==a.TYPES["float"])c.writeFloat32(b);else if(this.type== | ||
a.TYPES["double"])c.writeFloat64(b);else if(this.type==a.TYPES.string)c.writeVString(b);else if(this.type==a.TYPES.bytes)b.offset>b.length&&(c=c.clone().flip()),c.writeVarint32(b.remaining()),c.append(b);else if(this.type==a.TYPES.message){var d=c.offset;c.writeUint8(0);this.resolvedType.encode(b,c);var e=c.offset-d-1,f=k.calculateVarint32(e);if(1<f){var g=c.clone();g.offset-=e;c.append(g.flip(),d-1+f)}c.writeVarint32(e,d)}else throw Error("[INTERNAL ERROR] Illegal value to encode in "+this.toString(!0)+ | ||
": "+b+" (unknown type)");};b.Message.Field=g;var j=function(a,b){f.call(this,a,b);this.built=null};j.prototype=Object.create(f.prototype);j.prototype.build=function(){for(var a={},b=this.getChildren(j.Value),d=0;d<b.length;d++)a[b[d].name]=b[d].id;return this.built=a};b.Enum=j;g=function(a,b,d){e.call(this,a,b);this.id=d};g.prototype=Object.create(e.prototype);b.Enum.Value=g;return b}(f);var j=f.Lang,n=f.Reflect,m=function(){this.ptr=this.ns=new n.Namespace(null,"");this.resolved=!1;this.result= | ||
null};m.prototype.reset=function(){this.ptr=this.ns};m.prototype.define=function(a){if("string"!=typeof a||!j.TYPEDEF.test(a))throw Error("Illegal package name: "+a);a=a.split(".");var b;for(b=0;b<a.length;b++)if(!j.NAME.test(a[b]))throw Error("Illegal package name: "+a[b]);for(b=0;b<a.length;b++)this.ptr.hasChild(a[b])||this.ptr.addChild(new n.Namespace(this.ptr,a[b])),this.ptr=this.ptr.getChild(a[b]);return this};m.isValidMessage=function(a){if("string"!=typeof a.name||!j.NAME.test(a.name)||"undefined"!= | ||
typeof a.values)return!1;var b;if("undefined"!=typeof a.fields){if(!(a.fields instanceof Array))return!1;var e=[],f;for(b=0;b<a.fields.length;b++){if(!m.isValidMessageField(a.fields[b]))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(b=0;b<a.enums.length;b++)if(!m.isValidEnum(a.enums[b]))return!1}if("undefined"!=typeof a.messages){if(!(a.messages instanceof Array))return!1;for(b=0;b<a.messages.length;b++)if(!m.isValidMessage(a.messages[b]))return!1}return!0}; | ||
m.isValidMessageField=function(a){if("string"!=typeof a.rule||"string"!=typeof a.name||"string"!=typeof a.type||"undefined"==typeof a.id||!j.RULE.test(a.rule)||!j.NAME.test(a.name)||!j.TYPEREF.test(a.type)||!j.ID.test(""+a.id))return!1;if("undefined"!=typeof a.options){if("object"!=typeof a.options)return!1;for(var b=Object.keys(a.options),e=0;e<b.length;e++)if(!j.NAME.test(b[e])||!j.ID.test(""+a.options[b[e]])&&!j.TYPEREF.test(a.options[b[e]]))return!1}return!0};m.isValidEnum=function(a){if("string"!= | ||
typeof a.name||!j.NAME.test(a.name)||"undefined"==typeof a.values||!(a.values instanceof Array)||0==a.values.length)return!1;for(var b=0;b<a.values.length;b++)if("object"!=typeof a.values[b]||"string"!=typeof a.values[b].name||"undefined"==typeof a.values[b].id||!j.NAME.test(a.values[b].name)||!j.ID.test(""+a.values[b].id))return!1;return!0};m.prototype.create=function(a){if(a&&(a instanceof Array||(a=[a]),0!=a.length)){var b=[],e,f,l,g,k;for(b.push(a);0<b.length;){a=b.pop();if(a instanceof Array)for(;0< | ||
a.length;)if(e=a.shift(),m.isValidMessage(e)){f=new n.Message(this.ptr,e.name);if(e.fields&&0<e.fields.length)for(g=0;g<e.fields.length;g++){if(!m.isValidMessageField(e.fields[g]))throw Error("Not a valid message field definition in message "+f.name+": "+JSON.stringify(e.fields[g]));if(e.fields[g].options){l=Object.keys(e.fields[g].options);for(k=0;k<l.length;k++){if(!j.NAME.test(l[k]))throw Error("Illegal field option name in message "+f.name+"#"+e.fields[g].name+": "+l[k]);if(!j.ID.test(""+e.fields[g].options[l[k]])&& | ||
!j.TYPEREF.test(e.fields[g].options[l[k]]))throw Error("Illegal field option value in message "+f.name+"#"+e.fields[g].name+"#"+l[k]+": "+e.fields[g].options[l[k]]);}}f.addChild(new n.Message.Field(f,e.fields[g].rule,e.fields[g].type,e.fields[g].name,e.fields[g].id,e.fields[g].options))}l=[];if("undefined"!=typeof e.enums&&0<e.enums.length)for(g=0;g<e.enums.length;g++)l.push(e.enums[g]);if(e.messages&&0<e.messages.length)for(g=0;g<e.messages.length;g++)l.push(e.messages[g]);this.ptr.addChild(f);0< | ||
l.length&&(b.push(a),a=l,this.ptr=f)}else if(m.isValidEnum(e)){f=new n.Enum(this.ptr,e.name);for(g=0;g<e.values.length;g++)f.addChild(new n.Enum.Value(f,e.values[g].name,e.values[g].id));this.ptr.addChild(f)}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}};m.prototype.resolveAll=function(){if(!(null==this.ptr||"object"==typeof this.ptr.type)){if(this.ptr instanceof | ||
n.Namespace)for(var a=this.ptr.getChildren(),b=0;b<a.length;b++)this.ptr=a[b],this.resolveAll();else if(this.ptr instanceof n.Message.Field)if(j.TYPE.test(this.ptr.type))this.ptr.type=f.TYPES[this.ptr.type];else{if(!j.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 | ||
n.Enum)this.ptr.type=f.TYPES["enum"];else if(a instanceof n.Message)this.ptr.type=f.TYPES.message;else throw Error("Illegal type reference in "+this.ptr.toString(!0)+": "+this.ptr.type);}else if(!(this.ptr instanceof f.Reflect.Enum.Value))throw Error("Illegal object type in namespace: "+typeof this.ptr+":"+this.ptr);this.reset()}};m.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,e=0;e<a.length;e++)if(b[a[e]])b=b[a[e]];else{b=null;break}return b}return this.result};m.prototype.toString=function(){return"Builder"};f.Builder=m;f.protoFromString=function(){throw Error("This build of ProtoBuf.js does not include DotProto support. See: https://github.com/dcodeIO/ProtoBuf.js");};f.protoFromFile=function(){throw Error("This build of ProtoBuf.js does not include DotProto support. See: https://github.com/dcodeIO/ProtoBuf.js");};f.newBuilder=function(a){var b= | ||
new f.Builder;"undefined"!=typeof a&&b.define(a);return b};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); | ||
(function(p){function q(n){if(!n||!n.calculateUTF8String||!n.zigZagEncode32)if("undefined"!=typeof dcodeIO&&dcodeIO.ByteBuffer&&(n=dcodeIO.ByteBuffer),!n&&"function"==typeof require&&(n=require("ByteBuffer")),!n)throw Error("ProtoBuf.js requires ByteBuffer.js >=1.1.0: Get it at https://github.com/dcodeIO/ByteBuffer.js");var h={VERSION:"0.9.5",WIRE_TYPES:{}};h.WIRE_TYPES.VARINT=0;h.WIRE_TYPES.BITS64=1;h.WIRE_TYPES.LDELIM=2;h.WIRE_TYPES.STARTGROUP=3;h.WIRE_TYPES.ENDGROUP=4;h.WIRE_TYPES.BITS32=5;h.TYPES= | ||
{int32:{name:"int32",wireType:h.WIRE_TYPES.VARINT},uint32:{name:"uint32",wireType:h.WIRE_TYPES.VARINT},sint32:{name:"sint32",wireType:h.WIRE_TYPES.VARINT},bool:{name:"bool",wireType:h.WIRE_TYPES.VARINT},"double":{name:"double",wireType:h.WIRE_TYPES.BITS64},string:{name:"string",wireType:h.WIRE_TYPES.LDELIM},bytes:{name:"bytes",wireType:h.WIRE_TYPES.LDELIM},fixed32:{name:"fixed32",wireType:h.WIRE_TYPES.BITS32},sfixed32:{name:"sfixed32",wireType:h.WIRE_TYPES.BITS32},"float":{name:"float",wireType:h.WIRE_TYPES.BITS32}, | ||
"enum":{name:"enum",wireType:h.WIRE_TYPES.VARINT},message:{name:"message",wireType:h.WIRE_TYPES.LDELIM}};h.Util=function(){Object.create||(Object.create=function(c){function l(){}if(1<arguments.length)throw Error("Object.create implementation only accepts the first parameter.");l.prototype=c;return new l});var c={};c.IS_NODE=("undefined"==typeof window||!window.window)&&"function"==typeof require;c.XHR=function(){for(var c=[function(){return new XMLHttpRequest},function(){return new ActiveXObject("Msxml2.XMLHTTP")}, | ||
function(){return new ActiveXObject("Msxml3.XMLHTTP")},function(){return new ActiveXObject("Microsoft.XMLHTTP")}],l=null,m=0;m<c.length;m++){try{l=c[m]()}catch(a){continue}break}if(!l)throw Error("XMLHttpRequest is not supported");return l};c.fetch=function(g,l){l&&"function"!=typeof l&&(l=null);if(c.IS_NODE)if(l)require("fs").readFile(g,function(a,c){a?l(null):l(""+c)});else try{return require("fs").readFileSync(g)}catch(m){return null}else{var a=c.XHR();a.open("GET",g,l?!0:!1);a.setRequestHeader("User-Agent", | ||
"XMLHTTP/1.0");if(l)a.onreadystatechange=function(){4==a.readyState&&(200==a.status?l(a.responseText):l(null))},4!=a.readyState&&a.send(null);else return 200==a.status?a.responseText:null}};return c}();h.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:'"'};h.Reflect=function(c){var g={},l=function(d,b){this.parent=d;this.name=b;this.resolvedType=null};l.prototype.toString=function(d){var b=this.name,e=this;do{e=e.parent;if(null==e)break;b=e.name+"."+b}while(1);d&&(this instanceof g.Message?b="Message "+b:this instanceof a.Field?b="Message.Field "+b:this instanceof f?b="Enum "+ | ||
b:this instanceof f.Value?b="Enum.Value "+b:this instanceof m&&(b="Namespace "+b));return b};l.prototype.build=function(){throw Error(this.toString(!0)+" cannot be built directly");};g.T=l;var m=function(d,b){l.call(this,d,b);this.children=[]};m.prototype=Object.create(l.prototype);m.prototype.getChildren=function(d){d=d||null;if(null==d)return this.children.slice();for(var b=[],e=0;e<this.children.length;e++)this.children[e]instanceof d&&b.push(this.children[e]);return b};m.prototype.addChild=function(d){if(this.hasChild(d.name))throw Error("Duplicate name in namespace "+ | ||
this.toString(!0)+": "+d.name);this.children.push(d)};m.prototype.hasChild=function(d){var b;if("number"==typeof d)for(b=0;b<this.children.length;b++){if(this.children[b]instanceof a.Field&&this.children[b].id==d)return!0}else for(b=0;b<this.children.length;b++)if(this.children[b].name==d)return!0;return!1};m.prototype.getChild=function(d){var b;if("number"==typeof d)for(b=0;b<this.children.length;b++){if(this.children[b]instanceof a.Field&&this.children[b].id==d)return this.children[b]}else for(b= | ||
0;b<this.children.length;b++)if(this.children[b].name==d)return this.children[b];return null};m.prototype.resolve=function(d){var b=d.split("."),e=this,a=0;if(""==b[a]){for(;null!=e.parent;)e=e.parent;a++}do{do{e=e.getChild(b[a]);if(!e||!(e instanceof g.T)){e=null;break}a++}while(a<b.length);if(null!=e)break;if(null!==this.parent)return this.parent.resolve(d)}while(null!=e);return e};m.prototype.build=function(){for(var d={},b=this.getChildren(),a,c=0;c<b.length;c++)a=b[c],a instanceof m&&(d[a.name]= | ||
a.build());return d};g.Namespace=m;var a=function(d,b){m.call(this,d,b);this.built=null};a.prototype=Object.create(m.prototype);a.prototype.build=function(){for(var d=function(b,d){var a=d.getChildren(b.Message.Field),e=eval("(function "+d.name+"() { this.__construct.apply(this, arguments); })");e.prototype.__construct=function(b){var d,e;for(d=0;d<a.length;d++)e=a[d],this[e.name]=e.repeated?[]:null;for(d=0;d<a.length;d++)if(e=a[d],"undefined"!=typeof e.options["default"])try{this.set(e.name,e.options["default"])}catch(c){throw Error("[INTERNAL ERROR] "+ | ||
c);}if("object"==typeof b&&"function"!=typeof b.encode){e=Object.keys(b);for(d=0;d<e.length;d++)this.set(e[d],b[e[d]])}else for(d=0;d<arguments.length;d++)d<a.length&&this.set(a[d].name,arguments[d])};e.prototype.add=function(e,a){var c=d.getChild(e);if(!c)throw Error(this+"#"+e+" is undefined");if(!(c instanceof b.Message.Field))throw Error(this+"#"+e+" is not a field: "+c.toString(!0));if(!c.repeated)throw Error(this+"#"+e+" is not a repeated field");null===this[c.name]&&(this[c.name]=[]);this[c.name].push(c.verifyValue(a))}; | ||
e.prototype.set=function(e,a){var c=d.getChild(e);if(!c)throw Error(this+"#"+e+" is not a field: undefined");if(!(c instanceof b.Message.Field))throw Error(this+"#"+e+" is not a field: "+c.toString(!0));this[c.name]=c.verifyValue(a)};e.prototype.get=function(e){var a=d.getChild(e);if(!a||!(a instanceof b.Message.Field))throw Error(this+"#"+e+" is not a field: undefined");if(!(a instanceof b.Message.Field))throw Error(this+"#"+e+" is not a field: "+a.toString(!0));return this[a.name]};for(var c=0;c< | ||
a.length;c++)(function(b){var a=b.name.replace(/(_[a-zA-Z])/g,function(d){return d.toUpperCase().replace("_","")}),a=a.substring(0,1).toUpperCase()+a.substring(1),c=b.name.replace(/([A-Z])/g,function(d){return"_"+d});d.hasChild("set"+a)||(e.prototype["set"+a]=function(d){this.set(b.name,d)});d.hasChild("set_"+c)||(e.prototype["set_"+c]=function(d){this.set(b.name,d)});d.hasChild("get"+a)||(e.prototype["get"+a]=function(){return this.get(b.name)});d.hasChild("get_"+c)||(e.prototype["get_"+c]=function(){return this.get(b.name)})})(a[c]); | ||
e.prototype.encode=function(b){b=b||new n;d.encode(this,b);return b.flip()};e.prototype.toArrayBuffer=function(){return this.encode().toArrayBuffer()};e.decode=function(b){b=b?b instanceof n?b:n.wrap(b):new n;return d.decode(b)};e.prototype.toString=function(){return d.toString()};return e}(g,this),b=this.getChildren(),e=0;e<b.length;e++)if(b[e]instanceof f)d[b[e].name]=b[e].build();else if(b[e]instanceof a)d[b[e].name]=b[e].build();else if(!(b[e]instanceof a.Field))throw Error("Illegal reflect child of "+ | ||
this.toString(!0)+": "+b[e].toString(!0));return this.built=d};a.prototype.encode=function(d,b){for(var e=this.getChildren(a.Field),c=0;c<e.length;c++)e[c].encode(d.get(e[c].name),b)};a.prototype.decode=function(d,b){b=b||-1;for(var a=d.offset,c=new this.built;d.offset<a+b||-1==b&&0<d.remaining();){var k=d.readVarint32(),f=k&7,k=k>>3,g=this.getChild(k);if(!g)throw Error("Illegal field id in "+this.toString(!0)+"#decode: "+k);c.set(g.name,g.decode(f,d))}return c};g.Message=a;var k=function(d,b,a,c, | ||
k,f){l.call(this,d,c);this.required="required"==b;this.repeated="repeated"==b;this.type=a;this.id=k;this.options=f||{}};k.prototype=Object.create(l.prototype);k.prototype.verifyValue=function(d,b){b=b||!1;if(null===d){if(this.required)throw Error("Illegal value for "+this.toString(!0)+": "+d+" (required)");return null}var a,k;if(this.repeated&&!b){if(!(d instanceof Array))throw Error("Illegal value for "+this.toString(!0)+": "+d+" (not an array)");k=[];for(a=0;a<d.length;a++)k.push(this.verifyValue(d[a], | ||
!0));return k}if(!this.repeated&&d instanceof Array)throw Error("Illegal value for "+this.toString(!0)+": "+d+" (is array)");if(this.type!=c.TYPES.message&&d instanceof Object)throw Error("Illegal value for "+this.toString(!0)+": "+d+" (is object)");if(this.type==c.TYPES.int32||this.type==c.TYPES.sint32||this.type==c.TYPES.fixed32||this.type==c.TYPES.sfixed32)return parseInt(d,10);if(this.type==c.TYPES.uint32){d=parseInt(d,10);if(0>d)throw Error("Illegal value for "+this.toString(!0)+": "+d+" (must not be negative)"); | ||
return d}if(this.type==c.TYPES.bool)return!!d;if(this.type==c.TYPES["float"]||this.type==c.TYPES["double"])return parseFloat(d);if(this.type==c.TYPES.string)return""+d;if(this.type==c.TYPES.bytes)return n.wrap(d);if(this.type==c.TYPES["enum"]){k=this.resolvedType.getChildren(f.Value);for(a=0;a<k.length;a++)if(k[a].name==d||k[a].id==d)return k[a].id;throw Error("Illegal value for "+this.toString(!0)+": "+d+" (not a valid enum value)");}if(this.type==c.TYPES.message){if(d instanceof this.resolvedType.built)return d; | ||
if("object"==typeof d)return new this.resolvedType.built(d);throw Error("Illegal value for "+this.toString(!0)+": "+d+" (not an instance of "+this.resolvedType+")");}throw Error("[INTERNAL ERROR] Illegal value for "+this.toString(!0)+": "+d+" (undefined type "+this.type+")");};k.prototype.encode=function(d,b){d=this.verifyValue(d);if(null==this.type||"object"!=typeof this.type)throw Error("[INTERNAL ERROR] Unresolved type in "+this.toString(!0)+": "+this.type);if(null!==d)try{if(this.repeated){var a; | ||
if(this.options.packed){b.writeVarint32(this.id<<3|c.WIRE_TYPES.LDELIM);for(a=0;a<d.length;a++)this.encodeValue(d[a],b)}else for(a=0;a<d.length;a++)b.writeVarint32(this.id<<3|this.type.wireType),this.encodeValue(d[a],b)}else b.writeVarint32(this.id<<3|this.type.wireType),this.encodeValue(d,b)}catch(k){throw Error("Illegal value for "+this.toString(!0)+": "+d+" ("+k+")");}};k.prototype.decode=function(a,b){var e,k;if(a!=this.type.wireType)throw Error("Illegal wire type for field "+this.toString(!0)+ | ||
": "+a+" ("+this.type.wireType+" expected)");if(this.type==c.TYPES.int32)return b.readVarint32();if(this.type==c.TYPES.uint32)return e=b.readVarint32(),UINT32[0]=e,UINT32[0];if(this.type==c.TYPES.sint32)return b.readZigZagVarint32();if(this.type==c.TYPES.bool)return!!b.readVarint32();if(this.type==c.TYPES["enum"])return b.readVarint32();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 k=b.readVarint32(),e= | ||
b.clone(),e.length=e.offset+k,e;if(this.type==c.TYPES.message)return k=b.readVarint32(),this.resolvedType.decode(b,k);if(a==c.WIRE_TYPES.LDELIM&&this.repeated){k=b.readVarint32();for(k=b.offset+k;b.offset<k;)this.decode(this.type.wireType,b);return[]}if(this.type==c.TYPES.fixed32)return b.readInt32();if(this.type==c.TYPES.sfixed32)return n.zigZagDecode32(b.readUint32());if(this.type==c.TYPES["float"])return b.readFloat();throw Error("[INTERNAL ERROR] Illegal wire type for "+this.toString(!0)+": "+ | ||
a);};k.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.writeVarint32(n.zigZagEncode32(a));else if(this.type==c.TYPES.fixed32)b.writeUint32(a);else if(this.type==c.TYPES.sfixed32)b.writeUint32(n.zigZagEncode32(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 e=b.offset;b.writeUint8(0);this.resolvedType.encode(a,b);var k=b.offset-e-1,f=n.calculateVarint32(k);if(1<f){var g=b.clone();g.offset-=k;b.append(g.flip(),e-1+f)}b.writeVarint32(k,e)}else throw Error("[INTERNAL ERROR] Illegal value to encode in "+this.toString(!0)+ | ||
": "+a+" (unknown type)");};g.Message.Field=k;var f=function(a,b){m.call(this,a,b);this.built=null};f.prototype=Object.create(m.prototype);f.prototype.build=function(){for(var a={},b=this.getChildren(f.Value),e=0;e<b.length;e++)a[b[e].name]=b[e].id;return this.built=a};g.Enum=f;k=function(a,b,e){l.call(this,a,b);this.id=e};k.prototype=Object.create(l.prototype);g.Enum.Value=k;return g}(h);h.Builder=function(c,g,l){var m=function(){this.ptr=this.ns=new l.Namespace(null,"");this.resolved=!1;this.result= | ||
null};m.prototype.reset=function(){this.ptr=this.ns};m.prototype.define=function(a){if("string"!=typeof a||!g.TYPEDEF.test(a))throw Error("Illegal package name: "+a);a=a.split(".");var c;for(c=0;c<a.length;c++)if(!g.NAME.test(a[c]))throw Error("Illegal package name: "+a[c]);for(c=0;c<a.length;c++)this.ptr.hasChild(a[c])||this.ptr.addChild(new l.Namespace(this.ptr,a[c])),this.ptr=this.ptr.getChild(a[c]);return this};m.isValidMessage=function(a){if("string"!=typeof a.name||!g.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 f=[],d;for(c=0;c<a.fields.length;c++){if(!m.isValidMessageField(a.fields[c]))return!1;d=parseInt(a.id,10);if(0<=f.indexOf(d))return!1;f.push(d)}}if("undefined"!=typeof a.enums){if(!(a.enums instanceof Array))return!1;for(c=0;c<a.enums.length;c++)if(!m.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(!m.isValidMessage(a.messages[c]))return!1}return!0}; | ||
m.isValidMessageField=function(a){if("string"!=typeof a.rule||"string"!=typeof a.name||"string"!=typeof a.type||"undefined"==typeof a.id||!g.RULE.test(a.rule)||!g.NAME.test(a.name)||!g.TYPEREF.test(a.type)||!g.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),f=0;f<c.length;f++)if(!g.NAME.test(c[f])||!g.ID.test(""+a.options[c[f]])&&!g.TYPEREF.test(a.options[c[f]]))return!1}return!0};m.isValidEnum=function(a){if("string"!= | ||
typeof a.name||!g.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||!g.NAME.test(a.values[c].name)||!g.ID.test(""+a.values[c].id))return!1;return!0};m.prototype.create=function(a){if(a&&(a instanceof Array||(a=[a]),0!=a.length)){var c=[],f,d,b,e,h;for(c.push(a);0<c.length;){a=c.pop();if(a instanceof Array)for(;0< | ||
a.length;)if(f=a.shift(),m.isValidMessage(f)){d=new l.Message(this.ptr,f.name);if(f.fields&&0<f.fields.length)for(e=0;e<f.fields.length;e++){if(!m.isValidMessageField(f.fields[e]))throw Error("Not a valid message field definition in message "+d.name+": "+JSON.stringify(f.fields[e]));if(f.fields[e].options){b=Object.keys(f.fields[e].options);for(h=0;h<b.length;h++){if(!g.NAME.test(b[h]))throw Error("Illegal field option name in message "+d.name+"#"+f.fields[e].name+": "+b[h]);if(!g.ID.test(""+f.fields[e].options[b[h]])&& | ||
!g.TYPEREF.test(f.fields[e].options[b[h]]))throw Error("Illegal field option value in message "+d.name+"#"+f.fields[e].name+"#"+b[h]+": "+f.fields[e].options[b[h]]);}}d.addChild(new l.Message.Field(d,f.fields[e].rule,f.fields[e].type,f.fields[e].name,f.fields[e].id,f.fields[e].options))}b=[];if("undefined"!=typeof f.enums&&0<f.enums.length)for(e=0;e<f.enums.length;e++)b.push(f.enums[e]);if(f.messages&&0<f.messages.length)for(e=0;e<f.messages.length;e++)b.push(f.messages[e]);this.ptr.addChild(d);0< | ||
b.length&&(c.push(a),a=b,this.ptr=d)}else if(m.isValidEnum(f)){d=new l.Enum(this.ptr,f.name);for(e=0;e<f.values.length;e++)d.addChild(new l.Enum.Value(d,f.values[e].name,f.values[e].id));this.ptr.addChild(d)}else throw Error("Not a valid message or enum definition: "+JSON.stringify(f));else throw Error("Not a valid namespace definition: "+JSON.stringify(a));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 | ||
l.Namespace)for(var a=this.ptr.getChildren(),k=0;k<a.length;k++)this.ptr=a[k],this.resolveAll();else if(this.ptr instanceof l.Message.Field)if(g.TYPE.test(this.ptr.type))this.ptr.type=c.TYPES[this.ptr.type];else{if(!g.TYPEREF.test(this.ptr.type))throw Error("Illegal type reference in "+this.ptr.toString(!0)+": "+this.ptr.type);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 | ||
l.Enum)this.ptr.type=c.TYPES["enum"];else if(a instanceof l.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()}};m.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 c=this.result,f=0;f<a.length;f++)if(c[a[f]])c=c[a[f]];else{c=null;break}return c}return this.result};m.prototype.toString=function(){return"Builder"};return m}(h,h.Lang,h.Reflect);h.protoFromString=function(c){throw Error("This build of ProtoBuf.js does not include DotProto support. See: https://github.com/dcodeIO/ProtoBuf.js");};h.protoFromFile=function(c,g){g&&"function"!=typeof g&&(g=null);if(g)h.Util.fetch(c,function(c){g(h.protoFromString(c))});else{var l=h.Util.fetch(c); | ||
return null!==l?h.protoFromString(l):null}};h.newBuilder=function(c){var g=new h.Builder;"undefined"!=typeof c&&g.define(c);return g};return h}"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); |
@@ -1,2 +0,2 @@ | ||
ProtoBuf.js - protobuf for JavaScript [![Build Status](https://travis-ci.org/dcodeIO/ProtoBuf.js.png?branch=master)](https://travis-ci.org/dcodeIO/ProtoBuf.js) | ||
![ProtoBuf.js - protobuf for JavaScript](https://raw.github.com/dcodeIO/ProtoBuf.js/master/ProtoBuf.png) | ||
===================================== | ||
@@ -9,2 +9,14 @@ | ||
Features | ||
-------- | ||
* [CommonJS](http://www.commonjs.org/) compatible | ||
* [RequireJS](http://requirejs.org/)/AMD compatible | ||
* Shim compatible (include the script, then use `var ProtoBuf = dcodeIO.ProtoBuf;`) | ||
* [node.js](http://nodejs.org) compatible, also available via [npm](https://npmjs.org/package/protobufjs) | ||
* [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 a noparse build) | ||
Builder | ||
@@ -230,2 +242,3 @@ ------- | ||
} | ||
``` | ||
@@ -321,3 +334,3 @@ #### Not (yet) supported #### | ||
Tests (& Examples) | ||
Tests (& Examples) [![Build Status](https://travis-ci.org/dcodeIO/ProtoBuf.js.png?branch=master)](https://travis-ci.org/dcodeIO/ProtoBuf.js) | ||
------------------ | ||
@@ -327,16 +340,4 @@ * [View source](https://github.com/dcodeIO/ProtoBuf.js/blob/master/tests/suite.js) | ||
Features | ||
-------- | ||
* [CommonJS](http://www.commonjs.org/) compatible | ||
* [RequireJS](http://requirejs.org/)/AMD compatible | ||
* Shim compatible (include the script, then use `var ProtoBuf = dcodeIO.ProtoBuf;`) | ||
* [node.js](http://nodejs.org) compatible, also available via [npm](https://npmjs.org/package/protobufjs) | ||
* [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 a noparse build) | ||
License | ||
------- | ||
Apache License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0.html |
@@ -23,2 +23,3 @@ /* | ||
(function(global) { | ||
"use strict"; | ||
@@ -37,16 +38,2 @@ function loadProtoBuf(ByteBuffer) { | ||
// Object.create polyfill | ||
// ref: https://developer.mozilla.org/de/docs/JavaScript/Reference/Global_Objects/Object/create | ||
if (!Object.create) { | ||
/** @expose */ | ||
Object.create = function (o) { | ||
if (arguments.length > 1) { | ||
throw new Error('Object.create implementation only accepts the first parameter.'); | ||
} | ||
function F() {} | ||
F.prototype = o; | ||
return new F(); | ||
}; | ||
} | ||
/** | ||
@@ -184,2 +171,4 @@ * The ProtoBuf namespace. | ||
// #include "ProtoBuf/Util.js" | ||
// #include "ProtoBuf/Lang.js" | ||
@@ -229,56 +218,20 @@ | ||
* Builds a .proto file and returns the Builder. | ||
* <p>Node.js: If no callback is specified, this will read the file synchronously using the "fs" module and | ||
* return the Builder. If a callback is specified, this will read the file asynchronously and call the callback | ||
* with the Builder as its first argument afterwards.</p> | ||
* <p>Browser: Will read the file asynchronously and call the callback with the Builder as its first argument | ||
* afterwards.</p> | ||
* @param {string} filename Path to proto filename | ||
* @param {function(ProtoBuf.Builder)=} callback Callback that will receive the Builder as its first argument | ||
* @return {ProtoBuf.Builder|undefined} The Builder if synchronous (no callback), else undefined | ||
* @throws {Error} If the file cannot be read or cannot be parsed | ||
* @param {function(ProtoBuf.Builder)=} callback Callback that will receive the Builder as its first argument. | ||
* If the request has failed, builder will be NULL. If omitted, the file will be read synchronously and this | ||
* function will return the Builder or NULL if the request has failed. | ||
* @return {?ProtoBuf.Builder|undefined} The Builder if synchronous (no callback specified, will be NULL if the | ||
* request has failed), else undefined | ||
* @expose | ||
*/ | ||
ProtoBuf.protoFromFile = function(filename, callback) { | ||
// #ifdef NOPARSE | ||
throw(new Error("This build of ProtoBuf.js does not include DotProto support. See: https://github.com/dcodeIO/ProtoBuf.js")); | ||
// #else | ||
if ((typeof window == 'undefined' || !window.window) && typeof require == 'function') { // Node.js | ||
var fs = require("fs"); | ||
if (typeof callback == 'function') { | ||
fs.readFile(filename, function(err, data) { | ||
callback(ProtoBuf.protoFromString(data)); | ||
}); | ||
} else { | ||
return ProtoBuf.protoFromString(require("fs").readFileSync(filename)); | ||
} | ||
} else { // Browser, no dependencies please, ref: http://www.quirksmode.org/js/xmlhttp.html | ||
if (typeof callback != 'function') { | ||
throw(new Error("Cannot read '"+filename+"': ProtoBuf.protoFromFile requires a callback")); | ||
} | ||
var XMLHttpFactories = [ | ||
function () {return new XMLHttpRequest()}, | ||
function () {return new ActiveXObject("Msxml2.XMLHTTP")}, | ||
function () {return new ActiveXObject("Msxml3.XMLHTTP")}, | ||
function () {return new ActiveXObject("Microsoft.XMLHTTP")} | ||
]; | ||
var xhr = false; | ||
for (var i=0;i<XMLHttpFactories.length;i++) { | ||
try { xhr = XMLHttpFactories[i](); } | ||
catch (e) { continue; } | ||
break; | ||
} | ||
if (!xhr) throw(new Error("Cannot read '"+filename+"': Your browser does not support XMLHttpRequest")); | ||
xhr.open('GET', filename, true); | ||
xhr.setRequestHeader('User-Agent', 'XMLHTTP/1.0'); | ||
xhr.onreadystatechange = function() { | ||
if (xhr.readyState != 4) return; | ||
if (xhr.status != 200 && xhr.status != 304) { | ||
throw(new Error("Failed to read '"+filename+"': Server returned status code "+xhr.status)); | ||
} | ||
callback(ProtoBuf.protoFromString(xhr.responseText)); | ||
}; | ||
if (xhr.readyState == 4) return; | ||
xhr.send(); | ||
if (callback && typeof callback != 'function') callback = null; | ||
if (callback) { | ||
ProtoBuf.Util.fetch(filename, function(contents) { | ||
callback(ProtoBuf.protoFromString(contents)); | ||
}); | ||
} else { | ||
var contents = ProtoBuf.Util.fetch(filename); | ||
return contents !== null ? ProtoBuf.protoFromString(contents) : null; | ||
} | ||
// #endif | ||
}; | ||
@@ -285,0 +238,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
676887
56
8581
0
340
3
22
Updatedbytebuffer@>=1.1.2