protobufjs
Advanced tools
Comparing version 0.12.11 to 0.12.12
{ | ||
"name": "protobufjs", | ||
"version": "0.12.11", | ||
"version": "0.12.12", | ||
"description": "ProtoBuf.js: protobuf for JavaScript. No compilation step required, works out of the box.", | ||
@@ -35,3 +35,3 @@ "author": "Daniel Wirtz <dcode@dcode.io>", | ||
"prepublish": "npm test", | ||
"test": "nodeunit tests/suite.js", | ||
"test": "node node_modules/testjs/bin/testjs tests/suite.js", | ||
@@ -38,0 +38,0 @@ "make": "npm run-script build && npm run-script compile && npm test && npm run-script jsdoc", |
@@ -6,3 +6,3 @@ /* | ||
*/ | ||
(function(p){function q(n){if(!n||!n.zigZagEncode32)throw Error("ProtoBuf.js requires ByteBuffer.js >=1.1.0: Get it at https://github.com/dcodeIO/ByteBuffer.js");var f={VERSION:"0.12.11",WIRE_TYPES:{}};f.WIRE_TYPES.VARINT=0;f.WIRE_TYPES.BITS64=1;f.WIRE_TYPES.LDELIM=2;f.WIRE_TYPES.STARTGROUP=3;f.WIRE_TYPES.ENDGROUP=4;f.WIRE_TYPES.BITS32=5;f.TYPES={int32:{name:"int32",wireType:f.WIRE_TYPES.VARINT},uint32:{name:"uint32",wireType:f.WIRE_TYPES.VARINT},sint32:{name:"sint32",wireType:f.WIRE_TYPES.VARINT}, | ||
(function(p){function q(n){if(!n||!n.zigZagEncode32)throw Error("ProtoBuf.js requires ByteBuffer.js >=1.1.0: Get it at https://github.com/dcodeIO/ByteBuffer.js");var f={VERSION:"0.12.12",WIRE_TYPES:{}};f.WIRE_TYPES.VARINT=0;f.WIRE_TYPES.BITS64=1;f.WIRE_TYPES.LDELIM=2;f.WIRE_TYPES.STARTGROUP=3;f.WIRE_TYPES.ENDGROUP=4;f.WIRE_TYPES.BITS32=5;f.TYPES={int32:{name:"int32",wireType:f.WIRE_TYPES.VARINT},uint32:{name:"uint32",wireType:f.WIRE_TYPES.VARINT},sint32:{name:"sint32",wireType:f.WIRE_TYPES.VARINT}, | ||
int64:{name:"int64",wireType:f.WIRE_TYPES.VARINT},uint64:{name:"uint64",wireType:f.WIRE_TYPES.VARINT},sint64:{name:"sint64",wireType:f.WIRE_TYPES.VARINT},bool:{name:"bool",wireType:f.WIRE_TYPES.VARINT},"double":{name:"double",wireType:f.WIRE_TYPES.BITS64},string:{name:"string",wireType:f.WIRE_TYPES.LDELIM},bytes:{name:"bytes",wireType:f.WIRE_TYPES.LDELIM},fixed32:{name:"fixed32",wireType:f.WIRE_TYPES.BITS32},sfixed32:{name:"sfixed32",wireType:f.WIRE_TYPES.BITS32},fixed64:{name:"fixed64",wireType:f.WIRE_TYPES.BITS64}, | ||
@@ -29,3 +29,3 @@ sfixed64:{name:"sfixed64",wireType:f.WIRE_TYPES.BITS64},"float":{name:"float",wireType:f.WIRE_TYPES.BITS32},"enum":{name:"enum",wireType:f.WIRE_TYPES.VARINT},message:{name:"message",wireType:f.WIRE_TYPES.LDELIM}};f.Long=n.Long;f.Util=function(){Object.create||(Object.create=function(b){function c(){}if(1<arguments.length)throw Error("Object.create implementation only accepts the first parameter.");c.prototype=b;return new c});var c={};c.IS_NODE=("undefined"==typeof window||!window.window)&&"function"== | ||
c.name+": "+a+" ('"+b.EQUAL+"' expected)");a=this.tn.next();if(!b.ID.test(a))throw Error("Illegal enum value value in enum "+c.name+": "+a);d.id=parseInt(a,10);c.values.push(d);a=this.tn.next();a==b.OPTOPEN&&(this._parseFieldOptions(c,{options:{}},a),a=this.tn.next());if(a!=b.END)throw Error("Illegal enum value delimiter in enum "+c.name+": "+a+" ('"+b.END+"' expected)");};c.prototype.toString=function(){return"Parser"};return c}(f,f.Lang,f.DotProto.Tokenizer);f.Reflect=function(c){var b={},f=function(a, | ||
c){this.parent=a;this.name=c;this.resolvedType=null};f.prototype.toString=function(c){var l=this.name,d=this;do{d=d.parent;if(null==d)break;l=d.name+"."+l}while(1);c&&(this instanceof b.Message?l="Message "+l:this instanceof a.Field?l="Message.Field "+l:this instanceof e?l="Enum "+l:this instanceof e.Value?l="Enum.Value "+l:this instanceof h&&(l="Namespace "+l));return l};f.prototype.build=function(){throw Error(this.toString(!0)+" cannot be built directly");};b.T=f;var h=function(a,c,b){f.call(this, | ||
c){this.parent=a;this.name=c;this.resolvedType=null};f.prototype.toString=function(c){var k=this.name,d=this;do{d=d.parent;if(null==d)break;k=d.name+"."+k}while(1);c&&(this instanceof b.Message?k="Message "+k:this instanceof a.Field?k="Message.Field "+k:this instanceof e?k="Enum "+k:this instanceof e.Value?k="Enum.Value "+k:this instanceof h&&(k="Namespace "+k));return k};f.prototype.build=function(){throw Error(this.toString(!0)+" cannot be built directly");};b.T=f;var h=function(a,c,b){f.call(this, | ||
a,c);this.children=[];this.options=b||{}};h.prototype=Object.create(f.prototype);h.prototype.getChildren=function(a){a=a||null;if(null==a)return this.children.slice();for(var c=[],b=0;b<this.children.length;b++)this.children[b]instanceof a&&c.push(this.children[b]);return c};h.prototype.addChild=function(a){if(this.hasChild(a.name))throw Error("Duplicate name in namespace "+this.toString(!0)+": "+a.name);this.children.push(a)};h.prototype.hasChild=function(c){var b;if("number"==typeof c)for(b=0;b< | ||
@@ -35,8 +35,8 @@ 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= | ||
return a};h.prototype.buildOpt=function(){for(var a={},c=Object.keys(this.options),b=0;b<c.length;b++)a[c[b]]=this.options[c[b]];return a};h.prototype.getOption=function(a){return"undefined"==typeof a?this.options:"undefined"!=typeof this.options[a]?this.options[a]:null};b.Namespace=h;var a=function(a,c,b){h.call(this,a,c,b);this.built=null};a.prototype=Object.create(h.prototype);a.prototype.build=function(){for(var d=function(a,b){var d=b.getChildren(a.Message.Field),g=eval("(function "+b.name+"() { this.__construct.apply(this, arguments); })"); | ||
g.prototype.__construct=function(a){var b,g;for(b=0;b<d.length;b++)g=d[b],this[g.name]=g.repeated?[]:null;for(b=0;b<d.length;b++)if(g=d[b],"undefined"!=typeof g.options["default"])try{this.set(g.name,g.options["default"])}catch(l){throw Error("[INTERNAL ERROR] "+l);}if(1==arguments.length&&"object"==typeof a&&"function"!=typeof a.encode&&!(a instanceof Array)&&!(a instanceof n)&&!(a instanceof ArrayBuffer)&&!(c.Long&&a instanceof c.Long)){g=Object.keys(a);for(b=0;b<g.length;b++)this.set(g[b],a[g[b]])}else for(b= | ||
g.prototype.__construct=function(a){var b,g;for(b=0;b<d.length;b++)g=d[b],this[g.name]=g.repeated?[]:null;for(b=0;b<d.length;b++)if(g=d[b],"undefined"!=typeof g.options["default"])try{this.set(g.name,g.options["default"])}catch(k){throw Error("[INTERNAL ERROR] "+k);}if(1==arguments.length&&"object"==typeof a&&"function"!=typeof a.encode&&!(a instanceof Array)&&!(a instanceof n)&&!(a instanceof ArrayBuffer)&&!(c.Long&&a instanceof c.Long)){g=Object.keys(a);for(b=0;b<g.length;b++)this.set(g[b],a[g[b]])}else for(b= | ||
0;b<arguments.length;b++)b<d.length&&this.set(d[b].name,arguments[b])};g.prototype.add=function(c,d){var g=b.getChild(c);if(!g)throw Error(this+"#"+c+" is undefined");if(!(g instanceof a.Message.Field))throw Error(this+"#"+c+" is not a field: "+g.toString(!0));if(!g.repeated)throw Error(this+"#"+c+" is not a repeated field");null===this[g.name]&&(this[g.name]=[]);this[g.name].push(g.verifyValue(d,!0))};g.prototype.set=function(c,d){var g=b.getChild(c);if(!g)throw Error(this+"#"+c+" is not a field: undefined"); | ||
if(!(g instanceof a.Message.Field))throw Error(this+"#"+c+" is not a field: "+g.toString(!0));this[g.name]=g.verifyValue(d)};g.prototype.get=function(c){var g=b.getChild(c);if(!g||!(g instanceof a.Message.Field))throw Error(this+"#"+c+" is not a field: undefined");if(!(g instanceof a.Message.Field))throw Error(this+"#"+c+" is not a field: "+g.toString(!0));return this[g.name]};for(var l=0;l<d.length;l++)(function(a){var c=a.name.replace(/(_[a-zA-Z])/g,function(a){return a.toUpperCase().replace("_", | ||
"")}),c=c.substring(0,1).toUpperCase()+c.substring(1),d=a.name.replace(/([A-Z])/g,function(a){return"_"+a});b.hasChild("set"+c)||(g.prototype["set"+c]=function(b){this.set(a.name,b)});b.hasChild("set_"+d)||(g.prototype["set_"+d]=function(b){this.set(a.name,b)});b.hasChild("get"+c)||(g.prototype["get"+c]=function(){return this.get(a.name)});b.hasChild("get_"+d)||(g.prototype["get_"+d]=function(){return this.get(a.name)})})(d[l]);g.prototype.encode=function(a){a=a||new n;var c=a.littleEndian,g=b.encode(this, | ||
a.LE()).flip();a.littleEndian=c;return g};g.prototype.toArrayBuffer=function(){return this.encode().toArrayBuffer()};g.decode=function(a){a=a?a instanceof n?a:n.wrap(a):new n;var c=a.littleEndian,g=b.decode(a.LE());a.littleEndian=c;return g};g.prototype.toString=function(){return b.toString()};Object.defineProperty&&Object.defineProperty(g,"$options",{value:b.buildOpt(),enumerable:!1,configurable:!1,writable:!1});return g}(b,this),l=this.getChildren(),k=0;k<l.length;k++)if(l[k]instanceof e)d[l[k].name]= | ||
l[k].build();else if(l[k]instanceof a)d[l[k].name]=l[k].build();else if(!(l[k]instanceof a.Field))throw Error("Illegal reflect child of "+this.toString(!0)+": "+l[k].toString(!0));return this.built=d};a.prototype.encode=function(b,c){for(var d=this.getChildren(a.Field),e=0;e<d.length;e++)d[e].encode(b.get(d[e].name),c);return c};a.prototype.decode=function(a,c){c=c||-1;for(var d=a.offset,e=new this.built;a.offset<d+c||-1==c&&0<a.remaining();){var f=a.readVarint32(),h=f&7,f=f>>3,m=this.getChild(f); | ||
if(!(g instanceof a.Message.Field))throw Error(this+"#"+c+" is not a field: "+g.toString(!0));this[g.name]=g.verifyValue(d)};g.prototype.get=function(c){var g=b.getChild(c);if(!g||!(g instanceof a.Message.Field))throw Error(this+"#"+c+" is not a field: undefined");if(!(g instanceof a.Message.Field))throw Error(this+"#"+c+" is not a field: "+g.toString(!0));return this[g.name]};for(var k=0;k<d.length;k++)(function(a){var c=a.name.replace(/(_[a-zA-Z])/g,function(a){return a.toUpperCase().replace("_", | ||
"")}),c=c.substring(0,1).toUpperCase()+c.substring(1),d=a.name.replace(/([A-Z])/g,function(a){return"_"+a});b.hasChild("set"+c)||(g.prototype["set"+c]=function(b){this.set(a.name,b)});b.hasChild("set_"+d)||(g.prototype["set_"+d]=function(b){this.set(a.name,b)});b.hasChild("get"+c)||(g.prototype["get"+c]=function(){return this.get(a.name)});b.hasChild("get_"+d)||(g.prototype["get_"+d]=function(){return this.get(a.name)})})(d[k]);g.prototype.encode=function(a){a=a||new n;var c=a.littleEndian,g=b.encode(this, | ||
a.LE()).flip();a.littleEndian=c;return g};g.prototype.toArrayBuffer=function(){return this.encode().toArrayBuffer()};g.decode=function(a){a=a?a instanceof n?a:n.wrap(a):new n;var c=a.littleEndian,g=b.decode(a.LE());a.littleEndian=c;return g};g.prototype.toString=function(){return b.toString()};Object.defineProperty&&Object.defineProperty(g,"$options",{value:b.buildOpt(),enumerable:!1,configurable:!1,writable:!1});return g}(b,this),k=this.getChildren(),l=0;l<k.length;l++)if(k[l]instanceof e)d[k[l].name]= | ||
k[l].build();else if(k[l]instanceof a)d[k[l].name]=k[l].build();else if(!(k[l]instanceof a.Field))throw Error("Illegal reflect child of "+this.toString(!0)+": "+k[l].toString(!0));return this.built=d};a.prototype.encode=function(b,c){for(var d=this.getChildren(a.Field),e=0;e<d.length;e++)d[e].encode(b.get(d[e].name),c);return c};a.prototype.decode=function(a,c){c=c||-1;for(var d=a.offset,e=new this.built;a.offset<d+c||-1==c&&0<a.remaining();){var f=a.readVarint32(),h=f&7,f=f>>3,m=this.getChild(f); | ||
if(!m)throw Error("Illegal field id in "+this.toString(!0)+"#decode: "+f);m.repeated&&!m.options.packed?e.add(m.name,m.decode(h,a)):e.set(m.name,m.decode(h,a))}d=this.getChildren(b.Field);for(h=0;h<d.length;h++)if(d[h].required&&null===e[d[h].name])throw d=Error("Missing field "+d[h].toString(!0)+" in "+this.toString(!0)+"#decode"),d.msg=e,d;return e};b.Message=a;var d=function(a,b,c,d,e,h){f.call(this,a,d);this.required="required"==b;this.repeated="repeated"==b;this.type=c;this.id=e;this.options= | ||
@@ -49,17 +49,17 @@ h||{}};d.prototype=Object.create(f.prototype);d.prototype.verifyValue=function(a,b){b=b||!1;if(null===a){if(this.required)throw Error("Illegal value for "+this.toString(!0)+": "+a+" (required)");return null}var d,f;if(this.repeated&&!b){a instanceof Array||(a=[a]);f=[];for(d=0;d<a.length;d++)f.push(this.verifyValue(a[d],!0));return f}if(!this.repeated&&a instanceof Array)throw Error("Illegal value for "+this.toString(!0)+": "+a+" (no array expected)");if(this.type==c.TYPES.int32||this.type==c.TYPES.sint32|| | ||
a+" ("+p+")");}return b};d.prototype.encodeValue=function(a,b){if(null!==a){if(this.type==c.TYPES.int32||this.type==c.TYPES.uint32)b.writeVarint32(a);else if(this.type==c.TYPES.sint32)b.writeZigZagVarint32(a);else if(this.type==c.TYPES.fixed32)b.writeUint32(a);else if(this.type==c.TYPES.sfixed32)b.writeInt32(a);else if(this.type==c.TYPES.int64||this.type==c.TYPES.uint64)b.writeVarint64(a);else if(this.type==c.TYPES.sint64)b.writeZigZagVarint64(a);else if(this.type==c.TYPES.fixed64)b.writeUint64(a); | ||
else if(this.type==c.TYPES.sfixed64)b.writeInt64(a);else if(this.type==c.TYPES.bool)b.writeVarint32(a?1:0);else if(this.type==c.TYPES["enum"])b.writeVarint32(a);else if(this.type==c.TYPES["float"])b.writeFloat32(a);else if(this.type==c.TYPES["double"])b.writeFloat64(a);else if(this.type==c.TYPES.string)b.writeVString(a);else if(this.type==c.TYPES.bytes)a.offset>a.length&&(b=b.clone().flip()),b.writeVarint32(a.remaining()),b.append(a);else if(this.type==c.TYPES.message){var d=b.offset;b.writeUint8(0); | ||
this.resolvedType.encode(a,b);var e=b.offset-d-1,f=n.calculateVarint32(e);if(1<f){var h=b.clone().flip();h.offset=h.length-e;b.append(h,d+f)}b.writeVarint32(e,d)}else throw Error("[INTERNAL ERROR] Illegal value to encode in "+this.toString(!0)+": "+a+" (unknown type)");return b}};d.prototype.decode=function(a,b,d){if(a!=this.type.wireType&&(d||a!=c.WIRE_TYPES.LDELIM||!this.repeated))throw Error("Illegal wire type for field "+this.toString(!0)+": "+a+" ("+this.type.wireType+" expected)");if(a==c.WIRE_TYPES.LDELIM&& | ||
(this.repeated&&this.options.packed)&&!d){a=b.readVarint32();a=b.offset+a;for(d=[];b.offset<a;)d.push(this.decode(this.type.wireType,b,!0));return d}if(this.type==c.TYPES.int32)return b.readVarint32()|0;if(this.type==c.TYPES.uint32)return b.readVarint32()>>>0;if(this.type==c.TYPES.sint32)return b.readZigZagVarint32()|0;if(this.type==c.TYPES.fixed32)return b.readUint32()>>>0;if(this.type==c.TYPES.sfixed32)return b.readInt32()|0;if(this.type==c.TYPES.int64)return b.readVarint64();if(this.type==c.TYPES.uint64)return b.readVarint64().toUnsigned(); | ||
if(this.type==c.TYPES.sint64)return b.readZigZagVarint64();if(this.type==c.TYPES.fixed64)return b.readUint64();if(this.type==c.TYPES.sfixed64)return b.readInt64();if(this.type==c.TYPES.bool)return!!b.readVarint32();if(this.type==c.TYPES["enum"])return b.readVarint32();if(this.type==c.TYPES["float"])return b.readFloat();if(this.type==c.TYPES["double"])return b.readDouble();if(this.type==c.TYPES.string)return b.readVString();if(this.type==c.TYPES.bytes)return a=b.readVarint32(),d=b.clone(),d.length= | ||
d.offset+a,b.offset+=a,d;if(this.type==c.TYPES.message)return a=b.readVarint32(),this.resolvedType.decode(b,a);throw Error("[INTERNAL ERROR] Illegal wire type for "+this.toString(!0)+": "+a);};b.Message.Field=d;var e=function(a,b,c){h.call(this,a,b,c);this.built=null};e.prototype=Object.create(h.prototype);e.prototype.build=function(){for(var a={},b=this.getChildren(e.Value),c=0;c<b.length;c++)a[b[c].name]=b[c].id;Object.defineProperty&&Object.defineProperty(a,"$options",{value:this.buildOpt(),enumerable:!1, | ||
configurable:!1,writable:!1});return this.built=a};b.Enum=e;d=function(a,b,c){f.call(this,a,b);this.id=c};d.prototype=Object.create(f.prototype);b.Enum.Value=d;return b}(f);f.Builder=function(c,b,f){var h=function(){this.ptr=this.ns=new f.Namespace(null,"");this.resolved=!1;this.result=null};h.prototype.reset=function(){this.ptr=this.ns};h.prototype.define=function(a,c){if("string"!=typeof a||!b.TYPEDEF.test(a))throw Error("Illegal package name: "+a);var e=a.split("."),g;for(g=0;g<e.length;g++)if(!b.NAME.test(e[g]))throw Error("Illegal package name: "+ | ||
e[g]);for(g=0;g<e.length;g++)this.ptr.hasChild(e[g])||this.ptr.addChild(new f.Namespace(this.ptr,e[g],c)),this.ptr=this.ptr.getChild(e[g]);return this};h.isValidMessage=function(a){if("string"!=typeof a.name||!b.NAME.test(a.name)||"undefined"!=typeof a.values)return!1;var c;if("undefined"!=typeof a.fields){if(!(a.fields instanceof Array))return!1;var e=[],f;for(c=0;c<a.fields.length;c++){if(!h.isValidMessageField(a.fields[c]))return!1;f=parseInt(a.id,10);if(0<=e.indexOf(f))return!1;e.push(f)}}if("undefined"!= | ||
typeof a.enums){if(!(a.enums instanceof Array))return!1;for(c=0;c<a.enums.length;c++)if(!h.isValidEnum(a.enums[c]))return!1}if("undefined"!=typeof a.messages){if(!(a.messages instanceof Array))return!1;for(c=0;c<a.messages.length;c++)if(!h.isValidMessage(a.messages[c]))return!1}return!0};h.isValidMessageField=function(a){if("string"!=typeof a.rule||"string"!=typeof a.name||"string"!=typeof a.type||"undefined"==typeof a.id||!b.RULE.test(a.rule)||!b.NAME.test(a.name)||!b.TYPEREF.test(a.type)||!b.ID.test(""+ | ||
a.id))return!1;if("undefined"!=typeof a.options){if("object"!=typeof a.options)return!1;for(var c=Object.keys(a.options),e=0;e<c.length;e++)if(!b.NAME.test(c[e])||!b.ID.test(""+a.options[c[e]])&&!b.TYPEREF.test(a.options[c[e]]))return!1}return!0};h.isValidEnum=function(a){if("string"!=typeof a.name||!b.NAME.test(a.name)||"undefined"==typeof a.values||!(a.values instanceof Array)||0==a.values.length)return!1;for(var c=0;c<a.values.length;c++)if("object"!=typeof a.values[c]||"string"!=typeof a.values[c].name|| | ||
"undefined"==typeof a.values[c].id||!b.NAME.test(a.values[c].name)||!b.ID.test(""+a.values[c].id))return!1;return!0};h.prototype.create=function(a){if(a&&(a instanceof Array||(a=[a]),0!=a.length)){var c=[],e,g,l,k,n;for(c.push(a);0<c.length;){a=c.pop();if(a instanceof Array)for(;0<a.length;)if(e=a.shift(),h.isValidMessage(e)){g=new f.Message(this.ptr,e.name,e.options);if(e.fields&&0<e.fields.length)for(k=0;k<e.fields.length;k++){if(!h.isValidMessageField(e.fields[k]))throw Error("Not a valid message field definition in message "+ | ||
g.name+": "+JSON.stringify(e.fields[k]));if(g.hasChild(e.fields[k].id))throw Error("Duplicate field id in message "+g.name+": "+e.fields[k].id);if(e.fields[k].options){l=Object.keys(e.fields[k].options);for(n=0;n<l.length;n++){if(!b.NAME.test(l[n]))throw Error("Illegal field option name in message "+g.name+"#"+e.fields[k].name+": "+l[n]);if(!b.ID.test(""+e.fields[k].options[l[n]])&&!b.TYPEREF.test(e.fields[k].options[l[n]]))throw Error("Illegal field option value in message "+g.name+"#"+e.fields[k].name+ | ||
"#"+l[n]+": "+e.fields[k].options[l[n]]);}}g.addChild(new f.Message.Field(g,e.fields[k].rule,e.fields[k].type,e.fields[k].name,e.fields[k].id,e.fields[k].options))}l=[];if("undefined"!=typeof e.enums&&0<e.enums.length)for(k=0;k<e.enums.length;k++)l.push(e.enums[k]);if(e.messages&&0<e.messages.length)for(k=0;k<e.messages.length;k++)l.push(e.messages[k]);this.ptr.addChild(g);0<l.length&&(c.push(a),a=l,this.ptr=g)}else if(h.isValidEnum(e)){g=new f.Enum(this.ptr,e.name,e.options);for(k=0;k<e.values.length;k++)g.addChild(new f.Enum.Value(g, | ||
e.values[k].name,e.values[k].id));this.ptr.addChild(g)}else throw Error("Not a valid message or enum definition: "+JSON.stringify(e));else throw Error("Not a valid namespace definition: "+JSON.stringify(a));this.ptr=this.ptr.parent}this.resolved=!1;this.result=null;return this}};h.prototype["import"]=function(a,b){a["package"]&&this.define(a["package"],a.options);a.messages&&this.create(a.messages);this.reset();a["package"]&&this.define(a["package"],a.options);a.enums&&this.create(a.enums);this.reset(); | ||
if(a.imports&&0<a.imports.length){if(!b)throw Error("Cannot determine import root: File name is unknown");for(var e=b.replace(/[\/\\][^\/\\]*$/,""),f=0;f<a.imports.length;f++){var h=e+"/"+a.imports[f];if(/\.json$/i.test(h)){var k=c.Util.fetch(h);if(null===k)throw Error("Failed to import '"+h+"' in '"+b+"': File not found");this["import"](JSON.parse(k),h)}else if(!/google\/protobuf\//.test(h)){k=c.Util.fetch(h);if(null===k)throw Error("Failed to import '"+h+"' in '"+b+"': File not found");k=new c.DotProto.Parser(k+ | ||
"");this["import"](k.parse(),h)}}}return this};h.prototype.resolveAll=function(){if(!(null==this.ptr||"object"==typeof this.ptr.type)){if(this.ptr instanceof f.Namespace)for(var a=this.ptr.getChildren(),d=0;d<a.length;d++)this.ptr=a[d],this.resolveAll();else if(this.ptr instanceof f.Message.Field)if(b.TYPE.test(this.ptr.type))this.ptr.type=c.TYPES[this.ptr.type];else{if(!b.TYPEREF.test(this.ptr.type))throw Error("Illegal type reference in "+this.ptr.toString(!0)+": "+this.ptr.type);a=this.ptr.parent.resolve(this.ptr.type); | ||
else if(this.type==c.TYPES.sfixed64)b.writeInt64(a);else if(this.type==c.TYPES.bool)b.writeVarint32(a?1:0);else if(this.type==c.TYPES["enum"])b.writeVarint32(a);else if(this.type==c.TYPES["float"])b.writeFloat32(a);else if(this.type==c.TYPES["double"])b.writeFloat64(a);else if(this.type==c.TYPES.string)b.writeVString(a);else if(this.type==c.TYPES.bytes)a.offset>a.length&&(b=b.clone().flip()),b.writeVarint32(a.remaining()),b.append(a);else if(this.type==c.TYPES.message){var d=new n;this.resolvedType.encode(a, | ||
d);b.writeVarint32(d.offset);b.append(d.flip())}else throw Error("[INTERNAL ERROR] Illegal value to encode in "+this.toString(!0)+": "+a+" (unknown type)");return b}};d.prototype.decode=function(a,b,d){if(a!=this.type.wireType&&(d||a!=c.WIRE_TYPES.LDELIM||!this.repeated))throw Error("Illegal wire type for field "+this.toString(!0)+": "+a+" ("+this.type.wireType+" expected)");if(a==c.WIRE_TYPES.LDELIM&&(this.repeated&&this.options.packed)&&!d){a=b.readVarint32();a=b.offset+a;for(d=[];b.offset<a;)d.push(this.decode(this.type.wireType, | ||
b,!0));return d}if(this.type==c.TYPES.int32)return b.readVarint32()|0;if(this.type==c.TYPES.uint32)return b.readVarint32()>>>0;if(this.type==c.TYPES.sint32)return b.readZigZagVarint32()|0;if(this.type==c.TYPES.fixed32)return b.readUint32()>>>0;if(this.type==c.TYPES.sfixed32)return b.readInt32()|0;if(this.type==c.TYPES.int64)return b.readVarint64();if(this.type==c.TYPES.uint64)return b.readVarint64().toUnsigned();if(this.type==c.TYPES.sint64)return b.readZigZagVarint64();if(this.type==c.TYPES.fixed64)return b.readUint64(); | ||
if(this.type==c.TYPES.sfixed64)return b.readInt64();if(this.type==c.TYPES.bool)return!!b.readVarint32();if(this.type==c.TYPES["enum"])return b.readVarint32();if(this.type==c.TYPES["float"])return b.readFloat();if(this.type==c.TYPES["double"])return b.readDouble();if(this.type==c.TYPES.string)return b.readVString();if(this.type==c.TYPES.bytes)return a=b.readVarint32(),d=b.clone(),d.length=d.offset+a,b.offset+=a,d;if(this.type==c.TYPES.message)return a=b.readVarint32(),this.resolvedType.decode(b,a); | ||
throw Error("[INTERNAL ERROR] Illegal wire type for "+this.toString(!0)+": "+a);};b.Message.Field=d;var e=function(a,b,c){h.call(this,a,b,c);this.built=null};e.prototype=Object.create(h.prototype);e.prototype.build=function(){for(var a={},b=this.getChildren(e.Value),c=0;c<b.length;c++)a[b[c].name]=b[c].id;Object.defineProperty&&Object.defineProperty(a,"$options",{value:this.buildOpt(),enumerable:!1,configurable:!1,writable:!1});return this.built=a};b.Enum=e;d=function(a,b,c){f.call(this,a,b);this.id= | ||
c};d.prototype=Object.create(f.prototype);b.Enum.Value=d;return b}(f);f.Builder=function(c,b,f){var h=function(){this.ptr=this.ns=new f.Namespace(null,"");this.resolved=!1;this.result=null};h.prototype.reset=function(){this.ptr=this.ns};h.prototype.define=function(a,c){if("string"!=typeof a||!b.TYPEDEF.test(a))throw Error("Illegal package name: "+a);var e=a.split("."),g;for(g=0;g<e.length;g++)if(!b.NAME.test(e[g]))throw Error("Illegal package name: "+e[g]);for(g=0;g<e.length;g++)this.ptr.hasChild(e[g])|| | ||
this.ptr.addChild(new f.Namespace(this.ptr,e[g],c)),this.ptr=this.ptr.getChild(e[g]);return this};h.isValidMessage=function(a){if("string"!=typeof a.name||!b.NAME.test(a.name)||"undefined"!=typeof a.values)return!1;var c;if("undefined"!=typeof a.fields){if(!(a.fields instanceof Array))return!1;var e=[],g;for(c=0;c<a.fields.length;c++){if(!h.isValidMessageField(a.fields[c]))return!1;g=parseInt(a.id,10);if(0<=e.indexOf(g))return!1;e.push(g)}}if("undefined"!=typeof a.enums){if(!(a.enums instanceof Array))return!1; | ||
for(c=0;c<a.enums.length;c++)if(!h.isValidEnum(a.enums[c]))return!1}if("undefined"!=typeof a.messages){if(!(a.messages instanceof Array))return!1;for(c=0;c<a.messages.length;c++)if(!h.isValidMessage(a.messages[c]))return!1}return!0};h.isValidMessageField=function(a){if("string"!=typeof a.rule||"string"!=typeof a.name||"string"!=typeof a.type||"undefined"==typeof a.id||!b.RULE.test(a.rule)||!b.NAME.test(a.name)||!b.TYPEREF.test(a.type)||!b.ID.test(""+a.id))return!1;if("undefined"!=typeof a.options){if("object"!= | ||
typeof a.options)return!1;for(var c=Object.keys(a.options),e=0;e<c.length;e++)if(!b.NAME.test(c[e])||!b.ID.test(""+a.options[c[e]])&&!b.TYPEREF.test(a.options[c[e]]))return!1}return!0};h.isValidEnum=function(a){if("string"!=typeof a.name||!b.NAME.test(a.name)||"undefined"==typeof a.values||!(a.values instanceof Array)||0==a.values.length)return!1;for(var c=0;c<a.values.length;c++)if("object"!=typeof a.values[c]||"string"!=typeof a.values[c].name||"undefined"==typeof a.values[c].id||!b.NAME.test(a.values[c].name)|| | ||
!b.ID.test(""+a.values[c].id))return!1;return!0};h.prototype.create=function(a){if(a&&(a instanceof Array||(a=[a]),0!=a.length)){var c=[],e,g,k,l,n;for(c.push(a);0<c.length;){a=c.pop();if(a instanceof Array)for(;0<a.length;)if(e=a.shift(),h.isValidMessage(e)){g=new f.Message(this.ptr,e.name,e.options);if(e.fields&&0<e.fields.length)for(l=0;l<e.fields.length;l++){if(!h.isValidMessageField(e.fields[l]))throw Error("Not a valid message field definition in message "+g.name+": "+JSON.stringify(e.fields[l])); | ||
if(g.hasChild(e.fields[l].id))throw Error("Duplicate field id in message "+g.name+": "+e.fields[l].id);if(e.fields[l].options){k=Object.keys(e.fields[l].options);for(n=0;n<k.length;n++){if(!b.NAME.test(k[n]))throw Error("Illegal field option name in message "+g.name+"#"+e.fields[l].name+": "+k[n]);if(!b.ID.test(""+e.fields[l].options[k[n]])&&!b.TYPEREF.test(e.fields[l].options[k[n]]))throw Error("Illegal field option value in message "+g.name+"#"+e.fields[l].name+"#"+k[n]+": "+e.fields[l].options[k[n]]); | ||
}}g.addChild(new f.Message.Field(g,e.fields[l].rule,e.fields[l].type,e.fields[l].name,e.fields[l].id,e.fields[l].options))}k=[];if("undefined"!=typeof e.enums&&0<e.enums.length)for(l=0;l<e.enums.length;l++)k.push(e.enums[l]);if(e.messages&&0<e.messages.length)for(l=0;l<e.messages.length;l++)k.push(e.messages[l]);this.ptr.addChild(g);0<k.length&&(c.push(a),a=k,this.ptr=g)}else if(h.isValidEnum(e)){g=new f.Enum(this.ptr,e.name,e.options);for(l=0;l<e.values.length;l++)g.addChild(new f.Enum.Value(g,e.values[l].name, | ||
e.values[l].id));this.ptr.addChild(g)}else throw Error("Not a valid message or enum definition: "+JSON.stringify(e));else throw Error("Not a valid namespace definition: "+JSON.stringify(a));this.ptr=this.ptr.parent}this.resolved=!1;this.result=null;return this}};h.prototype["import"]=function(a,b){a["package"]&&this.define(a["package"],a.options);a.messages&&this.create(a.messages);this.reset();a["package"]&&this.define(a["package"],a.options);a.enums&&this.create(a.enums);this.reset();if(a.imports&& | ||
0<a.imports.length){if(!b)throw Error("Cannot determine import root: File name is unknown");for(var e=b.replace(/[\/\\][^\/\\]*$/,""),g=0;g<a.imports.length;g++){var f=e+"/"+a.imports[g];if(/\.json$/i.test(f)){var h=c.Util.fetch(f);if(null===h)throw Error("Failed to import '"+f+"' in '"+b+"': File not found");this["import"](JSON.parse(h),f)}else if(!/google\/protobuf\//.test(f)){h=c.Util.fetch(f);if(null===h)throw Error("Failed to import '"+f+"' in '"+b+"': File not found");h=new c.DotProto.Parser(h+ | ||
"");this["import"](h.parse(),f)}}}return this};h.prototype.resolveAll=function(){if(!(null==this.ptr||"object"==typeof this.ptr.type)){if(this.ptr instanceof f.Namespace)for(var a=this.ptr.getChildren(),d=0;d<a.length;d++)this.ptr=a[d],this.resolveAll();else if(this.ptr instanceof f.Message.Field)if(b.TYPE.test(this.ptr.type))this.ptr.type=c.TYPES[this.ptr.type];else{if(!b.TYPEREF.test(this.ptr.type))throw Error("Illegal type reference in "+this.ptr.toString(!0)+": "+this.ptr.type);a=this.ptr.parent.resolve(this.ptr.type); | ||
if(!a)throw Error("Unresolvable type reference in "+this.ptr.toString(!0)+": "+this.ptr.type);this.ptr.resolvedType=a;if(a instanceof f.Enum)this.ptr.type=c.TYPES["enum"];else if(a instanceof f.Message)this.ptr.type=c.TYPES.message;else throw Error("Illegal type reference in "+this.ptr.toString(!0)+": "+this.ptr.type);}else if(!(this.ptr instanceof c.Reflect.Enum.Value))throw Error("Illegal object type in namespace: "+typeof this.ptr+":"+this.ptr);this.reset()}};h.prototype.build=function(a){this.reset(); | ||
@@ -66,0 +66,0 @@ this.resolved||(this.resolveAll(),this.resolved=!0,this.result=null);null==this.result&&(this.result=this.ns.build());if(a){a=a.split(".");for(var b=this.result,c=0;c<a.length;c++)if(b[a[c]])b=b[a[c]];else{b=null;break}return b}return this.result};h.prototype.toString=function(){return"Builder"};return h}(f,f.Lang,f.Reflect);f.protoFromString=function(c,b,m){"string"==typeof b&&(m=b,b=null);c=(new f.DotProto.Parser(c+"")).parse();b="object"==typeof b?b:new f.Builder;null!==c["package"]&&b.define(c["package"], |
@@ -6,43 +6,43 @@ /* | ||
*/ | ||
(function(p){function q(l){if(!l||!l.zigZagEncode32)throw Error("ProtoBuf.js requires ByteBuffer.js >=1.1.0: Get it at https://github.com/dcodeIO/ByteBuffer.js");var f={VERSION:"0.12.11",WIRE_TYPES:{}};f.WIRE_TYPES.VARINT=0;f.WIRE_TYPES.BITS64=1;f.WIRE_TYPES.LDELIM=2;f.WIRE_TYPES.STARTGROUP=3;f.WIRE_TYPES.ENDGROUP=4;f.WIRE_TYPES.BITS32=5;f.TYPES={int32:{name:"int32",wireType:f.WIRE_TYPES.VARINT},uint32:{name:"uint32",wireType:f.WIRE_TYPES.VARINT},sint32:{name:"sint32",wireType:f.WIRE_TYPES.VARINT}, | ||
(function(p){function q(l){if(!l||!l.zigZagEncode32)throw Error("ProtoBuf.js requires ByteBuffer.js >=1.1.0: Get it at https://github.com/dcodeIO/ByteBuffer.js");var f={VERSION:"0.12.12",WIRE_TYPES:{}};f.WIRE_TYPES.VARINT=0;f.WIRE_TYPES.BITS64=1;f.WIRE_TYPES.LDELIM=2;f.WIRE_TYPES.STARTGROUP=3;f.WIRE_TYPES.ENDGROUP=4;f.WIRE_TYPES.BITS32=5;f.TYPES={int32:{name:"int32",wireType:f.WIRE_TYPES.VARINT},uint32:{name:"uint32",wireType:f.WIRE_TYPES.VARINT},sint32:{name:"sint32",wireType:f.WIRE_TYPES.VARINT}, | ||
int64:{name:"int64",wireType:f.WIRE_TYPES.VARINT},uint64:{name:"uint64",wireType:f.WIRE_TYPES.VARINT},sint64:{name:"sint64",wireType:f.WIRE_TYPES.VARINT},bool:{name:"bool",wireType:f.WIRE_TYPES.VARINT},"double":{name:"double",wireType:f.WIRE_TYPES.BITS64},string:{name:"string",wireType:f.WIRE_TYPES.LDELIM},bytes:{name:"bytes",wireType:f.WIRE_TYPES.LDELIM},fixed32:{name:"fixed32",wireType:f.WIRE_TYPES.BITS32},sfixed32:{name:"sfixed32",wireType:f.WIRE_TYPES.BITS32},fixed64:{name:"fixed64",wireType:f.WIRE_TYPES.BITS64}, | ||
sfixed64:{name:"sfixed64",wireType:f.WIRE_TYPES.BITS64},"float":{name:"float",wireType:f.WIRE_TYPES.BITS32},"enum":{name:"enum",wireType:f.WIRE_TYPES.VARINT},message:{name:"message",wireType:f.WIRE_TYPES.LDELIM}};f.Long=l.Long;f.Util=function(){Object.create||(Object.create=function(c){function k(){}if(1<arguments.length)throw Error("Object.create implementation only accepts the first parameter.");k.prototype=c;return new k});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")}],k=null,f=0;f<c.length;f++){try{k=c[f]()}catch(a){continue}break}if(!k)throw Error("XMLHttpRequest is not supported");return k};c.fetch=function(n,f){f&&"function"!=typeof f&&(f=null);if(c.IS_NODE)if(f)require("fs").readFile(n,function(a,c){a?f(null):f(""+ | ||
c)});else try{return require("fs").readFileSync(n)}catch(h){return null}else{var a=c.XHR();a.open("GET",n,f?!0:!1);a.setRequestHeader("User-Agent","XMLHTTP/1.0");a.setRequestHeader("Accept","text/plain");if(f)a.onreadystatechange=function(){4==a.readyState&&(200==a.status?f(a.responseText):f(null))},4!=a.readyState&&a.send(null);else return a.send(null),a.responseText}};return c}();f.Lang={OPEN:"{",CLOSE:"}",OPTOPEN:"[",OPTCLOSE:"]",OPTEND:",",EQUAL:"=",END:";",DELIM:/[\s\{\}=;\[\],"\(\)]/g,KEYWORD:/package|option|import|message|enum|extend|service/, | ||
RULE:/required|optional|repeated/,TYPE:/double|float|int32|uint32|sint32|int64|uint64|sint64|fixed32|sfixed32|fixed64|sfixed64|bool|string|bytes/,NAME:/[a-zA-Z][a-zA-Z_0-9]*/,TYPEDEF:/[a-zA-Z](\.?[a-zA-Z_0-9])*/,TYPEREF:/\.?[a-zA-Z](\.?[a-zA-Z_0-9])*/,NUMBER:/^-?([1-9][0-9]*)|0$/,ID:/[0-9]+/,WHITESPACE:/\s/,STRING:/"([^"\\]*(\\.[^"\\]*)*)"/g,STRINGOPEN:'"',STRINGCLOSE:'"',COPTOPEN:"(",COPTCLOSE:")"};f.Reflect=function(c){var f={},k=function(b,d){this.parent=b;this.name=d;this.resolvedType=null};k.prototype.toString= | ||
function(b){var d=this.name,e=this;do{e=e.parent;if(null==e)break;d=e.name+"."+d}while(1);b&&(this instanceof f.Message?d="Message "+d:this instanceof a.Field?d="Message.Field "+d:this instanceof g?d="Enum "+d:this instanceof g.Value?d="Enum.Value "+d:this instanceof h&&(d="Namespace "+d));return d};k.prototype.build=function(){throw Error(this.toString(!0)+" cannot be built directly");};f.T=k;var h=function(b,d,e){k.call(this,b,d);this.children=[];this.options=e||{}};h.prototype=Object.create(k.prototype); | ||
h.prototype.getChildren=function(b){b=b||null;if(null==b)return this.children.slice();for(var d=[],e=0;e<this.children.length;e++)this.children[e]instanceof b&&d.push(this.children[e]);return d};h.prototype.addChild=function(b){if(this.hasChild(b.name))throw Error("Duplicate name in namespace "+this.toString(!0)+": "+b.name);this.children.push(b)};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(b){var d=b.split("."),e=this,a=0;if(""==d[a]){for(;null!=e.parent;)e=e.parent;a++}do{do{e= | ||
e.getChild(d[a]);if(!e||!(e instanceof f.T)){e=null;break}a++}while(a<d.length);if(null!=e)break;if(null!==this.parent)return this.parent.resolve(b)}while(null!=e);return e};h.prototype.build=function(){for(var b={},d=this.getChildren(),e,a=0;a<d.length;a++)e=d[a],e instanceof h&&(b[e.name]=e.build());Object.defineProperty&&Object.defineProperty(b,"$options",{value:this.buildOpt(),enumerable:!1,configurable:!1,writable:!1});return b};h.prototype.buildOpt=function(){for(var b={},d=Object.keys(this.options), | ||
e=0;e<d.length;e++)b[d[e]]=this.options[d[e]];return b};h.prototype.getOption=function(b){return"undefined"==typeof b?this.options:"undefined"!=typeof this.options[b]?this.options[b]:null};f.Namespace=h;var a=function(b,d,e){h.call(this,b,d,e);this.built=null};a.prototype=Object.create(h.prototype);a.prototype.build=function(){for(var b=function(b,d){var e=d.getChildren(b.Message.Field),a=eval("(function "+d.name+"() { this.__construct.apply(this, arguments); })");a.prototype.__construct=function(d){var b, | ||
a;for(b=0;b<e.length;b++)a=e[b],this[a.name]=a.repeated?[]:null;for(b=0;b<e.length;b++)if(a=e[b],"undefined"!=typeof a.options["default"])try{this.set(a.name,a.options["default"])}catch(g){throw Error("[INTERNAL ERROR] "+g);}if(1==arguments.length&&"object"==typeof d&&"function"!=typeof d.encode&&!(d instanceof Array)&&!(d instanceof l)&&!(d instanceof ArrayBuffer)&&!(c.Long&&d instanceof c.Long)){a=Object.keys(d);for(b=0;b<a.length;b++)this.set(a[b],d[a[b]])}else for(b=0;b<arguments.length;b++)b< | ||
e.length&&this.set(e[b].name,arguments[b])};a.prototype.add=function(a,e){var c=d.getChild(a);if(!c)throw Error(this+"#"+a+" is undefined");if(!(c instanceof b.Message.Field))throw Error(this+"#"+a+" is not a field: "+c.toString(!0));if(!c.repeated)throw Error(this+"#"+a+" is not a repeated field");null===this[c.name]&&(this[c.name]=[]);this[c.name].push(c.verifyValue(e,!0))};a.prototype.set=function(a,e){var c=d.getChild(a);if(!c)throw Error(this+"#"+a+" is not a field: undefined");if(!(c instanceof | ||
b.Message.Field))throw Error(this+"#"+a+" is not a field: "+c.toString(!0));this[c.name]=c.verifyValue(e)};a.prototype.get=function(a){var e=d.getChild(a);if(!e||!(e instanceof b.Message.Field))throw Error(this+"#"+a+" is not a field: undefined");if(!(e instanceof b.Message.Field))throw Error(this+"#"+a+" is not a field: "+e.toString(!0));return this[e.name]};for(var g=0;g<e.length;g++)(function(b){var e=b.name.replace(/(_[a-zA-Z])/g,function(b){return b.toUpperCase().replace("_","")}),e=e.substring(0, | ||
1).toUpperCase()+e.substring(1),c=b.name.replace(/([A-Z])/g,function(b){return"_"+b});d.hasChild("set"+e)||(a.prototype["set"+e]=function(d){this.set(b.name,d)});d.hasChild("set_"+c)||(a.prototype["set_"+c]=function(d){this.set(b.name,d)});d.hasChild("get"+e)||(a.prototype["get"+e]=function(){return this.get(b.name)});d.hasChild("get_"+c)||(a.prototype["get_"+c]=function(){return this.get(b.name)})})(e[g]);a.prototype.encode=function(b){b=b||new l;var a=b.littleEndian,e=d.encode(this,b.LE()).flip(); | ||
b.littleEndian=a;return e};a.prototype.toArrayBuffer=function(){return this.encode().toArrayBuffer()};a.decode=function(b){b=b?b instanceof l?b:l.wrap(b):new l;var a=b.littleEndian,e=d.decode(b.LE());b.littleEndian=a;return e};a.prototype.toString=function(){return d.toString()};Object.defineProperty&&Object.defineProperty(a,"$options",{value:d.buildOpt(),enumerable:!1,configurable:!1,writable:!1});return a}(f,this),d=this.getChildren(),e=0;e<d.length;e++)if(d[e]instanceof g)b[d[e].name]=d[e].build(); | ||
else if(d[e]instanceof a)b[d[e].name]=d[e].build();else if(!(d[e]instanceof a.Field))throw Error("Illegal reflect child of "+this.toString(!0)+": "+d[e].toString(!0));return this.built=b};a.prototype.encode=function(b,d){for(var e=this.getChildren(a.Field),c=0;c<e.length;c++)e[c].encode(b.get(e[c].name),d);return d};a.prototype.decode=function(b,d){d=d||-1;for(var a=b.offset,c=new this.built;b.offset<a+d||-1==d&&0<b.remaining();){var g=b.readVarint32(),m=g&7,g=g>>3,h=this.getChild(g);if(!h)throw Error("Illegal field id in "+ | ||
this.toString(!0)+"#decode: "+g);h.repeated&&!h.options.packed?c.add(h.name,h.decode(m,b)):c.set(h.name,h.decode(m,b))}a=this.getChildren(f.Field);for(m=0;m<a.length;m++)if(a[m].required&&null===c[a[m].name])throw a=Error("Missing field "+a[m].toString(!0)+" in "+this.toString(!0)+"#decode"),a.msg=c,a;return c};f.Message=a;var m=function(b,d,a,c,g,f){k.call(this,b,c);this.required="required"==d;this.repeated="repeated"==d;this.type=a;this.id=g;this.options=f||{}};m.prototype=Object.create(k.prototype); | ||
m.prototype.verifyValue=function(b,d){d=d||!1;if(null===b){if(this.required)throw Error("Illegal value for "+this.toString(!0)+": "+b+" (required)");return null}var a,f;if(this.repeated&&!d){b instanceof Array||(b=[b]);f=[];for(a=0;a<b.length;a++)f.push(this.verifyValue(b[a],!0));return f}if(!this.repeated&&b instanceof Array)throw Error("Illegal value for "+this.toString(!0)+": "+b+" (no array expected)");if(this.type==c.TYPES.int32||this.type==c.TYPES.sint32||this.type==c.TYPES.sfixed32)return parseInt(b, | ||
10)|0;if(this.type==c.TYPES.uint32||this.type==c.TYPES.fixed32)return parseInt(b,10)>>>0;if(c.Long){if(this.type==c.TYPES.int64||this.type==c.TYPES.sint64||this.type==c.TYPES.sfixed64)return!("object"==typeof b&&b instanceof c.Long)?c.Long.fromNumber(b,!1):b.unsigned?b.toSigned():b;if(this.type==c.TYPES.uint64||this.type==c.TYPES.fixed64)return!("object"==typeof b&&b instanceof c.Long)?c.Long.fromNumber(b,!0):b.unsigned?b:b.toUnsigned()}if(this.type==c.TYPES.bool)return!!b;if(this.type==c.TYPES["float"]|| | ||
this.type==c.TYPES["double"])return parseFloat(b);if(this.type==c.TYPES.string)return""+b;if(this.type==c.TYPES.bytes)return"object"==typeof b&&b instanceof l?b:l.wrap(b);if(this.type==c.TYPES["enum"]){f=this.resolvedType.getChildren(g.Value);for(a=0;a<f.length;a++)if(f[a].name==b||f[a].id==b)return f[a].id;throw Error("Illegal value for "+this.toString(!0)+": "+b+" (not a valid enum value)");}if(this.type==c.TYPES.message){if("object"!=typeof b)throw Error("Illegal value for "+this.toString(!0)+ | ||
": "+b+" (object expected)");return b instanceof this.resolvedType.built?b:new this.resolvedType.built(b)}throw Error("[INTERNAL ERROR] Illegal value for "+this.toString(!0)+": "+b+" (undefined type "+this.type+")");};m.prototype.encode=function(b,d){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||this.repeated&&0==b.length)return d;try{if(this.repeated){var a;if(this.options.packed){d.writeVarint32(this.id<< | ||
3|c.WIRE_TYPES.LDELIM);d.ensureCapacity(d.offset+=1);var g=d.offset;for(a=0;a<b.length;a++)this.encodeValue(b[a],d);var f=d.offset-g,m=l.calculateVarint32(f);if(1<m){var h=d.slice(g,d.offset),g=g+(m-1);d.offset=g;d.append(h)}d.writeVarint32(f,g-m)}else for(a=0;a<b.length;a++)d.writeVarint32(this.id<<3|this.type.wireType),this.encodeValue(b[a],d)}else d.writeVarint32(this.id<<3|this.type.wireType),this.encodeValue(b,d)}catch(n){throw d.littleEndian=le,Error("Illegal value for "+this.toString(!0)+": "+ | ||
b+" ("+n+")");}return d};m.prototype.encodeValue=function(b,a){if(null!==b){if(this.type==c.TYPES.int32||this.type==c.TYPES.uint32)a.writeVarint32(b);else if(this.type==c.TYPES.sint32)a.writeZigZagVarint32(b);else if(this.type==c.TYPES.fixed32)a.writeUint32(b);else if(this.type==c.TYPES.sfixed32)a.writeInt32(b);else if(this.type==c.TYPES.int64||this.type==c.TYPES.uint64)a.writeVarint64(b);else if(this.type==c.TYPES.sint64)a.writeZigZagVarint64(b);else if(this.type==c.TYPES.fixed64)a.writeUint64(b); | ||
else if(this.type==c.TYPES.sfixed64)a.writeInt64(b);else if(this.type==c.TYPES.bool)a.writeVarint32(b?1:0);else if(this.type==c.TYPES["enum"])a.writeVarint32(b);else if(this.type==c.TYPES["float"])a.writeFloat32(b);else if(this.type==c.TYPES["double"])a.writeFloat64(b);else if(this.type==c.TYPES.string)a.writeVString(b);else if(this.type==c.TYPES.bytes)b.offset>b.length&&(a=a.clone().flip()),a.writeVarint32(b.remaining()),a.append(b);else if(this.type==c.TYPES.message){var e=a.offset;a.writeUint8(0); | ||
this.resolvedType.encode(b,a);var g=a.offset-e-1,f=l.calculateVarint32(g);if(1<f){var m=a.clone().flip();m.offset=m.length-g;a.append(m,e+f)}a.writeVarint32(g,e)}else throw Error("[INTERNAL ERROR] Illegal value to encode in "+this.toString(!0)+": "+b+" (unknown type)");return a}};m.prototype.decode=function(b,a,e){if(b!=this.type.wireType&&(e||b!=c.WIRE_TYPES.LDELIM||!this.repeated))throw Error("Illegal wire type for field "+this.toString(!0)+": "+b+" ("+this.type.wireType+" expected)");if(b==c.WIRE_TYPES.LDELIM&& | ||
(this.repeated&&this.options.packed)&&!e){b=a.readVarint32();b=a.offset+b;for(e=[];a.offset<b;)e.push(this.decode(this.type.wireType,a,!0));return e}if(this.type==c.TYPES.int32)return a.readVarint32()|0;if(this.type==c.TYPES.uint32)return a.readVarint32()>>>0;if(this.type==c.TYPES.sint32)return a.readZigZagVarint32()|0;if(this.type==c.TYPES.fixed32)return a.readUint32()>>>0;if(this.type==c.TYPES.sfixed32)return a.readInt32()|0;if(this.type==c.TYPES.int64)return a.readVarint64();if(this.type==c.TYPES.uint64)return a.readVarint64().toUnsigned(); | ||
if(this.type==c.TYPES.sint64)return a.readZigZagVarint64();if(this.type==c.TYPES.fixed64)return a.readUint64();if(this.type==c.TYPES.sfixed64)return a.readInt64();if(this.type==c.TYPES.bool)return!!a.readVarint32();if(this.type==c.TYPES["enum"])return a.readVarint32();if(this.type==c.TYPES["float"])return a.readFloat();if(this.type==c.TYPES["double"])return a.readDouble();if(this.type==c.TYPES.string)return a.readVString();if(this.type==c.TYPES.bytes)return b=a.readVarint32(),e=a.clone(),e.length= | ||
e.offset+b,a.offset+=b,e;if(this.type==c.TYPES.message)return b=a.readVarint32(),this.resolvedType.decode(a,b);throw Error("[INTERNAL ERROR] Illegal wire type for "+this.toString(!0)+": "+b);};f.Message.Field=m;var g=function(a,d,e){h.call(this,a,d,e);this.built=null};g.prototype=Object.create(h.prototype);g.prototype.build=function(){for(var a={},d=this.getChildren(g.Value),e=0;e<d.length;e++)a[d[e].name]=d[e].id;Object.defineProperty&&Object.defineProperty(a,"$options",{value:this.buildOpt(),enumerable:!1, | ||
configurable:!1,writable:!1});return this.built=a};f.Enum=g;m=function(a,d,e){k.call(this,a,d);this.id=e};m.prototype=Object.create(k.prototype);f.Enum.Value=m;return f}(f);f.Builder=function(c,f,k){var h=function(){this.ptr=this.ns=new k.Namespace(null,"");this.resolved=!1;this.result=null};h.prototype.reset=function(){this.ptr=this.ns};h.prototype.define=function(a,c){if("string"!=typeof a||!f.TYPEDEF.test(a))throw Error("Illegal package name: "+a);var g=a.split("."),b;for(b=0;b<g.length;b++)if(!f.NAME.test(g[b]))throw Error("Illegal package name: "+ | ||
g[b]);for(b=0;b<g.length;b++)this.ptr.hasChild(g[b])||this.ptr.addChild(new k.Namespace(this.ptr,g[b],c)),this.ptr=this.ptr.getChild(g[b]);return this};h.isValidMessage=function(a){if("string"!=typeof a.name||!f.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 g=[],b;for(c=0;c<a.fields.length;c++){if(!h.isValidMessageField(a.fields[c]))return!1;b=parseInt(a.id,10);if(0<=g.indexOf(b))return!1;g.push(b)}}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||!f.RULE.test(a.rule)||!f.NAME.test(a.name)||!f.TYPEREF.test(a.type)||!f.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),g=0;g<c.length;g++)if(!f.NAME.test(c[g])||!f.ID.test(""+a.options[c[g]])&&!f.TYPEREF.test(a.options[c[g]]))return!1}return!0};h.isValidEnum=function(a){if("string"!=typeof a.name||!f.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||!f.NAME.test(a.values[c].name)||!f.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=[],g,b,d,e,l;for(c.push(a);0<c.length;){a=c.pop();if(a instanceof Array)for(;0<a.length;)if(g=a.shift(),h.isValidMessage(g)){b=new k.Message(this.ptr,g.name,g.options);if(g.fields&&0<g.fields.length)for(e=0;e<g.fields.length;e++){if(!h.isValidMessageField(g.fields[e]))throw Error("Not a valid message field definition in message "+ | ||
b.name+": "+JSON.stringify(g.fields[e]));if(b.hasChild(g.fields[e].id))throw Error("Duplicate field id in message "+b.name+": "+g.fields[e].id);if(g.fields[e].options){d=Object.keys(g.fields[e].options);for(l=0;l<d.length;l++){if(!f.NAME.test(d[l]))throw Error("Illegal field option name in message "+b.name+"#"+g.fields[e].name+": "+d[l]);if(!f.ID.test(""+g.fields[e].options[d[l]])&&!f.TYPEREF.test(g.fields[e].options[d[l]]))throw Error("Illegal field option value in message "+b.name+"#"+g.fields[e].name+ | ||
"#"+d[l]+": "+g.fields[e].options[d[l]]);}}b.addChild(new k.Message.Field(b,g.fields[e].rule,g.fields[e].type,g.fields[e].name,g.fields[e].id,g.fields[e].options))}d=[];if("undefined"!=typeof g.enums&&0<g.enums.length)for(e=0;e<g.enums.length;e++)d.push(g.enums[e]);if(g.messages&&0<g.messages.length)for(e=0;e<g.messages.length;e++)d.push(g.messages[e]);this.ptr.addChild(b);0<d.length&&(c.push(a),a=d,this.ptr=b)}else if(h.isValidEnum(g)){b=new k.Enum(this.ptr,g.name,g.options);for(e=0;e<g.values.length;e++)b.addChild(new k.Enum.Value(b, | ||
g.values[e].name,g.values[e].id));this.ptr.addChild(b)}else throw Error("Not a valid message or enum definition: "+JSON.stringify(g));else throw Error("Not a valid namespace definition: "+JSON.stringify(a));this.ptr=this.ptr.parent}this.resolved=!1;this.result=null;return this}};h.prototype["import"]=function(a,f){a["package"]&&this.define(a["package"],a.options);a.messages&&this.create(a.messages);this.reset();a["package"]&&this.define(a["package"],a.options);a.enums&&this.create(a.enums);this.reset(); | ||
if(a.imports&&0<a.imports.length){if(!f)throw Error("Cannot determine import root: File name is unknown");for(var g=f.replace(/[\/\\][^\/\\]*$/,""),b=0;b<a.imports.length;b++){var d=g+"/"+a.imports[b];if(/\.json$/i.test(d)){var e=c.Util.fetch(d);if(null===e)throw Error("Failed to import '"+d+"' in '"+f+"': File not found");this["import"](JSON.parse(e),d)}else throw Error("This build of ProtoBuf.js does not include DotProto support. See: https://github.com/dcodeIO/ProtoBuf.js");}}return this};h.prototype.resolveAll= | ||
function(){if(!(null==this.ptr||"object"==typeof this.ptr.type)){if(this.ptr instanceof k.Namespace)for(var a=this.ptr.getChildren(),h=0;h<a.length;h++)this.ptr=a[h],this.resolveAll();else if(this.ptr instanceof k.Message.Field)if(f.TYPE.test(this.ptr.type))this.ptr.type=c.TYPES[this.ptr.type];else{if(!f.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 k.Enum)this.ptr.type=c.TYPES["enum"];else if(a instanceof k.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 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};h.prototype.toString=function(){return"Builder"};return h}(f,f.Lang,f.Reflect);f.protoFromString=function(c,f,k){throw Error("This build of ProtoBuf.js does not include DotProto support. See: https://github.com/dcodeIO/ProtoBuf.js");};f.protoFromFile=function(c,l,k){if(l&&"object"==typeof l)k=l,l=null; | ||
else if(!l||"function"!=typeof l)l=null;if(l)f.Util.fetch(c,function(a){l(f.protoFromString(a,k,c))});else{var h=f.Util.fetch(c);return null!==h?f.protoFromString(h,k,c):null}};f.newBuilder=function(c,l){var k=new f.Builder;"undefined"!=typeof c&&k.define(c,l);return k};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); | ||
sfixed64:{name:"sfixed64",wireType:f.WIRE_TYPES.BITS64},"float":{name:"float",wireType:f.WIRE_TYPES.BITS32},"enum":{name:"enum",wireType:f.WIRE_TYPES.VARINT},message:{name:"message",wireType:f.WIRE_TYPES.LDELIM}};f.Long=l.Long;f.Util=function(){Object.create||(Object.create=function(d){function k(){}if(1<arguments.length)throw Error("Object.create implementation only accepts the first parameter.");k.prototype=d;return new k});var d={};d.IS_NODE=("undefined"==typeof window||!window.window)&&"function"== | ||
typeof require;d.XHR=function(){for(var d=[function(){return new XMLHttpRequest},function(){return new ActiveXObject("Msxml2.XMLHTTP")},function(){return new ActiveXObject("Msxml3.XMLHTTP")},function(){return new ActiveXObject("Microsoft.XMLHTTP")}],k=null,f=0;f<d.length;f++){try{k=d[f]()}catch(a){continue}break}if(!k)throw Error("XMLHttpRequest is not supported");return k};d.fetch=function(n,f){f&&"function"!=typeof f&&(f=null);if(d.IS_NODE)if(f)require("fs").readFile(n,function(a,d){a?f(null):f(""+ | ||
d)});else try{return require("fs").readFileSync(n)}catch(h){return null}else{var a=d.XHR();a.open("GET",n,f?!0:!1);a.setRequestHeader("User-Agent","XMLHTTP/1.0");a.setRequestHeader("Accept","text/plain");if(f)a.onreadystatechange=function(){4==a.readyState&&(200==a.status?f(a.responseText):f(null))},4!=a.readyState&&a.send(null);else return a.send(null),a.responseText}};return d}();f.Lang={OPEN:"{",CLOSE:"}",OPTOPEN:"[",OPTCLOSE:"]",OPTEND:",",EQUAL:"=",END:";",DELIM:/[\s\{\}=;\[\],"\(\)]/g,KEYWORD:/package|option|import|message|enum|extend|service/, | ||
RULE:/required|optional|repeated/,TYPE:/double|float|int32|uint32|sint32|int64|uint64|sint64|fixed32|sfixed32|fixed64|sfixed64|bool|string|bytes/,NAME:/[a-zA-Z][a-zA-Z_0-9]*/,TYPEDEF:/[a-zA-Z](\.?[a-zA-Z_0-9])*/,TYPEREF:/\.?[a-zA-Z](\.?[a-zA-Z_0-9])*/,NUMBER:/^-?([1-9][0-9]*)|0$/,ID:/[0-9]+/,WHITESPACE:/\s/,STRING:/"([^"\\]*(\\.[^"\\]*)*)"/g,STRINGOPEN:'"',STRINGCLOSE:'"',COPTOPEN:"(",COPTCLOSE:")"};f.Reflect=function(d){var f={},k=function(c,b){this.parent=c;this.name=b;this.resolvedType=null};k.prototype.toString= | ||
function(c){var b=this.name,e=this;do{e=e.parent;if(null==e)break;b=e.name+"."+b}while(1);c&&(this instanceof f.Message?b="Message "+b:this instanceof a.Field?b="Message.Field "+b:this instanceof g?b="Enum "+b:this instanceof g.Value?b="Enum.Value "+b:this instanceof h&&(b="Namespace "+b));return b};k.prototype.build=function(){throw Error(this.toString(!0)+" cannot be built directly");};f.T=k;var h=function(c,b,e){k.call(this,c,b);this.children=[];this.options=e||{}};h.prototype=Object.create(k.prototype); | ||
h.prototype.getChildren=function(c){c=c||null;if(null==c)return this.children.slice();for(var b=[],e=0;e<this.children.length;e++)this.children[e]instanceof c&&b.push(this.children[e]);return b};h.prototype.addChild=function(c){if(this.hasChild(c.name))throw Error("Duplicate name in namespace "+this.toString(!0)+": "+c.name);this.children.push(c)};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(c){var b=c.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 f.T)){e=null;break}a++}while(a<b.length);if(null!=e)break;if(null!==this.parent)return this.parent.resolve(c)}while(null!=e);return e};h.prototype.build=function(){for(var c={},b=this.getChildren(),e,a=0;a<b.length;a++)e=b[a],e instanceof h&&(c[e.name]=e.build());Object.defineProperty&&Object.defineProperty(c,"$options",{value:this.buildOpt(),enumerable:!1,configurable:!1,writable:!1});return c};h.prototype.buildOpt=function(){for(var c={},b=Object.keys(this.options), | ||
e=0;e<b.length;e++)c[b[e]]=this.options[b[e]];return c};h.prototype.getOption=function(c){return"undefined"==typeof c?this.options:"undefined"!=typeof this.options[c]?this.options[c]:null};f.Namespace=h;var a=function(c,b,e){h.call(this,c,b,e);this.built=null};a.prototype=Object.create(h.prototype);a.prototype.build=function(){for(var c=function(c,b){var e=b.getChildren(c.Message.Field),a=eval("(function "+b.name+"() { this.__construct.apply(this, arguments); })");a.prototype.__construct=function(c){var b, | ||
a;for(b=0;b<e.length;b++)a=e[b],this[a.name]=a.repeated?[]:null;for(b=0;b<e.length;b++)if(a=e[b],"undefined"!=typeof a.options["default"])try{this.set(a.name,a.options["default"])}catch(g){throw Error("[INTERNAL ERROR] "+g);}if(1==arguments.length&&"object"==typeof c&&"function"!=typeof c.encode&&!(c instanceof Array)&&!(c instanceof l)&&!(c instanceof ArrayBuffer)&&!(d.Long&&c instanceof d.Long)){a=Object.keys(c);for(b=0;b<a.length;b++)this.set(a[b],c[a[b]])}else for(b=0;b<arguments.length;b++)b< | ||
e.length&&this.set(e[b].name,arguments[b])};a.prototype.add=function(a,e){var d=b.getChild(a);if(!d)throw Error(this+"#"+a+" is undefined");if(!(d instanceof c.Message.Field))throw Error(this+"#"+a+" is not a field: "+d.toString(!0));if(!d.repeated)throw Error(this+"#"+a+" is not a repeated field");null===this[d.name]&&(this[d.name]=[]);this[d.name].push(d.verifyValue(e,!0))};a.prototype.set=function(a,e){var d=b.getChild(a);if(!d)throw Error(this+"#"+a+" is not a field: undefined");if(!(d instanceof | ||
c.Message.Field))throw Error(this+"#"+a+" is not a field: "+d.toString(!0));this[d.name]=d.verifyValue(e)};a.prototype.get=function(a){var e=b.getChild(a);if(!e||!(e instanceof c.Message.Field))throw Error(this+"#"+a+" is not a field: undefined");if(!(e instanceof c.Message.Field))throw Error(this+"#"+a+" is not a field: "+e.toString(!0));return this[e.name]};for(var g=0;g<e.length;g++)(function(c){var e=c.name.replace(/(_[a-zA-Z])/g,function(b){return b.toUpperCase().replace("_","")}),e=e.substring(0, | ||
1).toUpperCase()+e.substring(1),d=c.name.replace(/([A-Z])/g,function(b){return"_"+b});b.hasChild("set"+e)||(a.prototype["set"+e]=function(b){this.set(c.name,b)});b.hasChild("set_"+d)||(a.prototype["set_"+d]=function(b){this.set(c.name,b)});b.hasChild("get"+e)||(a.prototype["get"+e]=function(){return this.get(c.name)});b.hasChild("get_"+d)||(a.prototype["get_"+d]=function(){return this.get(c.name)})})(e[g]);a.prototype.encode=function(c){c=c||new l;var a=c.littleEndian,e=b.encode(this,c.LE()).flip(); | ||
c.littleEndian=a;return e};a.prototype.toArrayBuffer=function(){return this.encode().toArrayBuffer()};a.decode=function(c){c=c?c instanceof l?c:l.wrap(c):new l;var a=c.littleEndian,e=b.decode(c.LE());c.littleEndian=a;return e};a.prototype.toString=function(){return b.toString()};Object.defineProperty&&Object.defineProperty(a,"$options",{value:b.buildOpt(),enumerable:!1,configurable:!1,writable:!1});return a}(f,this),b=this.getChildren(),e=0;e<b.length;e++)if(b[e]instanceof g)c[b[e].name]=b[e].build(); | ||
else if(b[e]instanceof a)c[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=c};a.prototype.encode=function(c,b){for(var e=this.getChildren(a.Field),d=0;d<e.length;d++)e[d].encode(c.get(e[d].name),b);return b};a.prototype.decode=function(c,b){b=b||-1;for(var a=c.offset,d=new this.built;c.offset<a+b||-1==b&&0<c.remaining();){var g=c.readVarint32(),m=g&7,g=g>>3,h=this.getChild(g);if(!h)throw Error("Illegal field id in "+ | ||
this.toString(!0)+"#decode: "+g);h.repeated&&!h.options.packed?d.add(h.name,h.decode(m,c)):d.set(h.name,h.decode(m,c))}a=this.getChildren(f.Field);for(m=0;m<a.length;m++)if(a[m].required&&null===d[a[m].name])throw a=Error("Missing field "+a[m].toString(!0)+" in "+this.toString(!0)+"#decode"),a.msg=d,a;return d};f.Message=a;var m=function(c,b,a,d,g,f){k.call(this,c,d);this.required="required"==b;this.repeated="repeated"==b;this.type=a;this.id=g;this.options=f||{}};m.prototype=Object.create(k.prototype); | ||
m.prototype.verifyValue=function(c,b){b=b||!1;if(null===c){if(this.required)throw Error("Illegal value for "+this.toString(!0)+": "+c+" (required)");return null}var a,f;if(this.repeated&&!b){c instanceof Array||(c=[c]);f=[];for(a=0;a<c.length;a++)f.push(this.verifyValue(c[a],!0));return f}if(!this.repeated&&c instanceof Array)throw Error("Illegal value for "+this.toString(!0)+": "+c+" (no array expected)");if(this.type==d.TYPES.int32||this.type==d.TYPES.sint32||this.type==d.TYPES.sfixed32)return parseInt(c, | ||
10)|0;if(this.type==d.TYPES.uint32||this.type==d.TYPES.fixed32)return parseInt(c,10)>>>0;if(d.Long){if(this.type==d.TYPES.int64||this.type==d.TYPES.sint64||this.type==d.TYPES.sfixed64)return!("object"==typeof c&&c instanceof d.Long)?d.Long.fromNumber(c,!1):c.unsigned?c.toSigned():c;if(this.type==d.TYPES.uint64||this.type==d.TYPES.fixed64)return!("object"==typeof c&&c instanceof d.Long)?d.Long.fromNumber(c,!0):c.unsigned?c:c.toUnsigned()}if(this.type==d.TYPES.bool)return!!c;if(this.type==d.TYPES["float"]|| | ||
this.type==d.TYPES["double"])return parseFloat(c);if(this.type==d.TYPES.string)return""+c;if(this.type==d.TYPES.bytes)return"object"==typeof c&&c instanceof l?c:l.wrap(c);if(this.type==d.TYPES["enum"]){f=this.resolvedType.getChildren(g.Value);for(a=0;a<f.length;a++)if(f[a].name==c||f[a].id==c)return f[a].id;throw Error("Illegal value for "+this.toString(!0)+": "+c+" (not a valid enum value)");}if(this.type==d.TYPES.message){if("object"!=typeof c)throw Error("Illegal value for "+this.toString(!0)+ | ||
": "+c+" (object expected)");return c instanceof this.resolvedType.built?c:new this.resolvedType.built(c)}throw Error("[INTERNAL ERROR] Illegal value for "+this.toString(!0)+": "+c+" (undefined type "+this.type+")");};m.prototype.encode=function(c,b){c=this.verifyValue(c);if(null==this.type||"object"!=typeof this.type)throw Error("[INTERNAL ERROR] Unresolved type in "+this.toString(!0)+": "+this.type);if(null===c||this.repeated&&0==c.length)return b;try{if(this.repeated){var a;if(this.options.packed){b.writeVarint32(this.id<< | ||
3|d.WIRE_TYPES.LDELIM);b.ensureCapacity(b.offset+=1);var g=b.offset;for(a=0;a<c.length;a++)this.encodeValue(c[a],b);var f=b.offset-g,m=l.calculateVarint32(f);if(1<m){var h=b.slice(g,b.offset),g=g+(m-1);b.offset=g;b.append(h)}b.writeVarint32(f,g-m)}else for(a=0;a<c.length;a++)b.writeVarint32(this.id<<3|this.type.wireType),this.encodeValue(c[a],b)}else b.writeVarint32(this.id<<3|this.type.wireType),this.encodeValue(c,b)}catch(n){throw b.littleEndian=le,Error("Illegal value for "+this.toString(!0)+": "+ | ||
c+" ("+n+")");}return b};m.prototype.encodeValue=function(c,b){if(null!==c){if(this.type==d.TYPES.int32||this.type==d.TYPES.uint32)b.writeVarint32(c);else if(this.type==d.TYPES.sint32)b.writeZigZagVarint32(c);else if(this.type==d.TYPES.fixed32)b.writeUint32(c);else if(this.type==d.TYPES.sfixed32)b.writeInt32(c);else if(this.type==d.TYPES.int64||this.type==d.TYPES.uint64)b.writeVarint64(c);else if(this.type==d.TYPES.sint64)b.writeZigZagVarint64(c);else if(this.type==d.TYPES.fixed64)b.writeUint64(c); | ||
else if(this.type==d.TYPES.sfixed64)b.writeInt64(c);else if(this.type==d.TYPES.bool)b.writeVarint32(c?1:0);else if(this.type==d.TYPES["enum"])b.writeVarint32(c);else if(this.type==d.TYPES["float"])b.writeFloat32(c);else if(this.type==d.TYPES["double"])b.writeFloat64(c);else if(this.type==d.TYPES.string)b.writeVString(c);else if(this.type==d.TYPES.bytes)c.offset>c.length&&(b=b.clone().flip()),b.writeVarint32(c.remaining()),b.append(c);else if(this.type==d.TYPES.message){var a=new l;this.resolvedType.encode(c, | ||
a);b.writeVarint32(a.offset);b.append(a.flip())}else throw Error("[INTERNAL ERROR] Illegal value to encode in "+this.toString(!0)+": "+c+" (unknown type)");return b}};m.prototype.decode=function(c,b,a){if(c!=this.type.wireType&&(a||c!=d.WIRE_TYPES.LDELIM||!this.repeated))throw Error("Illegal wire type for field "+this.toString(!0)+": "+c+" ("+this.type.wireType+" expected)");if(c==d.WIRE_TYPES.LDELIM&&(this.repeated&&this.options.packed)&&!a){c=b.readVarint32();c=b.offset+c;for(a=[];b.offset<c;)a.push(this.decode(this.type.wireType, | ||
b,!0));return a}if(this.type==d.TYPES.int32)return b.readVarint32()|0;if(this.type==d.TYPES.uint32)return b.readVarint32()>>>0;if(this.type==d.TYPES.sint32)return b.readZigZagVarint32()|0;if(this.type==d.TYPES.fixed32)return b.readUint32()>>>0;if(this.type==d.TYPES.sfixed32)return b.readInt32()|0;if(this.type==d.TYPES.int64)return b.readVarint64();if(this.type==d.TYPES.uint64)return b.readVarint64().toUnsigned();if(this.type==d.TYPES.sint64)return b.readZigZagVarint64();if(this.type==d.TYPES.fixed64)return b.readUint64(); | ||
if(this.type==d.TYPES.sfixed64)return b.readInt64();if(this.type==d.TYPES.bool)return!!b.readVarint32();if(this.type==d.TYPES["enum"])return b.readVarint32();if(this.type==d.TYPES["float"])return b.readFloat();if(this.type==d.TYPES["double"])return b.readDouble();if(this.type==d.TYPES.string)return b.readVString();if(this.type==d.TYPES.bytes)return c=b.readVarint32(),a=b.clone(),a.length=a.offset+c,b.offset+=c,a;if(this.type==d.TYPES.message)return c=b.readVarint32(),this.resolvedType.decode(b,c); | ||
throw Error("[INTERNAL ERROR] Illegal wire type for "+this.toString(!0)+": "+c);};f.Message.Field=m;var g=function(a,b,e){h.call(this,a,b,e);this.built=null};g.prototype=Object.create(h.prototype);g.prototype.build=function(){for(var a={},b=this.getChildren(g.Value),e=0;e<b.length;e++)a[b[e].name]=b[e].id;Object.defineProperty&&Object.defineProperty(a,"$options",{value:this.buildOpt(),enumerable:!1,configurable:!1,writable:!1});return this.built=a};f.Enum=g;m=function(a,b,e){k.call(this,a,b);this.id= | ||
e};m.prototype=Object.create(k.prototype);f.Enum.Value=m;return f}(f);f.Builder=function(d,f,k){var h=function(){this.ptr=this.ns=new k.Namespace(null,"");this.resolved=!1;this.result=null};h.prototype.reset=function(){this.ptr=this.ns};h.prototype.define=function(a,d){if("string"!=typeof a||!f.TYPEDEF.test(a))throw Error("Illegal package name: "+a);var g=a.split("."),c;for(c=0;c<g.length;c++)if(!f.NAME.test(g[c]))throw Error("Illegal package name: "+g[c]);for(c=0;c<g.length;c++)this.ptr.hasChild(g[c])|| | ||
this.ptr.addChild(new k.Namespace(this.ptr,g[c],d)),this.ptr=this.ptr.getChild(g[c]);return this};h.isValidMessage=function(a){if("string"!=typeof a.name||!f.NAME.test(a.name)||"undefined"!=typeof a.values)return!1;var d;if("undefined"!=typeof a.fields){if(!(a.fields instanceof Array))return!1;var g=[],c;for(d=0;d<a.fields.length;d++){if(!h.isValidMessageField(a.fields[d]))return!1;c=parseInt(a.id,10);if(0<=g.indexOf(c))return!1;g.push(c)}}if("undefined"!=typeof a.enums){if(!(a.enums instanceof Array))return!1; | ||
for(d=0;d<a.enums.length;d++)if(!h.isValidEnum(a.enums[d]))return!1}if("undefined"!=typeof a.messages){if(!(a.messages instanceof Array))return!1;for(d=0;d<a.messages.length;d++)if(!h.isValidMessage(a.messages[d]))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||!f.RULE.test(a.rule)||!f.NAME.test(a.name)||!f.TYPEREF.test(a.type)||!f.ID.test(""+a.id))return!1;if("undefined"!=typeof a.options){if("object"!= | ||
typeof a.options)return!1;for(var d=Object.keys(a.options),g=0;g<d.length;g++)if(!f.NAME.test(d[g])||!f.ID.test(""+a.options[d[g]])&&!f.TYPEREF.test(a.options[d[g]]))return!1}return!0};h.isValidEnum=function(a){if("string"!=typeof a.name||!f.NAME.test(a.name)||"undefined"==typeof a.values||!(a.values instanceof Array)||0==a.values.length)return!1;for(var d=0;d<a.values.length;d++)if("object"!=typeof a.values[d]||"string"!=typeof a.values[d].name||"undefined"==typeof a.values[d].id||!f.NAME.test(a.values[d].name)|| | ||
!f.ID.test(""+a.values[d].id))return!1;return!0};h.prototype.create=function(a){if(a&&(a instanceof Array||(a=[a]),0!=a.length)){var d=[],g,c,b,e,l;for(d.push(a);0<d.length;){a=d.pop();if(a instanceof Array)for(;0<a.length;)if(g=a.shift(),h.isValidMessage(g)){c=new k.Message(this.ptr,g.name,g.options);if(g.fields&&0<g.fields.length)for(e=0;e<g.fields.length;e++){if(!h.isValidMessageField(g.fields[e]))throw Error("Not a valid message field definition in message "+c.name+": "+JSON.stringify(g.fields[e])); | ||
if(c.hasChild(g.fields[e].id))throw Error("Duplicate field id in message "+c.name+": "+g.fields[e].id);if(g.fields[e].options){b=Object.keys(g.fields[e].options);for(l=0;l<b.length;l++){if(!f.NAME.test(b[l]))throw Error("Illegal field option name in message "+c.name+"#"+g.fields[e].name+": "+b[l]);if(!f.ID.test(""+g.fields[e].options[b[l]])&&!f.TYPEREF.test(g.fields[e].options[b[l]]))throw Error("Illegal field option value in message "+c.name+"#"+g.fields[e].name+"#"+b[l]+": "+g.fields[e].options[b[l]]); | ||
}}c.addChild(new k.Message.Field(c,g.fields[e].rule,g.fields[e].type,g.fields[e].name,g.fields[e].id,g.fields[e].options))}b=[];if("undefined"!=typeof g.enums&&0<g.enums.length)for(e=0;e<g.enums.length;e++)b.push(g.enums[e]);if(g.messages&&0<g.messages.length)for(e=0;e<g.messages.length;e++)b.push(g.messages[e]);this.ptr.addChild(c);0<b.length&&(d.push(a),a=b,this.ptr=c)}else if(h.isValidEnum(g)){c=new k.Enum(this.ptr,g.name,g.options);for(e=0;e<g.values.length;e++)c.addChild(new k.Enum.Value(c,g.values[e].name, | ||
g.values[e].id));this.ptr.addChild(c)}else throw Error("Not a valid message or enum definition: "+JSON.stringify(g));else throw Error("Not a valid namespace definition: "+JSON.stringify(a));this.ptr=this.ptr.parent}this.resolved=!1;this.result=null;return this}};h.prototype["import"]=function(a,f){a["package"]&&this.define(a["package"],a.options);a.messages&&this.create(a.messages);this.reset();a["package"]&&this.define(a["package"],a.options);a.enums&&this.create(a.enums);this.reset();if(a.imports&& | ||
0<a.imports.length){if(!f)throw Error("Cannot determine import root: File name is unknown");for(var g=f.replace(/[\/\\][^\/\\]*$/,""),c=0;c<a.imports.length;c++){var b=g+"/"+a.imports[c];if(/\.json$/i.test(b)){var e=d.Util.fetch(b);if(null===e)throw Error("Failed to import '"+b+"' in '"+f+"': File not found");this["import"](JSON.parse(e),b)}else throw Error("This build of ProtoBuf.js does not include DotProto support. See: https://github.com/dcodeIO/ProtoBuf.js");}}return this};h.prototype.resolveAll= | ||
function(){if(!(null==this.ptr||"object"==typeof this.ptr.type)){if(this.ptr instanceof k.Namespace)for(var a=this.ptr.getChildren(),h=0;h<a.length;h++)this.ptr=a[h],this.resolveAll();else if(this.ptr instanceof k.Message.Field)if(f.TYPE.test(this.ptr.type))this.ptr.type=d.TYPES[this.ptr.type];else{if(!f.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 k.Enum)this.ptr.type=d.TYPES["enum"];else if(a instanceof k.Message)this.ptr.type=d.TYPES.message;else throw Error("Illegal type reference in "+this.ptr.toString(!0)+": "+this.ptr.type);}else if(!(this.ptr instanceof d.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 d=this.result,f=0;f<a.length;f++)if(d[a[f]])d=d[a[f]];else{d=null;break}return d}return this.result};h.prototype.toString=function(){return"Builder"};return h}(f,f.Lang,f.Reflect);f.protoFromString=function(d,f,k){throw Error("This build of ProtoBuf.js does not include DotProto support. See: https://github.com/dcodeIO/ProtoBuf.js");};f.protoFromFile=function(d,l,k){if(l&&"object"==typeof l)k=l,l=null; | ||
else if(!l||"function"!=typeof l)l=null;if(l)f.Util.fetch(d,function(a){l(f.protoFromString(a,k,d))});else{var h=f.Util.fetch(d);return null!==h?f.protoFromString(h,k,d):null}};f.newBuilder=function(d,l){var k=new f.Builder;"undefined"!=typeof d&&k.define(d,l);return k};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); |
@@ -17,3 +17,3 @@ ![ProtoBuf.js - protobuf for JavaScript](https://raw.github.com/dcodeIO/ProtoBuf.js/master/ProtoBuf.png) | ||
* Fully documented using [jsdoc3](https://github.com/jsdoc3/jsdoc) | ||
* Well tested through [nodeunit](https://github.com/caolan/nodeunit) | ||
* Well tested through [test.js](https://github.com/dcodeIO/test.js) | ||
* [ByteBuffer.js](https://github.com/dcodeIO/ByteBuffer.js) is the only production dependency | ||
@@ -20,0 +20,0 @@ * Small footprint (even smaller if you use a noparse build) |
@@ -982,17 +982,6 @@ // #ifdef UNDEFINED | ||
} else if (this.type == ProtoBuf.TYPES["message"]) { | ||
// We do not know the length of the embedded message yet. To avoid creating a second buffer, let's assume | ||
// the length varint might consist of one byte and encode the embedded message to the current offset+1. | ||
// When we know the length and it is one byte long, all we have to do is to write the length varint. If | ||
// it's longer than one byte, we need to copy. Finally we did it all with just one buffer. | ||
var start = buffer.offset; | ||
buffer.writeUint8(0x00); // Placeholder (calls ensureCapacity) | ||
this.resolvedType.encode(value, buffer); | ||
var messageBytes = buffer.offset - start - 1; | ||
var sizeBytes = ByteBuffer.calculateVarint32(messageBytes); | ||
if (sizeBytes > 1) { // We need to copy | ||
var bb = buffer.clone().flip(); | ||
bb.offset = bb.length - messageBytes; | ||
buffer.append(bb, start + sizeBytes); | ||
} | ||
buffer.writeVarint32(messageBytes, start); | ||
var bb = new ByteBuffer(); | ||
this.resolvedType.encode(value, bb); | ||
buffer.writeVarint32(bb.offset); | ||
buffer.append(bb.flip()); | ||
} else { | ||
@@ -999,0 +988,0 @@ // We should never end here |
@@ -101,10 +101,2 @@ /* | ||
setUp: function (callback) { | ||
callback(); | ||
}, | ||
tearDown: function (callback) { | ||
callback(); | ||
}, | ||
"init": function(test) { | ||
@@ -358,19 +350,42 @@ test.ok(typeof ProtoBuf == "object"); | ||
"innerStringLenGt70": function(test) { | ||
try { | ||
var builder = ProtoBuf.protoFromString("message Test { required Inner a = 1; message Inner { required string b = 1; } }"); | ||
var Test = builder.build("Test"); | ||
var t = new Test(); | ||
var data = "0123456789"; // 10: 20, 40, 80, 160, 320 bytes | ||
for (var i=0; i<5; i++) data += data; | ||
test.equal(data.length, 320); | ||
t.a = new Test.Inner(data); | ||
var bb = t.encode(); | ||
var t2 = Test.decode(bb); | ||
test.equal(t2.a.b.length, 320); | ||
test.equal(data, t2.a.b); | ||
} catch (e) { | ||
fail(e); | ||
"inner": { | ||
"longstr": function(test) { | ||
try { | ||
var builder = ProtoBuf.protoFromString("message Test { required Inner a = 1; message Inner { required string b = 1; } }"); | ||
var Test = builder.build("Test"); | ||
var t = new Test(); | ||
var data = "0123456789"; // 10: 20, 40, 80, 160, 320 bytes | ||
for (var i=0; i<5; i++) data += data; | ||
test.equal(data.length, 320); | ||
t.a = new Test.Inner(data); | ||
var bb = t.encode(); | ||
var t2 = Test.decode(bb); | ||
test.equal(t2.a.b.length, 320); | ||
test.equal(data, t2.a.b); | ||
} catch (e) { | ||
fail(e); | ||
} | ||
test.done(); | ||
}, | ||
"multiple": function(test) { | ||
try { | ||
var str = ""; | ||
for (var i=0; i<200; i++) str += 'a'; | ||
var builder = ProtoBuf.protoFromFile(__dirname+"/inner.proto"); | ||
var fooCls = builder.build("Foo"); | ||
var barCls = builder.build("Bar"); | ||
var bazCls = builder.build("Baz"); | ||
var foo = new fooCls(new barCls(str), new bazCls(str)); | ||
var fooEncoded = foo.encode(); | ||
test.doesNotThrow(function() { | ||
fooCls.decode(fooEncoded); | ||
}); | ||
} catch (e) { | ||
fail(e); | ||
} | ||
test.done(); | ||
} | ||
test.done(); | ||
}, | ||
@@ -377,0 +392,0 @@ |
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
74
910879
12442