protobufjs
Advanced tools
Comparing version 3.3.1 to 3.4.0
{ | ||
"name": "protobuf", | ||
"description": "Protocol Buffers for JavaScript. Finally.", | ||
"version": "3.3.1", | ||
"version": "3.4.0", | ||
"main": "dist/ProtoBuf.js", | ||
@@ -6,0 +6,0 @@ "license": "Apache-2.0", |
@@ -6,3 +6,3 @@ /* | ||
*/ | ||
(function(q){function r(k){var g={VERSION:"3.3.1",WIRE_TYPES:{}};g.WIRE_TYPES.VARINT=0;g.WIRE_TYPES.BITS64=1;g.WIRE_TYPES.LDELIM=2;g.WIRE_TYPES.STARTGROUP=3;g.WIRE_TYPES.ENDGROUP=4;g.WIRE_TYPES.BITS32=5;g.PACKABLE_WIRE_TYPES=[g.WIRE_TYPES.VARINT,g.WIRE_TYPES.BITS64,g.WIRE_TYPES.BITS32];g.TYPES={int32:{name:"int32",wireType:g.WIRE_TYPES.VARINT},uint32:{name:"uint32",wireType:g.WIRE_TYPES.VARINT},sint32:{name:"sint32",wireType:g.WIRE_TYPES.VARINT},int64:{name:"int64",wireType:g.WIRE_TYPES.VARINT},uint64:{name:"uint64", | ||
(function(q){function r(k){var g={VERSION:"3.4.0",WIRE_TYPES:{}};g.WIRE_TYPES.VARINT=0;g.WIRE_TYPES.BITS64=1;g.WIRE_TYPES.LDELIM=2;g.WIRE_TYPES.STARTGROUP=3;g.WIRE_TYPES.ENDGROUP=4;g.WIRE_TYPES.BITS32=5;g.PACKABLE_WIRE_TYPES=[g.WIRE_TYPES.VARINT,g.WIRE_TYPES.BITS64,g.WIRE_TYPES.BITS32];g.TYPES={int32:{name:"int32",wireType:g.WIRE_TYPES.VARINT},uint32:{name:"uint32",wireType:g.WIRE_TYPES.VARINT},sint32:{name:"sint32",wireType:g.WIRE_TYPES.VARINT},int64:{name:"int64",wireType:g.WIRE_TYPES.VARINT},uint64:{name:"uint64", | ||
wireType:g.WIRE_TYPES.VARINT},sint64:{name:"sint64",wireType:g.WIRE_TYPES.VARINT},bool:{name:"bool",wireType:g.WIRE_TYPES.VARINT},"double":{name:"double",wireType:g.WIRE_TYPES.BITS64},string:{name:"string",wireType:g.WIRE_TYPES.LDELIM},bytes:{name:"bytes",wireType:g.WIRE_TYPES.LDELIM},fixed32:{name:"fixed32",wireType:g.WIRE_TYPES.BITS32},sfixed32:{name:"sfixed32",wireType:g.WIRE_TYPES.BITS32},fixed64:{name:"fixed64",wireType:g.WIRE_TYPES.BITS64},sfixed64:{name:"sfixed64",wireType:g.WIRE_TYPES.BITS64}, | ||
@@ -50,4 +50,4 @@ "float":{name:"float",wireType:g.WIRE_TYPES.BITS32},"enum":{name:"enum",wireType:g.WIRE_TYPES.VARINT},message:{name:"message",wireType:g.WIRE_TYPES.LDELIM},group:{name:"group",wireType:g.WIRE_TYPES.STARTGROUP}};g.ID_MIN=1;g.ID_MAX=536870911;g.ByteBuffer=k;g.Long=k.Long||null;g.convertFieldsToCamelCase=!1;g.populateAccessors=!0;g.Util=function(){Object.create||(Object.create=function(e){function d(){}if(1<arguments.length)throw Error("Object.create polyfill only accepts the first parameter.");d.prototype= | ||
!!f};a.prototype=Object.create(b.prototype);a.prototype.build=function(b){if(this.clazz&&!b)return this.clazz;b=function(a,d){function b(a,d){var c={},e;for(e in a)a.hasOwnProperty(e)&&(null===a[e]||"object"!==typeof a[e]?c[e]=a[e]:a[e]instanceof k?d&&(c[e]=a.toBuffer()):c[e]=b(a[e],d));return c}var c=d.getChildren(a.Reflect.Message.Field),e=function(b,e){a.Builder.Message.call(this);var m,f;Object.defineProperty&&Object.defineProperty(this,"$type",{get:function(){return d}});for(m=0;m<c.length;m++)f= | ||
c[m],this[f.name]=f.repeated?[]:null;for(m=0;m<c.length;m++)if(f=c[m],"undefined"!=typeof f.options["default"])try{this.$set(f.name,f.options["default"])}catch(s){throw Error("[INTERNAL] "+s);}if(1!=arguments.length||"object"!=typeof b||"function"==typeof b.encode||a.Util.isArray(b)||b instanceof k||b instanceof ArrayBuffer||a.Long&&b instanceof a.Long)for(m=0;m<arguments.length;m++)m<c.length&&this.$set(c[m].name,arguments[m]);else for(f=Object.keys(b),m=0;m<f.length;m++)this.$set(f[m],b[f[m]])}; | ||
e.prototype=Object.create(a.Builder.Message.prototype);e.prototype.add=function(b,c,e){var m=d.getChild(b);if(!m)throw Error(this+"#"+b+" is undefined");if(!(m instanceof a.Reflect.Message.Field))throw Error(this+"#"+b+" is not a field: "+m.toString(!0));if(!m.repeated)throw Error(this+"#"+b+" is not a repeated field");null===this[m.name]&&(this[m.name]=[]);this[m.name].push(e?c:m.verifyValue(c,!0))};e.prototype.$add=e.prototype.add;e.prototype.set=function(b,c,e){var m=d.getChild(b);if(!m)throw Error(this+ | ||
c[m],this[f.name]=f.repeated?[]:null;for(m=0;m<c.length;m++)if(f=c[m],f.required&&"undefined"!==typeof f.options["default"])try{this.$set(f.name,f.options["default"])}catch(t){throw Error("[INTERNAL] "+t);}if(1!=arguments.length||"object"!=typeof b||"function"==typeof b.encode||a.Util.isArray(b)||b instanceof k||b instanceof ArrayBuffer||a.Long&&b instanceof a.Long)for(m=0;m<arguments.length;m++)m<c.length&&this.$set(c[m].name,arguments[m]);else for(f=Object.keys(b),m=0;m<f.length;m++)this.$set(f[m], | ||
b[f[m]])};e.prototype=Object.create(a.Builder.Message.prototype);e.prototype.add=function(b,c,e){var m=d.getChild(b);if(!m)throw Error(this+"#"+b+" is undefined");if(!(m instanceof a.Reflect.Message.Field))throw Error(this+"#"+b+" is not a field: "+m.toString(!0));if(!m.repeated)throw Error(this+"#"+b+" is not a repeated field");null===this[m.name]&&(this[m.name]=[]);this[m.name].push(e?c:m.verifyValue(c,!0))};e.prototype.$add=e.prototype.add;e.prototype.set=function(b,c,e){var m=d.getChild(b);if(!m)throw Error(this+ | ||
"#"+b+" is not a field: undefined");if(!(m instanceof a.Reflect.Message.Field))throw Error(this+"#"+b+" is not a field: "+m.toString(!0));this[m.name]=e?c:m.verifyValue(c)};e.prototype.$set=e.prototype.set;e.prototype.get=function(b){var c=d.getChild(b);if(!(c&&c instanceof a.Reflect.Message.Field))throw Error(this+"#"+b+" is not a field: undefined");if(!(c instanceof a.Reflect.Message.Field))throw Error(this+"#"+b+" is not a field: "+c.toString(!0));return this[c.name]};e.prototype.$get=e.prototype.get; | ||
@@ -60,27 +60,27 @@ for(var m=0;m<c.length;m++){var f=c[m];a.populateAccessors&&function(a){var b=a.originalName.replace(/(_[a-zA-Z])/g,function(a){return a.toUpperCase().replace("_","")}),b=b.substring(0,1).toUpperCase()+b.substring(1),c=a.originalName.replace(/([A-Z])/g,function(a){return"_"+a});d.hasChild("set"+b)||(e.prototype["set"+b]=function(d){this.$set(a.name,d)});d.hasChild("set_"+c)||(e.prototype["set_"+c]=function(d){this.$set(a.name,d)});d.hasChild("get"+b)||(e.prototype["get"+b]=function(){return this.$get(a.name)}); | ||
e=0;e<c.length;e++)if(c[e]instanceof h)b[c[e].name]=c[e].build();else if(c[e]instanceof a)b[c[e].name]=c[e].build();else if(!(c[e]instanceof a.Field))throw Error("Illegal reflect child of "+this.toString(!0)+": "+c[e].toString(!0));return this.clazz=b};a.prototype.encode=function(d,b){for(var c=this.getChildren(a.Field),e=null,f=0,g;f<c.length;f++)g=d.$get(c[f].name),c[f].required&&null===g?null===e&&(e=c[f]):c[f].encode(g,b);if(null!==e)throw c=Error("Missing at least one required field for "+this.toString(!0)+ | ||
": "+e),c.encoded=b,c;return b};a.prototype.calculate=function(d){for(var b=this.getChildren(a.Field),c=0,e=0,f;e<b.length;e++){f=d.$get(b[e].name);if(b[e].required&&null===f)throw Error("Missing at least one required field for "+this.toString(!0)+": "+b[e]);c+=b[e].calculate(f)}return c};a.prototype.decode=function(a,b,c){b="number"===typeof b?b:-1;for(var f=a.offset,g=new this.clazz,h,l;a.offset<f+b||-1==b&&0<a.remaining();){h=a.readVarint32();l=h&7;h>>=3;if(l===d.WIRE_TYPES.ENDGROUP){if(h!==c)throw Error("Illegal group end indicator for "+ | ||
this.toString(!0)+": "+h+" ("+(c?c+" expected":"not a group")+")");break}var k=this.getChild(h);if(k)k.repeated&&!k.options.packed?g.$add(k.name,k.decode(l,a),!0):g.$set(k.name,k.decode(l,a),!0);else switch(l){case d.WIRE_TYPES.VARINT:a.readVarint32();break;case d.WIRE_TYPES.BITS32:a.offset+=4;break;case d.WIRE_TYPES.BITS64:a.offset+=8;break;case d.WIRE_TYPES.LDELIM:l=a.readVarint32();a.offset+=l;break;case d.WIRE_TYPES.STARTGROUP:for(;e(h,a););break;default:throw Error("Illegal wire type for unknown field "+ | ||
h+" in "+this.toString(!0)+"#decode: "+l);}}a=this.getChildren(d.Reflect.Field);for(b=0;b<a.length;b++)if(a[b].required&&null===g[a[b].name])throw a=Error("Missing at least one required field for "+this.toString(!0)+": "+a[b].name),a.decoded=g,a;return g};l.Message=a;var f=function(a,b,e,f,g,h){c.call(this,a,f);this.className="Message.Field";this.required="required"==b;this.repeated="repeated"==b;this.type=e;this.resolvedType=null;this.id=g;this.options=h||{};this.originalName=this.name;d.convertFieldsToCamelCase&& | ||
(this.name=this.name.replace(/_([a-zA-Z])/g,function(a,b){return b.toUpperCase()}))};f.prototype=Object.create(c.prototype);f.prototype.verifyValue=function(a,b){b=b||!1;var c=function(a,b){throw Error("Illegal value for "+this.toString(!0)+" of type "+this.type.name+": "+a+" ("+b+")");}.bind(this);if(null===a)return this.required&&c(typeof a,"required"),null;var e;if(this.repeated&&!b){d.Util.isArray(a)||(a=[a]);c=[];for(e=0;e<a.length;e++)c.push(this.verifyValue(a[e],!0));return c}!this.repeated&& | ||
d.Util.isArray(a)&&c(typeof a,"no array expected");switch(this.type){case d.TYPES.int32:case d.TYPES.sint32:case d.TYPES.sfixed32:return("number"!==typeof a||a===a&&0!==a%1)&&c(typeof a,"not an integer"),4294967295<a?a|0:a;case d.TYPES.uint32:case d.TYPES.fixed32:return("number"!==typeof a||a===a&&0!==a%1)&&c(typeof a,"not an integer"),0>a?a>>>0:a;case d.TYPES.int64:case d.TYPES.sint64:case d.TYPES.sfixed64:if(d.Long)try{return g(a,!1)}catch(f){c(typeof a,f.message)}else c(typeof a,"requires Long.js"); | ||
case d.TYPES.uint64:case d.TYPES.fixed64:if(d.Long)try{return g(a,!0)}catch(l){c(typeof a,l.message)}else c(typeof a,"requires Long.js");case d.TYPES.bool:return"boolean"!==typeof a&&c(typeof a,"not a boolean"),a;case d.TYPES["float"]:case d.TYPES["double"]:return"number"!==typeof a&&c(typeof a,"not a number"),a;case d.TYPES.string:return"string"===typeof a||a&&a instanceof String||c(typeof a,"not a string"),""+a;case d.TYPES.bytes:return a&&a instanceof k?a:k.wrap(a);case d.TYPES["enum"]:var n=this.resolvedType.getChildren(h.Value); | ||
for(e=0;e<n.length;e++)if(n[e].name==a||n[e].id==a)return n[e].id;c(a,"not a valid enum value");case d.TYPES.group:case d.TYPES.message:return a&&"object"===typeof a||c(typeof a,"object expected"),a instanceof this.resolvedType.clazz?a:new this.resolvedType.clazz(a)}throw Error("[INTERNAL] Illegal value for "+this.toString(!0)+": "+a+" (undefined type "+this.type+")");};f.prototype.encode=function(a,b){a=this.verifyValue(a);if(null===this.type||"object"!==typeof this.type)throw Error("[INTERNAL] Unresolved type in "+ | ||
this.toString(!0)+": "+this.type);if(null===a||this.repeated&&0==a.length)return b;try{if(this.repeated){var c;if(this.options.packed&&0<=d.PACKABLE_WIRE_TYPES.indexOf(this.type.wireType)){b.writeVarint32(this.id<<3|d.WIRE_TYPES.LDELIM);b.ensureCapacity(b.offset+=1);var e=b.offset;for(c=0;c<a.length;c++)this.encodeValue(a[c],b);var f=b.offset-e,g=k.calculateVarint32(f);if(1<g){var h=b.slice(e,b.offset),e=e+(g-1);b.offset=e;b.append(h)}b.writeVarint32(f,e-g)}else for(c=0;c<a.length;c++)b.writeVarint32(this.id<< | ||
3|this.type.wireType),this.encodeValue(a[c],b)}else b.writeVarint32(this.id<<3|this.type.wireType),this.encodeValue(a,b)}catch(l){throw Error("Illegal value for "+this.toString(!0)+": "+a+" ("+l+")");}return b};f.prototype.encodeValue=function(a,b){if(null===a)return b;switch(this.type){case d.TYPES.int32:0>a?b.writeVarint64(a):b.writeVarint32(a);break;case d.TYPES.uint32:b.writeVarint32(a);break;case d.TYPES.sint32:b.writeVarint32ZigZag(a);break;case d.TYPES.fixed32:b.writeUint32(a);break;case d.TYPES.sfixed32:b.writeInt32(a); | ||
break;case d.TYPES.int64:case d.TYPES.uint64:b.writeVarint64(a);break;case d.TYPES.sint64:b.writeVarint64ZigZag(a);break;case d.TYPES.fixed64:b.writeUint64(a);break;case d.TYPES.sfixed64:b.writeInt64(a);break;case d.TYPES.bool:"string"===typeof a?b.writeVarint32("false"===a.toLowerCase()?0:!!a):b.writeVarint32(a?1:0);break;case d.TYPES["enum"]:b.writeVarint32(a);break;case d.TYPES["float"]:b.writeFloat32(a);break;case d.TYPES["double"]:b.writeFloat64(a);break;case d.TYPES.string:b.writeVString(a); | ||
break;case d.TYPES.bytes:if(0>a.remaining())throw Error("Illegal value for "+this.toString(!0)+": "+a.remaining()+" bytes remaining");var c=a.offset;b.writeVarint32(a.remaining());b.append(a);a.offset=c;break;case d.TYPES.message:c=(new k).LE();this.resolvedType.encode(a,c);b.writeVarint32(c.offset);b.append(c.flip());break;case d.TYPES.group:this.resolvedType.encode(a,b);b.writeVarint32(this.id<<3|d.WIRE_TYPES.ENDGROUP);break;default:throw Error("[INTERNAL] Illegal value to encode in "+this.toString(!0)+ | ||
": "+a+" (unknown type)");}return b};f.prototype.calculate=function(a){a=this.verifyValue(a);if(null===this.type||"object"!==typeof this.type)throw Error("[INTERNAL] Unresolved type in "+this.toString(!0)+": "+this.type);if(null===a||this.repeated&&0==a.length)return 0;var b=0;try{if(this.repeated){var c,e;if(this.options.packed&&0<=d.PACKABLE_WIRE_TYPES.indexOf(this.type.wireType)){b+=k.calculateVarint32(this.id<<3|d.WIRE_TYPES.LDELIM);for(c=e=0;c<a.length;c++)e+=this.calculateValue(a[c]);b+=k.calculateVarint32(e); | ||
b+=e}else for(c=0;c<a.length;c++)b+=k.calculateVarint32(this.id<<3|this.type.wireType),b+=this.calculateValue(a[c])}else b+=k.calculateVarint32(this.id<<3|this.type.wireType),b+=this.calculateValue(a)}catch(f){throw Error("Illegal value for "+this.toString(!0)+": "+a+" ("+f+")");}return b};f.prototype.calculateValue=function(a){if(null===a)return 0;switch(this.type){case d.TYPES.int32:return 0>a?k.calculateVarint64(a):k.calculateVarint32(a);case d.TYPES.uint32:return k.calculateVarint32(a);case d.TYPES.sint32:return k.calculateVarint32(k.zigZagEncode32(a)); | ||
case d.TYPES.fixed32:case d.TYPES.sfixed32:case d.TYPES["float"]:return 4;case d.TYPES.int64:case d.TYPES.uint64:return k.calculateVarint64(a);case d.TYPES.sint64:return k.calculateVarint64(k.zigZagEncode64(a));case d.TYPES.fixed64:case d.TYPES.sfixed64:return 8;case d.TYPES.bool:return 1;case d.TYPES["enum"]:return k.calculateVarint32(a);case d.TYPES["double"]:return 8;case d.TYPES.string:return a=k.calculateUTF8Bytes(a),k.calculateVarint32(a)+a;case d.TYPES.bytes:if(0>a.remaining())throw Error("Illegal value for "+ | ||
this.toString(!0)+": "+a.remaining()+" bytes remaining");return k.calculateVarint32(a.remaining())+a.remaining();case d.TYPES.message:return a=this.resolvedType.calculate(a),k.calculateVarint32(a)+a;case d.TYPES.group:return a=this.resolvedType.calculate(a),a+k.calculateVarint32(this.id<<3|d.WIRE_TYPES.ENDGROUP)}throw Error("[INTERNAL] Illegal value to encode in "+this.toString(!0)+": "+a+" (unknown type)");};f.prototype.decode=function(a,b,c){if(a!=this.type.wireType&&(c||a!=d.WIRE_TYPES.LDELIM|| | ||
!this.repeated))throw Error("Illegal wire type for field "+this.toString(!0)+": "+a+" ("+this.type.wireType+" expected)");if(a==d.WIRE_TYPES.LDELIM&&this.repeated&&this.options.packed&&0<=d.PACKABLE_WIRE_TYPES.indexOf(this.type.wireType)&&!c){a=b.readVarint32();a=b.offset+a;for(c=[];b.offset<a;)c.push(this.decode(this.type.wireType,b,!0));return c}switch(this.type){case d.TYPES.int32:return b.readVarint32()|0;case d.TYPES.uint32:return b.readVarint32()>>>0;case d.TYPES.sint32:return b.readVarint32ZigZag()| | ||
0;case d.TYPES.fixed32:return b.readUint32()>>>0;case d.TYPES.sfixed32:return b.readInt32()|0;case d.TYPES.int64:return b.readVarint64();case d.TYPES.uint64:return b.readVarint64().toUnsigned();case d.TYPES.sint64:return b.readVarint64ZigZag();case d.TYPES.fixed64:return b.readUint64();case d.TYPES.sfixed64:return b.readInt64();case d.TYPES.bool:return!!b.readVarint32();case d.TYPES["enum"]:return b.readVarint32();case d.TYPES["float"]:return b.readFloat();case d.TYPES["double"]:return b.readDouble(); | ||
case d.TYPES.string:return b.readVString();case d.TYPES.bytes:a=b.readVarint32();if(b.remaining()<a)throw Error("Illegal number of bytes for "+this.toString(!0)+": "+a+" required but got only "+b.remaining());c=b.clone();c.limit=c.offset+a;b.offset+=a;return c;case d.TYPES.message:return a=b.readVarint32(),this.resolvedType.decode(b,a);case d.TYPES.group:return this.resolvedType.decode(b,-1,this.id)}throw Error("[INTERNAL] Illegal wire type for "+this.toString(!0)+": "+a);};l.Message.Field=f;var n= | ||
function(a,b,c,d,e,g){f.call(this,a,b,c,d,e,g)};n.prototype=Object.create(f.prototype);l.Message.ExtensionField=n;var h=function(a,c,d){b.call(this,a,c,d);this.className="Enum";this.object=null};h.prototype=Object.create(b.prototype);h.prototype.build=function(){for(var a={},b=this.getChildren(h.Value),c=0;c<b.length;c++)a[b[c].name]=b[c].id;Object.defineProperty&&Object.defineProperty(a,"$options",{value:this.buildOpt()});return this.object=a};l.Enum=h;n=function(a,b,d){c.call(this,a,b);this.className= | ||
"Enum.Value";this.id=d};n.prototype=Object.create(c.prototype);l.Enum.Value=n;n=function(a,c,d){b.call(this,a,c,d);this.className="Service";this.clazz=null};n.prototype=Object.create(b.prototype);n.prototype.build=function(a){return this.clazz&&!a?this.clazz:this.clazz=function(a,b){var c=function(b){a.Builder.Service.call(this);this.rpcImpl=b||function(a,b,c){setTimeout(c.bind(this,Error("Not implemented, see: https://github.com/dcodeIO/ProtoBuf.js/wiki/Services")),0)}};c.prototype=Object.create(a.Builder.Service.prototype); | ||
Object.defineProperty&&(Object.defineProperty(c,"$options",{value:b.buildOpt()}),Object.defineProperty(c.prototype,"$options",{value:c.$options}));for(var d=b.getChildren(a.Reflect.Service.RPCMethod),e=0;e<d.length;e++)(function(a){c.prototype[a.name]=function(c,d){try{c&&c instanceof a.resolvedRequestType.clazz?this.rpcImpl(a.fqn(),c,function(c,e){if(c)d(c);else{try{e=a.resolvedResponseType.clazz.decode(e)}catch(f){}e&&e instanceof a.resolvedResponseType.clazz?d(null,e):d(Error("Illegal response type received in service method "+ | ||
b.name+"#"+a.name))}}):setTimeout(d.bind(this,Error("Illegal request type provided to service method "+b.name+"#"+a.name)),0)}catch(e){setTimeout(d.bind(this,e),0)}};c[a.name]=function(b,d,e){(new c(b))[a.name](d,e)};Object.defineProperty&&(Object.defineProperty(c[a.name],"$options",{value:a.buildOpt()}),Object.defineProperty(c.prototype[a.name],"$options",{value:c[a.name].$options}))})(d[e]);return c}(d,this)};l.Service=n;var p=function(a,b,d){c.call(this,a,b);this.className="Service.Method";this.options= | ||
d||{}};p.prototype=Object.create(c.prototype);p.prototype.buildOpt=b.prototype.buildOpt;l.Service.Method=p;n=function(a,b,c,d,e){p.call(this,a,b,e);this.className="Service.RPCMethod";this.requestName=c;this.responseName=d;this.resolvedResponseType=this.resolvedRequestType=null};n.prototype=Object.create(p.prototype);l.Service.RPCMethod=n;return l}(g);g.Builder=function(d,e,g){var l=function(){this.ptr=this.ns=new g.Namespace(null,"");this.resolved=!1;this.result=null;this.files={};this.importRoot= | ||
null};l.prototype.reset=function(){this.ptr=this.ns};l.prototype.define=function(c,b){if("string"!==typeof c||!e.TYPEREF.test(c))throw Error("Illegal package: "+c);var a=c.split("."),d;for(d=0;d<a.length;d++)if(!e.NAME.test(a[d]))throw Error("Illegal package: "+a[d]);for(d=0;d<a.length;d++)this.ptr.hasChild(a[d])||this.ptr.addChild(new g.Namespace(this.ptr,a[d],b)),this.ptr=this.ptr.getChild(a[d]);return this};l.isValidMessage=function(c){if("string"!==typeof c.name||!e.NAME.test(c.name)||"undefined"!== | ||
typeof c.values||"undefined"!==typeof c.rpc)return!1;var b;if("undefined"!==typeof c.fields){if(!d.Util.isArray(c.fields))return!1;var a=[],f;for(b=0;b<c.fields.length;b++){if(!l.isValidMessageField(c.fields[b]))return!1;f=parseInt(c.fields[b].id,10);if(0<=a.indexOf(f))return!1;a.push(f)}}if("undefined"!==typeof c.enums){if(!d.Util.isArray(c.enums))return!1;for(b=0;b<c.enums.length;b++)if(!l.isValidEnum(c.enums[b]))return!1}if("undefined"!==typeof c.messages){if(!d.Util.isArray(c.messages))return!1; | ||
": "+e),c.encoded=b,c;return b};a.prototype.calculate=function(d){for(var b=this.getChildren(a.Field),c=0,e=0,f;e<b.length;e++){f=d.$get(b[e].name);if(b[e].required&&null===f)throw Error("Missing at least one required field for "+this.toString(!0)+": "+b[e]);c+=b[e].calculate(f)}return c};a.prototype.decode=function(a,b,c){b="number"===typeof b?b:-1;for(var f=a.offset,g=new this.clazz,h,l,k;a.offset<f+b||-1==b&&0<a.remaining();){h=a.readVarint32();l=h&7;k=h>>3;if(l===d.WIRE_TYPES.ENDGROUP){if(k!== | ||
c)throw Error("Illegal group end indicator for "+this.toString(!0)+": "+k+" ("+(c?c+" expected":"not a group")+")");break}if(h=this.getChild(k))h.repeated&&!h.options.packed?g.$add(h.name,h.decode(l,a),!0):g.$set(h.name,h.decode(l,a),!0);else switch(l){case d.WIRE_TYPES.VARINT:a.readVarint32();break;case d.WIRE_TYPES.BITS32:a.offset+=4;break;case d.WIRE_TYPES.BITS64:a.offset+=8;break;case d.WIRE_TYPES.LDELIM:h=a.readVarint32();a.offset+=h;break;case d.WIRE_TYPES.STARTGROUP:for(;e(k,a););break;default:throw Error("Illegal wire type for unknown field "+ | ||
k+" in "+this.toString(!0)+"#decode: "+l);}}a=this.getChildren(d.Reflect.Field);for(b=0;b<a.length;b++)if(h=a[b],null===g[h.name]){if(h.required)throw a=Error("Missing at least one required field for "+this.toString(!0)+": "+h.name),a.decoded=g,a;if("undefined"!==typeof h.options["default"])try{g.$set(h.name,h.options["default"])}catch(s){throw Error("[INTERNAL] "+s);}}return g};l.Message=a;var f=function(a,b,e,f,g,h){c.call(this,a,f);this.className="Message.Field";this.required="required"==b;this.repeated= | ||
"repeated"==b;this.type=e;this.resolvedType=null;this.id=g;this.options=h||{};this.originalName=this.name;d.convertFieldsToCamelCase&&(this.name=this.name.replace(/_([a-zA-Z])/g,function(a,b){return b.toUpperCase()}))};f.prototype=Object.create(c.prototype);f.prototype.verifyValue=function(a,b){b=b||!1;var c=function(a,b){throw Error("Illegal value for "+this.toString(!0)+" of type "+this.type.name+": "+a+" ("+b+")");}.bind(this);if(null===a)return this.required&&c(typeof a,"required"),null;var e; | ||
if(this.repeated&&!b){d.Util.isArray(a)||(a=[a]);c=[];for(e=0;e<a.length;e++)c.push(this.verifyValue(a[e],!0));return c}!this.repeated&&d.Util.isArray(a)&&c(typeof a,"no array expected");switch(this.type){case d.TYPES.int32:case d.TYPES.sint32:case d.TYPES.sfixed32:return("number"!==typeof a||a===a&&0!==a%1)&&c(typeof a,"not an integer"),4294967295<a?a|0:a;case d.TYPES.uint32:case d.TYPES.fixed32:return("number"!==typeof a||a===a&&0!==a%1)&&c(typeof a,"not an integer"),0>a?a>>>0:a;case d.TYPES.int64:case d.TYPES.sint64:case d.TYPES.sfixed64:if(d.Long)try{return g(a, | ||
!1)}catch(f){c(typeof a,f.message)}else c(typeof a,"requires Long.js");case d.TYPES.uint64:case d.TYPES.fixed64:if(d.Long)try{return g(a,!0)}catch(l){c(typeof a,l.message)}else c(typeof a,"requires Long.js");case d.TYPES.bool:return"boolean"!==typeof a&&c(typeof a,"not a boolean"),a;case d.TYPES["float"]:case d.TYPES["double"]:return"number"!==typeof a&&c(typeof a,"not a number"),a;case d.TYPES.string:return"string"===typeof a||a&&a instanceof String||c(typeof a,"not a string"),""+a;case d.TYPES.bytes:return a&& | ||
a instanceof k?a:k.wrap(a);case d.TYPES["enum"]:var n=this.resolvedType.getChildren(h.Value);for(e=0;e<n.length;e++)if(n[e].name==a||n[e].id==a)return n[e].id;c(a,"not a valid enum value");case d.TYPES.group:case d.TYPES.message:return a&&"object"===typeof a||c(typeof a,"object expected"),a instanceof this.resolvedType.clazz?a:new this.resolvedType.clazz(a)}throw Error("[INTERNAL] Illegal value for "+this.toString(!0)+": "+a+" (undefined type "+this.type+")");};f.prototype.encode=function(a,b){a= | ||
this.verifyValue(a);if(null===this.type||"object"!==typeof this.type)throw Error("[INTERNAL] Unresolved type in "+this.toString(!0)+": "+this.type);if(null===a||this.repeated&&0==a.length)return b;try{if(this.repeated){var c;if(this.options.packed&&0<=d.PACKABLE_WIRE_TYPES.indexOf(this.type.wireType)){b.writeVarint32(this.id<<3|d.WIRE_TYPES.LDELIM);b.ensureCapacity(b.offset+=1);var e=b.offset;for(c=0;c<a.length;c++)this.encodeValue(a[c],b);var f=b.offset-e,g=k.calculateVarint32(f);if(1<g){var h=b.slice(e, | ||
b.offset),e=e+(g-1);b.offset=e;b.append(h)}b.writeVarint32(f,e-g)}else for(c=0;c<a.length;c++)b.writeVarint32(this.id<<3|this.type.wireType),this.encodeValue(a[c],b)}else b.writeVarint32(this.id<<3|this.type.wireType),this.encodeValue(a,b)}catch(l){throw Error("Illegal value for "+this.toString(!0)+": "+a+" ("+l+")");}return b};f.prototype.encodeValue=function(a,b){if(null===a)return b;switch(this.type){case d.TYPES.int32:0>a?b.writeVarint64(a):b.writeVarint32(a);break;case d.TYPES.uint32:b.writeVarint32(a); | ||
break;case d.TYPES.sint32:b.writeVarint32ZigZag(a);break;case d.TYPES.fixed32:b.writeUint32(a);break;case d.TYPES.sfixed32:b.writeInt32(a);break;case d.TYPES.int64:case d.TYPES.uint64:b.writeVarint64(a);break;case d.TYPES.sint64:b.writeVarint64ZigZag(a);break;case d.TYPES.fixed64:b.writeUint64(a);break;case d.TYPES.sfixed64:b.writeInt64(a);break;case d.TYPES.bool:"string"===typeof a?b.writeVarint32("false"===a.toLowerCase()?0:!!a):b.writeVarint32(a?1:0);break;case d.TYPES["enum"]:b.writeVarint32(a); | ||
break;case d.TYPES["float"]:b.writeFloat32(a);break;case d.TYPES["double"]:b.writeFloat64(a);break;case d.TYPES.string:b.writeVString(a);break;case d.TYPES.bytes:if(0>a.remaining())throw Error("Illegal value for "+this.toString(!0)+": "+a.remaining()+" bytes remaining");var c=a.offset;b.writeVarint32(a.remaining());b.append(a);a.offset=c;break;case d.TYPES.message:c=(new k).LE();this.resolvedType.encode(a,c);b.writeVarint32(c.offset);b.append(c.flip());break;case d.TYPES.group:this.resolvedType.encode(a, | ||
b);b.writeVarint32(this.id<<3|d.WIRE_TYPES.ENDGROUP);break;default:throw Error("[INTERNAL] Illegal value to encode in "+this.toString(!0)+": "+a+" (unknown type)");}return b};f.prototype.calculate=function(a){a=this.verifyValue(a);if(null===this.type||"object"!==typeof this.type)throw Error("[INTERNAL] Unresolved type in "+this.toString(!0)+": "+this.type);if(null===a||this.repeated&&0==a.length)return 0;var b=0;try{if(this.repeated){var c,e;if(this.options.packed&&0<=d.PACKABLE_WIRE_TYPES.indexOf(this.type.wireType)){b+= | ||
k.calculateVarint32(this.id<<3|d.WIRE_TYPES.LDELIM);for(c=e=0;c<a.length;c++)e+=this.calculateValue(a[c]);b+=k.calculateVarint32(e);b+=e}else for(c=0;c<a.length;c++)b+=k.calculateVarint32(this.id<<3|this.type.wireType),b+=this.calculateValue(a[c])}else b+=k.calculateVarint32(this.id<<3|this.type.wireType),b+=this.calculateValue(a)}catch(f){throw Error("Illegal value for "+this.toString(!0)+": "+a+" ("+f+")");}return b};f.prototype.calculateValue=function(a){if(null===a)return 0;switch(this.type){case d.TYPES.int32:return 0> | ||
a?k.calculateVarint64(a):k.calculateVarint32(a);case d.TYPES.uint32:return k.calculateVarint32(a);case d.TYPES.sint32:return k.calculateVarint32(k.zigZagEncode32(a));case d.TYPES.fixed32:case d.TYPES.sfixed32:case d.TYPES["float"]:return 4;case d.TYPES.int64:case d.TYPES.uint64:return k.calculateVarint64(a);case d.TYPES.sint64:return k.calculateVarint64(k.zigZagEncode64(a));case d.TYPES.fixed64:case d.TYPES.sfixed64:return 8;case d.TYPES.bool:return 1;case d.TYPES["enum"]:return k.calculateVarint32(a); | ||
case d.TYPES["double"]:return 8;case d.TYPES.string:return a=k.calculateUTF8Bytes(a),k.calculateVarint32(a)+a;case d.TYPES.bytes:if(0>a.remaining())throw Error("Illegal value for "+this.toString(!0)+": "+a.remaining()+" bytes remaining");return k.calculateVarint32(a.remaining())+a.remaining();case d.TYPES.message:return a=this.resolvedType.calculate(a),k.calculateVarint32(a)+a;case d.TYPES.group:return a=this.resolvedType.calculate(a),a+k.calculateVarint32(this.id<<3|d.WIRE_TYPES.ENDGROUP)}throw Error("[INTERNAL] Illegal value to encode in "+ | ||
this.toString(!0)+": "+a+" (unknown type)");};f.prototype.decode=function(a,b,c){if(a!=this.type.wireType&&(c||a!=d.WIRE_TYPES.LDELIM||!this.repeated))throw Error("Illegal wire type for field "+this.toString(!0)+": "+a+" ("+this.type.wireType+" expected)");if(a==d.WIRE_TYPES.LDELIM&&this.repeated&&this.options.packed&&0<=d.PACKABLE_WIRE_TYPES.indexOf(this.type.wireType)&&!c){a=b.readVarint32();a=b.offset+a;for(c=[];b.offset<a;)c.push(this.decode(this.type.wireType,b,!0));return c}switch(this.type){case d.TYPES.int32:return b.readVarint32()| | ||
0;case d.TYPES.uint32:return b.readVarint32()>>>0;case d.TYPES.sint32:return b.readVarint32ZigZag()|0;case d.TYPES.fixed32:return b.readUint32()>>>0;case d.TYPES.sfixed32:return b.readInt32()|0;case d.TYPES.int64:return b.readVarint64();case d.TYPES.uint64:return b.readVarint64().toUnsigned();case d.TYPES.sint64:return b.readVarint64ZigZag();case d.TYPES.fixed64:return b.readUint64();case d.TYPES.sfixed64:return b.readInt64();case d.TYPES.bool:return!!b.readVarint32();case d.TYPES["enum"]:return b.readVarint32(); | ||
case d.TYPES["float"]:return b.readFloat();case d.TYPES["double"]:return b.readDouble();case d.TYPES.string:return b.readVString();case d.TYPES.bytes:a=b.readVarint32();if(b.remaining()<a)throw Error("Illegal number of bytes for "+this.toString(!0)+": "+a+" required but got only "+b.remaining());c=b.clone();c.limit=c.offset+a;b.offset+=a;return c;case d.TYPES.message:return a=b.readVarint32(),this.resolvedType.decode(b,a);case d.TYPES.group:return this.resolvedType.decode(b,-1,this.id)}throw Error("[INTERNAL] Illegal wire type for "+ | ||
this.toString(!0)+": "+a);};l.Message.Field=f;var n=function(a,b,c,d,e,g){f.call(this,a,b,c,d,e,g)};n.prototype=Object.create(f.prototype);l.Message.ExtensionField=n;var h=function(a,c,d){b.call(this,a,c,d);this.className="Enum";this.object=null};h.prototype=Object.create(b.prototype);h.prototype.build=function(){for(var a={},b=this.getChildren(h.Value),c=0;c<b.length;c++)a[b[c].name]=b[c].id;Object.defineProperty&&Object.defineProperty(a,"$options",{value:this.buildOpt()});return this.object=a}; | ||
l.Enum=h;n=function(a,b,d){c.call(this,a,b);this.className="Enum.Value";this.id=d};n.prototype=Object.create(c.prototype);l.Enum.Value=n;n=function(a,c,d){b.call(this,a,c,d);this.className="Service";this.clazz=null};n.prototype=Object.create(b.prototype);n.prototype.build=function(a){return this.clazz&&!a?this.clazz:this.clazz=function(a,b){var c=function(b){a.Builder.Service.call(this);this.rpcImpl=b||function(a,b,c){setTimeout(c.bind(this,Error("Not implemented, see: https://github.com/dcodeIO/ProtoBuf.js/wiki/Services")), | ||
0)}};c.prototype=Object.create(a.Builder.Service.prototype);Object.defineProperty&&(Object.defineProperty(c,"$options",{value:b.buildOpt()}),Object.defineProperty(c.prototype,"$options",{value:c.$options}));for(var d=b.getChildren(a.Reflect.Service.RPCMethod),e=0;e<d.length;e++)(function(a){c.prototype[a.name]=function(c,d){try{c&&c instanceof a.resolvedRequestType.clazz?this.rpcImpl(a.fqn(),c,function(c,e){if(c)d(c);else{try{e=a.resolvedResponseType.clazz.decode(e)}catch(f){}e&&e instanceof a.resolvedResponseType.clazz? | ||
d(null,e):d(Error("Illegal response type received in service method "+b.name+"#"+a.name))}}):setTimeout(d.bind(this,Error("Illegal request type provided to service method "+b.name+"#"+a.name)),0)}catch(e){setTimeout(d.bind(this,e),0)}};c[a.name]=function(b,d,e){(new c(b))[a.name](d,e)};Object.defineProperty&&(Object.defineProperty(c[a.name],"$options",{value:a.buildOpt()}),Object.defineProperty(c.prototype[a.name],"$options",{value:c[a.name].$options}))})(d[e]);return c}(d,this)};l.Service=n;var p= | ||
function(a,b,d){c.call(this,a,b);this.className="Service.Method";this.options=d||{}};p.prototype=Object.create(c.prototype);p.prototype.buildOpt=b.prototype.buildOpt;l.Service.Method=p;n=function(a,b,c,d,e){p.call(this,a,b,e);this.className="Service.RPCMethod";this.requestName=c;this.responseName=d;this.resolvedResponseType=this.resolvedRequestType=null};n.prototype=Object.create(p.prototype);l.Service.RPCMethod=n;return l}(g);g.Builder=function(d,e,g){var l=function(){this.ptr=this.ns=new g.Namespace(null, | ||
"");this.resolved=!1;this.result=null;this.files={};this.importRoot=null};l.prototype.reset=function(){this.ptr=this.ns};l.prototype.define=function(c,b){if("string"!==typeof c||!e.TYPEREF.test(c))throw Error("Illegal package: "+c);var a=c.split("."),d;for(d=0;d<a.length;d++)if(!e.NAME.test(a[d]))throw Error("Illegal package: "+a[d]);for(d=0;d<a.length;d++)this.ptr.hasChild(a[d])||this.ptr.addChild(new g.Namespace(this.ptr,a[d],b)),this.ptr=this.ptr.getChild(a[d]);return this};l.isValidMessage=function(c){if("string"!== | ||
typeof c.name||!e.NAME.test(c.name)||"undefined"!==typeof c.values||"undefined"!==typeof c.rpc)return!1;var b;if("undefined"!==typeof c.fields){if(!d.Util.isArray(c.fields))return!1;var a=[],f;for(b=0;b<c.fields.length;b++){if(!l.isValidMessageField(c.fields[b]))return!1;f=parseInt(c.fields[b].id,10);if(0<=a.indexOf(f))return!1;a.push(f)}}if("undefined"!==typeof c.enums){if(!d.Util.isArray(c.enums))return!1;for(b=0;b<c.enums.length;b++)if(!l.isValidEnum(c.enums[b]))return!1}if("undefined"!==typeof c.messages){if(!d.Util.isArray(c.messages))return!1; | ||
for(b=0;b<c.messages.length;b++)if(!l.isValidMessage(c.messages[b])&&!l.isValidExtend(c.messages[b]))return!1}return"undefined"===typeof c.extensions||d.Util.isArray(c.extensions)&&2===c.extensions.length&&"number"===typeof c.extensions[0]&&"number"===typeof c.extensions[1]?!0:!1};l.isValidMessageField=function(c){if("string"!==typeof c.rule||"string"!==typeof c.name||"string"!==typeof c.type||"undefined"===typeof c.id||!(e.RULE.test(c.rule)&&e.NAME.test(c.name)&&e.TYPEREF.test(c.type)&&e.ID.test(""+ | ||
@@ -87,0 +87,0 @@ c.id)))return!1;if("undefined"!==typeof c.options){if("object"!==typeof c.options)return!1;for(var b=Object.keys(c.options),a=0,d;a<b.length;a++)if("string"!==typeof(d=b[a])||"string"!==typeof c.options[d]&&"number"!==typeof c.options[d]&&"boolean"!==typeof c.options[d])return!1}return!0};l.isValidEnum=function(c){if("string"!==typeof c.name||!e.NAME.test(c.name)||"undefined"===typeof c.values||!d.Util.isArray(c.values)||0==c.values.length)return!1;for(var b=0;b<c.values.length;b++)if("object"!=typeof c.values[b]|| |
@@ -6,5 +6,5 @@ /* | ||
*/ | ||
(function(s){function t(h){var g={VERSION:"3.3.1",WIRE_TYPES:{}};g.WIRE_TYPES.VARINT=0;g.WIRE_TYPES.BITS64=1;g.WIRE_TYPES.LDELIM=2;g.WIRE_TYPES.STARTGROUP=3;g.WIRE_TYPES.ENDGROUP=4;g.WIRE_TYPES.BITS32=5;g.PACKABLE_WIRE_TYPES=[g.WIRE_TYPES.VARINT,g.WIRE_TYPES.BITS64,g.WIRE_TYPES.BITS32];g.TYPES={int32:{name:"int32",wireType:g.WIRE_TYPES.VARINT},uint32:{name:"uint32",wireType:g.WIRE_TYPES.VARINT},sint32:{name:"sint32",wireType:g.WIRE_TYPES.VARINT},int64:{name:"int64",wireType:g.WIRE_TYPES.VARINT},uint64:{name:"uint64", | ||
(function(s){function t(l){var g={VERSION:"3.4.0",WIRE_TYPES:{}};g.WIRE_TYPES.VARINT=0;g.WIRE_TYPES.BITS64=1;g.WIRE_TYPES.LDELIM=2;g.WIRE_TYPES.STARTGROUP=3;g.WIRE_TYPES.ENDGROUP=4;g.WIRE_TYPES.BITS32=5;g.PACKABLE_WIRE_TYPES=[g.WIRE_TYPES.VARINT,g.WIRE_TYPES.BITS64,g.WIRE_TYPES.BITS32];g.TYPES={int32:{name:"int32",wireType:g.WIRE_TYPES.VARINT},uint32:{name:"uint32",wireType:g.WIRE_TYPES.VARINT},sint32:{name:"sint32",wireType:g.WIRE_TYPES.VARINT},int64:{name:"int64",wireType:g.WIRE_TYPES.VARINT},uint64:{name:"uint64", | ||
wireType:g.WIRE_TYPES.VARINT},sint64:{name:"sint64",wireType:g.WIRE_TYPES.VARINT},bool:{name:"bool",wireType:g.WIRE_TYPES.VARINT},"double":{name:"double",wireType:g.WIRE_TYPES.BITS64},string:{name:"string",wireType:g.WIRE_TYPES.LDELIM},bytes:{name:"bytes",wireType:g.WIRE_TYPES.LDELIM},fixed32:{name:"fixed32",wireType:g.WIRE_TYPES.BITS32},sfixed32:{name:"sfixed32",wireType:g.WIRE_TYPES.BITS32},fixed64:{name:"fixed64",wireType:g.WIRE_TYPES.BITS64},sfixed64:{name:"sfixed64",wireType:g.WIRE_TYPES.BITS64}, | ||
"float":{name:"float",wireType:g.WIRE_TYPES.BITS32},"enum":{name:"enum",wireType:g.WIRE_TYPES.VARINT},message:{name:"message",wireType:g.WIRE_TYPES.LDELIM},group:{name:"group",wireType:g.WIRE_TYPES.STARTGROUP}};g.ID_MIN=1;g.ID_MAX=536870911;g.ByteBuffer=h;g.Long=h.Long||null;g.convertFieldsToCamelCase=!1;g.populateAccessors=!0;g.Util=function(){Object.create||(Object.create=function(d){function m(){}if(1<arguments.length)throw Error("Object.create polyfill only accepts the first parameter.");m.prototype= | ||
"float":{name:"float",wireType:g.WIRE_TYPES.BITS32},"enum":{name:"enum",wireType:g.WIRE_TYPES.VARINT},message:{name:"message",wireType:g.WIRE_TYPES.LDELIM},group:{name:"group",wireType:g.WIRE_TYPES.STARTGROUP}};g.ID_MIN=1;g.ID_MAX=536870911;g.ByteBuffer=l;g.Long=l.Long||null;g.convertFieldsToCamelCase=!1;g.populateAccessors=!0;g.Util=function(){Object.create||(Object.create=function(d){function m(){}if(1<arguments.length)throw Error("Object.create polyfill only accepts the first parameter.");m.prototype= | ||
d;return new m});var d={IS_NODE:!1};try{d.IS_NODE="function"===typeof require&&"function"===typeof require("fs").readFileSync&&"function"===typeof require("path").resolve}catch(g){}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")}],m=null,b=0;b<d.length;b++){try{m=d[b]()}catch(e){continue}break}if(!m)throw Error("XMLHttpRequest is not supported"); | ||
@@ -14,61 +14,61 @@ return m};d.fetch=function(g,m){m&&"function"!=typeof m&&(m=null);if(d.IS_NODE)if(m)require("fs").readFile(g,function(d,b){d?m(null):m(""+b)});else try{return require("fs").readFileSync(g)}catch(b){return null}else{var e=d.XHR();e.open("GET",g,m?!0:!1);e.setRequestHeader("Accept","text/plain");"function"===typeof e.overrideMimeType&&e.overrideMimeType("text/plain");if(m)e.onreadystatechange=function(){4==e.readyState&&(200==e.status||0==e.status&&"string"===typeof e.responseText?m(e.responseText): | ||
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]*)+$/,FQTYPEREF:/^(?:\.[a-zA-Z][a-zA-Z_0-9]*)+$/,NUMBER:/^-?(?:[1-9][0-9]*|0|0x[0-9a-fA-F]+|0[0-7]+|([0-9]*\.[0-9]+([Ee][+-]?[0-9]+)?))$/,NUMBER_DEC:/^(?:[1-9][0-9]*|0)$/,NUMBER_HEX:/^0x[0-9a-fA-F]+$/,NUMBER_OCT:/^0[0-7]+$/,NUMBER_FLT:/^[0-9]*\.[0-9]+([Ee][+-]?[0-9]+)?$/,ID:/^(?:[1-9][0-9]*|0|0x[0-9a-fA-F]+|0[0-7]+)$/, | ||
NEGID:/^\-?(?:[1-9][0-9]*|0|0x[0-9a-fA-F]+|0[0-7]+)$/,WHITESPACE:/\s/,STRING:/['"]([^'"\\]*(\\.[^"\\]*)*)['"]/g,BOOL:/^(?:true|false)$/i};g.Reflect=function(d){function g(a,f){var b=f.readVarint32(),c=b&7,b=b>>3;switch(c){case d.WIRE_TYPES.VARINT:do b=f.readUint8();while(128===(b&128));break;case d.WIRE_TYPES.BITS64:f.offset+=8;break;case d.WIRE_TYPES.LDELIM:b=f.readVarint32();f.offset+=b;break;case d.WIRE_TYPES.STARTGROUP:g(b,f);break;case d.WIRE_TYPES.ENDGROUP:if(b===a)return!1;throw Error("Illegal GROUPEND after unknown group: "+ | ||
b+" ("+a+" expected)");case d.WIRE_TYPES.BITS32:f.offset+=4;break;default:throw Error("Illegal wire type in unknown group "+a+": "+c);}return!0}function q(a,f){if(a&&"number"===typeof a.low&&"number"===typeof a.high&&"boolean"===typeof a.unsigned&&a.low===a.low&&a.high===a.high)return new d.Long(a.low,a.high,"undefined"===typeof f?a.unsigned:f);if("string"===typeof a)return d.Long.fromString(a,f||!1,10);if("number"===typeof a)return d.Long.fromNumber(a,f||!1);throw Error("not convertible to Long"); | ||
}var m={},b=function(a,f){this.parent=a;this.name=f};b.prototype.fqn=function(){var a=this.name,f=this;do{f=f.parent;if(null==f)break;a=f.name+"."+a}while(1);return a};b.prototype.toString=function(a){return(a?this.className+" ":"")+this.fqn()};b.prototype.build=function(){throw Error(this.toString(!0)+" cannot be built directly");};m.T=b;var e=function(a,f,d){b.call(this,a,f);this.className="Namespace";this.children=[];this.options=d||{}};e.prototype=Object.create(b.prototype);e.prototype.getChildren= | ||
function(a){a=a||null;if(null==a)return this.children.slice();for(var f=[],b=0,d=this.children.length;b<d;++b)this.children[b]instanceof a&&(a===c.Field&&this.children[b]instanceof c.ExtensionField||f.push(this.children[b]));return f};e.prototype.addChild=function(a){var f;if(f=this.getChild(a.name))if(f instanceof c.Field&&f.name!==f.originalName&&!this.hasChild(f.originalName))f.name=f.originalName;else if(a instanceof c.Field&&a.name!==a.originalName&&!this.hasChild(a.originalName))a.name=a.originalName; | ||
else throw Error("Duplicate name in namespace "+this.toString(!0)+": "+a.name);this.children.push(a)};e.prototype.hasChild=function(a){return-1<this._indexOf(a)};e.prototype.getChild=function(a){a=this._indexOf(a);return-1<a?this.children[a]:null};e.prototype._indexOf=function(a){for(var f="number"===typeof a?"id":"name",b=0;b<this.children.length;b++)if("undefined"!==typeof this.children[b][f]&&this.children[b][f]==a)return b;return-1};e.prototype.resolve=function(a,f){var b=a.split("."),d=this, | ||
c=0;if(""==b[c]){for(;null!=d.parent;)d=d.parent;c++}do{do{d=d.getChild(b[c]);if(!(d&&d instanceof m.T)||f&&d instanceof m.Message.Field){d=null;break}c++}while(c<b.length);if(null!=d)break;if(null!==this.parent)return this.parent.resolve(a,f)}while(null!=d);return d};e.prototype.build=function(){for(var a={},f=this.getChildren(),b,d=0,c=f.length;d<c;++d)b=f[d],b instanceof e&&(a[b.name]=b.build());Object.defineProperty&&Object.defineProperty(a,"$options",{value:this.buildOpt()});return a};e.prototype.buildOpt= | ||
function(){for(var a={},f=Object.keys(this.options),b=0;b<f.length;b++)a[f[b]]=this.options[f[b]];return a};e.prototype.getOption=function(a){return"undefined"===typeof a?this.options:"undefined"!==typeof this.options[a]?this.options[a]:null};m.Namespace=e;var c=function(a,f,b,c){e.call(this,a,f,b);this.className="Message";this.extensions=[d.ID_MIN,d.ID_MAX];this.clazz=null;this.isGroup=!!c};c.prototype=Object.create(e.prototype);c.prototype.build=function(a){if(this.clazz&&!a)return this.clazz;a= | ||
function(a,b){function d(a,b){var f={},c;for(c in a)a.hasOwnProperty(c)&&(null===a[c]||"object"!==typeof a[c]?f[c]=a[c]:a[c]instanceof h?b&&(f[c]=a.toBuffer()):f[c]=d(a[c],b));return f}var f=b.getChildren(a.Reflect.Message.Field),c=function(d,c){a.Builder.Message.call(this);var e,p;Object.defineProperty&&Object.defineProperty(this,"$type",{get:function(){return b}});for(e=0;e<f.length;e++)p=f[e],this[p.name]=p.repeated?[]:null;for(e=0;e<f.length;e++)if(p=f[e],"undefined"!=typeof p.options["default"])try{this.$set(p.name, | ||
p.options["default"])}catch(k){throw Error("[INTERNAL] "+k);}if(1!=arguments.length||"object"!=typeof d||"function"==typeof d.encode||a.Util.isArray(d)||d instanceof h||d instanceof ArrayBuffer||a.Long&&d instanceof a.Long)for(e=0;e<arguments.length;e++)e<f.length&&this.$set(f[e].name,arguments[e]);else for(p=Object.keys(d),e=0;e<p.length;e++)this.$set(p[e],d[p[e]])};c.prototype=Object.create(a.Builder.Message.prototype);c.prototype.add=function(f,d,c){var e=b.getChild(f);if(!e)throw Error(this+"#"+ | ||
f+" is undefined");if(!(e instanceof a.Reflect.Message.Field))throw Error(this+"#"+f+" is not a field: "+e.toString(!0));if(!e.repeated)throw Error(this+"#"+f+" is not a repeated field");null===this[e.name]&&(this[e.name]=[]);this[e.name].push(c?d:e.verifyValue(d,!0))};c.prototype.$add=c.prototype.add;c.prototype.set=function(f,d,c){var e=b.getChild(f);if(!e)throw Error(this+"#"+f+" is not a field: undefined");if(!(e instanceof a.Reflect.Message.Field))throw Error(this+"#"+f+" is not a field: "+e.toString(!0)); | ||
this[e.name]=c?d:e.verifyValue(d)};c.prototype.$set=c.prototype.set;c.prototype.get=function(f){var d=b.getChild(f);if(!(d&&d instanceof a.Reflect.Message.Field))throw Error(this+"#"+f+" is not a field: undefined");if(!(d instanceof a.Reflect.Message.Field))throw Error(this+"#"+f+" is not a field: "+d.toString(!0));return this[d.name]};c.prototype.$get=c.prototype.get;for(var e=0;e<f.length;e++){var p=f[e];a.populateAccessors&&function(a){var f=a.originalName.replace(/(_[a-zA-Z])/g,function(a){return a.toUpperCase().replace("_", | ||
"")}),f=f.substring(0,1).toUpperCase()+f.substring(1),d=a.originalName.replace(/([A-Z])/g,function(a){return"_"+a});b.hasChild("set"+f)||(c.prototype["set"+f]=function(b){this.$set(a.name,b)});b.hasChild("set_"+d)||(c.prototype["set_"+d]=function(b){this.$set(a.name,b)});b.hasChild("get"+f)||(c.prototype["get"+f]=function(){return this.$get(a.name)});b.hasChild("get_"+d)||(c.prototype["get_"+d]=function(){return this.$get(a.name)})}(p)}c.prototype.encode=function(a){var f=!1;a||(a=new h,f=!0);var d= | ||
a.littleEndian;try{return b.encode(this,a.LE()),(f?a.flip():a).LE(d)}catch(c){throw a.LE(d),c;}};c.prototype.calculate=function(){return b.calculate(this)};c.prototype.encodeDelimited=function(a){var f=!1;a||(a=new h,f=!0);var d=(new h).LE();b.encode(this,d).flip();a.writeVarint32(d.remaining());a.append(d);return f?a.flip():a};c.prototype.encodeAB=function(){try{return this.encode().toArrayBuffer()}catch(a){throw a.encoded&&(a.encoded=a.encoded.toArrayBuffer()),a;}};c.prototype.toArrayBuffer=c.prototype.encodeAB; | ||
NEGID:/^\-?(?:[1-9][0-9]*|0|0x[0-9a-fA-F]+|0[0-7]+)$/,WHITESPACE:/\s/,STRING:/['"]([^'"\\]*(\\.[^"\\]*)*)['"]/g,BOOL:/^(?:true|false)$/i};g.Reflect=function(d){function g(a,k){var b=k.readVarint32(),c=b&7,b=b>>3;switch(c){case d.WIRE_TYPES.VARINT:do b=k.readUint8();while(128===(b&128));break;case d.WIRE_TYPES.BITS64:k.offset+=8;break;case d.WIRE_TYPES.LDELIM:b=k.readVarint32();k.offset+=b;break;case d.WIRE_TYPES.STARTGROUP:g(b,k);break;case d.WIRE_TYPES.ENDGROUP:if(b===a)return!1;throw Error("Illegal GROUPEND after unknown group: "+ | ||
b+" ("+a+" expected)");case d.WIRE_TYPES.BITS32:k.offset+=4;break;default:throw Error("Illegal wire type in unknown group "+a+": "+c);}return!0}function r(a,k){if(a&&"number"===typeof a.low&&"number"===typeof a.high&&"boolean"===typeof a.unsigned&&a.low===a.low&&a.high===a.high)return new d.Long(a.low,a.high,"undefined"===typeof k?a.unsigned:k);if("string"===typeof a)return d.Long.fromString(a,k||!1,10);if("number"===typeof a)return d.Long.fromNumber(a,k||!1);throw Error("not convertible to Long"); | ||
}var m={},b=function(a,k){this.parent=a;this.name=k};b.prototype.fqn=function(){var a=this.name,k=this;do{k=k.parent;if(null==k)break;a=k.name+"."+a}while(1);return a};b.prototype.toString=function(a){return(a?this.className+" ":"")+this.fqn()};b.prototype.build=function(){throw Error(this.toString(!0)+" cannot be built directly");};m.T=b;var e=function(a,k,d){b.call(this,a,k);this.className="Namespace";this.children=[];this.options=d||{}};e.prototype=Object.create(b.prototype);e.prototype.getChildren= | ||
function(a){a=a||null;if(null==a)return this.children.slice();for(var k=[],b=0,d=this.children.length;b<d;++b)this.children[b]instanceof a&&(a===c.Field&&this.children[b]instanceof c.ExtensionField||k.push(this.children[b]));return k};e.prototype.addChild=function(a){var k;if(k=this.getChild(a.name))if(k instanceof c.Field&&k.name!==k.originalName&&!this.hasChild(k.originalName))k.name=k.originalName;else if(a instanceof c.Field&&a.name!==a.originalName&&!this.hasChild(a.originalName))a.name=a.originalName; | ||
else throw Error("Duplicate name in namespace "+this.toString(!0)+": "+a.name);this.children.push(a)};e.prototype.hasChild=function(a){return-1<this._indexOf(a)};e.prototype.getChild=function(a){a=this._indexOf(a);return-1<a?this.children[a]:null};e.prototype._indexOf=function(a){for(var k="number"===typeof a?"id":"name",b=0;b<this.children.length;b++)if("undefined"!==typeof this.children[b][k]&&this.children[b][k]==a)return b;return-1};e.prototype.resolve=function(a,k){var b=a.split("."),d=this, | ||
c=0;if(""==b[c]){for(;null!=d.parent;)d=d.parent;c++}do{do{d=d.getChild(b[c]);if(!(d&&d instanceof m.T)||k&&d instanceof m.Message.Field){d=null;break}c++}while(c<b.length);if(null!=d)break;if(null!==this.parent)return this.parent.resolve(a,k)}while(null!=d);return d};e.prototype.build=function(){for(var a={},k=this.getChildren(),b,d=0,c=k.length;d<c;++d)b=k[d],b instanceof e&&(a[b.name]=b.build());Object.defineProperty&&Object.defineProperty(a,"$options",{value:this.buildOpt()});return a};e.prototype.buildOpt= | ||
function(){for(var a={},k=Object.keys(this.options),b=0;b<k.length;b++)a[k[b]]=this.options[k[b]];return a};e.prototype.getOption=function(a){return"undefined"===typeof a?this.options:"undefined"!==typeof this.options[a]?this.options[a]:null};m.Namespace=e;var c=function(a,b,c,f){e.call(this,a,b,c);this.className="Message";this.extensions=[d.ID_MIN,d.ID_MAX];this.clazz=null;this.isGroup=!!f};c.prototype=Object.create(e.prototype);c.prototype.build=function(a){if(this.clazz&&!a)return this.clazz;a= | ||
function(a,b){function d(a,b){var k={},c;for(c in a)a.hasOwnProperty(c)&&(null===a[c]||"object"!==typeof a[c]?k[c]=a[c]:a[c]instanceof l?b&&(k[c]=a.toBuffer()):k[c]=d(a[c],b));return k}var k=b.getChildren(a.Reflect.Message.Field),c=function(d,c){a.Builder.Message.call(this);var e,n;Object.defineProperty&&Object.defineProperty(this,"$type",{get:function(){return b}});for(e=0;e<k.length;e++)n=k[e],this[n.name]=n.repeated?[]:null;for(e=0;e<k.length;e++)if(n=k[e],n.required&&"undefined"!==typeof n.options["default"])try{this.$set(n.name, | ||
n.options["default"])}catch(f){throw Error("[INTERNAL] "+f);}if(1!=arguments.length||"object"!=typeof d||"function"==typeof d.encode||a.Util.isArray(d)||d instanceof l||d instanceof ArrayBuffer||a.Long&&d instanceof a.Long)for(e=0;e<arguments.length;e++)e<k.length&&this.$set(k[e].name,arguments[e]);else for(n=Object.keys(d),e=0;e<n.length;e++)this.$set(n[e],d[n[e]])};c.prototype=Object.create(a.Builder.Message.prototype);c.prototype.add=function(d,k,c){var e=b.getChild(d);if(!e)throw Error(this+"#"+ | ||
d+" is undefined");if(!(e instanceof a.Reflect.Message.Field))throw Error(this+"#"+d+" is not a field: "+e.toString(!0));if(!e.repeated)throw Error(this+"#"+d+" is not a repeated field");null===this[e.name]&&(this[e.name]=[]);this[e.name].push(c?k:e.verifyValue(k,!0))};c.prototype.$add=c.prototype.add;c.prototype.set=function(d,k,c){var e=b.getChild(d);if(!e)throw Error(this+"#"+d+" is not a field: undefined");if(!(e instanceof a.Reflect.Message.Field))throw Error(this+"#"+d+" is not a field: "+e.toString(!0)); | ||
this[e.name]=c?k:e.verifyValue(k)};c.prototype.$set=c.prototype.set;c.prototype.get=function(d){var k=b.getChild(d);if(!(k&&k instanceof a.Reflect.Message.Field))throw Error(this+"#"+d+" is not a field: undefined");if(!(k instanceof a.Reflect.Message.Field))throw Error(this+"#"+d+" is not a field: "+k.toString(!0));return this[k.name]};c.prototype.$get=c.prototype.get;for(var e=0;e<k.length;e++){var n=k[e];a.populateAccessors&&function(a){var d=a.originalName.replace(/(_[a-zA-Z])/g,function(a){return a.toUpperCase().replace("_", | ||
"")}),d=d.substring(0,1).toUpperCase()+d.substring(1),k=a.originalName.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_"+k)||(c.prototype["set_"+k]=function(b){this.$set(a.name,b)});b.hasChild("get"+d)||(c.prototype["get"+d]=function(){return this.$get(a.name)});b.hasChild("get_"+k)||(c.prototype["get_"+k]=function(){return this.$get(a.name)})}(n)}c.prototype.encode=function(a){var d=!1;a||(a=new l,d=!0);var k= | ||
a.littleEndian;try{return b.encode(this,a.LE()),(d?a.flip():a).LE(k)}catch(c){throw a.LE(k),c;}};c.prototype.calculate=function(){return b.calculate(this)};c.prototype.encodeDelimited=function(a){var d=!1;a||(a=new l,d=!0);var k=(new l).LE();b.encode(this,k).flip();a.writeVarint32(k.remaining());a.append(k);return d?a.flip():a};c.prototype.encodeAB=function(){try{return this.encode().toArrayBuffer()}catch(a){throw a.encoded&&(a.encoded=a.encoded.toArrayBuffer()),a;}};c.prototype.toArrayBuffer=c.prototype.encodeAB; | ||
c.prototype.encodeNB=function(){try{return this.encode().toBuffer()}catch(a){throw a.encoded&&(a.encoded=a.encoded.toBuffer()),a;}};c.prototype.toBuffer=c.prototype.encodeNB;c.prototype.encode64=function(){try{return this.encode().toBase64()}catch(a){throw a.encoded&&(a.encoded=a.encoded.toBase64()),a;}};c.prototype.toBase64=c.prototype.encode64;c.prototype.encodeHex=function(){try{return this.encode().toHex()}catch(a){throw a.encoded&&(a.encoded=a.encoded.toHex()),a;}};c.prototype.toHex=c.prototype.encodeHex; | ||
c.prototype.toRaw=function(a){return d(this,!!a)};c.decode=function(a,f){"string"===typeof a&&(a=h.wrap(a,f?f:"base64"));a=a instanceof h?a:h.wrap(a);var d=a.littleEndian;try{var c=b.decode(a.LE());a.LE(d);return c}catch(e){throw a.LE(d),e;}};c.decodeDelimited=function(a,f){"string"===typeof a&&(a=h.wrap(a,f?f:"base64"));a=a instanceof h?a:h.wrap(a);if(1>a.remaining())return null;var d=a.offset,c=a.readVarint32();if(a.remaining()<c)return a.offset=d,null;try{var e=b.decode(a.slice(a.offset,a.offset+ | ||
c).LE());a.offset+=c;return e}catch(p){throw a.offset+=c,p;}};c.decode64=function(a){return c.decode(a,"base64")};c.decodeHex=function(a){return c.decode(a,"hex")};c.prototype.toString=function(){return b.toString()};Object.defineProperty&&Object.defineProperty(c,"$options",{value:b.buildOpt()});return c}(d,this);for(var b=this.getChildren(),e=0;e<b.length;e++)if(b[e]instanceof l)a[b[e].name]=b[e].build();else if(b[e]instanceof c)a[b[e].name]=b[e].build();else if(!(b[e]instanceof c.Field))throw Error("Illegal reflect child of "+ | ||
this.toString(!0)+": "+b[e].toString(!0));return this.clazz=a};c.prototype.encode=function(a,f){for(var b=this.getChildren(c.Field),d=null,e=0,k;e<b.length;e++)k=a.$get(b[e].name),b[e].required&&null===k?null===d&&(d=b[e]):b[e].encode(k,f);if(null!==d)throw b=Error("Missing at least one required field for "+this.toString(!0)+": "+d),b.encoded=f,b;return f};c.prototype.calculate=function(a){for(var b=this.getChildren(c.Field),d=0,e=0,k;e<b.length;e++){k=a.$get(b[e].name);if(b[e].required&&null===k)throw Error("Missing at least one required field for "+ | ||
this.toString(!0)+": "+b[e]);d+=b[e].calculate(k)}return d};c.prototype.decode=function(a,b,c){b="number"===typeof b?b:-1;for(var e=a.offset,k=new this.clazz,l,m;a.offset<e+b||-1==b&&0<a.remaining();){l=a.readVarint32();m=l&7;l>>=3;if(m===d.WIRE_TYPES.ENDGROUP){if(l!==c)throw Error("Illegal group end indicator for "+this.toString(!0)+": "+l+" ("+(c?c+" expected":"not a group")+")");break}var h=this.getChild(l);if(h)h.repeated&&!h.options.packed?k.$add(h.name,h.decode(m,a),!0):k.$set(h.name,h.decode(m, | ||
a),!0);else switch(m){case d.WIRE_TYPES.VARINT:a.readVarint32();break;case d.WIRE_TYPES.BITS32:a.offset+=4;break;case d.WIRE_TYPES.BITS64:a.offset+=8;break;case d.WIRE_TYPES.LDELIM:m=a.readVarint32();a.offset+=m;break;case d.WIRE_TYPES.STARTGROUP:for(;g(l,a););break;default:throw Error("Illegal wire type for unknown field "+l+" in "+this.toString(!0)+"#decode: "+m);}}a=this.getChildren(d.Reflect.Field);for(b=0;b<a.length;b++)if(a[b].required&&null===k[a[b].name])throw a=Error("Missing at least one required field for "+ | ||
this.toString(!0)+": "+a[b].name),a.decoded=k,a;return k};m.Message=c;var k=function(a,f,c,e,k,l){b.call(this,a,e);this.className="Message.Field";this.required="required"==f;this.repeated="repeated"==f;this.type=c;this.resolvedType=null;this.id=k;this.options=l||{};this.originalName=this.name;d.convertFieldsToCamelCase&&(this.name=this.name.replace(/_([a-zA-Z])/g,function(a,b){return b.toUpperCase()}))};k.prototype=Object.create(b.prototype);k.prototype.verifyValue=function(a,b){b=b||!1;var c=function(a, | ||
b){throw Error("Illegal value for "+this.toString(!0)+" of type "+this.type.name+": "+a+" ("+b+")");}.bind(this);if(null===a)return this.required&&c(typeof a,"required"),null;var e;if(this.repeated&&!b){d.Util.isArray(a)||(a=[a]);c=[];for(e=0;e<a.length;e++)c.push(this.verifyValue(a[e],!0));return c}!this.repeated&&d.Util.isArray(a)&&c(typeof a,"no array expected");switch(this.type){case d.TYPES.int32:case d.TYPES.sint32:case d.TYPES.sfixed32:return("number"!==typeof a||a===a&&0!==a%1)&&c(typeof a, | ||
"not an integer"),4294967295<a?a|0:a;case d.TYPES.uint32:case d.TYPES.fixed32:return("number"!==typeof a||a===a&&0!==a%1)&&c(typeof a,"not an integer"),0>a?a>>>0:a;case d.TYPES.int64:case d.TYPES.sint64:case d.TYPES.sfixed64:if(d.Long)try{return q(a,!1)}catch(k){c(typeof a,k.message)}else c(typeof a,"requires Long.js");case d.TYPES.uint64:case d.TYPES.fixed64:if(d.Long)try{return q(a,!0)}catch(m){c(typeof a,m.message)}else c(typeof a,"requires Long.js");case d.TYPES.bool:return"boolean"!==typeof a&& | ||
c(typeof a,"not a boolean"),a;case d.TYPES["float"]:case d.TYPES["double"]:return"number"!==typeof a&&c(typeof a,"not a number"),a;case d.TYPES.string:return"string"===typeof a||a&&a instanceof String||c(typeof a,"not a string"),""+a;case d.TYPES.bytes:return a&&a instanceof h?a:h.wrap(a);case d.TYPES["enum"]:var g=this.resolvedType.getChildren(l.Value);for(e=0;e<g.length;e++)if(g[e].name==a||g[e].id==a)return g[e].id;c(a,"not a valid enum value");case d.TYPES.group:case d.TYPES.message:return a&& | ||
"object"===typeof a||c(typeof a,"object expected"),a instanceof this.resolvedType.clazz?a:new this.resolvedType.clazz(a)}throw Error("[INTERNAL] Illegal value for "+this.toString(!0)+": "+a+" (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] Unresolved type in "+this.toString(!0)+": "+this.type);if(null===a||this.repeated&&0==a.length)return b;try{if(this.repeated){var c;if(this.options.packed&& | ||
0<=d.PACKABLE_WIRE_TYPES.indexOf(this.type.wireType)){b.writeVarint32(this.id<<3|d.WIRE_TYPES.LDELIM);b.ensureCapacity(b.offset+=1);var e=b.offset;for(c=0;c<a.length;c++)this.encodeValue(a[c],b);var k=b.offset-e,l=h.calculateVarint32(k);if(1<l){var m=b.slice(e,b.offset),e=e+(l-1);b.offset=e;b.append(m)}b.writeVarint32(k,e-l)}else for(c=0;c<a.length;c++)b.writeVarint32(this.id<<3|this.type.wireType),this.encodeValue(a[c],b)}else b.writeVarint32(this.id<<3|this.type.wireType),this.encodeValue(a,b)}catch(g){throw Error("Illegal value for "+ | ||
this.toString(!0)+": "+a+" ("+g+")");}return b};k.prototype.encodeValue=function(a,b){if(null===a)return b;switch(this.type){case d.TYPES.int32:0>a?b.writeVarint64(a):b.writeVarint32(a);break;case d.TYPES.uint32:b.writeVarint32(a);break;case d.TYPES.sint32:b.writeVarint32ZigZag(a);break;case d.TYPES.fixed32:b.writeUint32(a);break;case d.TYPES.sfixed32:b.writeInt32(a);break;case d.TYPES.int64:case d.TYPES.uint64:b.writeVarint64(a);break;case d.TYPES.sint64:b.writeVarint64ZigZag(a);break;case d.TYPES.fixed64:b.writeUint64(a); | ||
c.prototype.toRaw=function(a){return d(this,!!a)};c.decode=function(a,d){"string"===typeof a&&(a=l.wrap(a,d?d:"base64"));a=a instanceof l?a:l.wrap(a);var k=a.littleEndian;try{var c=b.decode(a.LE());a.LE(k);return c}catch(e){throw a.LE(k),e;}};c.decodeDelimited=function(a,d){"string"===typeof a&&(a=l.wrap(a,d?d:"base64"));a=a instanceof l?a:l.wrap(a);if(1>a.remaining())return null;var k=a.offset,c=a.readVarint32();if(a.remaining()<c)return a.offset=k,null;try{var e=b.decode(a.slice(a.offset,a.offset+ | ||
c).LE());a.offset+=c;return e}catch(n){throw a.offset+=c,n;}};c.decode64=function(a){return c.decode(a,"base64")};c.decodeHex=function(a){return c.decode(a,"hex")};c.prototype.toString=function(){return b.toString()};Object.defineProperty&&Object.defineProperty(c,"$options",{value:b.buildOpt()});return c}(d,this);for(var b=this.getChildren(),e=0;e<b.length;e++)if(b[e]instanceof h)a[b[e].name]=b[e].build();else if(b[e]instanceof c)a[b[e].name]=b[e].build();else if(!(b[e]instanceof c.Field))throw Error("Illegal reflect child of "+ | ||
this.toString(!0)+": "+b[e].toString(!0));return this.clazz=a};c.prototype.encode=function(a,d){for(var b=this.getChildren(c.Field),e=null,f=0,h;f<b.length;f++)h=a.$get(b[f].name),b[f].required&&null===h?null===e&&(e=b[f]):b[f].encode(h,d);if(null!==e)throw b=Error("Missing at least one required field for "+this.toString(!0)+": "+e),b.encoded=d,b;return d};c.prototype.calculate=function(a){for(var b=this.getChildren(c.Field),d=0,e=0,f;e<b.length;e++){f=a.$get(b[e].name);if(b[e].required&&null===f)throw Error("Missing at least one required field for "+ | ||
this.toString(!0)+": "+b[e]);d+=b[e].calculate(f)}return d};c.prototype.decode=function(a,b,c){b="number"===typeof b?b:-1;for(var e=a.offset,f=new this.clazz,h,m,l;a.offset<e+b||-1==b&&0<a.remaining();){h=a.readVarint32();m=h&7;l=h>>3;if(m===d.WIRE_TYPES.ENDGROUP){if(l!==c)throw Error("Illegal group end indicator for "+this.toString(!0)+": "+l+" ("+(c?c+" expected":"not a group")+")");break}if(h=this.getChild(l))h.repeated&&!h.options.packed?f.$add(h.name,h.decode(m,a),!0):f.$set(h.name,h.decode(m, | ||
a),!0);else switch(m){case d.WIRE_TYPES.VARINT:a.readVarint32();break;case d.WIRE_TYPES.BITS32:a.offset+=4;break;case d.WIRE_TYPES.BITS64:a.offset+=8;break;case d.WIRE_TYPES.LDELIM:h=a.readVarint32();a.offset+=h;break;case d.WIRE_TYPES.STARTGROUP:for(;g(l,a););break;default:throw Error("Illegal wire type for unknown field "+l+" in "+this.toString(!0)+"#decode: "+m);}}a=this.getChildren(d.Reflect.Field);for(b=0;b<a.length;b++)if(h=a[b],null===f[h.name]){if(h.required)throw a=Error("Missing at least one required field for "+ | ||
this.toString(!0)+": "+h.name),a.decoded=f,a;if("undefined"!==typeof h.options["default"])try{f.$set(h.name,h.options["default"])}catch(q){throw Error("[INTERNAL] "+q);}}return f};m.Message=c;var f=function(a,k,c,e,f,h){b.call(this,a,e);this.className="Message.Field";this.required="required"==k;this.repeated="repeated"==k;this.type=c;this.resolvedType=null;this.id=f;this.options=h||{};this.originalName=this.name;d.convertFieldsToCamelCase&&(this.name=this.name.replace(/_([a-zA-Z])/g,function(a,b){return b.toUpperCase()}))}; | ||
f.prototype=Object.create(b.prototype);f.prototype.verifyValue=function(a,b){b=b||!1;var c=function(a,b){throw Error("Illegal value for "+this.toString(!0)+" of type "+this.type.name+": "+a+" ("+b+")");}.bind(this);if(null===a)return this.required&&c(typeof a,"required"),null;var e;if(this.repeated&&!b){d.Util.isArray(a)||(a=[a]);c=[];for(e=0;e<a.length;e++)c.push(this.verifyValue(a[e],!0));return c}!this.repeated&&d.Util.isArray(a)&&c(typeof a,"no array expected");switch(this.type){case d.TYPES.int32:case d.TYPES.sint32:case d.TYPES.sfixed32:return("number"!== | ||
typeof a||a===a&&0!==a%1)&&c(typeof a,"not an integer"),4294967295<a?a|0:a;case d.TYPES.uint32:case d.TYPES.fixed32:return("number"!==typeof a||a===a&&0!==a%1)&&c(typeof a,"not an integer"),0>a?a>>>0:a;case d.TYPES.int64:case d.TYPES.sint64:case d.TYPES.sfixed64:if(d.Long)try{return r(a,!1)}catch(f){c(typeof a,f.message)}else c(typeof a,"requires Long.js");case d.TYPES.uint64:case d.TYPES.fixed64:if(d.Long)try{return r(a,!0)}catch(m){c(typeof a,m.message)}else c(typeof a,"requires Long.js");case d.TYPES.bool:return"boolean"!== | ||
typeof a&&c(typeof a,"not a boolean"),a;case d.TYPES["float"]:case d.TYPES["double"]:return"number"!==typeof a&&c(typeof a,"not a number"),a;case d.TYPES.string:return"string"===typeof a||a&&a instanceof String||c(typeof a,"not a string"),""+a;case d.TYPES.bytes:return a&&a instanceof l?a:l.wrap(a);case d.TYPES["enum"]:var g=this.resolvedType.getChildren(h.Value);for(e=0;e<g.length;e++)if(g[e].name==a||g[e].id==a)return g[e].id;c(a,"not a valid enum value");case d.TYPES.group:case d.TYPES.message:return a&& | ||
"object"===typeof a||c(typeof a,"object expected"),a instanceof this.resolvedType.clazz?a:new this.resolvedType.clazz(a)}throw Error("[INTERNAL] Illegal value for "+this.toString(!0)+": "+a+" (undefined type "+this.type+")");};f.prototype.encode=function(a,b){a=this.verifyValue(a);if(null===this.type||"object"!==typeof this.type)throw Error("[INTERNAL] Unresolved type in "+this.toString(!0)+": "+this.type);if(null===a||this.repeated&&0==a.length)return b;try{if(this.repeated){var c;if(this.options.packed&& | ||
0<=d.PACKABLE_WIRE_TYPES.indexOf(this.type.wireType)){b.writeVarint32(this.id<<3|d.WIRE_TYPES.LDELIM);b.ensureCapacity(b.offset+=1);var e=b.offset;for(c=0;c<a.length;c++)this.encodeValue(a[c],b);var f=b.offset-e,h=l.calculateVarint32(f);if(1<h){var m=b.slice(e,b.offset),e=e+(h-1);b.offset=e;b.append(m)}b.writeVarint32(f,e-h)}else for(c=0;c<a.length;c++)b.writeVarint32(this.id<<3|this.type.wireType),this.encodeValue(a[c],b)}else b.writeVarint32(this.id<<3|this.type.wireType),this.encodeValue(a,b)}catch(g){throw Error("Illegal value for "+ | ||
this.toString(!0)+": "+a+" ("+g+")");}return b};f.prototype.encodeValue=function(a,b){if(null===a)return b;switch(this.type){case d.TYPES.int32:0>a?b.writeVarint64(a):b.writeVarint32(a);break;case d.TYPES.uint32:b.writeVarint32(a);break;case d.TYPES.sint32:b.writeVarint32ZigZag(a);break;case d.TYPES.fixed32:b.writeUint32(a);break;case d.TYPES.sfixed32:b.writeInt32(a);break;case d.TYPES.int64:case d.TYPES.uint64:b.writeVarint64(a);break;case d.TYPES.sint64:b.writeVarint64ZigZag(a);break;case d.TYPES.fixed64:b.writeUint64(a); | ||
break;case d.TYPES.sfixed64:b.writeInt64(a);break;case d.TYPES.bool:"string"===typeof a?b.writeVarint32("false"===a.toLowerCase()?0:!!a):b.writeVarint32(a?1:0);break;case d.TYPES["enum"]:b.writeVarint32(a);break;case d.TYPES["float"]:b.writeFloat32(a);break;case d.TYPES["double"]:b.writeFloat64(a);break;case d.TYPES.string:b.writeVString(a);break;case d.TYPES.bytes:if(0>a.remaining())throw Error("Illegal value for "+this.toString(!0)+": "+a.remaining()+" bytes remaining");var c=a.offset;b.writeVarint32(a.remaining()); | ||
b.append(a);a.offset=c;break;case d.TYPES.message:c=(new h).LE();this.resolvedType.encode(a,c);b.writeVarint32(c.offset);b.append(c.flip());break;case d.TYPES.group:this.resolvedType.encode(a,b);b.writeVarint32(this.id<<3|d.WIRE_TYPES.ENDGROUP);break;default:throw Error("[INTERNAL] Illegal value to encode in "+this.toString(!0)+": "+a+" (unknown type)");}return b};k.prototype.calculate=function(a){a=this.verifyValue(a);if(null===this.type||"object"!==typeof this.type)throw Error("[INTERNAL] Unresolved type in "+ | ||
this.toString(!0)+": "+this.type);if(null===a||this.repeated&&0==a.length)return 0;var b=0;try{if(this.repeated){var c,e;if(this.options.packed&&0<=d.PACKABLE_WIRE_TYPES.indexOf(this.type.wireType)){b+=h.calculateVarint32(this.id<<3|d.WIRE_TYPES.LDELIM);for(c=e=0;c<a.length;c++)e+=this.calculateValue(a[c]);b+=h.calculateVarint32(e);b+=e}else for(c=0;c<a.length;c++)b+=h.calculateVarint32(this.id<<3|this.type.wireType),b+=this.calculateValue(a[c])}else b+=h.calculateVarint32(this.id<<3|this.type.wireType), | ||
b+=this.calculateValue(a)}catch(k){throw Error("Illegal value for "+this.toString(!0)+": "+a+" ("+k+")");}return b};k.prototype.calculateValue=function(a){if(null===a)return 0;switch(this.type){case d.TYPES.int32:return 0>a?h.calculateVarint64(a):h.calculateVarint32(a);case d.TYPES.uint32:return h.calculateVarint32(a);case d.TYPES.sint32:return h.calculateVarint32(h.zigZagEncode32(a));case d.TYPES.fixed32:case d.TYPES.sfixed32:case d.TYPES["float"]:return 4;case d.TYPES.int64:case d.TYPES.uint64:return h.calculateVarint64(a); | ||
case d.TYPES.sint64:return h.calculateVarint64(h.zigZagEncode64(a));case d.TYPES.fixed64:case d.TYPES.sfixed64:return 8;case d.TYPES.bool:return 1;case d.TYPES["enum"]:return h.calculateVarint32(a);case d.TYPES["double"]:return 8;case d.TYPES.string:return a=h.calculateUTF8Bytes(a),h.calculateVarint32(a)+a;case d.TYPES.bytes:if(0>a.remaining())throw Error("Illegal value for "+this.toString(!0)+": "+a.remaining()+" bytes remaining");return h.calculateVarint32(a.remaining())+a.remaining();case d.TYPES.message:return a= | ||
this.resolvedType.calculate(a),h.calculateVarint32(a)+a;case d.TYPES.group:return a=this.resolvedType.calculate(a),a+h.calculateVarint32(this.id<<3|d.WIRE_TYPES.ENDGROUP)}throw Error("[INTERNAL] Illegal value to encode in "+this.toString(!0)+": "+a+" (unknown type)");};k.prototype.decode=function(a,b,c){if(a!=this.type.wireType&&(c||a!=d.WIRE_TYPES.LDELIM||!this.repeated))throw Error("Illegal wire type for field "+this.toString(!0)+": "+a+" ("+this.type.wireType+" expected)");if(a==d.WIRE_TYPES.LDELIM&& | ||
b.append(a);a.offset=c;break;case d.TYPES.message:c=(new l).LE();this.resolvedType.encode(a,c);b.writeVarint32(c.offset);b.append(c.flip());break;case d.TYPES.group:this.resolvedType.encode(a,b);b.writeVarint32(this.id<<3|d.WIRE_TYPES.ENDGROUP);break;default:throw Error("[INTERNAL] Illegal value to encode in "+this.toString(!0)+": "+a+" (unknown type)");}return b};f.prototype.calculate=function(a){a=this.verifyValue(a);if(null===this.type||"object"!==typeof this.type)throw Error("[INTERNAL] Unresolved type in "+ | ||
this.toString(!0)+": "+this.type);if(null===a||this.repeated&&0==a.length)return 0;var b=0;try{if(this.repeated){var c,e;if(this.options.packed&&0<=d.PACKABLE_WIRE_TYPES.indexOf(this.type.wireType)){b+=l.calculateVarint32(this.id<<3|d.WIRE_TYPES.LDELIM);for(c=e=0;c<a.length;c++)e+=this.calculateValue(a[c]);b+=l.calculateVarint32(e);b+=e}else for(c=0;c<a.length;c++)b+=l.calculateVarint32(this.id<<3|this.type.wireType),b+=this.calculateValue(a[c])}else b+=l.calculateVarint32(this.id<<3|this.type.wireType), | ||
b+=this.calculateValue(a)}catch(f){throw Error("Illegal value for "+this.toString(!0)+": "+a+" ("+f+")");}return b};f.prototype.calculateValue=function(a){if(null===a)return 0;switch(this.type){case d.TYPES.int32:return 0>a?l.calculateVarint64(a):l.calculateVarint32(a);case d.TYPES.uint32:return l.calculateVarint32(a);case d.TYPES.sint32:return l.calculateVarint32(l.zigZagEncode32(a));case d.TYPES.fixed32:case d.TYPES.sfixed32:case d.TYPES["float"]:return 4;case d.TYPES.int64:case d.TYPES.uint64:return l.calculateVarint64(a); | ||
case d.TYPES.sint64:return l.calculateVarint64(l.zigZagEncode64(a));case d.TYPES.fixed64:case d.TYPES.sfixed64:return 8;case d.TYPES.bool:return 1;case d.TYPES["enum"]:return l.calculateVarint32(a);case d.TYPES["double"]:return 8;case d.TYPES.string:return a=l.calculateUTF8Bytes(a),l.calculateVarint32(a)+a;case d.TYPES.bytes:if(0>a.remaining())throw Error("Illegal value for "+this.toString(!0)+": "+a.remaining()+" bytes remaining");return l.calculateVarint32(a.remaining())+a.remaining();case d.TYPES.message:return a= | ||
this.resolvedType.calculate(a),l.calculateVarint32(a)+a;case d.TYPES.group:return a=this.resolvedType.calculate(a),a+l.calculateVarint32(this.id<<3|d.WIRE_TYPES.ENDGROUP)}throw Error("[INTERNAL] Illegal value to encode in "+this.toString(!0)+": "+a+" (unknown type)");};f.prototype.decode=function(a,b,c){if(a!=this.type.wireType&&(c||a!=d.WIRE_TYPES.LDELIM||!this.repeated))throw Error("Illegal wire type for field "+this.toString(!0)+": "+a+" ("+this.type.wireType+" expected)");if(a==d.WIRE_TYPES.LDELIM&& | ||
this.repeated&&this.options.packed&&0<=d.PACKABLE_WIRE_TYPES.indexOf(this.type.wireType)&&!c){a=b.readVarint32();a=b.offset+a;for(c=[];b.offset<a;)c.push(this.decode(this.type.wireType,b,!0));return c}switch(this.type){case d.TYPES.int32:return b.readVarint32()|0;case d.TYPES.uint32:return b.readVarint32()>>>0;case d.TYPES.sint32:return b.readVarint32ZigZag()|0;case d.TYPES.fixed32:return b.readUint32()>>>0;case d.TYPES.sfixed32:return b.readInt32()|0;case d.TYPES.int64:return b.readVarint64();case d.TYPES.uint64:return b.readVarint64().toUnsigned(); | ||
case d.TYPES.sint64:return b.readVarint64ZigZag();case d.TYPES.fixed64:return b.readUint64();case d.TYPES.sfixed64:return b.readInt64();case d.TYPES.bool:return!!b.readVarint32();case d.TYPES["enum"]:return b.readVarint32();case d.TYPES["float"]:return b.readFloat();case d.TYPES["double"]:return b.readDouble();case d.TYPES.string:return b.readVString();case d.TYPES.bytes:a=b.readVarint32();if(b.remaining()<a)throw Error("Illegal number of bytes for "+this.toString(!0)+": "+a+" required but got only "+ | ||
b.remaining());c=b.clone();c.limit=c.offset+a;b.offset+=a;return c;case d.TYPES.message:return a=b.readVarint32(),this.resolvedType.decode(b,a);case d.TYPES.group:return this.resolvedType.decode(b,-1,this.id)}throw Error("[INTERNAL] Illegal wire type for "+this.toString(!0)+": "+a);};m.Message.Field=k;var r=function(a,b,c,d,e,l){k.call(this,a,b,c,d,e,l)};r.prototype=Object.create(k.prototype);m.Message.ExtensionField=r;var l=function(a,b,c){e.call(this,a,b,c);this.className="Enum";this.object=null}; | ||
l.prototype=Object.create(e.prototype);l.prototype.build=function(){for(var a={},b=this.getChildren(l.Value),c=0;c<b.length;c++)a[b[c].name]=b[c].id;Object.defineProperty&&Object.defineProperty(a,"$options",{value:this.buildOpt()});return this.object=a};m.Enum=l;r=function(a,c,d){b.call(this,a,c);this.className="Enum.Value";this.id=d};r.prototype=Object.create(b.prototype);m.Enum.Value=r;r=function(a,b,c){e.call(this,a,b,c);this.className="Service";this.clazz=null};r.prototype=Object.create(e.prototype); | ||
r.prototype.build=function(a){return this.clazz&&!a?this.clazz:this.clazz=function(a,b){var c=function(b){a.Builder.Service.call(this);this.rpcImpl=b||function(a,b,c){setTimeout(c.bind(this,Error("Not implemented, see: https://github.com/dcodeIO/ProtoBuf.js/wiki/Services")),0)}};c.prototype=Object.create(a.Builder.Service.prototype);Object.defineProperty&&(Object.defineProperty(c,"$options",{value:b.buildOpt()}),Object.defineProperty(c.prototype,"$options",{value:c.$options}));for(var d=b.getChildren(a.Reflect.Service.RPCMethod), | ||
b.remaining());c=b.clone();c.limit=c.offset+a;b.offset+=a;return c;case d.TYPES.message:return a=b.readVarint32(),this.resolvedType.decode(b,a);case d.TYPES.group:return this.resolvedType.decode(b,-1,this.id)}throw Error("[INTERNAL] Illegal wire type for "+this.toString(!0)+": "+a);};m.Message.Field=f;var q=function(a,b,c,d,e,h){f.call(this,a,b,c,d,e,h)};q.prototype=Object.create(f.prototype);m.Message.ExtensionField=q;var h=function(a,b,c){e.call(this,a,b,c);this.className="Enum";this.object=null}; | ||
h.prototype=Object.create(e.prototype);h.prototype.build=function(){for(var a={},b=this.getChildren(h.Value),c=0;c<b.length;c++)a[b[c].name]=b[c].id;Object.defineProperty&&Object.defineProperty(a,"$options",{value:this.buildOpt()});return this.object=a};m.Enum=h;q=function(a,c,d){b.call(this,a,c);this.className="Enum.Value";this.id=d};q.prototype=Object.create(b.prototype);m.Enum.Value=q;q=function(a,b,c){e.call(this,a,b,c);this.className="Service";this.clazz=null};q.prototype=Object.create(e.prototype); | ||
q.prototype.build=function(a){return this.clazz&&!a?this.clazz:this.clazz=function(a,b){var c=function(b){a.Builder.Service.call(this);this.rpcImpl=b||function(a,b,c){setTimeout(c.bind(this,Error("Not implemented, see: https://github.com/dcodeIO/ProtoBuf.js/wiki/Services")),0)}};c.prototype=Object.create(a.Builder.Service.prototype);Object.defineProperty&&(Object.defineProperty(c,"$options",{value:b.buildOpt()}),Object.defineProperty(c.prototype,"$options",{value:c.$options}));for(var d=b.getChildren(a.Reflect.Service.RPCMethod), | ||
e=0;e<d.length;e++)(function(a){c.prototype[a.name]=function(c,d){try{c&&c instanceof a.resolvedRequestType.clazz?this.rpcImpl(a.fqn(),c,function(c,e){if(c)d(c);else{try{e=a.resolvedResponseType.clazz.decode(e)}catch(f){}e&&e instanceof a.resolvedResponseType.clazz?d(null,e):d(Error("Illegal response type received in service method "+b.name+"#"+a.name))}}):setTimeout(d.bind(this,Error("Illegal request type provided to service method "+b.name+"#"+a.name)),0)}catch(e){setTimeout(d.bind(this,e),0)}}; | ||
c[a.name]=function(b,d,e){(new c(b))[a.name](d,e)};Object.defineProperty&&(Object.defineProperty(c[a.name],"$options",{value:a.buildOpt()}),Object.defineProperty(c.prototype[a.name],"$options",{value:c[a.name].$options}))})(d[e]);return c}(d,this)};m.Service=r;var n=function(a,c,d){b.call(this,a,c);this.className="Service.Method";this.options=d||{}};n.prototype=Object.create(b.prototype);n.prototype.buildOpt=e.prototype.buildOpt;m.Service.Method=n;r=function(a,b,c,d,e){n.call(this,a,b,e);this.className= | ||
"Service.RPCMethod";this.requestName=c;this.responseName=d;this.resolvedResponseType=this.resolvedRequestType=null};r.prototype=Object.create(n.prototype);m.Service.RPCMethod=r;return m}(g);g.Builder=function(d,g,h){var m=function(){this.ptr=this.ns=new h.Namespace(null,"");this.resolved=!1;this.result=null;this.files={};this.importRoot=null};m.prototype.reset=function(){this.ptr=this.ns};m.prototype.define=function(b,d){if("string"!==typeof b||!g.TYPEREF.test(b))throw Error("Illegal package: "+b); | ||
var c=b.split("."),k;for(k=0;k<c.length;k++)if(!g.NAME.test(c[k]))throw Error("Illegal package: "+c[k]);for(k=0;k<c.length;k++)this.ptr.hasChild(c[k])||this.ptr.addChild(new h.Namespace(this.ptr,c[k],d)),this.ptr=this.ptr.getChild(c[k]);return this};m.isValidMessage=function(b){if("string"!==typeof b.name||!g.NAME.test(b.name)||"undefined"!==typeof b.values||"undefined"!==typeof b.rpc)return!1;var e;if("undefined"!==typeof b.fields){if(!d.Util.isArray(b.fields))return!1;var c=[],k;for(e=0;e<b.fields.length;e++){if(!m.isValidMessageField(b.fields[e]))return!1; | ||
k=parseInt(b.fields[e].id,10);if(0<=c.indexOf(k))return!1;c.push(k)}}if("undefined"!==typeof b.enums){if(!d.Util.isArray(b.enums))return!1;for(e=0;e<b.enums.length;e++)if(!m.isValidEnum(b.enums[e]))return!1}if("undefined"!==typeof b.messages){if(!d.Util.isArray(b.messages))return!1;for(e=0;e<b.messages.length;e++)if(!m.isValidMessage(b.messages[e])&&!m.isValidExtend(b.messages[e]))return!1}return"undefined"===typeof b.extensions||d.Util.isArray(b.extensions)&&2===b.extensions.length&&"number"===typeof b.extensions[0]&& | ||
"number"===typeof b.extensions[1]?!0:!1};m.isValidMessageField=function(b){if("string"!==typeof b.rule||"string"!==typeof b.name||"string"!==typeof b.type||"undefined"===typeof b.id||!(g.RULE.test(b.rule)&&g.NAME.test(b.name)&&g.TYPEREF.test(b.type)&&g.ID.test(""+b.id)))return!1;if("undefined"!==typeof b.options){if("object"!==typeof b.options)return!1;for(var d=Object.keys(b.options),c=0,k;c<d.length;c++)if("string"!==typeof(k=d[c])||"string"!==typeof b.options[k]&&"number"!==typeof b.options[k]&& | ||
"boolean"!==typeof b.options[k])return!1}return!0};m.isValidEnum=function(b){if("string"!==typeof b.name||!g.NAME.test(b.name)||"undefined"===typeof b.values||!d.Util.isArray(b.values)||0==b.values.length)return!1;for(var e=0;e<b.values.length;e++)if("object"!=typeof b.values[e]||"string"!==typeof b.values[e].name||"undefined"===typeof b.values[e].id||!g.NAME.test(b.values[e].name)||!g.NEGID.test(""+b.values[e].id))return!1;return!0};m.prototype.create=function(b){if(!b)return this;d.Util.isArray(b)|| | ||
(b=[b]);if(0==b.length)return this;var e=[],c,k,g,l,n;for(e.push(b);0<e.length;){b=e.pop();if(d.Util.isArray(b))for(;0<b.length;)if(c=b.shift(),m.isValidMessage(c)){k=new h.Message(this.ptr,c.name,c.options,c.isGroup);if(c.fields&&0<c.fields.length)for(l=0;l<c.fields.length;l++){if(k.hasChild(c.fields[l].id))throw Error("Duplicate field id in message "+k.name+": "+c.fields[l].id);if(c.fields[l].options)for(g=Object.keys(c.fields[l].options),n=0;n<g.length;n++){if("string"!==typeof g[n])throw Error("Illegal field option name in message "+ | ||
k.name+"#"+c.fields[l].name+": "+g[n]);if("string"!==typeof c.fields[l].options[g[n]]&&"number"!==typeof c.fields[l].options[g[n]]&&"boolean"!==typeof c.fields[l].options[g[n]])throw Error("Illegal field option value in message "+k.name+"#"+c.fields[l].name+"#"+g[n]+": "+c.fields[l].options[g[n]]);}k.addChild(new h.Message.Field(k,c.fields[l].rule,c.fields[l].type,c.fields[l].name,c.fields[l].id,c.fields[l].options))}g=[];if("undefined"!==typeof c.enums&&0<c.enums.length)for(l=0;l<c.enums.length;l++)g.push(c.enums[l]); | ||
if(c.messages&&0<c.messages.length)for(l=0;l<c.messages.length;l++)g.push(c.messages[l]);c.extensions&&(k.extensions=c.extensions,k.extensions[0]<d.ID_MIN&&(k.extensions[0]=d.ID_MIN),k.extensions[1]>d.ID_MAX&&(k.extensions[1]=d.ID_MAX));this.ptr.addChild(k);0<g.length&&(e.push(b),b=g,this.ptr=k)}else if(m.isValidEnum(c)){k=new h.Enum(this.ptr,c.name,c.options);for(l=0;l<c.values.length;l++)k.addChild(new h.Enum.Value(k,c.values[l].name,c.values[l].id));this.ptr.addChild(k)}else if(m.isValidService(c)){k= | ||
new h.Service(this.ptr,c.name,c.options);for(l in c.rpc)c.rpc.hasOwnProperty(l)&&k.addChild(new h.Service.RPCMethod(k,l,c.rpc[l].request,c.rpc[l].response,c.rpc[l].options));this.ptr.addChild(k)}else if(m.isValidExtend(c))if(k=this.ptr.resolve(c.ref))for(l=0;l<c.fields.length;l++){if(k.hasChild(c.fields[l].id))throw Error("Duplicate extended field id in message "+k.name+": "+c.fields[l].id);if(c.fields[l].id<k.extensions[0]||c.fields[l].id>k.extensions[1])throw Error("Illegal extended field id in message "+ | ||
k.name+": "+c.fields[l].id+" ("+k.extensions.join(" to ")+" expected)");k.addChild(new h.Message.Field(k,c.fields[l].rule,c.fields[l].type,c.fields[l].name,c.fields[l].id,c.fields[l].options))}else{if(!/\.?google\.protobuf\./.test(c.ref))throw Error("Extended message "+c.ref+" is not defined");}else throw Error("Not a valid definition: "+JSON.stringify(c));else throw Error("Not a valid namespace: "+JSON.stringify(b));this.ptr=this.ptr.parent}this.resolved=!1;this.result=null;return this};m.prototype["import"]= | ||
function(b,e){if("string"===typeof e){d.Util.IS_NODE&&(e=require("path").resolve(e));if(!0===this.files[e])return this.reset(),this;this.files[e]=!0}if(b.imports&&0<b.imports.length){var c,g="/",m=!1;if("object"===typeof e){if(this.importRoot=e.root,m=!0,c=this.importRoot,e=e.file,0<=c.indexOf("\\")||0<=e.indexOf("\\"))g="\\"}else"string"===typeof e?this.importRoot?c=this.importRoot:0<=e.indexOf("/")?(c=e.replace(/\/[^\/]*$/,""),""===c&&(c="/")):0<=e.indexOf("\\")?(c=e.replace(/\\[^\\]*$/,""),g="\\"): | ||
c=".":c=null;for(var l=0;l<b.imports.length;l++)if("string"===typeof b.imports[l]){if(!c)throw Error("Cannot determine import root: File name is unknown");var h=b.imports[l];if(!/^google\/protobuf\//.test(h)&&(h=c+g+h,!0!==this.files[h])){/\.proto$/i.test(h)&&!d.DotProto&&(h=h.replace(/\.proto$/,".json"));var a=d.Util.fetch(h);if(null===a)throw Error("Failed to import '"+h+"' in '"+e+"': File not found");if(/\.json$/i.test(h))this["import"](JSON.parse(a+""),h);else this["import"]((new d.DotProto.Parser(a+ | ||
"")).parse(),h)}}else if(e)if(/\.(\w+)$/.test(e))this["import"](b.imports[l],e.replace(/^(.+)\.(\w+)$/,function(a,b,c){return b+"_import"+l+"."+c}));else this["import"](b.imports[l],e+"_import"+l);else this["import"](b.imports[l]);m&&(this.importRoot=null)}b.messages&&(b["package"]&&this.define(b["package"],b.options),this.create(b.messages),this.reset());b.enums&&(b["package"]&&this.define(b["package"],b.options),this.create(b.enums),this.reset());b.services&&(b["package"]&&this.define(b["package"], | ||
b.options),this.create(b.services),this.reset());b["extends"]&&(b["package"]&&this.define(b["package"],b.options),this.create(b["extends"]),this.reset());return this};m.isValidService=function(b){return!("string"!==typeof b.name||!g.NAME.test(b.name)||"object"!==typeof b.rpc)};m.isValidExtend=function(b){if("string"!==typeof b.ref||!g.TYPEREF.test(b.ref))return!1;var e;if("undefined"!==typeof b.fields){if(!d.Util.isArray(b.fields))return!1;var c=[],k;for(e=0;e<b.fields.length;e++){if(!m.isValidMessageField(b.fields[e]))return!1; | ||
k=parseInt(b.id,10);if(0<=c.indexOf(k))return!1;c.push(k)}}return!0};m.prototype.resolveAll=function(){var b;if(null!=this.ptr&&"object"!==typeof this.ptr.type){if(this.ptr instanceof h.Namespace){b=this.ptr.getChildren();for(var e=0;e<b.length;e++)this.ptr=b[e],this.resolveAll()}else if(this.ptr instanceof h.Message.Field)if(g.TYPE.test(this.ptr.type))this.ptr.type=d.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); | ||
b=this.ptr.parent.resolve(this.ptr.type,!0);if(!b)throw Error("Unresolvable type reference in "+this.ptr.toString(!0)+": "+this.ptr.type);this.ptr.resolvedType=b;if(b instanceof h.Enum)this.ptr.type=d.TYPES["enum"];else if(b instanceof h.Message)this.ptr.type=b.isGroup?d.TYPES.group: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))if(this.ptr instanceof d.Reflect.Service.Method)if(this.ptr instanceof | ||
c[a.name]=function(b,d,e){(new c(b))[a.name](d,e)};Object.defineProperty&&(Object.defineProperty(c[a.name],"$options",{value:a.buildOpt()}),Object.defineProperty(c.prototype[a.name],"$options",{value:c[a.name].$options}))})(d[e]);return c}(d,this)};m.Service=q;var p=function(a,c,d){b.call(this,a,c);this.className="Service.Method";this.options=d||{}};p.prototype=Object.create(b.prototype);p.prototype.buildOpt=e.prototype.buildOpt;m.Service.Method=p;q=function(a,b,c,d,e){p.call(this,a,b,e);this.className= | ||
"Service.RPCMethod";this.requestName=c;this.responseName=d;this.resolvedResponseType=this.resolvedRequestType=null};q.prototype=Object.create(p.prototype);m.Service.RPCMethod=q;return m}(g);g.Builder=function(d,g,l){var m=function(){this.ptr=this.ns=new l.Namespace(null,"");this.resolved=!1;this.result=null;this.files={};this.importRoot=null};m.prototype.reset=function(){this.ptr=this.ns};m.prototype.define=function(b,d){if("string"!==typeof b||!g.TYPEREF.test(b))throw Error("Illegal package: "+b); | ||
var c=b.split("."),f;for(f=0;f<c.length;f++)if(!g.NAME.test(c[f]))throw Error("Illegal package: "+c[f]);for(f=0;f<c.length;f++)this.ptr.hasChild(c[f])||this.ptr.addChild(new l.Namespace(this.ptr,c[f],d)),this.ptr=this.ptr.getChild(c[f]);return this};m.isValidMessage=function(b){if("string"!==typeof b.name||!g.NAME.test(b.name)||"undefined"!==typeof b.values||"undefined"!==typeof b.rpc)return!1;var e;if("undefined"!==typeof b.fields){if(!d.Util.isArray(b.fields))return!1;var c=[],f;for(e=0;e<b.fields.length;e++){if(!m.isValidMessageField(b.fields[e]))return!1; | ||
f=parseInt(b.fields[e].id,10);if(0<=c.indexOf(f))return!1;c.push(f)}}if("undefined"!==typeof b.enums){if(!d.Util.isArray(b.enums))return!1;for(e=0;e<b.enums.length;e++)if(!m.isValidEnum(b.enums[e]))return!1}if("undefined"!==typeof b.messages){if(!d.Util.isArray(b.messages))return!1;for(e=0;e<b.messages.length;e++)if(!m.isValidMessage(b.messages[e])&&!m.isValidExtend(b.messages[e]))return!1}return"undefined"===typeof b.extensions||d.Util.isArray(b.extensions)&&2===b.extensions.length&&"number"===typeof b.extensions[0]&& | ||
"number"===typeof b.extensions[1]?!0:!1};m.isValidMessageField=function(b){if("string"!==typeof b.rule||"string"!==typeof b.name||"string"!==typeof b.type||"undefined"===typeof b.id||!(g.RULE.test(b.rule)&&g.NAME.test(b.name)&&g.TYPEREF.test(b.type)&&g.ID.test(""+b.id)))return!1;if("undefined"!==typeof b.options){if("object"!==typeof b.options)return!1;for(var d=Object.keys(b.options),c=0,f;c<d.length;c++)if("string"!==typeof(f=d[c])||"string"!==typeof b.options[f]&&"number"!==typeof b.options[f]&& | ||
"boolean"!==typeof b.options[f])return!1}return!0};m.isValidEnum=function(b){if("string"!==typeof b.name||!g.NAME.test(b.name)||"undefined"===typeof b.values||!d.Util.isArray(b.values)||0==b.values.length)return!1;for(var e=0;e<b.values.length;e++)if("object"!=typeof b.values[e]||"string"!==typeof b.values[e].name||"undefined"===typeof b.values[e].id||!g.NAME.test(b.values[e].name)||!g.NEGID.test(""+b.values[e].id))return!1;return!0};m.prototype.create=function(b){if(!b)return this;d.Util.isArray(b)|| | ||
(b=[b]);if(0==b.length)return this;var e=[],c,f,g,h,p;for(e.push(b);0<e.length;){b=e.pop();if(d.Util.isArray(b))for(;0<b.length;)if(c=b.shift(),m.isValidMessage(c)){f=new l.Message(this.ptr,c.name,c.options,c.isGroup);if(c.fields&&0<c.fields.length)for(h=0;h<c.fields.length;h++){if(f.hasChild(c.fields[h].id))throw Error("Duplicate field id in message "+f.name+": "+c.fields[h].id);if(c.fields[h].options)for(g=Object.keys(c.fields[h].options),p=0;p<g.length;p++){if("string"!==typeof g[p])throw Error("Illegal field option name in message "+ | ||
f.name+"#"+c.fields[h].name+": "+g[p]);if("string"!==typeof c.fields[h].options[g[p]]&&"number"!==typeof c.fields[h].options[g[p]]&&"boolean"!==typeof c.fields[h].options[g[p]])throw Error("Illegal field option value in message "+f.name+"#"+c.fields[h].name+"#"+g[p]+": "+c.fields[h].options[g[p]]);}f.addChild(new l.Message.Field(f,c.fields[h].rule,c.fields[h].type,c.fields[h].name,c.fields[h].id,c.fields[h].options))}g=[];if("undefined"!==typeof c.enums&&0<c.enums.length)for(h=0;h<c.enums.length;h++)g.push(c.enums[h]); | ||
if(c.messages&&0<c.messages.length)for(h=0;h<c.messages.length;h++)g.push(c.messages[h]);c.extensions&&(f.extensions=c.extensions,f.extensions[0]<d.ID_MIN&&(f.extensions[0]=d.ID_MIN),f.extensions[1]>d.ID_MAX&&(f.extensions[1]=d.ID_MAX));this.ptr.addChild(f);0<g.length&&(e.push(b),b=g,this.ptr=f)}else if(m.isValidEnum(c)){f=new l.Enum(this.ptr,c.name,c.options);for(h=0;h<c.values.length;h++)f.addChild(new l.Enum.Value(f,c.values[h].name,c.values[h].id));this.ptr.addChild(f)}else if(m.isValidService(c)){f= | ||
new l.Service(this.ptr,c.name,c.options);for(h in c.rpc)c.rpc.hasOwnProperty(h)&&f.addChild(new l.Service.RPCMethod(f,h,c.rpc[h].request,c.rpc[h].response,c.rpc[h].options));this.ptr.addChild(f)}else if(m.isValidExtend(c))if(f=this.ptr.resolve(c.ref))for(h=0;h<c.fields.length;h++){if(f.hasChild(c.fields[h].id))throw Error("Duplicate extended field id in message "+f.name+": "+c.fields[h].id);if(c.fields[h].id<f.extensions[0]||c.fields[h].id>f.extensions[1])throw Error("Illegal extended field id in message "+ | ||
f.name+": "+c.fields[h].id+" ("+f.extensions.join(" to ")+" expected)");f.addChild(new l.Message.Field(f,c.fields[h].rule,c.fields[h].type,c.fields[h].name,c.fields[h].id,c.fields[h].options))}else{if(!/\.?google\.protobuf\./.test(c.ref))throw Error("Extended message "+c.ref+" is not defined");}else throw Error("Not a valid definition: "+JSON.stringify(c));else throw Error("Not a valid namespace: "+JSON.stringify(b));this.ptr=this.ptr.parent}this.resolved=!1;this.result=null;return this};m.prototype["import"]= | ||
function(b,e){if("string"===typeof e){d.Util.IS_NODE&&(e=require("path").resolve(e));if(!0===this.files[e])return this.reset(),this;this.files[e]=!0}if(b.imports&&0<b.imports.length){var c,f="/",g=!1;if("object"===typeof e){if(this.importRoot=e.root,g=!0,c=this.importRoot,e=e.file,0<=c.indexOf("\\")||0<=e.indexOf("\\"))f="\\"}else"string"===typeof e?this.importRoot?c=this.importRoot:0<=e.indexOf("/")?(c=e.replace(/\/[^\/]*$/,""),""===c&&(c="/")):0<=e.indexOf("\\")?(c=e.replace(/\\[^\\]*$/,""),f="\\"): | ||
c=".":c=null;for(var h=0;h<b.imports.length;h++)if("string"===typeof b.imports[h]){if(!c)throw Error("Cannot determine import root: File name is unknown");var m=b.imports[h];if(!/^google\/protobuf\//.test(m)&&(m=c+f+m,!0!==this.files[m])){/\.proto$/i.test(m)&&!d.DotProto&&(m=m.replace(/\.proto$/,".json"));var a=d.Util.fetch(m);if(null===a)throw Error("Failed to import '"+m+"' in '"+e+"': File not found");if(/\.json$/i.test(m))this["import"](JSON.parse(a+""),m);else this["import"]((new d.DotProto.Parser(a+ | ||
"")).parse(),m)}}else if(e)if(/\.(\w+)$/.test(e))this["import"](b.imports[h],e.replace(/^(.+)\.(\w+)$/,function(a,b,c){return b+"_import"+h+"."+c}));else this["import"](b.imports[h],e+"_import"+h);else this["import"](b.imports[h]);g&&(this.importRoot=null)}b.messages&&(b["package"]&&this.define(b["package"],b.options),this.create(b.messages),this.reset());b.enums&&(b["package"]&&this.define(b["package"],b.options),this.create(b.enums),this.reset());b.services&&(b["package"]&&this.define(b["package"], | ||
b.options),this.create(b.services),this.reset());b["extends"]&&(b["package"]&&this.define(b["package"],b.options),this.create(b["extends"]),this.reset());return this};m.isValidService=function(b){return!("string"!==typeof b.name||!g.NAME.test(b.name)||"object"!==typeof b.rpc)};m.isValidExtend=function(b){if("string"!==typeof b.ref||!g.TYPEREF.test(b.ref))return!1;var e;if("undefined"!==typeof b.fields){if(!d.Util.isArray(b.fields))return!1;var c=[],f;for(e=0;e<b.fields.length;e++){if(!m.isValidMessageField(b.fields[e]))return!1; | ||
f=parseInt(b.id,10);if(0<=c.indexOf(f))return!1;c.push(f)}}return!0};m.prototype.resolveAll=function(){var b;if(null!=this.ptr&&"object"!==typeof this.ptr.type){if(this.ptr instanceof l.Namespace){b=this.ptr.getChildren();for(var e=0;e<b.length;e++)this.ptr=b[e],this.resolveAll()}else if(this.ptr instanceof l.Message.Field)if(g.TYPE.test(this.ptr.type))this.ptr.type=d.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); | ||
b=this.ptr.parent.resolve(this.ptr.type,!0);if(!b)throw Error("Unresolvable type reference in "+this.ptr.toString(!0)+": "+this.ptr.type);this.ptr.resolvedType=b;if(b instanceof l.Enum)this.ptr.type=d.TYPES["enum"];else if(b instanceof l.Message)this.ptr.type=b.isGroup?d.TYPES.group: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))if(this.ptr instanceof d.Reflect.Service.Method)if(this.ptr instanceof | ||
d.Reflect.Service.RPCMethod){b=this.ptr.parent.resolve(this.ptr.requestName);if(!(b&&b instanceof d.Reflect.Message))throw Error("Illegal type reference in "+this.ptr.toString(!0)+": "+this.ptr.requestName);this.ptr.resolvedRequestType=b;b=this.ptr.parent.resolve(this.ptr.responseName);if(!(b&&b instanceof d.Reflect.Message))throw Error("Illegal type reference in "+this.ptr.toString(!0)+": "+this.ptr.responseName);this.ptr.resolvedResponseType=b}else throw Error("Illegal service type in "+this.ptr.toString(!0)); | ||
else throw Error("Illegal object in namespace: "+typeof this.ptr+":"+this.ptr);this.reset()}};m.prototype.build=function(b){this.reset();this.resolved||(this.resolveAll(),this.resolved=!0,this.result=null);null==this.result&&(this.result=this.ns.build());if(b){b=b.split(".");for(var d=this.result,c=0;c<b.length;c++)if(d[b[c]])d=d[b[c]];else{d=null;break}return d}return this.result};m.prototype.lookup=function(b){return b?this.ns.resolve(b):this.ns};m.prototype.toString=function(){return"Builder"}; | ||
m.Message=function(){};m.Service=function(){};return m}(g,g.Lang,g.Reflect);g.newBuilder=function(d,h){var q=new g.Builder;"undefined"!==typeof d&&null!==d&&q.define(d,h);return q};g.loadJson=function(d,h,q){if("string"===typeof h||h&&"string"===typeof h.file&&"string"===typeof h.root)q=h,h=null;h&&"object"===typeof h||(h=g.newBuilder());"string"===typeof d&&(d=JSON.parse(d));h["import"](d,q);h.resolveAll();h.build();return h};g.loadJsonFile=function(d,h,q){h&&"object"===typeof h?(q=h,h=null):h&& | ||
"function"===typeof h||(h=null);if(h)return g.Util.fetch("string"===typeof d?d:d.root+"/"+d.file,function(b){if(null===b)h(Error("Failed to fetch file"));else try{h(null,g.loadJson(JSON.parse(b),q,d))}catch(e){h(e)}});var m=g.Util.fetch("object"===typeof d?d.root+"/"+d.file:d);return null===m?null:g.loadJson(JSON.parse(m),q,d)};return g}"undefined"!==typeof module&&module.exports?module.exports=t(require("bytebuffer")):"function"===typeof define&&define.amd?define(["ByteBuffer"],t):(s.dcodeIO=s.dcodeIO|| | ||
m.Message=function(){};m.Service=function(){};return m}(g,g.Lang,g.Reflect);g.newBuilder=function(d,l){var r=new g.Builder;"undefined"!==typeof d&&null!==d&&r.define(d,l);return r};g.loadJson=function(d,l,r){if("string"===typeof l||l&&"string"===typeof l.file&&"string"===typeof l.root)r=l,l=null;l&&"object"===typeof l||(l=g.newBuilder());"string"===typeof d&&(d=JSON.parse(d));l["import"](d,r);l.resolveAll();l.build();return l};g.loadJsonFile=function(d,l,r){l&&"object"===typeof l?(r=l,l=null):l&& | ||
"function"===typeof l||(l=null);if(l)return g.Util.fetch("string"===typeof d?d:d.root+"/"+d.file,function(b){if(null===b)l(Error("Failed to fetch file"));else try{l(null,g.loadJson(JSON.parse(b),r,d))}catch(e){l(e)}});var m=g.Util.fetch("object"===typeof d?d.root+"/"+d.file:d);return null===m?null:g.loadJson(JSON.parse(m),r,d)};return g}"undefined"!==typeof module&&module.exports?module.exports=t(require("bytebuffer")):"function"===typeof define&&define.amd?define(["ByteBuffer"],t):(s.dcodeIO=s.dcodeIO|| | ||
{}).ProtoBuf=t(s.dcodeIO.ByteBuffer)})(this); |
{ | ||
"name": "protobufjs", | ||
"version": "3.3.1", | ||
"version": "3.4.0", | ||
"description": "Protocol Buffers for JavaScript. Finally.", | ||
@@ -5,0 +5,0 @@ "author": "Daniel Wirtz <dcode@dcode.io>", |
@@ -31,6 +31,6 @@ /*? | ||
} | ||
// Set the default values | ||
// Set the default values for required fields | ||
for (i=0; i<fields.length; i++) { | ||
field = fields[i]; | ||
if (typeof field.options['default'] != 'undefined') { | ||
if (field.required && typeof field.options['default'] !== 'undefined') | ||
try { | ||
@@ -41,3 +41,2 @@ this.$set(field.name, field.options['default']); // Should not throw | ||
} | ||
} | ||
} | ||
@@ -44,0 +43,0 @@ // Set field values from a values object |
@@ -221,11 +221,20 @@ /** | ||
// Check if all required fields are present | ||
// Check if all required fields are present and set default values for optional fields that are not | ||
var fields = this.getChildren(ProtoBuf.Reflect.Field); | ||
for (var i=0; i<fields.length; i++) | ||
if (fields[i].required && msg[fields[i].name] === null) { | ||
var err = Error("Missing at least one required field for "+this.toString(true)+": "+fields[i].name); | ||
err["decoded"] = msg; // Still expose what we got | ||
throw(err); | ||
} | ||
for (var i=0; i<fields.length; i++) { | ||
field = fields[i]; | ||
if (msg[field.name] === null) | ||
if (field.required) { | ||
var err = Error("Missing at least one required field for "+this.toString(true)+": "+field.name); | ||
err["decoded"] = msg; // Still expose what we got | ||
throw(err); | ||
} else if (typeof field.options['default'] !== 'undefined') { | ||
try { | ||
msg.$set(field.name, field.options['default']); // Should not throw | ||
} catch (e) { | ||
throw Error("[INTERNAL] "+e); | ||
} | ||
} | ||
} | ||
return msg; | ||
}; |
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 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 not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
1823204
18496