protobufjs
Advanced tools
Comparing version 0.9.9 to 0.9.10
@@ -322,2 +322,3 @@ /* | ||
* @param {!ByteBuffer} buffer | ||
* @return {!ByteBuffer} | ||
* @throws {string} | ||
@@ -384,2 +385,3 @@ */ | ||
* @param {!ByteBuffer} buffer | ||
* @return {!ByteBuffer} | ||
* @throws {Error} | ||
@@ -402,2 +404,3 @@ * @nosideeffects | ||
* @param {!ByteBuffer} buffer | ||
* @return {!ByteBuffer} | ||
* @throws {Error} | ||
@@ -404,0 +407,0 @@ * @nosideeffects |
{ | ||
"name": "protobufjs", | ||
"version": "0.9.9", | ||
"version": "0.9.10", | ||
"author": "Daniel Wirtz <dcode@dcode.io>", | ||
@@ -5,0 +5,0 @@ "description": "ProtoBuf.js: protobuf for JavaScript. No compilation step required, works out of the box.", |
@@ -6,6 +6,6 @@ /* | ||
*/ | ||
(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.8",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= | ||
(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.10",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 b(){}if(1<arguments.length)throw Error("Object.create implementation only accepts the first parameter.");b.prototype=d;return new b});var b={};b.IS_NODE=("undefined"==typeof window||!window.window)&&"function"==typeof require;b.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")}],b=null,h=0;h<d.length;h++){try{b=d[h]()}catch(a){continue}break}if(!b)throw Error("XMLHttpRequest is not supported");return b};b.fetch=function(d,n){n&&"function"!=typeof n&&(n=null);if(b.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=b.XHR();a.open("GET",d,n?!0:!1);a.setRequestHeader("User-Agent", | ||
function(){return new ActiveXObject("Msxml3.XMLHTTP")},function(){return new ActiveXObject("Microsoft.XMLHTTP")}],b=null,g=0;g<d.length;g++){try{b=d[g]()}catch(a){continue}break}if(!b)throw Error("XMLHttpRequest is not supported");return b};b.fetch=function(d,n){n&&"function"!=typeof n&&(n=null);if(b.IS_NODE)if(n)require("fs").readFile(d,function(a,d){a?n(null):n(""+d)});else try{return require("fs").readFileSync(d)}catch(g){return null}else{var a=b.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 b}();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])*/, | ||
@@ -15,4 +15,4 @@ 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(b){var d=function(d){this.source=""+d;this.index=0;this.stack=[];this.readingString=!1};d.prototype._readString=function(){b.STRING.lastIndex=this.index-1;var d;if(null!==(d=b.STRING.exec(this.source)))return d=d[1],this.index=b.STRING.lastIndex,this.stack.push(b.STRINGCLOSE),d;throw Error("Illegal string value at index "+ | ||
" ('"+b.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;b.DELIM.lastIndex=0;if(b.DELIM.test(this.source.charAt(d)))d++;else for(d++;d<this.source.length&&!b.DELIM.test(this.source.charAt(d));)d++;d=this.source.substring(this.index,this.index=d);d==b.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(b,d,e){b=function(d){this.tn=new e(d)};b.prototype.parse=function(){var d=[],a=null,c={name:"[ROOT]",options:{}},b,g=!0;do{b=this.tn.next();if(null==b)break;if("package"==b){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(b)}else if("message"==b)b=this._parseMessage(null,b), | ||
d.push(b),g=!1;else if("option"==b){if(!g)throw Error("Illegal option definition: Must be declared before the first message");this._parseOption(c,b)}else throw Error("Illegal top level declaration: "+b);}while(1);return{"package":a,options:c.options,messages:d}};b.prototype._parsePackage=function(b){b=this.tn.next();if(!d.TYPEDEF.test(b))throw Error("Illegal package name: "+b);var a=b;b=this.tn.next();if(b!=d.END)throw Error("Illegal end of package definition: "+b+" ('"+d.END+"' expected)");return a}; | ||
this.index+"/"+this.source.length+")"};return d}(e.Lang);e.DotProto.Parser=function(b,d,e){b=function(d){this.tn=new e(d)};b.prototype.parse=function(){var d=[],a=null,c={name:"[ROOT]",options:{}},b,h=!0;do{b=this.tn.next();if(null==b)break;if("package"==b){if(!h)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(b)}else if("message"==b)b=this._parseMessage(null,b), | ||
d.push(b),h=!1;else if("option"==b){if(!h)throw Error("Illegal option definition: Must be declared before the first message");this._parseOption(c,b)}else throw Error("Illegal top level declaration: "+b);}while(1);return{"package":a,options:c.options,messages:d}};b.prototype._parsePackage=function(b){b=this.tn.next();if(!d.TYPEDEF.test(b))throw Error("Illegal package name: "+b);var a=b;b=this.tn.next();if(b!=d.END)throw Error("Illegal end of package definition: "+b+" ('"+d.END+"' expected)");return a}; | ||
b.prototype._parseOption=function(b,a){a=this.tn.next();if(!d.NAME.test(a))throw Error("Illegal option name in message "+b.name+": "+a);var c=a;a=this.tn.next();if(a!=d.EQUAL)throw Error("Illegal option operator in message "+b.name+", option "+c+": "+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 "+b.name+", option "+c+": "+a+" ('"+d.STRINGCLOSE+"' expected)");}else if(d.NUMBER.test(a))f= | ||
@@ -23,35 +23,35 @@ parseInt(a);else if(d.NAME.test(a))f=a;else throw Error("Illegal option value in message "+b.name+", option "+c+": "+a);a=this.tn.next();if(a!=d.END)throw Error("Illegal end of option in message "+b.name+", option "+c+": "+a+" ('"+d.END+"' expected)");b.options[c]=f};b.prototype._parseMessage=function(b,a){var c={};a=this.tn.next();if(!d.NAME.test(a))throw Error("Illegal message name"+(b?" in message "+b.name:"")+": "+a);c.name=a;a=this.tn.next();if(a!=d.OPEN)throw Error("Illegal OPEN after message "+ | ||
d.END)throw Error("Illegal field delimiter in message "+b.name+"#"+c.name+": "+a+" ('"+d.END+"' expected)");b.fields.push(c)};b.prototype._parseMessageFieldOptions=function(b,a,c){var f=!0;do{c=this.tn.next();if(c==d.OPTCLOSE)break;else if(c==d.OPTEND){if(f)throw Error("Illegal start of message field options in message "+b.name+"#"+a.name+": "+c);c=this.tn.next()}if(!d.NAME.test(c))throw Error("Illegal field option in message "+b.name+"#"+a.name+": "+c);this._parseMessageFieldOption(b,a,c);f=!1}while(1)}; | ||
b.prototype._parseMessageFieldOption=function(b,a,c){var f=c;c=this.tn.next();if(c!=d.EQUAL)throw Error("Illegal field option operation in message "+b.name+"#"+a.name+": "+c+" ('=' expected)");var g;c=this.tn.next();if(c==d.STRINGOPEN){if(g=this.tn.next(),c=this.tn.next(),c!=d.STRINGCLOSE)throw Error("Illegal end of field value in message "+b.name+"#"+a.name+", option "+f+": "+c+" ('"+d.STRINGCLOSE+"' expected)");}else if(d.NUMBER.test(c))g=parseInt(c,10);else if(d.NAME.test(c))g=c;else throw Error("Illegal field option value in message "+ | ||
b.name+"#"+a.name+", option "+f+": "+c);a.options[f]=g};b.prototype._parseEnum=function(b,a){var c={};a=this.tn.next();if(!d.NAME.test(a))throw Error("Illegal enum name in message "+b.name+": "+a);c.name=a;a=this.tn.next();if(a!=d.OPEN)throw Error("Illegal OPEN after enum "+c.name+": "+a);c.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 "+c.name+": "+a);this._parseEnumValue(c,a)}while(1);b.enums.push(c)};b.prototype._parseEnumValue= | ||
b.prototype._parseMessageFieldOption=function(b,a,c){var f=c;c=this.tn.next();if(c!=d.EQUAL)throw Error("Illegal field option operation in message "+b.name+"#"+a.name+": "+c+" ('=' expected)");var h;c=this.tn.next();if(c==d.STRINGOPEN){if(h=this.tn.next(),c=this.tn.next(),c!=d.STRINGCLOSE)throw Error("Illegal end of field value in message "+b.name+"#"+a.name+", option "+f+": "+c+" ('"+d.STRINGCLOSE+"' expected)");}else if(d.NUMBER.test(c))h=parseInt(c,10);else if(d.NAME.test(c))h=c;else throw Error("Illegal field option value in message "+ | ||
b.name+"#"+a.name+", option "+f+": "+c);a.options[f]=h};b.prototype._parseEnum=function(b,a){var c={};a=this.tn.next();if(!d.NAME.test(a))throw Error("Illegal enum name in message "+b.name+": "+a);c.name=a;a=this.tn.next();if(a!=d.OPEN)throw Error("Illegal OPEN after enum "+c.name+": "+a);c.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 "+c.name+": "+a);this._parseEnumValue(c,a)}while(1);b.enums.push(c)};b.prototype._parseEnumValue= | ||
function(b,a){var c={};c.name=a;a=this.tn.next();if(a!=d.EQUAL)throw Error("Illegal enum value operator in enum "+b.name+": "+a+" ('"+d.EQUAL+"' expected)");a=this.tn.next();if(!d.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!=d.END)throw Error("Illegal enum value delimiter in enum "+b.name+": "+a+" ('"+d.END+"' expected)");};b.prototype.toString=function(){return"Parser"};return b}(e,e.Lang,e.DotProto.Tokenizer); | ||
e.Reflect=function(b){var d={},e=function(a,b){this.parent=a;this.name=b;this.resolvedType=null};e.prototype.toString=function(b){var m=this.name,c=this;do{c=c.parent;if(null==c)break;m=c.name+"."+m}while(1);b&&(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,b){e.call(this,a,b);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 b=[],d=0;d<this.children.length;d++)this.children[d]instanceof a&&b.push(this.children[d]);return b};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(b){var d;if("number"== | ||
typeof b)for(d=0;d<this.children.length;d++){if(this.children[d]instanceof a.Field&&this.children[d].id==b)return!0}else for(d=0;d<this.children.length;d++)if(this.children[d].name==b)return!0;return!1};h.prototype.getChild=function(b){var d;if("number"==typeof b)for(d=0;d<this.children.length;d++){if(this.children[d]instanceof a.Field&&this.children[d].id==b)return this.children[d]}else for(d=0;d<this.children.length;d++)if(this.children[d].name==b)return this.children[d];return null};h.prototype.resolve= | ||
function(a){var b=a.split("."),c=this,f=0;if(""==b[f]){for(;null!=c.parent;)c=c.parent;f++}do{do{c=c.getChild(b[f]);if(!c||!(c instanceof d.T)){c=null;break}f++}while(f<b.length);if(null!=c)break;if(null!==this.parent)return this.parent.resolve(a)}while(null!=c);return c};h.prototype.build=function(){for(var a={},b=this.getChildren(),d,c=0;c<b.length;c++)d=b[c],d instanceof h&&(a[d.name]=d.build());return a};d.Namespace=h;var a=function(a,b){h.call(this,a,b);this.built=null};a.prototype=Object.create(h.prototype); | ||
a.prototype.build=function(){for(var b=function(a,b){var d=b.getChildren(a.Message.Field),c=eval("(function "+b.name+"() { this.__construct.apply(this, arguments); })");c.prototype.__construct=function(a){var b,c;for(b=0;b<d.length;b++)c=d[b],this[c.name]=c.repeated?[]:null;for(b=0;b<d.length;b++)if(c=d[b],"undefined"!=typeof c.options["default"])try{this.set(c.name,c.options["default"])}catch(g){throw Error("[INTERNAL ERROR] "+g);}if("object"==typeof a&&"function"!=typeof a.encode){c=Object.keys(a); | ||
for(b=0;b<c.length;b++)this.set(c[b],a[c[b]])}else for(b=0;b<arguments.length;b++)b<d.length&&this.set(d[b].name,arguments[b])};c.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))};c.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)};c.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<d.length;g++)(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),g=a.name.replace(/([A-Z])/g,function(a){return"_"+a});b.hasChild("set"+d)||(c.prototype["set"+d]=function(b){this.set(a.name,b)});b.hasChild("set_"+g)||(c.prototype["set_"+g]=function(b){this.set(a.name,b)});b.hasChild("get"+d)||(c.prototype["get"+d]=function(){return this.get(a.name)});b.hasChild("get_"+g)||(c.prototype["get_"+g]=function(){return this.get(a.name)})})(d[g]);c.prototype.encode=function(a){a= | ||
a||new l;b.encode(this,a);return a.flip()};c.prototype.toArrayBuffer=function(){return this.encode().toArrayBuffer()};c.decode=function(a){a=a?a instanceof l?a:l.wrap(a):new l;return b.decode(a)};c.prototype.toString=function(){return b.toString()};return c}(d,this),c=this.getChildren(),k=0;k<c.length;k++)if(c[k]instanceof f)b[c[k].name]=c[k].build();else if(c[k]instanceof a)b[c[k].name]=c[k].build();else if(!(c[k]instanceof a.Field))throw Error("Illegal reflect child of "+this.toString(!0)+": "+ | ||
c[k].toString(!0));return this.built=b};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 c=function(a,b,d,c,f,h){e.call(this,a,c); | ||
this.required="required"==b;this.repeated="repeated"==b;this.type=d;this.id=f;this.options=h||{}};c.prototype=Object.create(e.prototype);c.prototype.verifyValue=function(a,d){d=d||!1;if(null===a){if(this.required)throw Error("Illegal value for "+this.toString(!0)+": "+a+" (required)");return null}var c,e;if(this.repeated&&!d){if(!(a instanceof Array))throw Error("Illegal value for "+this.toString(!0)+": "+a+" (not an array)");e=[];for(c=0;c<a.length;c++)e.push(this.verifyValue(a[c],!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)return l.cast(l.UINT32,parseInt(a,10));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 l.wrap(a);if(this.type==b.TYPES["enum"]){e=this.resolvedType.getChildren(f.Value);for(c=0;c<e.length;c++)if(e[c].name==a||e[c].id==a)return e[c].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+")");};c.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(f){throw Error("Illegal value for "+this.toString(!0)+": "+a+" ("+f+")");}};c.prototype.decode=function(a,c){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==b.TYPES.int32)return c.readVarint32();if(this.type==b.TYPES.uint32)return l.cast(l.UINT32, | ||
c.readVarint32());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 f=c.readVarint32(),d=c.clone(),d.length=d.offset+f,d;if(this.type==b.TYPES.message)return f=c.readVarint32(),this.resolvedType.decode(c,f);if(a==b.WIRE_TYPES.LDELIM&&this.repeated){f= | ||
c.readVarint32();for(f=c.offset+f;c.offset<f;)this.decode(this.type.wireType,c);return[]}if(this.type==b.TYPES.fixed32)return c.readInt32();if(this.type==b.TYPES.sfixed32)return l.zigZagDecode32(c.readUint32());if(this.type==b.TYPES["float"])return c.readFloat();throw Error("[INTERNAL ERROR] Illegal wire type for "+this.toString(!0)+": "+a);};c.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(l.zigZagEncode32(a)); | ||
else if(this.type==b.TYPES.fixed32)c.writeUint32(a);else if(this.type==b.TYPES.sfixed32)c.writeUint32(l.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 f=c.offset-d-1,e=l.calculateVarint32(f);if(1<e){var h=c.clone();h.offset-=f;c.append(h.flip(),d-1+e)}c.writeVarint32(f,d)}else throw Error("[INTERNAL ERROR] Illegal value to encode in "+this.toString(!0)+": "+a+" (unknown type)");};d.Message.Field=c;var f=function(a,c){h.call(this,a,c);this.built=null};f.prototype=Object.create(h.prototype);f.prototype.build=function(){for(var a={},c=this.getChildren(f.Value), | ||
d=0;d<c.length;d++)a[c[d].name]=c[d].id;return this.built=a};d.Enum=f;c=function(a,c,d){e.call(this,a,c);this.id=d};c.prototype=Object.create(e.prototype);d.Enum.Value=c;return d}(e);e.Builder=function(b,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 c;for(c=0;c<a.length;c++)if(!d.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 e.Namespace(this.ptr,a[c])),this.ptr=this.ptr.getChild(a[c]);return this};h.isValidMessage=function(a){if("string"!=typeof a.name||!d.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 b=[],e;for(c=0;c<a.fields.length;c++){if(!h.isValidMessageField(a.fields[c]))return!1;e=parseInt(a.id,10);if(0<=b.indexOf(e))return!1;b.push(e)}}if("undefined"!= | ||
typeof a.enums){if(!(a.enums instanceof Array))return!1;for(c=0;c<a.enums.length;c++)if(!h.isValidEnum(a.enums[c]))return!1}if("undefined"!=typeof a.messages){if(!(a.messages instanceof Array))return!1;for(c=0;c<a.messages.length;c++)if(!h.isValidMessage(a.messages[c]))return!1}return!0};h.isValidMessageField=function(a){if("string"!=typeof a.rule||"string"!=typeof a.name||"string"!=typeof a.type||"undefined"==typeof a.id||!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 c=Object.keys(a.options),b=0;b<c.length;b++)if(!d.NAME.test(c[b])||!d.ID.test(""+a.options[c[b]])&&!d.TYPEREF.test(a.options[c[b]]))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 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||!d.NAME.test(a.values[c].name)||!d.ID.test(""+a.values[c].id))return!1;return!0};h.prototype.create=function(a){if(a&&(a instanceof Array||(a=[a]),0!=a.length)){var c=[],b,g,m,k,l;for(c.push(a);0<c.length;){a=c.pop();if(a instanceof Array)for(;0<a.length;)if(b=a.shift(),h.isValidMessage(b)){g=new e.Message(this.ptr,b.name);if(b.fields&&0<b.fields.length)for(k=0;k<b.fields.length;k++){if(!h.isValidMessageField(b.fields[k]))throw Error("Not a valid message field definition in message "+ | ||
g.name+": "+JSON.stringify(b.fields[k]));if(b.fields[k].options){m=Object.keys(b.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+"#"+b.fields[k].name+": "+m[l]);if(!d.ID.test(""+b.fields[k].options[m[l]])&&!d.TYPEREF.test(b.fields[k].options[m[l]]))throw Error("Illegal field option value in message "+g.name+"#"+b.fields[k].name+"#"+m[l]+": "+b.fields[k].options[m[l]]);}}g.addChild(new e.Message.Field(g,b.fields[k].rule,b.fields[k].type, | ||
b.fields[k].name,b.fields[k].id,b.fields[k].options))}m=[];if("undefined"!=typeof b.enums&&0<b.enums.length)for(k=0;k<b.enums.length;k++)m.push(b.enums[k]);if(b.messages&&0<b.messages.length)for(k=0;k<b.messages.length;k++)m.push(b.messages[k]);this.ptr.addChild(g);0<m.length&&(c.push(a),a=m,this.ptr=g)}else if(h.isValidEnum(b)){g=new e.Enum(this.ptr,b.name);for(k=0;k<b.values.length;k++)g.addChild(new e.Enum.Value(g,b.values[k].name,b.values[k].id));this.ptr.addChild(g)}else throw Error("Not a valid message or enum definition: "+ | ||
JSON.stringify(b));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(),c=0;c<a.length;c++)this.ptr=a[c],this.resolveAll();else if(this.ptr instanceof e.Message.Field)if(d.TYPE.test(this.ptr.type))this.ptr.type=b.TYPES[this.ptr.type];else{if(!d.TYPEREF.test(this.ptr.type))throw Error("Illegal type reference in "+ | ||
this.ptr.toString(!0)+": "+this.ptr.type);a=this.ptr.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=b.TYPES["enum"];else if(a instanceof e.Message)this.ptr.type=b.TYPES.message;else throw Error("Illegal type reference in "+this.ptr.toString(!0)+": "+this.ptr.type);}else if(!(this.ptr instanceof b.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 c=this.result,b=0;b<a.length;b++)if(c[a[b]])c=c[a[b]];else{c=null;break}return c}return this.result};h.prototype.toString=function(){return"Builder"};return h}(e,e.Lang,e.Reflect);e.protoFromString=function(b,d){var l=(new e.DotProto.Parser(b+"")).parse();d="object"== | ||
typeof d?d:new e.Builder;null!==l["package"]&&d.define(l["package"]);d.create(l.messages);d.reset();d.resolveAll();d.build();return d};e.protoFromFile=function(b,d,l){if(d&&"object"==typeof d)l=d,d=null;else if(!d||"function"!=typeof d)d=null;if(d)e.Util.fetch(b,function(b){d(e.protoFromString(b,l))});else return b=e.Util.fetch(b),null!==b?e.protoFromString(b,l):null};e.newBuilder=function(b){var d=new e.Builder;"undefined"!=typeof b&&d.define(b);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); | ||
e.Reflect=function(b){var d={},e=function(a,b){this.parent=a;this.name=b;this.resolvedType=null};e.prototype.toString=function(b){var m=this.name,c=this;do{c=c.parent;if(null==c)break;m=c.name+"."+m}while(1);b&&(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 g&&(m="Namespace "+m));return m};e.prototype.build=function(){throw Error(this.toString(!0)+" cannot be built directly"); | ||
};d.T=e;var g=function(a,b){e.call(this,a,b);this.children=[]};g.prototype=Object.create(e.prototype);g.prototype.getChildren=function(a){a=a||null;if(null==a)return this.children.slice();for(var b=[],d=0;d<this.children.length;d++)this.children[d]instanceof a&&b.push(this.children[d]);return b};g.prototype.addChild=function(a){if(this.hasChild(a.name))throw Error("Duplicate name in namespace "+this.toString(!0)+": "+a.name);this.children.push(a)};g.prototype.hasChild=function(b){var d;if("number"== | ||
typeof b)for(d=0;d<this.children.length;d++){if(this.children[d]instanceof a.Field&&this.children[d].id==b)return!0}else for(d=0;d<this.children.length;d++)if(this.children[d].name==b)return!0;return!1};g.prototype.getChild=function(b){var d;if("number"==typeof b)for(d=0;d<this.children.length;d++){if(this.children[d]instanceof a.Field&&this.children[d].id==b)return this.children[d]}else for(d=0;d<this.children.length;d++)if(this.children[d].name==b)return this.children[d];return null};g.prototype.resolve= | ||
function(a){var b=a.split("."),c=this,f=0;if(""==b[f]){for(;null!=c.parent;)c=c.parent;f++}do{do{c=c.getChild(b[f]);if(!c||!(c instanceof d.T)){c=null;break}f++}while(f<b.length);if(null!=c)break;if(null!==this.parent)return this.parent.resolve(a)}while(null!=c);return c};g.prototype.build=function(){for(var a={},b=this.getChildren(),d,c=0;c<b.length;c++)d=b[c],d instanceof g&&(a[d.name]=d.build());return a};d.Namespace=g;var a=function(a,b){g.call(this,a,b);this.built=null};a.prototype=Object.create(g.prototype); | ||
a.prototype.build=function(){for(var b=function(a,b){var d=b.getChildren(a.Message.Field),c=eval("(function "+b.name+"() { this.__construct.apply(this, arguments); })");c.prototype.__construct=function(a){var b,c;for(b=0;b<d.length;b++)c=d[b],this[c.name]=c.repeated?[]:null;for(b=0;b<d.length;b++)if(c=d[b],"undefined"!=typeof c.options["default"])try{this.set(c.name,c.options["default"])}catch(h){throw Error("[INTERNAL ERROR] "+h);}if("object"==typeof a&&"function"!=typeof a.encode){c=Object.keys(a); | ||
for(b=0;b<c.length;b++)this.set(c[b],a[c[b]])}else for(b=0;b<arguments.length;b++)b<d.length&&this.set(d[b].name,arguments[b])};c.prototype.add=function(c,d){var h=b.getChild(c);if(!h)throw Error(this+"#"+c+" is undefined");if(!(h instanceof a.Message.Field))throw Error(this+"#"+c+" is not a field: "+h.toString(!0));if(!h.repeated)throw Error(this+"#"+c+" is not a repeated field");null===this[h.name]&&(this[h.name]=[]);this[h.name].push(h.verifyValue(d,!0))};c.prototype.set=function(c,d){var h=b.getChild(c); | ||
if(!h)throw Error(this+"#"+c+" is not a field: undefined");if(!(h instanceof a.Message.Field))throw Error(this+"#"+c+" is not a field: "+h.toString(!0));this[h.name]=h.verifyValue(d)};c.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 h=0;h<d.length;h++)(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),h=a.name.replace(/([A-Z])/g,function(a){return"_"+a});b.hasChild("set"+d)||(c.prototype["set"+d]=function(b){this.set(a.name,b)});b.hasChild("set_"+h)||(c.prototype["set_"+h]=function(b){this.set(a.name,b)});b.hasChild("get"+d)||(c.prototype["get"+d]=function(){return this.get(a.name)});b.hasChild("get_"+h)||(c.prototype["get_"+h]=function(){return this.get(a.name)})})(d[h]);c.prototype.encode=function(a){a= | ||
a||new l;return b.encode(this,a).flip()};c.prototype.toArrayBuffer=function(){return this.encode().toArrayBuffer()};c.decode=function(a){a=a?a instanceof l?a:l.wrap(a):new l;return b.decode(a)};c.prototype.toString=function(){return b.toString()};return c}(d,this),c=this.getChildren(),k=0;k<c.length;k++)if(c[k]instanceof f)b[c[k].name]=c[k].build();else if(c[k]instanceof a)b[c[k].name]=c[k].build();else if(!(c[k]instanceof a.Field))throw Error("Illegal reflect child of "+this.toString(!0)+": "+c[k].toString(!0)); | ||
return this.built=b};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);return c};a.prototype.decode=function(a,b){b=b||-1;for(var c=a.offset,d=new this.built;a.offset<c+b||-1==b&&0<a.remaining();){var f=a.readVarint32(),e=f&7,f=f>>3,g=this.getChild(f);if(!g)throw Error("Illegal field id in "+this.toString(!0)+"#decode: "+f);g.repeated?d.add(g.name,g.decode(e,a)):d.set(g.name,g.decode(e,a))}return d};d.Message=a;var c=function(a, | ||
b,d,c,f,g){e.call(this,a,c);this.required="required"==b;this.repeated="repeated"==b;this.type=d;this.id=f;this.options=g||{}};c.prototype=Object.create(e.prototype);c.prototype.verifyValue=function(a,d){d=d||!1;if(null===a){if(this.required)throw Error("Illegal value for "+this.toString(!0)+": "+a+" (required)");return null}var c,e;if(this.repeated&&!d){if(!(a instanceof Array))throw Error("Illegal value for "+this.toString(!0)+": "+a+" (not an array)");e=[];for(c=0;c<a.length;c++)e.push(this.verifyValue(a[c], | ||
!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)return l.cast(l.UINT32,parseInt(a,10));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 l.wrap(a);if(this.type==b.TYPES["enum"]){e=this.resolvedType.getChildren(f.Value);for(c=0;c<e.length;c++)if(e[c].name==a||e[c].id==a)return e[c].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+")");};c.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||this.options.packed&&0==a.length)return c;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(f){throw Error("Illegal value for "+this.toString(!0)+": "+a+" ("+f+")");}return c};c.prototype.decode=function(a,c){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==b.TYPES.int32)return c.readVarint32();if(this.type==b.TYPES.uint32)return l.cast(l.UINT32,c.readVarint32());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 f=c.readVarint32(),d=c.clone(),d.length=d.offset+f,d;if(this.type==b.TYPES.message)return f= | ||
c.readVarint32(),this.resolvedType.decode(c,f);if(a==b.WIRE_TYPES.LDELIM&&this.repeated){f=c.readVarint32();for(f=c.offset+f;c.offset<f;)this.decode(this.type.wireType,c);return[]}if(this.type==b.TYPES.fixed32)return c.readInt32();if(this.type==b.TYPES.sfixed32)return l.zigZagDecode32(c.readUint32());if(this.type==b.TYPES["float"])return c.readFloat();throw Error("[INTERNAL ERROR] Illegal wire type for "+this.toString(!0)+": "+a);};c.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(l.zigZagEncode32(a));else if(this.type==b.TYPES.fixed32)c.writeUint32(a);else if(this.type==b.TYPES.sfixed32)c.writeUint32(l.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 f=c.offset-d-1,e=l.calculateVarint32(f);if(1<e){var g=c.clone();g.offset-=f;c.append(g.flip(),d-1+e)}c.writeVarint32(f,d)}else throw Error("[INTERNAL ERROR] Illegal value to encode in "+this.toString(!0)+": "+a+" (unknown type)");return c}};d.Message.Field=c;var f=function(a,c){g.call(this, | ||
a,c);this.built=null};f.prototype=Object.create(g.prototype);f.prototype.build=function(){for(var a={},c=this.getChildren(f.Value),d=0;d<c.length;d++)a[c[d].name]=c[d].id;return this.built=a};d.Enum=f;c=function(a,c,d){e.call(this,a,c);this.id=d};c.prototype=Object.create(e.prototype);d.Enum.Value=c;return d}(e);e.Builder=function(b,d,e){var g=function(){this.ptr=this.ns=new e.Namespace(null,"");this.resolved=!1;this.result=null};g.prototype.reset=function(){this.ptr=this.ns};g.prototype.define=function(a){if("string"!= | ||
typeof a||!d.TYPEDEF.test(a))throw Error("Illegal package name: "+a);a=a.split(".");var c;for(c=0;c<a.length;c++)if(!d.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 e.Namespace(this.ptr,a[c])),this.ptr=this.ptr.getChild(a[c]);return this};g.isValidMessage=function(a){if("string"!=typeof a.name||!d.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 b=[],e;for(c=0;c<a.fields.length;c++){if(!g.isValidMessageField(a.fields[c]))return!1;e=parseInt(a.id,10);if(0<=b.indexOf(e))return!1;b.push(e)}}if("undefined"!=typeof a.enums){if(!(a.enums instanceof Array))return!1;for(c=0;c<a.enums.length;c++)if(!g.isValidEnum(a.enums[c]))return!1}if("undefined"!=typeof a.messages){if(!(a.messages instanceof Array))return!1;for(c=0;c<a.messages.length;c++)if(!g.isValidMessage(a.messages[c]))return!1}return!0};g.isValidMessageField=function(a){if("string"!= | ||
typeof a.rule||"string"!=typeof a.name||"string"!=typeof a.type||"undefined"==typeof a.id||!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 c=Object.keys(a.options),b=0;b<c.length;b++)if(!d.NAME.test(c[b])||!d.ID.test(""+a.options[c[b]])&&!d.TYPEREF.test(a.options[c[b]]))return!1}return!0};g.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 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||!d.NAME.test(a.values[c].name)||!d.ID.test(""+a.values[c].id))return!1;return!0};g.prototype.create=function(a){if(a&&(a instanceof Array||(a=[a]),0!=a.length)){var c=[],b,h,m,k,l;for(c.push(a);0<c.length;){a=c.pop();if(a instanceof Array)for(;0<a.length;)if(b=a.shift(),g.isValidMessage(b)){h= | ||
new e.Message(this.ptr,b.name);if(b.fields&&0<b.fields.length)for(k=0;k<b.fields.length;k++){if(!g.isValidMessageField(b.fields[k]))throw Error("Not a valid message field definition in message "+h.name+": "+JSON.stringify(b.fields[k]));if(b.fields[k].options){m=Object.keys(b.fields[k].options);for(l=0;l<m.length;l++){if(!d.NAME.test(m[l]))throw Error("Illegal field option name in message "+h.name+"#"+b.fields[k].name+": "+m[l]);if(!d.ID.test(""+b.fields[k].options[m[l]])&&!d.TYPEREF.test(b.fields[k].options[m[l]]))throw Error("Illegal field option value in message "+ | ||
h.name+"#"+b.fields[k].name+"#"+m[l]+": "+b.fields[k].options[m[l]]);}}h.addChild(new e.Message.Field(h,b.fields[k].rule,b.fields[k].type,b.fields[k].name,b.fields[k].id,b.fields[k].options))}m=[];if("undefined"!=typeof b.enums&&0<b.enums.length)for(k=0;k<b.enums.length;k++)m.push(b.enums[k]);if(b.messages&&0<b.messages.length)for(k=0;k<b.messages.length;k++)m.push(b.messages[k]);this.ptr.addChild(h);0<m.length&&(c.push(a),a=m,this.ptr=h)}else if(g.isValidEnum(b)){h=new e.Enum(this.ptr,b.name);for(k= | ||
0;k<b.values.length;k++)h.addChild(new e.Enum.Value(h,b.values[k].name,b.values[k].id));this.ptr.addChild(h)}else throw Error("Not a valid message or enum definition: "+JSON.stringify(b));else throw Error("Not a valid namespace definition: "+JSON.stringify(a));this.ptr=this.ptr.parent}this.resolved=!1;this.result=null;return this}};g.prototype.resolveAll=function(){if(!(null==this.ptr||"object"==typeof this.ptr.type)){if(this.ptr instanceof e.Namespace)for(var a=this.ptr.getChildren(),c=0;c<a.length;c++)this.ptr= | ||
a[c],this.resolveAll();else if(this.ptr instanceof e.Message.Field)if(d.TYPE.test(this.ptr.type))this.ptr.type=b.TYPES[this.ptr.type];else{if(!d.TYPEREF.test(this.ptr.type))throw Error("Illegal type reference in "+this.ptr.toString(!0)+": "+this.ptr.type);a=this.ptr.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=b.TYPES["enum"];else if(a instanceof e.Message)this.ptr.type= | ||
b.TYPES.message;else throw Error("Illegal type reference in "+this.ptr.toString(!0)+": "+this.ptr.type);}else if(!(this.ptr instanceof b.Reflect.Enum.Value))throw Error("Illegal object type in namespace: "+typeof this.ptr+":"+this.ptr);this.reset()}};g.prototype.build=function(a){this.reset();this.resolved||(this.resolveAll(),this.resolved=!0,this.result=null);null==this.result&&(this.result=this.ns.build());if(a){a=a.split(".");for(var c=this.result,b=0;b<a.length;b++)if(c[a[b]])c=c[a[b]];else{c= | ||
null;break}return c}return this.result};g.prototype.toString=function(){return"Builder"};return g}(e,e.Lang,e.Reflect);e.protoFromString=function(b,d){var l=(new e.DotProto.Parser(b+"")).parse();d="object"==typeof d?d:new e.Builder;null!==l["package"]&&d.define(l["package"]);d.create(l.messages);d.reset();d.resolveAll();d.build();return d};e.protoFromFile=function(b,d,l){if(d&&"object"==typeof d)l=d,d=null;else if(!d||"function"!=typeof d)d=null;if(d)e.Util.fetch(b,function(b){d(e.protoFromString(b, | ||
l))});else return b=e.Util.fetch(b),null!==b?e.protoFromString(b,l):null};e.newBuilder=function(b){var d=new e.Builder;"undefined"!=typeof b&&d.define(b);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,3 +6,3 @@ /* | ||
*/ | ||
(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.8",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= | ||
(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.10",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}, | ||
@@ -12,32 +12,32 @@ "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")}, | ||
"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(e,b){this.parent=e;this.name=b;this.resolvedType=null};l.prototype.toString=function(e){var b=this.name,d=this;do{d=d.parent;if(null==d)break;b=d.name+"."+b}while(1);e&&(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(e,b){l.call(this,e,b);this.children=[]};m.prototype=Object.create(l.prototype);m.prototype.getChildren=function(e){e=e||null;if(null==e)return this.children.slice();for(var b=[],d=0;d<this.children.length;d++)this.children[d]instanceof e&&b.push(this.children[d]);return b};m.prototype.addChild=function(e){if(this.hasChild(e.name))throw Error("Duplicate name in namespace "+ | ||
this.toString(!0)+": "+e.name);this.children.push(e)};m.prototype.hasChild=function(e){var b;if("number"==typeof e)for(b=0;b<this.children.length;b++){if(this.children[b]instanceof a.Field&&this.children[b].id==e)return!0}else for(b=0;b<this.children.length;b++)if(this.children[b].name==e)return!0;return!1};m.prototype.getChild=function(e){var b;if("number"==typeof e)for(b=0;b<this.children.length;b++){if(this.children[b]instanceof a.Field&&this.children[b].id==e)return this.children[b]}else for(b= | ||
0;b<this.children.length;b++)if(this.children[b].name==e)return this.children[b];return null};m.prototype.resolve=function(e){var b=e.split("."),d=this,a=0;if(""==b[a]){for(;null!=d.parent;)d=d.parent;a++}do{do{d=d.getChild(b[a]);if(!d||!(d instanceof g.T)){d=null;break}a++}while(a<b.length);if(null!=d)break;if(null!==this.parent)return this.parent.resolve(e)}while(null!=d);return d};m.prototype.build=function(){for(var e={},b=this.getChildren(),a,c=0;c<b.length;c++)a=b[c],a instanceof m&&(e[a.name]= | ||
a.build());return e};g.Namespace=m;var a=function(e,b){m.call(this,e,b);this.built=null};a.prototype=Object.create(m.prototype);a.prototype.build=function(){for(var e=function(b,e){var a=e.getChildren(b.Message.Field),d=eval("(function "+e.name+"() { this.__construct.apply(this, arguments); })");d.prototype.__construct=function(b){var e,d;for(e=0;e<a.length;e++)d=a[e],this[d.name]=d.repeated?[]:null;for(e=0;e<a.length;e++)if(d=a[e],"undefined"!=typeof d.options["default"])try{this.set(d.name,d.options["default"])}catch(c){throw Error("[INTERNAL ERROR] "+ | ||
c);}if("object"==typeof b&&"function"!=typeof b.encode){d=Object.keys(b);for(e=0;e<d.length;e++)this.set(d[e],b[d[e]])}else for(e=0;e<arguments.length;e++)e<a.length&&this.set(a[e].name,arguments[e])};d.prototype.add=function(d,a){var c=e.getChild(d);if(!c)throw Error(this+"#"+d+" is undefined");if(!(c instanceof b.Message.Field))throw Error(this+"#"+d+" is not a field: "+c.toString(!0));if(!c.repeated)throw Error(this+"#"+d+" is not a repeated field");null===this[c.name]&&(this[c.name]=[]);this[c.name].push(c.verifyValue(a))}; | ||
d.prototype.set=function(d,a){var c=e.getChild(d);if(!c)throw Error(this+"#"+d+" is not a field: undefined");if(!(c instanceof b.Message.Field))throw Error(this+"#"+d+" is not a field: "+c.toString(!0));this[c.name]=c.verifyValue(a)};d.prototype.get=function(d){var a=e.getChild(d);if(!a||!(a instanceof b.Message.Field))throw Error(this+"#"+d+" is not a field: undefined");if(!(a instanceof b.Message.Field))throw Error(this+"#"+d+" 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(b){return b.toUpperCase().replace("_","")}),a=a.substring(0,1).toUpperCase()+a.substring(1),c=b.name.replace(/([A-Z])/g,function(b){return"_"+b});e.hasChild("set"+a)||(d.prototype["set"+a]=function(e){this.set(b.name,e)});e.hasChild("set_"+c)||(d.prototype["set_"+c]=function(e){this.set(b.name,e)});e.hasChild("get"+a)||(d.prototype["get"+a]=function(){return this.get(b.name)});e.hasChild("get_"+c)||(d.prototype["get_"+c]=function(){return this.get(b.name)})})(a[c]); | ||
d.prototype.encode=function(b){b=b||new n;e.encode(this,b);return b.flip()};d.prototype.toArrayBuffer=function(){return this.encode().toArrayBuffer()};d.decode=function(b){b=b?b instanceof n?b:n.wrap(b):new n;return e.decode(b)};d.prototype.toString=function(){return e.toString()};return d}(g,this),b=this.getChildren(),d=0;d<b.length;d++)if(b[d]instanceof f)e[b[d].name]=b[d].build();else if(b[d]instanceof a)e[b[d].name]=b[d].build();else if(!(b[d]instanceof a.Field))throw Error("Illegal reflect child of "+ | ||
this.toString(!0)+": "+b[d].toString(!0));return this.built=e};a.prototype.encode=function(e,b){for(var d=this.getChildren(a.Field),c=0;c<d.length;c++)d[c].encode(e.get(d[c].name),b)};a.prototype.decode=function(e,b){b=b||-1;for(var a=e.offset,c=new this.built;e.offset<a+b||-1==b&&0<e.remaining();){var k=e.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,e))}return c};g.Message=a;var k=function(e,b,a,c, | ||
k,f){l.call(this,e,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(e,b){b=b||!1;if(null===e){if(this.required)throw Error("Illegal value for "+this.toString(!0)+": "+e+" (required)");return null}var a,k;if(this.repeated&&!b){if(!(e instanceof Array))throw Error("Illegal value for "+this.toString(!0)+": "+e+" (not an array)");k=[];for(a=0;a<e.length;a++)k.push(this.verifyValue(e[a], | ||
!0));return k}if(!this.repeated&&e instanceof Array)throw Error("Illegal value for "+this.toString(!0)+": "+e+" (is array)");if(this.type!=c.TYPES.message&&e instanceof Object)throw Error("Illegal value for "+this.toString(!0)+": "+e+" (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(e,10);if(this.type==c.TYPES.uint32)return n.cast(n.UINT32,parseInt(e,10));if(this.type==c.TYPES.bool)return!!e;if(this.type== | ||
c.TYPES["float"]||this.type==c.TYPES["double"])return parseFloat(e);if(this.type==c.TYPES.string)return""+e;if(this.type==c.TYPES.bytes)return n.wrap(e);if(this.type==c.TYPES["enum"]){k=this.resolvedType.getChildren(f.Value);for(a=0;a<k.length;a++)if(k[a].name==e||k[a].id==e)return k[a].id;throw Error("Illegal value for "+this.toString(!0)+": "+e+" (not a valid enum value)");}if(this.type==c.TYPES.message){if(e instanceof this.resolvedType.built)return e;if("object"==typeof e)return new this.resolvedType.built(e); | ||
throw Error("Illegal value for "+this.toString(!0)+": "+e+" (not an instance of "+this.resolvedType+")");}throw Error("[INTERNAL ERROR] Illegal value for "+this.toString(!0)+": "+e+" (undefined type "+this.type+")");};k.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(k){throw Error("Illegal value for "+this.toString(!0)+": "+a+" ("+k+")");}};k.prototype.decode=function(a,b){var d,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 n.cast(n.UINT32,b.readVarint32());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(),d=b.clone(),d.length=d.offset+k,d;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 d=b.offset;b.writeUint8(0);this.resolvedType.encode(a,b);var k=b.offset-d-1,f=n.calculateVarint32(k);if(1<f){var g=b.clone();g.offset-=k;b.append(g.flip(),d-1+f)}b.writeVarint32(k,d)}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),d=0;d<b.length;d++)a[b[d].name]=b[d].id;return this.built=a};g.Enum=f;k=function(a,b,d){l.call(this,a,b);this.id=d};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=[],e;for(c=0;c<a.fields.length;c++){if(!m.isValidMessageField(a.fields[c]))return!1; | ||
e=parseInt(a.id,10);if(0<=f.indexOf(e))return!1;f.push(e)}}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,e,b,d,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)){e=new l.Message(this.ptr,f.name);if(f.fields&&0<f.fields.length)for(d=0;d<f.fields.length;d++){if(!m.isValidMessageField(f.fields[d]))throw Error("Not a valid message field definition in message "+ | ||
e.name+": "+JSON.stringify(f.fields[d]));if(f.fields[d].options){b=Object.keys(f.fields[d].options);for(h=0;h<b.length;h++){if(!g.NAME.test(b[h]))throw Error("Illegal field option name in message "+e.name+"#"+f.fields[d].name+": "+b[h]);if(!g.ID.test(""+f.fields[d].options[b[h]])&&!g.TYPEREF.test(f.fields[d].options[b[h]]))throw Error("Illegal field option value in message "+e.name+"#"+f.fields[d].name+"#"+b[h]+": "+f.fields[d].options[b[h]]);}}e.addChild(new l.Message.Field(e,f.fields[d].rule,f.fields[d].type, | ||
f.fields[d].name,f.fields[d].id,f.fields[d].options))}b=[];if("undefined"!=typeof f.enums&&0<f.enums.length)for(d=0;d<f.enums.length;d++)b.push(f.enums[d]);if(f.messages&&0<f.messages.length)for(d=0;d<f.messages.length;d++)b.push(f.messages[d]);this.ptr.addChild(e);0<b.length&&(c.push(a),a=b,this.ptr=e)}else if(m.isValidEnum(f)){e=new l.Enum(this.ptr,f.name);for(d=0;d<f.values.length;d++)e.addChild(new l.Enum.Value(e,f.values[d].name,f.values[d].id));this.ptr.addChild(e)}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,g){throw Error("This build of ProtoBuf.js does not include DotProto support. See: https://github.com/dcodeIO/ProtoBuf.js"); | ||
};h.protoFromFile=function(c,g,l){if(g&&"object"==typeof g)l=g,g=null;else if(!g||"function"!=typeof g)g=null;if(g)h.Util.fetch(c,function(c){g(h.protoFromString(c,l))});else return c=h.Util.fetch(c),null!==c?h.protoFromString(c,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); | ||
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, | ||
!0))};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(b){return b.toUpperCase().replace("_","")}),a=a.substring(0,1).toUpperCase()+a.substring(1),c=b.name.replace(/([A-Z])/g,function(b){return"_"+b});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;return d.encode(this,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);return 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);g.repeated?c.add(g.name,g.decode(f,d)):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)return n.cast(n.UINT32,parseInt(d, | ||
10));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||this.options.packed&&0== | ||
d.length)return b;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+")");}return b};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 n.cast(n.UINT32,b.readVarint32());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)");return b}};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,g){throw Error("This build of ProtoBuf.js does not include DotProto support. See: https://github.com/dcodeIO/ProtoBuf.js");};h.protoFromFile=function(c,g,l){if(g&&"object"==typeof g)l=g,g=null;else if(!g||"function"!=typeof g)g=null;if(g)h.Util.fetch(c,function(c){g(h.protoFromString(c, | ||
l))});else return c=h.Util.fetch(c),null!==c?h.protoFromString(c,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); |
@@ -359,3 +359,3 @@ // #ifdef UNDEFINED | ||
if (this[field.name] === null) this[field.name] = []; | ||
this[field.name].push(field.verifyValue(value)); | ||
this[field.name].push(field.verifyValue(value, true)); | ||
}; | ||
@@ -498,4 +498,3 @@ | ||
buffer = buffer || new ByteBuffer(); | ||
T.encode(this, buffer); | ||
return buffer.flip(); | ||
return T.encode(this, buffer).flip(); | ||
}; | ||
@@ -565,3 +564,4 @@ | ||
* @param {ProtoBuf.Builder.Message} message Built message to encode | ||
* @param {ByteBuffer} buffer BufferBuffer to write to | ||
* @param {ByteBuffer} buffer ByteBuffer to write to | ||
* @return {ByteBuffer} The ByteBuffer for chaining | ||
* @throws {string} If the message cannot be encoded | ||
@@ -575,2 +575,3 @@ * @expose | ||
} | ||
return buffer; | ||
}; | ||
@@ -598,3 +599,7 @@ | ||
} | ||
msg.set(field.name, field.decode(wireType, buffer)); | ||
if (field.repeated) { | ||
msg.add(field.name, field.decode(wireType, buffer)); | ||
} else{ | ||
msg.set(field.name, field.decode(wireType, buffer)); | ||
} | ||
} | ||
@@ -745,2 +750,3 @@ return msg; | ||
* @param {ByteBuffer} buffer ByteBuffer to encode to | ||
* @return {ByteBuffer} The ByteBuffer for chaining | ||
* @throws {Error} If the field cannot be encoded | ||
@@ -754,3 +760,3 @@ * @expose | ||
} | ||
if (value === null) return; // Optional omitted | ||
if (value === null || (this.options["packed"] && value.length == 0)) return buffer; // Optional omitted | ||
try { | ||
@@ -782,2 +788,3 @@ if (this.repeated) { | ||
} | ||
return buffer; | ||
}; | ||
@@ -844,2 +851,3 @@ | ||
* @param {ByteBuffer} buffer ByteBuffer to encode to | ||
* @return {ByteBuffer} The ByteBuffer for chaining | ||
* @throws {Error} If the value cannot be encoded | ||
@@ -895,2 +903,3 @@ * @expose | ||
} | ||
return buffer; | ||
}; | ||
@@ -897,0 +906,0 @@ |
@@ -265,2 +265,24 @@ /* | ||
}, | ||
// Inner messages test | ||
"innerrepeated": function(test) { | ||
try { | ||
var builder = ProtoBuf.protoFromFile(__dirname+"/innerrepeated.proto"); | ||
var root = builder.build(); | ||
var Outer = root.Outer; | ||
var Inner = root.Inner; | ||
var outer = new Outer({ inner: [new Inner(1), new Inner(2)] }); | ||
var bb = new ByteBuffer(8); | ||
outer.encode(bb); | ||
test.equal("<0A 02 08 01 0A 02 08 02>", bb.toHex()); | ||
var douter = Outer.decode(bb); | ||
test.ok(douter.inner instanceof Array); | ||
test.equal(douter.inner.length, 2); | ||
test.equal(douter.inner[0].inner_value, 1); | ||
test.equal(douter.inner[1].inner_value, 2); | ||
} catch (e) { | ||
fail(e); | ||
} | ||
test.done(); | ||
}, | ||
@@ -267,0 +289,0 @@ "commonjs": function(test) { |
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
692246
58
8716