Socket
Socket
Sign inDemoInstall

protobufjs

Package Overview
Dependencies
Maintainers
1
Versions
168
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

protobufjs - npm Package Compare versions

Comparing version 0.12.9 to 0.12.10

2

package.json
{
"name": "protobufjs",
"version": "0.12.9",
"version": "0.12.10",
"description": "ProtoBuf.js: protobuf for JavaScript. No compilation step required, works out of the box.",

@@ -5,0 +5,0 @@ "author": "Daniel Wirtz <dcode@dcode.io>",

@@ -6,3 +6,3 @@ /*

*/
(function(p){function q(n){if(!n||!n.zigZagEncode32)throw Error("ProtoBuf.js requires ByteBuffer.js >=1.1.0: Get it at https://github.com/dcodeIO/ByteBuffer.js");var f={VERSION:"0.12.9",WIRE_TYPES:{}};f.WIRE_TYPES.VARINT=0;f.WIRE_TYPES.BITS64=1;f.WIRE_TYPES.LDELIM=2;f.WIRE_TYPES.STARTGROUP=3;f.WIRE_TYPES.ENDGROUP=4;f.WIRE_TYPES.BITS32=5;f.TYPES={int32:{name:"int32",wireType:f.WIRE_TYPES.VARINT},uint32:{name:"uint32",wireType:f.WIRE_TYPES.VARINT},sint32:{name:"sint32",wireType:f.WIRE_TYPES.VARINT},
(function(p){function q(n){if(!n||!n.zigZagEncode32)throw Error("ProtoBuf.js requires ByteBuffer.js >=1.1.0: Get it at https://github.com/dcodeIO/ByteBuffer.js");var f={VERSION:"0.12.10",WIRE_TYPES:{}};f.WIRE_TYPES.VARINT=0;f.WIRE_TYPES.BITS64=1;f.WIRE_TYPES.LDELIM=2;f.WIRE_TYPES.STARTGROUP=3;f.WIRE_TYPES.ENDGROUP=4;f.WIRE_TYPES.BITS32=5;f.TYPES={int32:{name:"int32",wireType:f.WIRE_TYPES.VARINT},uint32:{name:"uint32",wireType:f.WIRE_TYPES.VARINT},sint32:{name:"sint32",wireType:f.WIRE_TYPES.VARINT},
int64:{name:"int64",wireType:f.WIRE_TYPES.VARINT},uint64:{name:"uint64",wireType:f.WIRE_TYPES.VARINT},sint64:{name:"sint64",wireType:f.WIRE_TYPES.VARINT},bool:{name:"bool",wireType:f.WIRE_TYPES.VARINT},"double":{name:"double",wireType:f.WIRE_TYPES.BITS64},string:{name:"string",wireType:f.WIRE_TYPES.LDELIM},bytes:{name:"bytes",wireType:f.WIRE_TYPES.LDELIM},fixed32:{name:"fixed32",wireType:f.WIRE_TYPES.BITS32},sfixed32:{name:"sfixed32",wireType:f.WIRE_TYPES.BITS32},fixed64:{name:"fixed64",wireType:f.WIRE_TYPES.BITS64},

@@ -47,9 +47,9 @@ sfixed64:{name:"sfixed64",wireType:f.WIRE_TYPES.BITS64},"float":{name:"float",wireType:f.WIRE_TYPES.BITS32},"enum":{name:"enum",wireType:f.WIRE_TYPES.VARINT},message:{name:"message",wireType:f.WIRE_TYPES.LDELIM}};f.Long=n.Long;f.Util=function(){Object.create||(Object.create=function(b){function c(){}if(1<arguments.length)throw Error("Object.create implementation only accepts the first parameter.");c.prototype=b;return new c});var c={};c.IS_NODE=("undefined"==typeof window||!window.window)&&"function"==

else if(this.type==c.TYPES.sint32)b.writeZigZagVarint32(a);else if(this.type==c.TYPES.fixed32)b.writeUint32(a);else if(this.type==c.TYPES.sfixed32)b.writeInt32(a);else if(this.type==c.TYPES.int64||this.type==c.TYPES.uint64)b.writeVarint64(a);else if(this.type==c.TYPES.sint64)b.writeZigZagVarint64(a);else if(this.type==c.TYPES.fixed64)b.writeUint64(a);else if(this.type==c.TYPES.sfixed64)b.writeInt64(a);else if(this.type==c.TYPES.bool)b.writeVarint32(a?1:0);else if(this.type==c.TYPES["enum"])b.writeVarint32(a);
else if(this.type==c.TYPES["float"])b.writeFloat32(a);else if(this.type==c.TYPES["double"])b.writeFloat64(a);else if(this.type==c.TYPES.string)b.writeVString(a);else if(this.type==c.TYPES.bytes)a.offset>a.length&&(b=b.clone().flip()),b.writeVarint32(a.remaining()),b.append(a);else if(this.type==c.TYPES.message){var d=b.offset;b.writeUint8(0);this.resolvedType.encode(a,b);var e=b.offset-d-1,f=n.calculateVarint32(e);if(1<f){var h=b.clone();h.offset-=e;b.append(h.flip(),d-1+f)}b.writeVarint32(e,d)}else throw Error("[INTERNAL ERROR] Illegal value to encode in "+
this.toString(!0)+": "+a+" (unknown type)");return b}};d.prototype.decode=function(a,b,d){if(a!=this.type.wireType&&(d||a!=c.WIRE_TYPES.LDELIM||!this.repeated))throw Error("Illegal wire type for field "+this.toString(!0)+": "+a+" ("+this.type.wireType+" expected)");if(a==c.WIRE_TYPES.LDELIM&&(this.repeated&&this.options.packed)&&!d){a=b.readVarint32();a=b.offset+a;for(d=[];b.offset<a;)d.push(this.decode(this.type.wireType,b,!0));return d}if(this.type==c.TYPES.int32)return b.readVarint32()|0;if(this.type==
c.TYPES.uint32)return b.readVarint32()>>>0;if(this.type==c.TYPES.sint32)return b.readZigZagVarint32()|0;if(this.type==c.TYPES.fixed32)return b.readUint32()>>>0;if(this.type==c.TYPES.sfixed32)return b.readInt32()|0;if(this.type==c.TYPES.int64)return b.readVarint64();if(this.type==c.TYPES.uint64)return b.readVarint64().toUnsigned();if(this.type==c.TYPES.sint64)return b.readZigZagVarint64();if(this.type==c.TYPES.fixed64)return b.readUint64();if(this.type==c.TYPES.sfixed64)return b.readInt64();if(this.type==
c.TYPES.bool)return!!b.readVarint32();if(this.type==c.TYPES["enum"])return b.readVarint32();if(this.type==c.TYPES["float"])return b.readFloat();if(this.type==c.TYPES["double"])return b.readDouble();if(this.type==c.TYPES.string)return b.readVString();if(this.type==c.TYPES.bytes)return a=b.readVarint32(),d=b.clone(),d.length=d.offset+a,b.offset+=a,d;if(this.type==c.TYPES.message)return a=b.readVarint32(),this.resolvedType.decode(b,a);throw Error("[INTERNAL ERROR] Illegal wire type for "+this.toString(!0)+
": "+a);};b.Message.Field=d;var e=function(a,b,c){h.call(this,a,b,c);this.built=null};e.prototype=Object.create(h.prototype);e.prototype.build=function(){for(var a={},b=this.getChildren(e.Value),c=0;c<b.length;c++)a[b[c].name]=b[c].id;Object.defineProperty&&Object.defineProperty(a,"$options",{value:this.buildOpt(),enumerable:!1,configurable:!1,writable:!1});return this.built=a};b.Enum=e;d=function(a,b,c){f.call(this,a,b);this.id=c};d.prototype=Object.create(f.prototype);b.Enum.Value=d;return b}(f);
f.Builder=function(c,b,f){var h=function(){this.ptr=this.ns=new f.Namespace(null,"");this.resolved=!1;this.result=null};h.prototype.reset=function(){this.ptr=this.ns};h.prototype.define=function(a,c){if("string"!=typeof a||!b.TYPEDEF.test(a))throw Error("Illegal package name: "+a);var e=a.split("."),g;for(g=0;g<e.length;g++)if(!b.NAME.test(e[g]))throw Error("Illegal package name: "+e[g]);for(g=0;g<e.length;g++)this.ptr.hasChild(e[g])||this.ptr.addChild(new f.Namespace(this.ptr,e[g],c)),this.ptr=this.ptr.getChild(e[g]);
return this};h.isValidMessage=function(a){if("string"!=typeof a.name||!b.NAME.test(a.name)||"undefined"!=typeof a.values)return!1;var c;if("undefined"!=typeof a.fields){if(!(a.fields instanceof Array))return!1;var e=[],g;for(c=0;c<a.fields.length;c++){if(!h.isValidMessageField(a.fields[c]))return!1;g=parseInt(a.id,10);if(0<=e.indexOf(g))return!1;e.push(g)}}if("undefined"!=typeof a.enums){if(!(a.enums instanceof Array))return!1;for(c=0;c<a.enums.length;c++)if(!h.isValidEnum(a.enums[c]))return!1}if("undefined"!=
else if(this.type==c.TYPES["float"])b.writeFloat32(a);else if(this.type==c.TYPES["double"])b.writeFloat64(a);else if(this.type==c.TYPES.string)b.writeVString(a);else if(this.type==c.TYPES.bytes)a.offset>a.length&&(b=b.clone().flip()),b.writeVarint32(a.remaining()),b.append(a);else if(this.type==c.TYPES.message){var d=new n;this.resolvedType.encode(a,d);b.writeVarint32(d.offset);b.append(d.flip())}else throw Error("[INTERNAL ERROR] Illegal value to encode in "+this.toString(!0)+": "+a+" (unknown type)");
return b}};d.prototype.decode=function(a,b,d){if(a!=this.type.wireType&&(d||a!=c.WIRE_TYPES.LDELIM||!this.repeated))throw Error("Illegal wire type for field "+this.toString(!0)+": "+a+" ("+this.type.wireType+" expected)");if(a==c.WIRE_TYPES.LDELIM&&(this.repeated&&this.options.packed)&&!d){a=b.readVarint32();a=b.offset+a;for(d=[];b.offset<a;)d.push(this.decode(this.type.wireType,b,!0));return d}if(this.type==c.TYPES.int32)return b.readVarint32()|0;if(this.type==c.TYPES.uint32)return b.readVarint32()>>>
0;if(this.type==c.TYPES.sint32)return b.readZigZagVarint32()|0;if(this.type==c.TYPES.fixed32)return b.readUint32()>>>0;if(this.type==c.TYPES.sfixed32)return b.readInt32()|0;if(this.type==c.TYPES.int64)return b.readVarint64();if(this.type==c.TYPES.uint64)return b.readVarint64().toUnsigned();if(this.type==c.TYPES.sint64)return b.readZigZagVarint64();if(this.type==c.TYPES.fixed64)return b.readUint64();if(this.type==c.TYPES.sfixed64)return b.readInt64();if(this.type==c.TYPES.bool)return!!b.readVarint32();
if(this.type==c.TYPES["enum"])return b.readVarint32();if(this.type==c.TYPES["float"])return b.readFloat();if(this.type==c.TYPES["double"])return b.readDouble();if(this.type==c.TYPES.string)return b.readVString();if(this.type==c.TYPES.bytes)return a=b.readVarint32(),d=b.clone(),d.length=d.offset+a,b.offset+=a,d;if(this.type==c.TYPES.message)return a=b.readVarint32(),this.resolvedType.decode(b,a);throw Error("[INTERNAL ERROR] Illegal wire type for "+this.toString(!0)+": "+a);};b.Message.Field=d;var e=
function(a,b,c){h.call(this,a,b,c);this.built=null};e.prototype=Object.create(h.prototype);e.prototype.build=function(){for(var a={},b=this.getChildren(e.Value),c=0;c<b.length;c++)a[b[c].name]=b[c].id;Object.defineProperty&&Object.defineProperty(a,"$options",{value:this.buildOpt(),enumerable:!1,configurable:!1,writable:!1});return this.built=a};b.Enum=e;d=function(a,b,c){f.call(this,a,b);this.id=c};d.prototype=Object.create(f.prototype);b.Enum.Value=d;return b}(f);f.Builder=function(c,b,f){var h=
function(){this.ptr=this.ns=new f.Namespace(null,"");this.resolved=!1;this.result=null};h.prototype.reset=function(){this.ptr=this.ns};h.prototype.define=function(a,c){if("string"!=typeof a||!b.TYPEDEF.test(a))throw Error("Illegal package name: "+a);var e=a.split("."),g;for(g=0;g<e.length;g++)if(!b.NAME.test(e[g]))throw Error("Illegal package name: "+e[g]);for(g=0;g<e.length;g++)this.ptr.hasChild(e[g])||this.ptr.addChild(new f.Namespace(this.ptr,e[g],c)),this.ptr=this.ptr.getChild(e[g]);return this};
h.isValidMessage=function(a){if("string"!=typeof a.name||!b.NAME.test(a.name)||"undefined"!=typeof a.values)return!1;var c;if("undefined"!=typeof a.fields){if(!(a.fields instanceof Array))return!1;var e=[],g;for(c=0;c<a.fields.length;c++){if(!h.isValidMessageField(a.fields[c]))return!1;g=parseInt(a.id,10);if(0<=e.indexOf(g))return!1;e.push(g)}}if("undefined"!=typeof a.enums){if(!(a.enums instanceof Array))return!1;for(c=0;c<a.enums.length;c++)if(!h.isValidEnum(a.enums[c]))return!1}if("undefined"!=
typeof a.messages){if(!(a.messages instanceof Array))return!1;for(c=0;c<a.messages.length;c++)if(!h.isValidMessage(a.messages[c]))return!1}return!0};h.isValidMessageField=function(a){if("string"!=typeof a.rule||"string"!=typeof a.name||"string"!=typeof a.type||"undefined"==typeof a.id||!b.RULE.test(a.rule)||!b.NAME.test(a.name)||!b.TYPEREF.test(a.type)||!b.ID.test(""+a.id))return!1;if("undefined"!=typeof a.options){if("object"!=typeof a.options)return!1;for(var c=Object.keys(a.options),e=0;e<c.length;e++)if(!b.NAME.test(c[e])||

@@ -56,0 +56,0 @@ !b.ID.test(""+a.options[c[e]])&&!b.TYPEREF.test(a.options[c[e]]))return!1}return!0};h.isValidEnum=function(a){if("string"!=typeof a.name||!b.NAME.test(a.name)||"undefined"==typeof a.values||!(a.values instanceof Array)||0==a.values.length)return!1;for(var c=0;c<a.values.length;c++)if("object"!=typeof a.values[c]||"string"!=typeof a.values[c].name||"undefined"==typeof a.values[c].id||!b.NAME.test(a.values[c].name)||!b.ID.test(""+a.values[c].id))return!1;return!0};h.prototype.create=function(a){if(a&&

@@ -6,43 +6,43 @@ /*

*/
(function(n){function p(l){if(!l||!l.zigZagEncode32)throw Error("ProtoBuf.js requires ByteBuffer.js >=1.1.0: Get it at https://github.com/dcodeIO/ByteBuffer.js");var f={VERSION:"0.12.9",WIRE_TYPES:{}};f.WIRE_TYPES.VARINT=0;f.WIRE_TYPES.BITS64=1;f.WIRE_TYPES.LDELIM=2;f.WIRE_TYPES.STARTGROUP=3;f.WIRE_TYPES.ENDGROUP=4;f.WIRE_TYPES.BITS32=5;f.TYPES={int32:{name:"int32",wireType:f.WIRE_TYPES.VARINT},uint32:{name:"uint32",wireType:f.WIRE_TYPES.VARINT},sint32:{name:"sint32",wireType:f.WIRE_TYPES.VARINT},
(function(n){function p(l){if(!l||!l.zigZagEncode32)throw Error("ProtoBuf.js requires ByteBuffer.js >=1.1.0: Get it at https://github.com/dcodeIO/ByteBuffer.js");var f={VERSION:"0.12.10",WIRE_TYPES:{}};f.WIRE_TYPES.VARINT=0;f.WIRE_TYPES.BITS64=1;f.WIRE_TYPES.LDELIM=2;f.WIRE_TYPES.STARTGROUP=3;f.WIRE_TYPES.ENDGROUP=4;f.WIRE_TYPES.BITS32=5;f.TYPES={int32:{name:"int32",wireType:f.WIRE_TYPES.VARINT},uint32:{name:"uint32",wireType:f.WIRE_TYPES.VARINT},sint32:{name:"sint32",wireType:f.WIRE_TYPES.VARINT},
int64:{name:"int64",wireType:f.WIRE_TYPES.VARINT},uint64:{name:"uint64",wireType:f.WIRE_TYPES.VARINT},sint64:{name:"sint64",wireType:f.WIRE_TYPES.VARINT},bool:{name:"bool",wireType:f.WIRE_TYPES.VARINT},"double":{name:"double",wireType:f.WIRE_TYPES.BITS64},string:{name:"string",wireType:f.WIRE_TYPES.LDELIM},bytes:{name:"bytes",wireType:f.WIRE_TYPES.LDELIM},fixed32:{name:"fixed32",wireType:f.WIRE_TYPES.BITS32},sfixed32:{name:"sfixed32",wireType:f.WIRE_TYPES.BITS32},fixed64:{name:"fixed64",wireType:f.WIRE_TYPES.BITS64},
sfixed64:{name:"sfixed64",wireType:f.WIRE_TYPES.BITS64},"float":{name:"float",wireType:f.WIRE_TYPES.BITS32},"enum":{name:"enum",wireType:f.WIRE_TYPES.VARINT},message:{name:"message",wireType:f.WIRE_TYPES.LDELIM}};f.Long=l.Long;f.Util=function(){Object.create||(Object.create=function(d){function h(){}if(1<arguments.length)throw Error("Object.create implementation only accepts the first parameter.");h.prototype=d;return new h});var d={};d.IS_NODE=("undefined"==typeof window||!window.window)&&"function"==
typeof require;d.XHR=function(){for(var d=[function(){return new XMLHttpRequest},function(){return new ActiveXObject("Msxml2.XMLHTTP")},function(){return new ActiveXObject("Msxml3.XMLHTTP")},function(){return new ActiveXObject("Microsoft.XMLHTTP")}],h=null,f=0;f<d.length;f++){try{h=d[f]()}catch(b){continue}break}if(!h)throw Error("XMLHttpRequest is not supported");return h};d.fetch=function(f,h){h&&"function"!=typeof h&&(h=null);if(d.IS_NODE)if(h)require("fs").readFile(f,function(b,d){b?h(null):h(""+
d)});else try{return require("fs").readFileSync(f)}catch(k){return null}else{var b=d.XHR();b.open("GET",f,h?!0:!1);b.setRequestHeader("User-Agent","XMLHTTP/1.0");b.setRequestHeader("Accept","text/plain");if(h)b.onreadystatechange=function(){4==b.readyState&&(200==b.status?h(b.responseText):h(null))},4!=b.readyState&&b.send(null);else return b.send(null),b.responseText}};return d}();f.Lang={OPEN:"{",CLOSE:"}",OPTOPEN:"[",OPTCLOSE:"]",OPTEND:",",EQUAL:"=",END:";",DELIM:/[\s\{\}=;\[\],"\(\)]/g,KEYWORD:/package|option|import|message|enum|extend|service/,
RULE:/required|optional|repeated/,TYPE:/double|float|int32|uint32|sint32|int64|uint64|sint64|fixed32|sfixed32|fixed64|sfixed64|bool|string|bytes/,NAME:/[a-zA-Z][a-zA-Z_0-9]*/,TYPEDEF:/[a-zA-Z](\.?[a-zA-Z_0-9])*/,TYPEREF:/\.?[a-zA-Z](\.?[a-zA-Z_0-9])*/,NUMBER:/^-?([1-9][0-9]*)|0$/,ID:/[0-9]+/,WHITESPACE:/\s/,STRING:/"([^"\\]*(\\.[^"\\]*)*)"/g,STRINGOPEN:'"',STRINGCLOSE:'"',COPTOPEN:"(",COPTCLOSE:")"};f.Reflect=function(d){var f={},h=function(a,c){this.parent=a;this.name=c;this.resolvedType=null};h.prototype.toString=
function(a){var c=this.name,e=this;do{e=e.parent;if(null==e)break;c=e.name+"."+c}while(1);a&&(this instanceof f.Message?c="Message "+c:this instanceof b.Field?c="Message.Field "+c:this instanceof g?c="Enum "+c:this instanceof g.Value?c="Enum.Value "+c:this instanceof k&&(c="Namespace "+c));return c};h.prototype.build=function(){throw Error(this.toString(!0)+" cannot be built directly");};f.T=h;var k=function(a,c,e){h.call(this,a,c);this.children=[];this.options=e||{}};k.prototype=Object.create(h.prototype);
k.prototype.getChildren=function(a){a=a||null;if(null==a)return this.children.slice();for(var c=[],e=0;e<this.children.length;e++)this.children[e]instanceof a&&c.push(this.children[e]);return c};k.prototype.addChild=function(a){if(this.hasChild(a.name))throw Error("Duplicate name in namespace "+this.toString(!0)+": "+a.name);this.children.push(a)};k.prototype.hasChild=function(a){var c;if("number"==typeof a)for(c=0;c<this.children.length;c++){if(this.children[c]instanceof b.Field&&this.children[c].id==
a)return!0}else for(c=0;c<this.children.length;c++)if(this.children[c].name==a)return!0;return!1};k.prototype.getChild=function(a){var c;if("number"==typeof a)for(c=0;c<this.children.length;c++){if(this.children[c]instanceof b.Field&&this.children[c].id==a)return this.children[c]}else for(c=0;c<this.children.length;c++)if(this.children[c].name==a)return this.children[c];return null};k.prototype.resolve=function(a){var c=a.split("."),e=this,b=0;if(""==c[b]){for(;null!=e.parent;)e=e.parent;b++}do{do{e=
e.getChild(c[b]);if(!e||!(e instanceof f.T)){e=null;break}b++}while(b<c.length);if(null!=e)break;if(null!==this.parent)return this.parent.resolve(a)}while(null!=e);return e};k.prototype.build=function(){for(var a={},c=this.getChildren(),e,b=0;b<c.length;b++)e=c[b],e instanceof k&&(a[e.name]=e.build());Object.defineProperty&&Object.defineProperty(a,"$options",{value:this.buildOpt(),enumerable:!1,configurable:!1,writable:!1});return a};k.prototype.buildOpt=function(){for(var a={},c=Object.keys(this.options),
e=0;e<c.length;e++)a[c[e]]=this.options[c[e]];return a};k.prototype.getOption=function(a){return"undefined"==typeof a?this.options:"undefined"!=typeof this.options[a]?this.options[a]:null};f.Namespace=k;var b=function(a,c,e){k.call(this,a,c,e);this.built=null};b.prototype=Object.create(k.prototype);b.prototype.build=function(){for(var a=function(a,c){var e=c.getChildren(a.Message.Field),b=eval("(function "+c.name+"() { this.__construct.apply(this, arguments); })");b.prototype.__construct=function(c){var a,
b;for(a=0;a<e.length;a++)b=e[a],this[b.name]=b.repeated?[]:null;for(a=0;a<e.length;a++)if(b=e[a],"undefined"!=typeof b.options["default"])try{this.set(b.name,b.options["default"])}catch(g){throw Error("[INTERNAL ERROR] "+g);}if(1==arguments.length&&"object"==typeof c&&"function"!=typeof c.encode&&!(c instanceof Array)&&!(c instanceof l)&&!(c instanceof ArrayBuffer)&&!(d.Long&&c instanceof d.Long)){b=Object.keys(c);for(a=0;a<b.length;a++)this.set(b[a],c[b[a]])}else for(a=0;a<arguments.length;a++)a<
e.length&&this.set(e[a].name,arguments[a])};b.prototype.add=function(b,e){var d=c.getChild(b);if(!d)throw Error(this+"#"+b+" is undefined");if(!(d instanceof a.Message.Field))throw Error(this+"#"+b+" is not a field: "+d.toString(!0));if(!d.repeated)throw Error(this+"#"+b+" is not a repeated field");null===this[d.name]&&(this[d.name]=[]);this[d.name].push(d.verifyValue(e,!0))};b.prototype.set=function(b,e){var d=c.getChild(b);if(!d)throw Error(this+"#"+b+" is not a field: undefined");if(!(d instanceof
a.Message.Field))throw Error(this+"#"+b+" is not a field: "+d.toString(!0));this[d.name]=d.verifyValue(e)};b.prototype.get=function(b){var e=c.getChild(b);if(!e||!(e instanceof a.Message.Field))throw Error(this+"#"+b+" is not a field: undefined");if(!(e instanceof a.Message.Field))throw Error(this+"#"+b+" is not a field: "+e.toString(!0));return this[e.name]};for(var g=0;g<e.length;g++)(function(a){var e=a.name.replace(/(_[a-zA-Z])/g,function(a){return a.toUpperCase().replace("_","")}),e=e.substring(0,
1).toUpperCase()+e.substring(1),d=a.name.replace(/([A-Z])/g,function(a){return"_"+a});c.hasChild("set"+e)||(b.prototype["set"+e]=function(c){this.set(a.name,c)});c.hasChild("set_"+d)||(b.prototype["set_"+d]=function(c){this.set(a.name,c)});c.hasChild("get"+e)||(b.prototype["get"+e]=function(){return this.get(a.name)});c.hasChild("get_"+d)||(b.prototype["get_"+d]=function(){return this.get(a.name)})})(e[g]);b.prototype.encode=function(a){a=a||new l;var b=a.littleEndian,e=c.encode(this,a.LE()).flip();
a.littleEndian=b;return e};b.prototype.toArrayBuffer=function(){return this.encode().toArrayBuffer()};b.decode=function(a){a=a?a instanceof l?a:l.wrap(a):new l;var b=a.littleEndian,e=c.decode(a.LE());a.littleEndian=b;return e};b.prototype.toString=function(){return c.toString()};Object.defineProperty&&Object.defineProperty(b,"$options",{value:c.buildOpt(),enumerable:!1,configurable:!1,writable:!1});return b}(f,this),c=this.getChildren(),e=0;e<c.length;e++)if(c[e]instanceof g)a[c[e].name]=c[e].build();
else if(c[e]instanceof b)a[c[e].name]=c[e].build();else if(!(c[e]instanceof b.Field))throw Error("Illegal reflect child of "+this.toString(!0)+": "+c[e].toString(!0));return this.built=a};b.prototype.encode=function(a,c){for(var e=this.getChildren(b.Field),d=0;d<e.length;d++)e[d].encode(a.get(e[d].name),c);return c};b.prototype.decode=function(a,c){c=c||-1;for(var b=a.offset,d=new this.built;a.offset<b+c||-1==c&&0<a.remaining();){var g=a.readVarint32(),f=g&7,g=g>>3,m=this.getChild(g);if(!m)throw Error("Illegal field id in "+
this.toString(!0)+"#decode: "+g);m.repeated&&!m.options.packed?d.add(m.name,m.decode(f,a)):d.set(m.name,m.decode(f,a))}return d};f.Message=b;var m=function(a,c,b,d,g,f){h.call(this,a,d);this.required="required"==c;this.repeated="repeated"==c;this.type=b;this.id=g;this.options=f||{}};m.prototype=Object.create(h.prototype);m.prototype.verifyValue=function(a,c){c=c||!1;if(null===a){if(this.required)throw Error("Illegal value for "+this.toString(!0)+": "+a+" (required)");return null}var b,f;if(this.repeated&&
!c){a instanceof Array||(a=[a]);f=[];for(b=0;b<a.length;b++)f.push(this.verifyValue(a[b],!0));return f}if(!this.repeated&&a instanceof Array)throw Error("Illegal value for "+this.toString(!0)+": "+a+" (no array expected)");if(this.type==d.TYPES.int32||this.type==d.TYPES.sint32||this.type==d.TYPES.sfixed32)return parseInt(a,10)|0;if(this.type==d.TYPES.uint32||this.type==d.TYPES.fixed32)return parseInt(a,10)>>>0;if(d.Long){if(this.type==d.TYPES.int64||this.type==d.TYPES.sint64||this.type==d.TYPES.sfixed64)return!("object"==
typeof a&&a instanceof d.Long)?d.Long.fromNumber(a,!1):a.unsigned?a.toSigned():a;if(this.type==d.TYPES.uint64||this.type==d.TYPES.fixed64)return!("object"==typeof a&&a instanceof d.Long)?d.Long.fromNumber(a,!0):a.unsigned?a:a.toUnsigned()}if(this.type==d.TYPES.bool)return!!a;if(this.type==d.TYPES["float"]||this.type==d.TYPES["double"])return parseFloat(a);if(this.type==d.TYPES.string)return""+a;if(this.type==d.TYPES.bytes)return"object"==typeof a&&a instanceof l?a:l.wrap(a);if(this.type==d.TYPES["enum"]){f=
this.resolvedType.getChildren(g.Value);for(b=0;b<f.length;b++)if(f[b].name==a||f[b].id==a)return f[b].id;throw Error("Illegal value for "+this.toString(!0)+": "+a+" (not a valid enum value)");}if(this.type==d.TYPES.message){if("object"!=typeof a)throw Error("Illegal value for "+this.toString(!0)+": "+a+" (object expected)");return a instanceof this.resolvedType.built?a:new this.resolvedType.built(a)}throw Error("[INTERNAL ERROR] Illegal value for "+this.toString(!0)+": "+a+" (undefined type "+this.type+
")");};m.prototype.encode=function(a,c){a=this.verifyValue(a);if(null==this.type||"object"!=typeof this.type)throw Error("[INTERNAL ERROR] Unresolved type in "+this.toString(!0)+": "+this.type);if(null===a||this.repeated&&0==a.length)return c;try{if(this.repeated){var b;if(this.options.packed){c.writeVarint32(this.id<<3|d.WIRE_TYPES.LDELIM);c.ensureCapacity(c.offset+=1);var g=c.offset;for(b=0;b<a.length;b++)this.encodeValue(a[b],c);var f=c.offset-g,m=l.calculateVarint32(f);if(1<m){var h=c.slice(g,
c.offset),g=g+(m-1);c.offset=g;c.append(h)}c.writeVarint32(f,g-m)}else for(b=0;b<a.length;b++)c.writeVarint32(this.id<<3|this.type.wireType),this.encodeValue(a[b],c)}else c.writeVarint32(this.id<<3|this.type.wireType),this.encodeValue(a,c)}catch(k){throw c.littleEndian=le,Error("Illegal value for "+this.toString(!0)+": "+a+" ("+k+")");}return c};m.prototype.encodeValue=function(a,c){if(null!==a){if(this.type==d.TYPES.int32||this.type==d.TYPES.uint32)c.writeVarint32(a);else if(this.type==d.TYPES.sint32)c.writeZigZagVarint32(a);
else if(this.type==d.TYPES.fixed32)c.writeUint32(a);else if(this.type==d.TYPES.sfixed32)c.writeInt32(a);else if(this.type==d.TYPES.int64||this.type==d.TYPES.uint64)c.writeVarint64(a);else if(this.type==d.TYPES.sint64)c.writeZigZagVarint64(a);else if(this.type==d.TYPES.fixed64)c.writeUint64(a);else if(this.type==d.TYPES.sfixed64)c.writeInt64(a);else if(this.type==d.TYPES.bool)c.writeVarint32(a?1:0);else if(this.type==d.TYPES["enum"])c.writeVarint32(a);else if(this.type==d.TYPES["float"])c.writeFloat32(a);
else if(this.type==d.TYPES["double"])c.writeFloat64(a);else if(this.type==d.TYPES.string)c.writeVString(a);else if(this.type==d.TYPES.bytes)a.offset>a.length&&(c=c.clone().flip()),c.writeVarint32(a.remaining()),c.append(a);else if(this.type==d.TYPES.message){var b=c.offset;c.writeUint8(0);this.resolvedType.encode(a,c);var g=c.offset-b-1,f=l.calculateVarint32(g);if(1<f){var m=c.clone();m.offset-=g;c.append(m.flip(),b-1+f)}c.writeVarint32(g,b)}else throw Error("[INTERNAL ERROR] Illegal value to encode in "+
this.toString(!0)+": "+a+" (unknown type)");return c}};m.prototype.decode=function(a,c,b){if(a!=this.type.wireType&&(b||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)&&!b){a=c.readVarint32();a=c.offset+a;for(b=[];c.offset<a;)b.push(this.decode(this.type.wireType,c,!0));return b}if(this.type==d.TYPES.int32)return c.readVarint32()|0;if(this.type==
d.TYPES.uint32)return c.readVarint32()>>>0;if(this.type==d.TYPES.sint32)return c.readZigZagVarint32()|0;if(this.type==d.TYPES.fixed32)return c.readUint32()>>>0;if(this.type==d.TYPES.sfixed32)return c.readInt32()|0;if(this.type==d.TYPES.int64)return c.readVarint64();if(this.type==d.TYPES.uint64)return c.readVarint64().toUnsigned();if(this.type==d.TYPES.sint64)return c.readZigZagVarint64();if(this.type==d.TYPES.fixed64)return c.readUint64();if(this.type==d.TYPES.sfixed64)return c.readInt64();if(this.type==
d.TYPES.bool)return!!c.readVarint32();if(this.type==d.TYPES["enum"])return c.readVarint32();if(this.type==d.TYPES["float"])return c.readFloat();if(this.type==d.TYPES["double"])return c.readDouble();if(this.type==d.TYPES.string)return c.readVString();if(this.type==d.TYPES.bytes)return a=c.readVarint32(),b=c.clone(),b.length=b.offset+a,c.offset+=a,b;if(this.type==d.TYPES.message)return a=c.readVarint32(),this.resolvedType.decode(c,a);throw Error("[INTERNAL ERROR] Illegal wire type for "+this.toString(!0)+
": "+a);};f.Message.Field=m;var g=function(a,b,e){k.call(this,a,b,e);this.built=null};g.prototype=Object.create(k.prototype);g.prototype.build=function(){for(var a={},b=this.getChildren(g.Value),e=0;e<b.length;e++)a[b[e].name]=b[e].id;Object.defineProperty&&Object.defineProperty(a,"$options",{value:this.buildOpt(),enumerable:!1,configurable:!1,writable:!1});return this.built=a};f.Enum=g;m=function(a,b,e){h.call(this,a,b);this.id=e};m.prototype=Object.create(h.prototype);f.Enum.Value=m;return f}(f);
f.Builder=function(d,f,h){var k=function(){this.ptr=this.ns=new h.Namespace(null,"");this.resolved=!1;this.result=null};k.prototype.reset=function(){this.ptr=this.ns};k.prototype.define=function(b,d){if("string"!=typeof b||!f.TYPEDEF.test(b))throw Error("Illegal package name: "+b);var g=b.split("."),a;for(a=0;a<g.length;a++)if(!f.NAME.test(g[a]))throw Error("Illegal package name: "+g[a]);for(a=0;a<g.length;a++)this.ptr.hasChild(g[a])||this.ptr.addChild(new h.Namespace(this.ptr,g[a],d)),this.ptr=this.ptr.getChild(g[a]);
return this};k.isValidMessage=function(b){if("string"!=typeof b.name||!f.NAME.test(b.name)||"undefined"!=typeof b.values)return!1;var d;if("undefined"!=typeof b.fields){if(!(b.fields instanceof Array))return!1;var g=[],a;for(d=0;d<b.fields.length;d++){if(!k.isValidMessageField(b.fields[d]))return!1;a=parseInt(b.id,10);if(0<=g.indexOf(a))return!1;g.push(a)}}if("undefined"!=typeof b.enums){if(!(b.enums instanceof Array))return!1;for(d=0;d<b.enums.length;d++)if(!k.isValidEnum(b.enums[d]))return!1}if("undefined"!=
typeof b.messages){if(!(b.messages instanceof Array))return!1;for(d=0;d<b.messages.length;d++)if(!k.isValidMessage(b.messages[d]))return!1}return!0};k.isValidMessageField=function(b){if("string"!=typeof b.rule||"string"!=typeof b.name||"string"!=typeof b.type||"undefined"==typeof b.id||!f.RULE.test(b.rule)||!f.NAME.test(b.name)||!f.TYPEREF.test(b.type)||!f.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),g=0;g<d.length;g++)if(!f.NAME.test(d[g])||
!f.ID.test(""+b.options[d[g]])&&!f.TYPEREF.test(b.options[d[g]]))return!1}return!0};k.isValidEnum=function(b){if("string"!=typeof b.name||!f.NAME.test(b.name)||"undefined"==typeof b.values||!(b.values instanceof Array)||0==b.values.length)return!1;for(var d=0;d<b.values.length;d++)if("object"!=typeof b.values[d]||"string"!=typeof b.values[d].name||"undefined"==typeof b.values[d].id||!f.NAME.test(b.values[d].name)||!f.ID.test(""+b.values[d].id))return!1;return!0};k.prototype.create=function(b){if(b&&
(b instanceof Array||(b=[b]),0!=b.length)){var d=[],g,a,c,e,l;for(d.push(b);0<d.length;){b=d.pop();if(b instanceof Array)for(;0<b.length;)if(g=b.shift(),k.isValidMessage(g)){a=new h.Message(this.ptr,g.name,g.options);if(g.fields&&0<g.fields.length)for(e=0;e<g.fields.length;e++){if(!k.isValidMessageField(g.fields[e]))throw Error("Not a valid message field definition in message "+a.name+": "+JSON.stringify(g.fields[e]));if(a.hasChild(g.fields[e].id))throw Error("Duplicate field id in message "+a.name+
": "+g.fields[e].id);if(g.fields[e].options){c=Object.keys(g.fields[e].options);for(l=0;l<c.length;l++){if(!f.NAME.test(c[l]))throw Error("Illegal field option name in message "+a.name+"#"+g.fields[e].name+": "+c[l]);if(!f.ID.test(""+g.fields[e].options[c[l]])&&!f.TYPEREF.test(g.fields[e].options[c[l]]))throw Error("Illegal field option value in message "+a.name+"#"+g.fields[e].name+"#"+c[l]+": "+g.fields[e].options[c[l]]);}}a.addChild(new h.Message.Field(a,g.fields[e].rule,g.fields[e].type,g.fields[e].name,
g.fields[e].id,g.fields[e].options))}c=[];if("undefined"!=typeof g.enums&&0<g.enums.length)for(e=0;e<g.enums.length;e++)c.push(g.enums[e]);if(g.messages&&0<g.messages.length)for(e=0;e<g.messages.length;e++)c.push(g.messages[e]);this.ptr.addChild(a);0<c.length&&(d.push(b),b=c,this.ptr=a)}else if(k.isValidEnum(g)){a=new h.Enum(this.ptr,g.name,g.options);for(e=0;e<g.values.length;e++)a.addChild(new h.Enum.Value(a,g.values[e].name,g.values[e].id));this.ptr.addChild(a)}else throw Error("Not a valid message or enum definition: "+
JSON.stringify(g));else throw Error("Not a valid namespace definition: "+JSON.stringify(b));this.ptr=this.ptr.parent}this.resolved=!1;this.result=null;return this}};k.prototype["import"]=function(b,f){b["package"]&&this.define(b["package"],b.options);b.messages&&this.create(b.messages);this.reset();b["package"]&&this.define(b["package"],b.options);b.enums&&this.create(b.enums);this.reset();if(b.imports&&0<b.imports.length){if(!f)throw Error("Cannot determine import root: File name is unknown");for(var g=
f.replace(/[\/\\][^\/\\]*$/,""),a=0;a<b.imports.length;a++){var c=g+"/"+b.imports[a];if(/\.json$/i.test(c)){var e=d.Util.fetch(c);if(null===e)throw Error("Failed to import '"+c+"' in '"+f+"': File not found");this["import"](JSON.parse(e),c)}else throw Error("This build of ProtoBuf.js does not include DotProto support. See: https://github.com/dcodeIO/ProtoBuf.js");}}return this};k.prototype.resolveAll=function(){if(!(null==this.ptr||"object"==typeof this.ptr.type)){if(this.ptr instanceof h.Namespace)for(var b=
this.ptr.getChildren(),k=0;k<b.length;k++)this.ptr=b[k],this.resolveAll();else if(this.ptr instanceof h.Message.Field)if(f.TYPE.test(this.ptr.type))this.ptr.type=d.TYPES[this.ptr.type];else{if(!f.TYPEREF.test(this.ptr.type))throw Error("Illegal type reference in "+this.ptr.toString(!0)+": "+this.ptr.type);b=this.ptr.parent.resolve(this.ptr.type);if(!b)throw Error("Unresolvable type reference in "+this.ptr.toString(!0)+": "+this.ptr.type);this.ptr.resolvedType=b;if(b instanceof h.Enum)this.ptr.type=
d.TYPES["enum"];else if(b instanceof h.Message)this.ptr.type=d.TYPES.message;else throw Error("Illegal type reference in "+this.ptr.toString(!0)+": "+this.ptr.type);}else if(!(this.ptr instanceof d.Reflect.Enum.Value))throw Error("Illegal object type in namespace: "+typeof this.ptr+":"+this.ptr);this.reset()}};k.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,f=0;f<b.length;f++)if(d[b[f]])d=d[b[f]];else{d=null;break}return d}return this.result};k.prototype.toString=function(){return"Builder"};return k}(f,f.Lang,f.Reflect);f.protoFromString=function(d,f,h){throw Error("This build of ProtoBuf.js does not include DotProto support. See: https://github.com/dcodeIO/ProtoBuf.js");};f.protoFromFile=function(d,l,h){if(l&&"object"==typeof l)h=l,l=null;else if(!l||"function"!=typeof l)l=null;if(l)f.Util.fetch(d,function(b){l(f.protoFromString(b,h,d))});
else{var k=f.Util.fetch(d);return null!==k?f.protoFromString(k,h,d):null}};f.newBuilder=function(d,l){var h=new f.Builder;"undefined"!=typeof d&&h.define(d,l);return h};return f}"undefined"!=typeof module&&module.exports?module.exports=p(require("bytebuffer")):"undefined"!=typeof define&&define.amd?define("ProtoBuf",["ByteBuffer"],p):(n.dcodeIO||(n.dcodeIO={}),n.dcodeIO.ProtoBuf=p(n.dcodeIO.ByteBuffer))})(this);
typeof require;d.XHR=function(){for(var d=[function(){return new XMLHttpRequest},function(){return new ActiveXObject("Msxml2.XMLHTTP")},function(){return new ActiveXObject("Msxml3.XMLHTTP")},function(){return new ActiveXObject("Microsoft.XMLHTTP")}],h=null,f=0;f<d.length;f++){try{h=d[f]()}catch(a){continue}break}if(!h)throw Error("XMLHttpRequest is not supported");return h};d.fetch=function(f,h){h&&"function"!=typeof h&&(h=null);if(d.IS_NODE)if(h)require("fs").readFile(f,function(a,d){a?h(null):h(""+
d)});else try{return require("fs").readFileSync(f)}catch(k){return null}else{var a=d.XHR();a.open("GET",f,h?!0:!1);a.setRequestHeader("User-Agent","XMLHTTP/1.0");a.setRequestHeader("Accept","text/plain");if(h)a.onreadystatechange=function(){4==a.readyState&&(200==a.status?h(a.responseText):h(null))},4!=a.readyState&&a.send(null);else return a.send(null),a.responseText}};return d}();f.Lang={OPEN:"{",CLOSE:"}",OPTOPEN:"[",OPTCLOSE:"]",OPTEND:",",EQUAL:"=",END:";",DELIM:/[\s\{\}=;\[\],"\(\)]/g,KEYWORD:/package|option|import|message|enum|extend|service/,
RULE:/required|optional|repeated/,TYPE:/double|float|int32|uint32|sint32|int64|uint64|sint64|fixed32|sfixed32|fixed64|sfixed64|bool|string|bytes/,NAME:/[a-zA-Z][a-zA-Z_0-9]*/,TYPEDEF:/[a-zA-Z](\.?[a-zA-Z_0-9])*/,TYPEREF:/\.?[a-zA-Z](\.?[a-zA-Z_0-9])*/,NUMBER:/^-?([1-9][0-9]*)|0$/,ID:/[0-9]+/,WHITESPACE:/\s/,STRING:/"([^"\\]*(\\.[^"\\]*)*)"/g,STRINGOPEN:'"',STRINGCLOSE:'"',COPTOPEN:"(",COPTCLOSE:")"};f.Reflect=function(d){var f={},h=function(b,c){this.parent=b;this.name=c;this.resolvedType=null};h.prototype.toString=
function(b){var c=this.name,e=this;do{e=e.parent;if(null==e)break;c=e.name+"."+c}while(1);b&&(this instanceof f.Message?c="Message "+c:this instanceof a.Field?c="Message.Field "+c:this instanceof g?c="Enum "+c:this instanceof g.Value?c="Enum.Value "+c:this instanceof k&&(c="Namespace "+c));return c};h.prototype.build=function(){throw Error(this.toString(!0)+" cannot be built directly");};f.T=h;var k=function(b,c,e){h.call(this,b,c);this.children=[];this.options=e||{}};k.prototype=Object.create(h.prototype);
k.prototype.getChildren=function(b){b=b||null;if(null==b)return this.children.slice();for(var c=[],e=0;e<this.children.length;e++)this.children[e]instanceof b&&c.push(this.children[e]);return c};k.prototype.addChild=function(b){if(this.hasChild(b.name))throw Error("Duplicate name in namespace "+this.toString(!0)+": "+b.name);this.children.push(b)};k.prototype.hasChild=function(b){var c;if("number"==typeof b)for(c=0;c<this.children.length;c++){if(this.children[c]instanceof a.Field&&this.children[c].id==
b)return!0}else for(c=0;c<this.children.length;c++)if(this.children[c].name==b)return!0;return!1};k.prototype.getChild=function(b){var c;if("number"==typeof b)for(c=0;c<this.children.length;c++){if(this.children[c]instanceof a.Field&&this.children[c].id==b)return this.children[c]}else for(c=0;c<this.children.length;c++)if(this.children[c].name==b)return this.children[c];return null};k.prototype.resolve=function(b){var c=b.split("."),e=this,a=0;if(""==c[a]){for(;null!=e.parent;)e=e.parent;a++}do{do{e=
e.getChild(c[a]);if(!e||!(e instanceof f.T)){e=null;break}a++}while(a<c.length);if(null!=e)break;if(null!==this.parent)return this.parent.resolve(b)}while(null!=e);return e};k.prototype.build=function(){for(var b={},c=this.getChildren(),e,a=0;a<c.length;a++)e=c[a],e instanceof k&&(b[e.name]=e.build());Object.defineProperty&&Object.defineProperty(b,"$options",{value:this.buildOpt(),enumerable:!1,configurable:!1,writable:!1});return b};k.prototype.buildOpt=function(){for(var b={},c=Object.keys(this.options),
e=0;e<c.length;e++)b[c[e]]=this.options[c[e]];return b};k.prototype.getOption=function(b){return"undefined"==typeof b?this.options:"undefined"!=typeof this.options[b]?this.options[b]:null};f.Namespace=k;var a=function(b,c,e){k.call(this,b,c,e);this.built=null};a.prototype=Object.create(k.prototype);a.prototype.build=function(){for(var b=function(b,c){var e=c.getChildren(b.Message.Field),a=eval("(function "+c.name+"() { this.__construct.apply(this, arguments); })");a.prototype.__construct=function(b){var c,
a;for(c=0;c<e.length;c++)a=e[c],this[a.name]=a.repeated?[]:null;for(c=0;c<e.length;c++)if(a=e[c],"undefined"!=typeof a.options["default"])try{this.set(a.name,a.options["default"])}catch(g){throw Error("[INTERNAL ERROR] "+g);}if(1==arguments.length&&"object"==typeof b&&"function"!=typeof b.encode&&!(b instanceof Array)&&!(b instanceof l)&&!(b instanceof ArrayBuffer)&&!(d.Long&&b instanceof d.Long)){a=Object.keys(b);for(c=0;c<a.length;c++)this.set(a[c],b[a[c]])}else for(c=0;c<arguments.length;c++)c<
e.length&&this.set(e[c].name,arguments[c])};a.prototype.add=function(a,e){var d=c.getChild(a);if(!d)throw Error(this+"#"+a+" is undefined");if(!(d instanceof b.Message.Field))throw Error(this+"#"+a+" is not a field: "+d.toString(!0));if(!d.repeated)throw Error(this+"#"+a+" is not a repeated field");null===this[d.name]&&(this[d.name]=[]);this[d.name].push(d.verifyValue(e,!0))};a.prototype.set=function(a,e){var d=c.getChild(a);if(!d)throw Error(this+"#"+a+" is not a field: undefined");if(!(d instanceof
b.Message.Field))throw Error(this+"#"+a+" is not a field: "+d.toString(!0));this[d.name]=d.verifyValue(e)};a.prototype.get=function(a){var e=c.getChild(a);if(!e||!(e instanceof b.Message.Field))throw Error(this+"#"+a+" is not a field: undefined");if(!(e instanceof b.Message.Field))throw Error(this+"#"+a+" is not a field: "+e.toString(!0));return this[e.name]};for(var g=0;g<e.length;g++)(function(b){var e=b.name.replace(/(_[a-zA-Z])/g,function(c){return c.toUpperCase().replace("_","")}),e=e.substring(0,
1).toUpperCase()+e.substring(1),d=b.name.replace(/([A-Z])/g,function(c){return"_"+c});c.hasChild("set"+e)||(a.prototype["set"+e]=function(c){this.set(b.name,c)});c.hasChild("set_"+d)||(a.prototype["set_"+d]=function(c){this.set(b.name,c)});c.hasChild("get"+e)||(a.prototype["get"+e]=function(){return this.get(b.name)});c.hasChild("get_"+d)||(a.prototype["get_"+d]=function(){return this.get(b.name)})})(e[g]);a.prototype.encode=function(b){b=b||new l;var a=b.littleEndian,e=c.encode(this,b.LE()).flip();
b.littleEndian=a;return e};a.prototype.toArrayBuffer=function(){return this.encode().toArrayBuffer()};a.decode=function(b){b=b?b instanceof l?b:l.wrap(b):new l;var a=b.littleEndian,e=c.decode(b.LE());b.littleEndian=a;return e};a.prototype.toString=function(){return c.toString()};Object.defineProperty&&Object.defineProperty(a,"$options",{value:c.buildOpt(),enumerable:!1,configurable:!1,writable:!1});return a}(f,this),c=this.getChildren(),e=0;e<c.length;e++)if(c[e]instanceof g)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.built=b};a.prototype.encode=function(b,c){for(var e=this.getChildren(a.Field),d=0;d<e.length;d++)e[d].encode(b.get(e[d].name),c);return c};a.prototype.decode=function(b,c){c=c||-1;for(var a=b.offset,d=new this.built;b.offset<a+c||-1==c&&0<b.remaining();){var g=b.readVarint32(),f=g&7,g=g>>3,m=this.getChild(g);if(!m)throw Error("Illegal field id in "+
this.toString(!0)+"#decode: "+g);m.repeated&&!m.options.packed?d.add(m.name,m.decode(f,b)):d.set(m.name,m.decode(f,b))}return d};f.Message=a;var m=function(b,c,a,d,g,f){h.call(this,b,d);this.required="required"==c;this.repeated="repeated"==c;this.type=a;this.id=g;this.options=f||{}};m.prototype=Object.create(h.prototype);m.prototype.verifyValue=function(b,c){c=c||!1;if(null===b){if(this.required)throw Error("Illegal value for "+this.toString(!0)+": "+b+" (required)");return null}var a,f;if(this.repeated&&
!c){b instanceof Array||(b=[b]);f=[];for(a=0;a<b.length;a++)f.push(this.verifyValue(b[a],!0));return f}if(!this.repeated&&b instanceof Array)throw Error("Illegal value for "+this.toString(!0)+": "+b+" (no array expected)");if(this.type==d.TYPES.int32||this.type==d.TYPES.sint32||this.type==d.TYPES.sfixed32)return parseInt(b,10)|0;if(this.type==d.TYPES.uint32||this.type==d.TYPES.fixed32)return parseInt(b,10)>>>0;if(d.Long){if(this.type==d.TYPES.int64||this.type==d.TYPES.sint64||this.type==d.TYPES.sfixed64)return!("object"==
typeof b&&b instanceof d.Long)?d.Long.fromNumber(b,!1):b.unsigned?b.toSigned():b;if(this.type==d.TYPES.uint64||this.type==d.TYPES.fixed64)return!("object"==typeof b&&b instanceof d.Long)?d.Long.fromNumber(b,!0):b.unsigned?b:b.toUnsigned()}if(this.type==d.TYPES.bool)return!!b;if(this.type==d.TYPES["float"]||this.type==d.TYPES["double"])return parseFloat(b);if(this.type==d.TYPES.string)return""+b;if(this.type==d.TYPES.bytes)return"object"==typeof b&&b instanceof l?b:l.wrap(b);if(this.type==d.TYPES["enum"]){f=
this.resolvedType.getChildren(g.Value);for(a=0;a<f.length;a++)if(f[a].name==b||f[a].id==b)return f[a].id;throw Error("Illegal value for "+this.toString(!0)+": "+b+" (not a valid enum value)");}if(this.type==d.TYPES.message){if("object"!=typeof b)throw Error("Illegal value for "+this.toString(!0)+": "+b+" (object expected)");return b instanceof this.resolvedType.built?b:new this.resolvedType.built(b)}throw Error("[INTERNAL ERROR] Illegal value for "+this.toString(!0)+": "+b+" (undefined type "+this.type+
")");};m.prototype.encode=function(b,c){b=this.verifyValue(b);if(null==this.type||"object"!=typeof this.type)throw Error("[INTERNAL ERROR] Unresolved type in "+this.toString(!0)+": "+this.type);if(null===b||this.repeated&&0==b.length)return c;try{if(this.repeated){var a;if(this.options.packed){c.writeVarint32(this.id<<3|d.WIRE_TYPES.LDELIM);c.ensureCapacity(c.offset+=1);var g=c.offset;for(a=0;a<b.length;a++)this.encodeValue(b[a],c);var f=c.offset-g,m=l.calculateVarint32(f);if(1<m){var h=c.slice(g,
c.offset),g=g+(m-1);c.offset=g;c.append(h)}c.writeVarint32(f,g-m)}else for(a=0;a<b.length;a++)c.writeVarint32(this.id<<3|this.type.wireType),this.encodeValue(b[a],c)}else c.writeVarint32(this.id<<3|this.type.wireType),this.encodeValue(b,c)}catch(k){throw c.littleEndian=le,Error("Illegal value for "+this.toString(!0)+": "+b+" ("+k+")");}return c};m.prototype.encodeValue=function(b,c){if(null!==b){if(this.type==d.TYPES.int32||this.type==d.TYPES.uint32)c.writeVarint32(b);else if(this.type==d.TYPES.sint32)c.writeZigZagVarint32(b);
else if(this.type==d.TYPES.fixed32)c.writeUint32(b);else if(this.type==d.TYPES.sfixed32)c.writeInt32(b);else if(this.type==d.TYPES.int64||this.type==d.TYPES.uint64)c.writeVarint64(b);else if(this.type==d.TYPES.sint64)c.writeZigZagVarint64(b);else if(this.type==d.TYPES.fixed64)c.writeUint64(b);else if(this.type==d.TYPES.sfixed64)c.writeInt64(b);else if(this.type==d.TYPES.bool)c.writeVarint32(b?1:0);else if(this.type==d.TYPES["enum"])c.writeVarint32(b);else if(this.type==d.TYPES["float"])c.writeFloat32(b);
else if(this.type==d.TYPES["double"])c.writeFloat64(b);else if(this.type==d.TYPES.string)c.writeVString(b);else if(this.type==d.TYPES.bytes)b.offset>b.length&&(c=c.clone().flip()),c.writeVarint32(b.remaining()),c.append(b);else if(this.type==d.TYPES.message){var a=new l;this.resolvedType.encode(b,a);c.writeVarint32(a.offset);c.append(a.flip())}else throw Error("[INTERNAL ERROR] Illegal value to encode in "+this.toString(!0)+": "+b+" (unknown type)");return c}};m.prototype.decode=function(b,c,a){if(b!=
this.type.wireType&&(a||b!=d.WIRE_TYPES.LDELIM||!this.repeated))throw Error("Illegal wire type for field "+this.toString(!0)+": "+b+" ("+this.type.wireType+" expected)");if(b==d.WIRE_TYPES.LDELIM&&(this.repeated&&this.options.packed)&&!a){b=c.readVarint32();b=c.offset+b;for(a=[];c.offset<b;)a.push(this.decode(this.type.wireType,c,!0));return a}if(this.type==d.TYPES.int32)return c.readVarint32()|0;if(this.type==d.TYPES.uint32)return c.readVarint32()>>>0;if(this.type==d.TYPES.sint32)return c.readZigZagVarint32()|
0;if(this.type==d.TYPES.fixed32)return c.readUint32()>>>0;if(this.type==d.TYPES.sfixed32)return c.readInt32()|0;if(this.type==d.TYPES.int64)return c.readVarint64();if(this.type==d.TYPES.uint64)return c.readVarint64().toUnsigned();if(this.type==d.TYPES.sint64)return c.readZigZagVarint64();if(this.type==d.TYPES.fixed64)return c.readUint64();if(this.type==d.TYPES.sfixed64)return c.readInt64();if(this.type==d.TYPES.bool)return!!c.readVarint32();if(this.type==d.TYPES["enum"])return c.readVarint32();if(this.type==
d.TYPES["float"])return c.readFloat();if(this.type==d.TYPES["double"])return c.readDouble();if(this.type==d.TYPES.string)return c.readVString();if(this.type==d.TYPES.bytes)return b=c.readVarint32(),a=c.clone(),a.length=a.offset+b,c.offset+=b,a;if(this.type==d.TYPES.message)return b=c.readVarint32(),this.resolvedType.decode(c,b);throw Error("[INTERNAL ERROR] Illegal wire type for "+this.toString(!0)+": "+b);};f.Message.Field=m;var g=function(b,c,a){k.call(this,b,c,a);this.built=null};g.prototype=Object.create(k.prototype);
g.prototype.build=function(){for(var b={},c=this.getChildren(g.Value),a=0;a<c.length;a++)b[c[a].name]=c[a].id;Object.defineProperty&&Object.defineProperty(b,"$options",{value:this.buildOpt(),enumerable:!1,configurable:!1,writable:!1});return this.built=b};f.Enum=g;m=function(b,a,d){h.call(this,b,a);this.id=d};m.prototype=Object.create(h.prototype);f.Enum.Value=m;return f}(f);f.Builder=function(d,f,h){var k=function(){this.ptr=this.ns=new h.Namespace(null,"");this.resolved=!1;this.result=null};k.prototype.reset=
function(){this.ptr=this.ns};k.prototype.define=function(a,d){if("string"!=typeof a||!f.TYPEDEF.test(a))throw Error("Illegal package name: "+a);var g=a.split("."),b;for(b=0;b<g.length;b++)if(!f.NAME.test(g[b]))throw Error("Illegal package name: "+g[b]);for(b=0;b<g.length;b++)this.ptr.hasChild(g[b])||this.ptr.addChild(new h.Namespace(this.ptr,g[b],d)),this.ptr=this.ptr.getChild(g[b]);return this};k.isValidMessage=function(a){if("string"!=typeof a.name||!f.NAME.test(a.name)||"undefined"!=typeof a.values)return!1;
var d;if("undefined"!=typeof a.fields){if(!(a.fields instanceof Array))return!1;var g=[],b;for(d=0;d<a.fields.length;d++){if(!k.isValidMessageField(a.fields[d]))return!1;b=parseInt(a.id,10);if(0<=g.indexOf(b))return!1;g.push(b)}}if("undefined"!=typeof a.enums){if(!(a.enums instanceof Array))return!1;for(d=0;d<a.enums.length;d++)if(!k.isValidEnum(a.enums[d]))return!1}if("undefined"!=typeof a.messages){if(!(a.messages instanceof Array))return!1;for(d=0;d<a.messages.length;d++)if(!k.isValidMessage(a.messages[d]))return!1}return!0};
k.isValidMessageField=function(a){if("string"!=typeof a.rule||"string"!=typeof a.name||"string"!=typeof a.type||"undefined"==typeof a.id||!f.RULE.test(a.rule)||!f.NAME.test(a.name)||!f.TYPEREF.test(a.type)||!f.ID.test(""+a.id))return!1;if("undefined"!=typeof a.options){if("object"!=typeof a.options)return!1;for(var d=Object.keys(a.options),g=0;g<d.length;g++)if(!f.NAME.test(d[g])||!f.ID.test(""+a.options[d[g]])&&!f.TYPEREF.test(a.options[d[g]]))return!1}return!0};k.isValidEnum=function(a){if("string"!=
typeof a.name||!f.NAME.test(a.name)||"undefined"==typeof a.values||!(a.values instanceof Array)||0==a.values.length)return!1;for(var d=0;d<a.values.length;d++)if("object"!=typeof a.values[d]||"string"!=typeof a.values[d].name||"undefined"==typeof a.values[d].id||!f.NAME.test(a.values[d].name)||!f.ID.test(""+a.values[d].id))return!1;return!0};k.prototype.create=function(a){if(a&&(a instanceof Array||(a=[a]),0!=a.length)){var d=[],g,b,c,e,l;for(d.push(a);0<d.length;){a=d.pop();if(a instanceof Array)for(;0<
a.length;)if(g=a.shift(),k.isValidMessage(g)){b=new h.Message(this.ptr,g.name,g.options);if(g.fields&&0<g.fields.length)for(e=0;e<g.fields.length;e++){if(!k.isValidMessageField(g.fields[e]))throw Error("Not a valid message field definition in message "+b.name+": "+JSON.stringify(g.fields[e]));if(b.hasChild(g.fields[e].id))throw Error("Duplicate field id in message "+b.name+": "+g.fields[e].id);if(g.fields[e].options){c=Object.keys(g.fields[e].options);for(l=0;l<c.length;l++){if(!f.NAME.test(c[l]))throw Error("Illegal field option name in message "+
b.name+"#"+g.fields[e].name+": "+c[l]);if(!f.ID.test(""+g.fields[e].options[c[l]])&&!f.TYPEREF.test(g.fields[e].options[c[l]]))throw Error("Illegal field option value in message "+b.name+"#"+g.fields[e].name+"#"+c[l]+": "+g.fields[e].options[c[l]]);}}b.addChild(new h.Message.Field(b,g.fields[e].rule,g.fields[e].type,g.fields[e].name,g.fields[e].id,g.fields[e].options))}c=[];if("undefined"!=typeof g.enums&&0<g.enums.length)for(e=0;e<g.enums.length;e++)c.push(g.enums[e]);if(g.messages&&0<g.messages.length)for(e=
0;e<g.messages.length;e++)c.push(g.messages[e]);this.ptr.addChild(b);0<c.length&&(d.push(a),a=c,this.ptr=b)}else if(k.isValidEnum(g)){b=new h.Enum(this.ptr,g.name,g.options);for(e=0;e<g.values.length;e++)b.addChild(new h.Enum.Value(b,g.values[e].name,g.values[e].id));this.ptr.addChild(b)}else throw Error("Not a valid message or enum definition: "+JSON.stringify(g));else throw Error("Not a valid namespace definition: "+JSON.stringify(a));this.ptr=this.ptr.parent}this.resolved=!1;this.result=null;return this}};
k.prototype["import"]=function(a,f){a["package"]&&this.define(a["package"],a.options);a.messages&&this.create(a.messages);this.reset();a["package"]&&this.define(a["package"],a.options);a.enums&&this.create(a.enums);this.reset();if(a.imports&&0<a.imports.length){if(!f)throw Error("Cannot determine import root: File name is unknown");for(var g=f.replace(/[\/\\][^\/\\]*$/,""),b=0;b<a.imports.length;b++){var c=g+"/"+a.imports[b];if(/\.json$/i.test(c)){var e=d.Util.fetch(c);if(null===e)throw Error("Failed to import '"+
c+"' in '"+f+"': File not found");this["import"](JSON.parse(e),c)}else throw Error("This build of ProtoBuf.js does not include DotProto support. See: https://github.com/dcodeIO/ProtoBuf.js");}}return this};k.prototype.resolveAll=function(){if(!(null==this.ptr||"object"==typeof this.ptr.type)){if(this.ptr instanceof h.Namespace)for(var a=this.ptr.getChildren(),k=0;k<a.length;k++)this.ptr=a[k],this.resolveAll();else if(this.ptr instanceof h.Message.Field)if(f.TYPE.test(this.ptr.type))this.ptr.type=
d.TYPES[this.ptr.type];else{if(!f.TYPEREF.test(this.ptr.type))throw Error("Illegal type reference in "+this.ptr.toString(!0)+": "+this.ptr.type);a=this.ptr.parent.resolve(this.ptr.type);if(!a)throw Error("Unresolvable type reference in "+this.ptr.toString(!0)+": "+this.ptr.type);this.ptr.resolvedType=a;if(a instanceof h.Enum)this.ptr.type=d.TYPES["enum"];else if(a instanceof h.Message)this.ptr.type=d.TYPES.message;else throw Error("Illegal type reference in "+this.ptr.toString(!0)+": "+this.ptr.type);
}else if(!(this.ptr instanceof d.Reflect.Enum.Value))throw Error("Illegal object type in namespace: "+typeof this.ptr+":"+this.ptr);this.reset()}};k.prototype.build=function(a){this.reset();this.resolved||(this.resolveAll(),this.resolved=!0,this.result=null);null==this.result&&(this.result=this.ns.build());if(a){a=a.split(".");for(var d=this.result,f=0;f<a.length;f++)if(d[a[f]])d=d[a[f]];else{d=null;break}return d}return this.result};k.prototype.toString=function(){return"Builder"};return k}(f,f.Lang,
f.Reflect);f.protoFromString=function(d,f,h){throw Error("This build of ProtoBuf.js does not include DotProto support. See: https://github.com/dcodeIO/ProtoBuf.js");};f.protoFromFile=function(d,l,h){if(l&&"object"==typeof l)h=l,l=null;else if(!l||"function"!=typeof l)l=null;if(l)f.Util.fetch(d,function(a){l(f.protoFromString(a,h,d))});else{var k=f.Util.fetch(d);return null!==k?f.protoFromString(k,h,d):null}};f.newBuilder=function(d,l){var h=new f.Builder;"undefined"!=typeof d&&h.define(d,l);return h};
return f}"undefined"!=typeof module&&module.exports?module.exports=p(require("bytebuffer")):"undefined"!=typeof define&&define.amd?define("ProtoBuf",["ByteBuffer"],p):(n.dcodeIO||(n.dcodeIO={}),n.dcodeIO.ProtoBuf=p(n.dcodeIO.ByteBuffer))})(this);

@@ -973,17 +973,6 @@ // #ifdef UNDEFINED

} else if (this.type == ProtoBuf.TYPES["message"]) {
// We do not know the length of the embedded message yet. To avoid creating a second buffer, let's assume
// the length varint might consist of one byte and encode the embedded message to the current offset+1.
// When we know the length and it is one byte long, all we have to do is to write the length varint. If
// it's longer than one byte, we need to copy. Finally we did it all with just one buffer.
var start = buffer.offset;
buffer.writeUint8(0x00); // Placeholder (calls ensureCapacity)
this.resolvedType.encode(value, buffer);
var messageBytes = buffer.offset-start-1;
var sizeBytes = ByteBuffer.calculateVarint32(messageBytes);
if (sizeBytes > 1) { // We need to copy
var bb = buffer.clone();
bb.offset -= messageBytes;
buffer.append(bb.flip(), start-1+sizeBytes);
}
buffer.writeVarint32(messageBytes, start);
var bb = new ByteBuffer();
this.resolvedType.encode(value, bb);
buffer.writeVarint32(bb.offset);
buffer.append(bb.flip());
} else {

@@ -990,0 +979,0 @@ // We should never end here

@@ -357,2 +357,21 @@ /*

"innerStringLenGt70": function(test) {
try {
var builder = ProtoBuf.protoFromString("message Test { required Inner a = 1; message Inner { required string b = 1; } }");
var Test = builder.build("Test");
var t = new Test();
var data = "0123456789"; // 10: 20, 40, 80, 160, 320 bytes
for (var i=0; i<5; i++) data += data;
test.equal(data.length, 320);
t.a = new Test.Inner(data);
var bb = t.encode();
var t2 = Test.decode(bb);
test.equal(t2.a.b.length, 320);
test.equal(data, t2.a.b);
} catch (e) {
fail(e);
}
test.done();
},
// Options on all levels

@@ -359,0 +378,0 @@ "options": {

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

Sorry, the diff of this file is not supported yet

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

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc