/
protobuf-light.min.js
88 lines (88 loc) · 41.8 KB
/
protobuf-light.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
protobuf.js (c) 2013 Daniel Wirtz <dcode@dcode.io>
Released under the Apache License, Version 2.0
see: https://github.com/dcodeIO/protobuf.js for details
*/
(function(h,y){"function"===typeof define&&define.amd?define(["bytebuffer"],y):"function"===typeof require&&"object"===typeof module&&module&&module.exports?module.exports=y(require("bytebuffer"),!0):(h.dcodeIO=h.dcodeIO||{}).ProtoBuf=y(h.dcodeIO.ByteBuffer)})(this,function(h,y){var d={};d.ByteBuffer=h;d.Long=h.Long||null;d.VERSION="5.0.3";d.WIRE_TYPES={};d.WIRE_TYPES.VARINT=0;d.WIRE_TYPES.BITS64=1;d.WIRE_TYPES.LDELIM=2;d.WIRE_TYPES.STARTGROUP=3;d.WIRE_TYPES.ENDGROUP=4;d.WIRE_TYPES.BITS32=5;d.PACKABLE_WIRE_TYPES=
[d.WIRE_TYPES.VARINT,d.WIRE_TYPES.BITS64,d.WIRE_TYPES.BITS32];d.TYPES={int32:{name:"int32",wireType:d.WIRE_TYPES.VARINT,defaultValue:0},uint32:{name:"uint32",wireType:d.WIRE_TYPES.VARINT,defaultValue:0},sint32:{name:"sint32",wireType:d.WIRE_TYPES.VARINT,defaultValue:0},int64:{name:"int64",wireType:d.WIRE_TYPES.VARINT,defaultValue:d.Long?d.Long.ZERO:void 0},uint64:{name:"uint64",wireType:d.WIRE_TYPES.VARINT,defaultValue:d.Long?d.Long.UZERO:void 0},sint64:{name:"sint64",wireType:d.WIRE_TYPES.VARINT,
defaultValue:d.Long?d.Long.ZERO:void 0},bool:{name:"bool",wireType:d.WIRE_TYPES.VARINT,defaultValue:!1},"double":{name:"double",wireType:d.WIRE_TYPES.BITS64,defaultValue:0},string:{name:"string",wireType:d.WIRE_TYPES.LDELIM,defaultValue:""},bytes:{name:"bytes",wireType:d.WIRE_TYPES.LDELIM,defaultValue:null},fixed32:{name:"fixed32",wireType:d.WIRE_TYPES.BITS32,defaultValue:0},sfixed32:{name:"sfixed32",wireType:d.WIRE_TYPES.BITS32,defaultValue:0},fixed64:{name:"fixed64",wireType:d.WIRE_TYPES.BITS64,
defaultValue:d.Long?d.Long.UZERO:void 0},sfixed64:{name:"sfixed64",wireType:d.WIRE_TYPES.BITS64,defaultValue:d.Long?d.Long.ZERO:void 0},"float":{name:"float",wireType:d.WIRE_TYPES.BITS32,defaultValue:0},"enum":{name:"enum",wireType:d.WIRE_TYPES.VARINT,defaultValue:0},message:{name:"message",wireType:d.WIRE_TYPES.LDELIM,defaultValue:null},group:{name:"group",wireType:d.WIRE_TYPES.STARTGROUP,defaultValue:null}};d.MAP_KEY_TYPES=[d.TYPES.int32,d.TYPES.sint32,d.TYPES.sfixed32,d.TYPES.uint32,d.TYPES.fixed32,
d.TYPES.int64,d.TYPES.sint64,d.TYPES.sfixed64,d.TYPES.uint64,d.TYPES.fixed64,d.TYPES.bool,d.TYPES.string,d.TYPES.bytes];d.ID_MIN=1;d.ID_MAX=536870911;d.convertFieldsToCamelCase=!1;d.populateAccessors=!0;d.populateDefaults=!0;d.Util=function(){var b={};b.IS_NODE=!("object"!==typeof process||"[object process]"!==process+""||process.browser);b.XHR=function(){for(var b=[function(){return new XMLHttpRequest},function(){return new ActiveXObject("Msxml2.XMLHTTP")},function(){return new ActiveXObject("Msxml3.XMLHTTP")},
function(){return new ActiveXObject("Microsoft.XMLHTTP")}],d=null,h=0;h<b.length;h++){try{d=b[h]()}catch(k){continue}break}if(!d)throw Error("XMLHttpRequest is not supported");return d};b.fetch=function(d,h){h&&"function"!=typeof h&&(h=null);if(b.IS_NODE){var p=require("fs");if(h)p.readFile(d,function(b,d){b?h(null):h(""+d)});else try{return p.readFileSync(d)}catch(k){return null}}else{var f=b.XHR();f.open("GET",d,h?!0:!1);f.setRequestHeader("Accept","text/plain");"function"===typeof f.overrideMimeType&&
f.overrideMimeType("text/plain");if(h)f.onreadystatechange=function(){4==f.readyState&&(200==f.status||0==f.status&&"string"===typeof f.responseText?h(f.responseText):h(null))},4!=f.readyState&&f.send(null);else return f.send(null),200==f.status||0==f.status&&"string"===typeof f.responseText?f.responseText:null}};b.toCamelCase=function(b){return b.replace(/_([a-zA-Z])/g,function(b,d){return d.toUpperCase()})};return b}();d.Lang={DELIM:/[\s\{\}=;:\[\],'"\(\)<>]/g,RULE:/^(?:required|optional|repeated|map)$/,
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]*)(?:\.[a-zA-Z_][a-zA-Z_0-9]*)*$/,FQTYPEREF:/^(?:\.[a-zA-Z_][a-zA-Z_0-9]*)+$/,NUMBER:/^-?(?:[1-9][0-9]*|0|0[xX][0-9a-fA-F]+|0[0-7]+|([0-9]*(\.[0-9]*)?([Ee][+-]?[0-9]+)?)|inf|nan)$/,NUMBER_DEC:/^(?:[1-9][0-9]*|0)$/,NUMBER_HEX:/^0[xX][0-9a-fA-F]+$/,NUMBER_OCT:/^0[0-7]+$/,NUMBER_FLT:/^([0-9]*(\.[0-9]*)?([Ee][+-]?[0-9]+)?|inf|nan)$/,
BOOL:/^(?:true|false)$/i,ID:/^(?:[1-9][0-9]*|0|0[xX][0-9a-fA-F]+|0[0-7]+)$/,NEGID:/^\-?(?:[1-9][0-9]*|0|0[xX][0-9a-fA-F]+|0[0-7]+)$/,WHITESPACE:/\s/,STRING:/(?:"([^"\\]*(?:\\.[^"\\]*)*)")|(?:'([^'\\]*(?:\\.[^'\\]*)*)')/g,STRING_DQ:/(?:"([^"\\]*(?:\\.[^"\\]*)*)")/g,STRING_SQ:/(?:'([^'\\]*(?:\\.[^'\\]*)*)')/g};d.Reflect=function(b){function d(a,g){if(a&&"number"===typeof a.low&&"number"===typeof a.high&&"boolean"===typeof a.unsigned&&a.low===a.low&&a.high===a.high)return new b.Long(a.low,a.high,"undefined"===
typeof g?a.unsigned:g);if("string"===typeof a)return b.Long.fromString(a,g||!1,10);if("number"===typeof a)return b.Long.fromNumber(a,g||!1);throw Error("not convertible to Long");}function t(a,g){var n=g.readVarint32(),c=n&7,n=n>>>3;switch(c){case b.WIRE_TYPES.VARINT:do n=g.readUint8();while(128===(n&128));break;case b.WIRE_TYPES.BITS64:g.offset+=8;break;case b.WIRE_TYPES.LDELIM:n=g.readVarint32();g.offset+=n;break;case b.WIRE_TYPES.STARTGROUP:t(n,g);break;case b.WIRE_TYPES.ENDGROUP:if(n===a)return!1;
throw Error("Illegal GROUPEND after unknown group: "+n+" ("+a+" expected)");case b.WIRE_TYPES.BITS32:g.offset+=4;break;default:throw Error("Illegal wire type in unknown group "+a+": "+c);}return!0}var p={},k=function(a,g,b){this.builder=a;this.parent=g;this.name=b},f=k.prototype;f.fqn=function(){var a=this.name,g=this;do{g=g.parent;if(null==g)break;a=g.name+"."+a}while(1);return a};f.toString=function(a){return(a?this.className+" ":"")+this.fqn()};f.build=function(){throw Error(this.toString(!0)+
" cannot be built directly");};p.T=k;var c=function(a,g,b,c,r){k.call(this,a,g,b);this.className="Namespace";this.children=[];this.options=c||{};this.syntax=r||"proto2"},f=c.prototype=Object.create(k.prototype);f.getChildren=function(a){a=a||null;if(null==a)return this.children.slice();for(var g=[],b=0,c=this.children.length;b<c;++b)this.children[b]instanceof a&&g.push(this.children[b]);return g};f.addChild=function(a){var g;if(g=this.getChild(a.name))if(g instanceof m.Field&&g.name!==g.originalName&&
null===this.getChild(g.originalName))g.name=g.originalName;else if(a instanceof m.Field&&a.name!==a.originalName&&null===this.getChild(a.originalName))a.name=a.originalName;else throw Error("Duplicate name in namespace "+this.toString(!0)+": "+a.name);this.children.push(a)};f.getChild=function(a){for(var g="number"===typeof a?"id":"name",b=0,c=this.children.length;b<c;++b)if(this.children[b][g]===a)return this.children[b];return null};f.resolve=function(a,g){var b="string"===typeof a?a.split("."):
a,c=this,r=0;if(""===b[r]){for(;null!==c.parent;)c=c.parent;r++}do{do{if(!(c instanceof p.Namespace)){c=null;break}c=c.getChild(b[r]);if(!(c&&c instanceof p.T)||g&&!(c instanceof p.Namespace)){c=null;break}r++}while(r<b.length);if(null!=c)break;if(null!==this.parent)return this.parent.resolve(a,g)}while(null!=c);return c};f.qn=function(a){var g=[],b=a;do g.unshift(b.name),b=b.parent;while(null!==b);for(b=1;b<=g.length;b++){var c=g.slice(g.length-b);if(a===this.resolve(c,a instanceof p.Namespace))return c.join(".")}return a.fqn()};
f.build=function(){for(var a={},b=this.children,n=0,d=b.length,r;n<d;++n)r=b[n],r instanceof c&&(a[r.name]=r.build());Object.defineProperty&&Object.defineProperty(a,"$options",{value:this.buildOpt()});return a};f.buildOpt=function(){for(var a={},b=Object.keys(this.options),c=0,d=b.length;c<d;++c)a[b[c]]=this.options[b[c]];return a};f.getOption=function(a){return"undefined"===typeof a?this.options:"undefined"!==typeof this.options[a]?this.options[a]:null};p.Namespace=c;var l=function(a,g,c,d,r){this.type=
a;this.resolvedType=g;this.isMapKey=c;this.syntax=d;this.name=r;if(c&&0>b.MAP_KEY_TYPES.indexOf(a))throw Error("Invalid map key type: "+a.name);},e=l.prototype;l.defaultFieldValue=function(a){"string"===typeof a&&(a=b.TYPES[a]);if("undefined"===typeof a.defaultValue)throw Error("default value for type "+a.name+" is not supported");return a==b.TYPES.bytes?new h(0):a.defaultValue};e.toString=function(){return(this.name||"")+(this.isMapKey?"map":"value")+" element"};e.verifyValue=function(a){function g(a,
b){throw Error("Illegal value for "+c.toString(!0)+" of type "+c.type.name+": "+a+" ("+b+")");}var c=this;switch(this.type){case b.TYPES.int32:case b.TYPES.sint32:case b.TYPES.sfixed32:return("number"!==typeof a||a===a&&0!==a%1)&&g(typeof a,"not an integer"),4294967295<a?a|0:a;case b.TYPES.uint32:case b.TYPES.fixed32:return("number"!==typeof a||a===a&&0!==a%1)&&g(typeof a,"not an integer"),0>a?a>>>0:a;case b.TYPES.int64:case b.TYPES.sint64:case b.TYPES.sfixed64:if(b.Long)try{return d(a,!1)}catch(e){g(typeof a,
e.message)}else g(typeof a,"requires Long.js");case b.TYPES.uint64:case b.TYPES.fixed64:if(b.Long)try{return d(a,!0)}catch(r){g(typeof a,r.message)}else g(typeof a,"requires Long.js");case b.TYPES.bool:return"boolean"!==typeof a&&g(typeof a,"not a boolean"),a;case b.TYPES["float"]:case b.TYPES["double"]:return"number"!==typeof a&&g(typeof a,"not a number"),a;case b.TYPES.string:return"string"===typeof a||a&&a instanceof String||g(typeof a,"not a string"),""+a;case b.TYPES.bytes:return h.isByteBuffer(a)?
a:h.wrap(a,"base64");case b.TYPES["enum"]:for(var v=this.resolvedType.getChildren(b.Reflect.Enum.Value),f=0;f<v.length;f++)if(v[f].name==a||v[f].id==a)return v[f].id;if("proto3"===this.syntax)return("number"!==typeof a||a===a&&0!==a%1)&&g(typeof a,"not an integer"),(4294967295<a||0>a)&&g(typeof a,"not in range for uint32"),a;g(a,"not a valid enum value");case b.TYPES.group:case b.TYPES.message:a&&"object"===typeof a||g(typeof a,"object expected");if(a instanceof this.resolvedType.clazz)return a;if(a instanceof
b.Builder.Message){var v={},f;for(f in a)a.hasOwnProperty(f)&&(v[f]=a[f]);a=v}return new this.resolvedType.clazz(a)}throw Error("[INTERNAL] Illegal value for "+this.toString(!0)+": "+a+" (undefined type "+this.type+")");};e.calculateLength=function(a,g){if(null===g)return 0;var c;switch(this.type){case b.TYPES.int32:return 0>g?h.calculateVarint64(g):h.calculateVarint32(g);case b.TYPES.uint32:return h.calculateVarint32(g);case b.TYPES.sint32:return h.calculateVarint32(h.zigZagEncode32(g));case b.TYPES.fixed32:case b.TYPES.sfixed32:case b.TYPES["float"]:return 4;
case b.TYPES.int64:case b.TYPES.uint64:return h.calculateVarint64(g);case b.TYPES.sint64:return h.calculateVarint64(h.zigZagEncode64(g));case b.TYPES.fixed64:case b.TYPES.sfixed64:return 8;case b.TYPES.bool:return 1;case b.TYPES["enum"]:return h.calculateVarint32(g);case b.TYPES["double"]:return 8;case b.TYPES.string:return c=h.calculateUTF8Bytes(g),h.calculateVarint32(c)+c;case b.TYPES.bytes:if(0>g.remaining())throw Error("Illegal value for "+this.toString(!0)+": "+g.remaining()+" bytes remaining");
return h.calculateVarint32(g.remaining())+g.remaining();case b.TYPES.message:return c=this.resolvedType.calculate(g),h.calculateVarint32(c)+c;case b.TYPES.group:return c=this.resolvedType.calculate(g),c+h.calculateVarint32(a<<3|b.WIRE_TYPES.ENDGROUP)}throw Error("[INTERNAL] Illegal value to encode in "+this.toString(!0)+": "+g+" (unknown type)");};e.encodeValue=function(a,g,c){if(null===g)return c;switch(this.type){case b.TYPES.int32:0>g?c.writeVarint64(g):c.writeVarint32(g);break;case b.TYPES.uint32:c.writeVarint32(g);
break;case b.TYPES.sint32:c.writeVarint32ZigZag(g);break;case b.TYPES.fixed32:c.writeUint32(g);break;case b.TYPES.sfixed32:c.writeInt32(g);break;case b.TYPES.int64:case b.TYPES.uint64:c.writeVarint64(g);break;case b.TYPES.sint64:c.writeVarint64ZigZag(g);break;case b.TYPES.fixed64:c.writeUint64(g);break;case b.TYPES.sfixed64:c.writeInt64(g);break;case b.TYPES.bool:"string"===typeof g?c.writeVarint32("false"===g.toLowerCase()?0:!!g):c.writeVarint32(g?1:0);break;case b.TYPES["enum"]:c.writeVarint32(g);
break;case b.TYPES["float"]:c.writeFloat32(g);break;case b.TYPES["double"]:c.writeFloat64(g);break;case b.TYPES.string:c.writeVString(g);break;case b.TYPES.bytes:if(0>g.remaining())throw Error("Illegal value for "+this.toString(!0)+": "+g.remaining()+" bytes remaining");a=g.offset;c.writeVarint32(g.remaining());c.append(g);g.offset=a;break;case b.TYPES.message:a=(new h).LE();this.resolvedType.encode(g,a);c.writeVarint32(a.offset);c.append(a.flip());break;case b.TYPES.group:this.resolvedType.encode(g,
c);c.writeVarint32(a<<3|b.WIRE_TYPES.ENDGROUP);break;default:throw Error("[INTERNAL] Illegal value to encode in "+this.toString(!0)+": "+g+" (unknown type)");}return c};e.decode=function(a,g,c){if(g!=this.type.wireType)throw Error("Unexpected wire type for element");switch(this.type){case b.TYPES.int32:return a.readVarint32()|0;case b.TYPES.uint32:return a.readVarint32()>>>0;case b.TYPES.sint32:return a.readVarint32ZigZag()|0;case b.TYPES.fixed32:return a.readUint32()>>>0;case b.TYPES.sfixed32:return a.readInt32()|
0;case b.TYPES.int64:return a.readVarint64();case b.TYPES.uint64:return a.readVarint64().toUnsigned();case b.TYPES.sint64:return a.readVarint64ZigZag();case b.TYPES.fixed64:return a.readUint64();case b.TYPES.sfixed64:return a.readInt64();case b.TYPES.bool:return!!a.readVarint32();case b.TYPES["enum"]:return a.readVarint32();case b.TYPES["float"]:return a.readFloat();case b.TYPES["double"]:return a.readDouble();case b.TYPES.string:return a.readVString();case b.TYPES.bytes:c=a.readVarint32();if(a.remaining()<
c)throw Error("Illegal number of bytes for "+this.toString(!0)+": "+c+" required but got only "+a.remaining());g=a.clone();g.limit=g.offset+c;a.offset+=c;return g;case b.TYPES.message:return c=a.readVarint32(),this.resolvedType.decode(a,c);case b.TYPES.group:return this.resolvedType.decode(a,-1,c)}throw Error("[INTERNAL] Illegal decode type");};e.valueFromString=function(a){if(!this.isMapKey)throw Error("valueFromString() called on non-map-key element");switch(this.type){case b.TYPES.int32:case b.TYPES.sint32:case b.TYPES.sfixed32:case b.TYPES.uint32:case b.TYPES.fixed32:return this.verifyValue(parseInt(a));
case b.TYPES.int64:case b.TYPES.sint64:case b.TYPES.sfixed64:case b.TYPES.uint64:case b.TYPES.fixed64:return this.verifyValue(a);case b.TYPES.bool:return"true"===a;case b.TYPES.string:return this.verifyValue(a);case b.TYPES.bytes:return h.fromBinary(a)}};e.valueToString=function(a){if(!this.isMapKey)throw Error("valueToString() called on non-map-key element");return this.type===b.TYPES.bytes?a.toString("binary"):a.toString()};p.Element=l;var m=function(a,b,d,e,r,f){c.call(this,a,b,d,e,f);this.className=
"Message";this.extensions=void 0;this.clazz=null;this.isGroup=!!r;this._fieldsByName=this._fieldsById=this._fields=null},e=m.prototype=Object.create(c.prototype);e.build=function(a){if(this.clazz&&!a)return this.clazz;a=function(a,b){function g(b,c,d,e){if(null===b||"object"!==typeof b){if(e&&e instanceof a.Reflect.Enum){var n=a.Reflect.Enum.getName(e.object,b);if(null!==n)return n}return b}if(h.isByteBuffer(b))return c?b.toBase64():b.toBuffer();if(a.Long.isLong(b))return d?b.toString():a.Long.fromValue(b);
var f;if(Array.isArray(b))return f=[],b.forEach(function(a,b){f[b]=g(a,c,d,e)}),f;f={};if(b instanceof a.Map){for(var n=b.entries(),l=n.next();!l.done;l=n.next())f[b.keyElem.valueToString(l.value[0])]=g(l.value[1],c,d,b.valueElem.resolvedType);return f}var n=b.$type,l=void 0,m;for(m in b)b.hasOwnProperty(m)&&(n&&(l=n.getChild(m))?f[m]=g(b[m],c,d,l.resolvedType):f[m]=g(b[m],c,d));return f}var c=b.getChildren(a.Reflect.Message.Field),d=b.getChildren(a.Reflect.Message.OneOf),n=function(g,e){a.Builder.Message.call(this);
for(var f=0,l=d.length;f<l;++f)this[d[f].name]=null;f=0;for(l=c.length;f<l;++f){var m=c[f];this[m.name]=m.repeated?[]:m.map?new a.Map(m):null;!m.required&&"proto3"!==b.syntax||null===m.defaultValue||(this[m.name]=m.defaultValue)}if(0<arguments.length)if(1!==arguments.length||null===g||"object"!==typeof g||!("function"!==typeof g.encode||g instanceof n)||Array.isArray(g)||g instanceof a.Map||h.isByteBuffer(g)||g instanceof ArrayBuffer||a.Long&&g instanceof a.Long)for(f=0,l=arguments.length;f<l;++f)"undefined"!==
typeof(m=arguments[f])&&this.$set(c[f].name,m);else this.$set(g)},e=n.prototype=Object.create(a.Builder.Message.prototype);e.add=function(g,c,d){var e=b._fieldsByName[g];if(!d){if(!e)throw Error(this+"#"+g+" is undefined");if(!(e instanceof a.Reflect.Message.Field))throw Error(this+"#"+g+" is not a field: "+e.toString(!0));if(!e.repeated)throw Error(this+"#"+g+" is not a repeated field");c=e.verifyValue(c,!0)}null===this[g]&&(this[g]=[]);this[g].push(c);return this};e.$add=e.add;e.set=function(g,
c,e){if(g&&"object"===typeof g){e=c;for(var d in g)g.hasOwnProperty(d)&&"undefined"!==typeof(c=g[d])&&void 0===b._oneofsByName[d]&&this.$set(d,c,e);return this}d=b._fieldsByName[g];if(e)this[g]=c;else{if(!d)throw Error(this+"#"+g+" is not a field: undefined");if(!(d instanceof a.Reflect.Message.Field))throw Error(this+"#"+g+" is not a field: "+d.toString(!0));this[d.name]=c=d.verifyValue(c)}d&&d.oneof&&(e=this[d.oneof.name],null!==c?(null!==e&&e!==d.name&&(this[e]=null),this[d.oneof.name]=d.name):
e===g&&(this[d.oneof.name]=null));return this};e.$set=e.set;e.get=function(g,c){if(c)return this[g];var d=b._fieldsByName[g];if(!(d&&d instanceof a.Reflect.Message.Field))throw Error(this+"#"+g+" is not a field: undefined");if(!(d instanceof a.Reflect.Message.Field))throw Error(this+"#"+g+" is not a field: "+d.toString(!0));return this[d.name]};e.$get=e.get;for(var f=0;f<c.length;f++){var l=c[f];l instanceof a.Reflect.Message.ExtensionField||b.builder.options.populateAccessors&&function(a){var g=
a.originalName.replace(/(_[a-zA-Z])/g,function(a){return a.toUpperCase().replace("_","")}),g=g.substring(0,1).toUpperCase()+g.substring(1),c=a.originalName.replace(/([A-Z])/g,function(a){return"_"+a}),d=function(b,g){this[a.name]=g?b:a.verifyValue(b);return this},n=function(){return this[a.name]};null===b.getChild("set"+g)&&(e["set"+g]=d);null===b.getChild("set_"+c)&&(e["set_"+c]=d);null===b.getChild("get"+g)&&(e["get"+g]=n);null===b.getChild("get_"+c)&&(e["get_"+c]=n)}(l)}e.encode=function(a,g){"boolean"===
typeof a&&(g=a,a=void 0);var c=!1;a||(a=new h,c=!0);var d=a.littleEndian;try{return b.encode(this,a.LE(),g),(c?a.flip():a).LE(d)}catch(e){throw a.LE(d),e;}};n.encode=function(a,b,g){return(new n(a)).encode(b,g)};e.calculate=function(){return b.calculate(this)};e.encodeDelimited=function(a,g){var c=!1;a||(a=new h,c=!0);var d=(new h).LE();b.encode(this,d,g).flip();a.writeVarint32(d.remaining());a.append(d);return c?a.flip():a};e.encodeAB=function(){try{return this.encode().toArrayBuffer()}catch(a){throw a.encoded&&
(a.encoded=a.encoded.toArrayBuffer()),a;}};e.toArrayBuffer=e.encodeAB;e.encodeNB=function(){try{return this.encode().toBuffer()}catch(a){throw a.encoded&&(a.encoded=a.encoded.toBuffer()),a;}};e.toBuffer=e.encodeNB;e.encode64=function(){try{return this.encode().toBase64()}catch(a){throw a.encoded&&(a.encoded=a.encoded.toBase64()),a;}};e.toBase64=e.encode64;e.encodeHex=function(){try{return this.encode().toHex()}catch(a){throw a.encoded&&(a.encoded=a.encoded.toHex()),a;}};e.toHex=e.encodeHex;e.toRaw=
function(a,b){return g(this,!!a,!!b,this.$type)};e.encodeJSON=function(){return JSON.stringify(g(this,!0,!0,this.$type))};n.decode=function(a,g,c){"string"===typeof g&&(c=g,g=-1);"string"===typeof a?a=h.wrap(a,c?c:"base64"):h.isByteBuffer(a)||(a=h.wrap(a));c=a.littleEndian;try{var d=b.decode(a.LE(),g);a.LE(c);return d}catch(e){throw a.LE(c),e;}};n.decodeDelimited=function(a,g){"string"===typeof a?a=h.wrap(a,g?g:"base64"):h.isByteBuffer(a)||(a=h.wrap(a));if(1>a.remaining())return null;var c=a.offset,
d=a.readVarint32();if(a.remaining()<d)return a.offset=c,null;try{var e=b.decode(a.slice(a.offset,a.offset+d).LE());a.offset+=d;return e}catch(n){throw a.offset+=d,n;}};n.decode64=function(a){return n.decode(a,"base64")};n.decodeHex=function(a){return n.decode(a,"hex")};n.decodeJSON=function(a){return new n(JSON.parse(a))};e.toString=function(){return b.toString()};Object.defineProperty&&(Object.defineProperty(n,"$options",{value:b.buildOpt()}),Object.defineProperty(e,"$options",{value:n.$options}),
Object.defineProperty(n,"$type",{value:b}),Object.defineProperty(e,"$type",{value:b}));return n}(b,this);this._fields=[];this._fieldsById={};this._fieldsByName={};this._oneofsByName={};for(var g=0,c=this.children.length,d;g<c;g++)if(d=this.children[g],d instanceof x||d instanceof m||d instanceof A){if(a.hasOwnProperty(d.name))throw Error("Illegal reflect child of "+this.toString(!0)+": "+d.toString(!0)+" cannot override static property '"+d.name+"'");a[d.name]=d.build()}else if(d instanceof m.Field)d.build(),
this._fields.push(d),this._fieldsById[d.id]=d,this._fieldsByName[d.name]=d;else if(d instanceof m.OneOf)this._oneofsByName[d.name]=d;else if(!(d instanceof m.OneOf||d instanceof w))throw Error("Illegal reflect child of "+this.toString(!0)+": "+this.children[g].toString(!0));return this.clazz=a};e.encode=function(a,b,c){for(var d=null,e,f=0,l=this._fields.length,m;f<l;++f)e=this._fields[f],m=a[e.name],e.required&&null===m?null===d&&(d=e):e.encode(c?m:e.verifyValue(m),b,a);if(null!==d)throw a=Error("Missing at least one required field for "+
this.toString(!0)+": "+d),a.encoded=b,a;return b};e.calculate=function(a){for(var b=0,c=0,d=this._fields.length,e,f;c<d;++c){e=this._fields[c];f=a[e.name];if(e.required&&null===f)throw Error("Missing at least one required field for "+this.toString(!0)+": "+e);b+=e.calculate(f,a)}return b};e.decode=function(a,g,c){"number"!==typeof g&&(g=-1);for(var d=a.offset,e=new this.clazz,f,l,m;a.offset<d+g||-1===g&&0<a.remaining();){f=a.readVarint32();l=f&7;m=f>>>3;if(l===b.WIRE_TYPES.ENDGROUP){if(m!==c)throw Error("Illegal group end indicator for "+
this.toString(!0)+": "+m+" ("+(c?c+" expected":"not a group")+")");break}if(f=this._fieldsById[m])f.repeated&&!f.options.packed?e[f.name].push(f.decode(l,a)):f.map?(l=f.decode(l,a),e[f.name].set(l[0],l[1])):(e[f.name]=f.decode(l,a),f.oneof&&(l=e[f.oneof.name],null!==l&&l!==f.name&&(e[l]=null),e[f.oneof.name]=f.name));else switch(l){case b.WIRE_TYPES.VARINT:a.readVarint32();break;case b.WIRE_TYPES.BITS32:a.offset+=4;break;case b.WIRE_TYPES.BITS64:a.offset+=8;break;case b.WIRE_TYPES.LDELIM:f=a.readVarint32();
a.offset+=f;break;case b.WIRE_TYPES.STARTGROUP:for(;t(m,a););break;default:throw Error("Illegal wire type for unknown field "+m+" in "+this.toString(!0)+"#decode: "+l);}}a=0;for(g=this._fields.length;a<g;++a)if(f=this._fields[a],null===e[f.name])if("proto3"===this.syntax)e[f.name]=f.defaultValue;else{if(f.required)throw a=Error("Missing at least one required field for "+this.toString(!0)+": "+f.name),a.decoded=e,a;b.populateDefaults&&null!==f.defaultValue&&(e[f.name]=f.defaultValue)}return e};p.Message=
m;var z=function(a,g,c,d,e,f,l,h,w,q){k.call(this,a,g,f);this.className="Message.Field";this.required="required"===c;this.repeated="repeated"===c;this.map="map"===c;this.keyType=d||null;this.type=e;this.resolvedType=null;this.id=l;this.options=h||{};this.defaultValue=null;this.oneof=w||null;this.syntax=q||"proto2";this.originalName=this.name;this.keyElement=this.element=null;!this.builder.options.convertFieldsToCamelCase||this instanceof m.ExtensionField||(this.name=b.Util.toCamelCase(this.name))},
e=z.prototype=Object.create(k.prototype);e.build=function(){this.element=new l(this.type,this.resolvedType,!1,this.syntax,this.name);this.map&&(this.keyElement=new l(this.keyType,void 0,!0,this.syntax,this.name));"proto3"!==this.syntax||this.repeated||this.map?"undefined"!==typeof this.options["default"]&&(this.defaultValue=this.verifyValue(this.options["default"])):this.defaultValue=l.defaultFieldValue(this.type)};e.verifyValue=function(a,g){function c(a,b){throw Error("Illegal value for "+d.toString(!0)+
" of type "+d.type.name+": "+a+" ("+b+")");}g=g||!1;var d=this;if(null===a)return this.required&&c(typeof a,"required"),"proto3"===this.syntax&&this.type!==b.TYPES.message&&c(typeof a,"proto3 field without field presence cannot be null"),null;var e;if(this.repeated&&!g){Array.isArray(a)||(a=[a]);var f=[];for(e=0;e<a.length;e++)f.push(this.element.verifyValue(a[e]));return f}if(this.map&&!g){if(a instanceof b.Map)return a;a instanceof Object||c(typeof a,"expected ProtoBuf.Map or raw object for map field");
return new b.Map(this,a)}!this.repeated&&Array.isArray(a)&&c(typeof a,"no array expected");return this.element.verifyValue(a)};e.hasWirePresence=function(a,c){if("proto3"!==this.syntax)return null!==a;if(this.oneof&&c[this.oneof.name]===this.name)return!0;switch(this.type){case b.TYPES.int32:case b.TYPES.sint32:case b.TYPES.sfixed32:case b.TYPES.uint32:case b.TYPES.fixed32:return 0!==a;case b.TYPES.int64:case b.TYPES.sint64:case b.TYPES.sfixed64:case b.TYPES.uint64:case b.TYPES.fixed64:return 0!==
a.low||0!==a.high;case b.TYPES.bool:return a;case b.TYPES["float"]:case b.TYPES["double"]:return 0!==a;case b.TYPES.string:return 0<a.length;case b.TYPES.bytes:return 0<a.remaining();case b.TYPES["enum"]:return 0!==a;case b.TYPES.message:return null!==a;default:return!0}};e.encode=function(a,c,d){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 c;try{if(this.repeated){var e;
if(this.options.packed&&0<=b.PACKABLE_WIRE_TYPES.indexOf(this.type.wireType)){c.writeVarint32(this.id<<3|b.WIRE_TYPES.LDELIM);c.ensureCapacity(c.offset+=1);var f=c.offset;for(e=0;e<a.length;e++)this.element.encodeValue(this.id,a[e],c);var l=c.offset-f,m=h.calculateVarint32(l);if(1<m){var w=c.slice(f,c.offset),f=f+(m-1);c.offset=f;c.append(w)}c.writeVarint32(l,f-m)}else for(e=0;e<a.length;e++)c.writeVarint32(this.id<<3|this.type.wireType),this.element.encodeValue(this.id,a[e],c)}else this.map?a.forEach(function(a,
d,e){e=h.calculateVarint32(8|this.keyType.wireType)+this.keyElement.calculateLength(1,d)+h.calculateVarint32(16|this.type.wireType)+this.element.calculateLength(2,a);c.writeVarint32(this.id<<3|b.WIRE_TYPES.LDELIM);c.writeVarint32(e);c.writeVarint32(8|this.keyType.wireType);this.keyElement.encodeValue(1,d,c);c.writeVarint32(16|this.type.wireType);this.element.encodeValue(2,a,c)},this):this.hasWirePresence(a,d)&&(c.writeVarint32(this.id<<3|this.type.wireType),this.element.encodeValue(this.id,a,c))}catch(k){throw Error("Illegal value for "+
this.toString(!0)+": "+a+" ("+k+")");}return c};e.calculate=function(a,c){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 d=0;try{if(this.repeated){var e,f;if(this.options.packed&&0<=b.PACKABLE_WIRE_TYPES.indexOf(this.type.wireType)){d+=h.calculateVarint32(this.id<<3|b.WIRE_TYPES.LDELIM);for(e=f=0;e<a.length;e++)f+=this.element.calculateLength(this.id,
a[e]);d+=h.calculateVarint32(f);d+=f}else for(e=0;e<a.length;e++)d+=h.calculateVarint32(this.id<<3|this.type.wireType),d+=this.element.calculateLength(this.id,a[e])}else this.map?a.forEach(function(a,c,g){a=h.calculateVarint32(8|this.keyType.wireType)+this.keyElement.calculateLength(1,c)+h.calculateVarint32(16|this.type.wireType)+this.element.calculateLength(2,a);d+=h.calculateVarint32(this.id<<3|b.WIRE_TYPES.LDELIM);d+=h.calculateVarint32(a);d+=a},this):this.hasWirePresence(a,c)&&(d+=h.calculateVarint32(this.id<<
3|this.type.wireType),d+=this.element.calculateLength(this.id,a))}catch(l){throw Error("Illegal value for "+this.toString(!0)+": "+a+" ("+l+")");}return d};e.decode=function(a,c,d){if(!(!this.map&&a==this.type.wireType||!d&&this.repeated&&this.options.packed&&a==b.WIRE_TYPES.LDELIM||this.map&&a==b.WIRE_TYPES.LDELIM))throw Error("Illegal wire type for field "+this.toString(!0)+": "+a+" ("+this.type.wireType+" expected)");if(a==b.WIRE_TYPES.LDELIM&&this.repeated&&this.options.packed&&0<=b.PACKABLE_WIRE_TYPES.indexOf(this.type.wireType)&&
!d){a=c.readVarint32();a=c.offset+a;for(d=[];c.offset<a;)d.push(this.decode(this.type.wireType,c,!0));return d}if(this.map){var e=l.defaultFieldValue(this.keyType);d=l.defaultFieldValue(this.type);a=c.readVarint32();if(c.remaining()<a)throw Error("Illegal number of bytes for "+this.toString(!0)+": "+a+" required but got only "+c.remaining());var f=c.clone();f.limit=f.offset+a;for(c.offset+=a;0<f.remaining();)if(c=f.readVarint32(),a=c&7,c>>>=3,1===c)e=this.keyElement.decode(f,a,c);else if(2===c)d=
this.element.decode(f,a,c);else throw Error("Unexpected tag in map field key/value submessage");return[e,d]}return this.element.decode(c,a,this.id)};p.Message.Field=z;e=function(a,c,b,d,e,f,l){z.call(this,a,c,b,null,d,e,f,l)};e.prototype=Object.create(z.prototype);p.Message.ExtensionField=e;p.Message.OneOf=function(a,c,b){k.call(this,a,c,b);this.fields=[]};var x=function(a,b,d,e,f){c.call(this,a,b,d,e,f);this.className="Enum";this.object=null};x.getName=function(a,c){for(var b=Object.keys(a),d=0,
e;d<b.length;++d)if(a[e=b[d]]===c)return e;return null};(x.prototype=Object.create(c.prototype)).build=function(a){if(this.object&&!a)return this.object;a=new b.Builder.Enum;for(var c=this.getChildren(x.Value),d=0,e=c.length;d<e;++d)a[c[d].name]=c[d].id;Object.defineProperty&&Object.defineProperty(a,"$options",{value:this.buildOpt(),enumerable:!1});return this.object=a};p.Enum=x;e=function(a,c,b,d){k.call(this,a,c,b);this.className="Enum.Value";this.id=d};e.prototype=Object.create(k.prototype);p.Enum.Value=
e;var w=function(a,c,b,d){k.call(this,a,c,b);this.field=d};w.prototype=Object.create(k.prototype);p.Extension=w;var A=function(a,b,d,e){c.call(this,a,b,d,e);this.className="Service";this.clazz=null};(A.prototype=Object.create(c.prototype)).build=function(a){return this.clazz&&!a?this.clazz:this.clazz=function(a,c){for(var b=function(c){a.Builder.Service.call(this);this.rpcImpl=c||function(a,c,b){setTimeout(b.bind(this,Error("Not implemented, see: https://github.com/dcodeIO/ProtoBuf.js/wiki/Services")),
0)}},d=b.prototype=Object.create(a.Builder.Service.prototype),e=c.getChildren(a.Reflect.Service.RPCMethod),f=0;f<e.length;f++)(function(a){d[a.name]=function(b,d){try{try{b=a.resolvedRequestType.clazz.decode(h.wrap(b))}catch(e){if(!(e instanceof TypeError))throw e;}if(null===b||"object"!==typeof b)throw Error("Illegal arguments");b instanceof a.resolvedRequestType.clazz||(b=new a.resolvedRequestType.clazz(b));this.rpcImpl(a.fqn(),b,function(b,e){if(b)d(b);else{null===e&&(e="");try{e=a.resolvedResponseType.clazz.decode(e)}catch(g){}e&&
e instanceof a.resolvedResponseType.clazz?d(null,e):d(Error("Illegal response type received in service method "+c.name+"#"+a.name))}})}catch(g){setTimeout(d.bind(this,g),0)}};b[a.name]=function(c,d,e){(new b(c))[a.name](d,e)};Object.defineProperty&&(Object.defineProperty(b[a.name],"$options",{value:a.buildOpt()}),Object.defineProperty(d[a.name],"$options",{value:b[a.name].$options}))})(e[f]);Object.defineProperty&&(Object.defineProperty(b,"$options",{value:c.buildOpt()}),Object.defineProperty(d,"$options",
{value:b.$options}),Object.defineProperty(b,"$type",{value:c}),Object.defineProperty(d,"$type",{value:c}));return b}(b,this)};p.Service=A;var u=function(a,c,b,d){k.call(this,a,c,b);this.className="Service.Method";this.options=d||{}};(u.prototype=Object.create(k.prototype)).buildOpt=f.buildOpt;p.Service.Method=u;f=function(a,c,b,d,e,f,l,m){u.call(this,a,c,b,m);this.className="Service.RPCMethod";this.requestName=d;this.responseName=e;this.requestStream=f;this.responseStream=l;this.resolvedResponseType=
this.resolvedRequestType=null};f.prototype=Object.create(u.prototype);p.Service.RPCMethod=f;return p}(d);d.Builder=function(b,d,h){function p(c){c.messages&&c.messages.forEach(function(b){b.syntax=c.syntax;p(b)});c.enums&&c.enums.forEach(function(b){b.syntax=c.syntax})}var k=function(c){this.ptr=this.ns=new h.Namespace(this,null,"");this.resolved=!1;this.result=null;this.files={};this.importRoot=null;this.options=c||{}},f=k.prototype;k.isMessage=function(c){return"string"!==typeof c.name||"undefined"!==
typeof c.values||"undefined"!==typeof c.rpc?!1:!0};k.isMessageField=function(c){return"string"!==typeof c.rule||"string"!==typeof c.name||"string"!==typeof c.type||"undefined"===typeof c.id?!1:!0};k.isEnum=function(c){return"string"===typeof c.name&&"undefined"!==typeof c.values&&Array.isArray(c.values)&&0!==c.values.length?!0:!1};k.isService=function(c){return"string"===typeof c.name&&"object"===typeof c.rpc&&c.rpc?!0:!1};k.isExtend=function(c){return"string"!==typeof c.ref?!1:!0};f.reset=function(){this.ptr=
this.ns;return this};f.define=function(c){if("string"!==typeof c||!d.TYPEREF.test(c))throw Error("illegal namespace: "+c);c.split(".").forEach(function(c){var b=this.ptr.getChild(c);null===b&&this.ptr.addChild(b=new h.Namespace(this,this.ptr,c));this.ptr=b},this);return this};f.create=function(c){if(!c)return this;if(Array.isArray(c)){if(0===c.length)return this;c=c.slice()}else c=[c];for(var d=[c];0<d.length;){c=d.pop();if(!Array.isArray(c))throw Error("not a valid namespace: "+JSON.stringify(c));
for(;0<c.length;){var e=c.shift();if(k.isMessage(e)){var f=new h.Message(this,this.ptr,e.name,e.options,e.isGroup,e.syntax),p={};e.oneofs&&Object.keys(e.oneofs).forEach(function(c){f.addChild(p[c]=new h.Message.OneOf(this,f,c))},this);e.fields&&e.fields.forEach(function(c){if(null!==f.getChild(c.id|0))throw Error("duplicate or invalid field id in "+f.name+": "+c.id);if(c.options&&"object"!==typeof c.options)throw Error("illegal field options in "+f.name+"#"+c.name);var b=null;if("string"===typeof c.oneof&&
!(b=p[c.oneof]))throw Error("illegal oneof in "+f.name+"#"+c.name+": "+c.oneof);c=new h.Message.Field(this,f,c.rule,c.keytype,c.type,c.name,c.id,c.options,b,e.syntax);b&&b.fields.push(c);f.addChild(c)},this);var q=[];e.enums&&e.enums.forEach(function(c){q.push(c)});e.messages&&e.messages.forEach(function(c){q.push(c)});e.services&&e.services.forEach(function(c){q.push(c)});e.extensions&&(f.extensions="number"===typeof e.extensions[0]?[e.extensions]:e.extensions);this.ptr.addChild(f);if(0<q.length){d.push(c);
c=q;q=null;this.ptr=f;f=null;continue}q=null}else if(k.isEnum(e))f=new h.Enum(this,this.ptr,e.name,e.options,e.syntax),e.values.forEach(function(c){f.addChild(new h.Enum.Value(this,f,c.name,c.id))},this),this.ptr.addChild(f);else if(k.isService(e))f=new h.Service(this,this.ptr,e.name,e.options),Object.keys(e.rpc).forEach(function(c){var b=e.rpc[c];f.addChild(new h.Service.RPCMethod(this,f,c,b.request,b.response,!!b.request_stream,!!b.response_stream,b.options))},this),this.ptr.addChild(f);else if(k.isExtend(e))if(f=
this.ptr.resolve(e.ref,!0))e.fields.forEach(function(c){if(null!==f.getChild(c.id|0))throw Error("duplicate extended field id in "+f.name+": "+c.id);if(f.extensions){var d=!1;f.extensions.forEach(function(a){c.id>=a[0]&&c.id<=a[1]&&(d=!0)});if(!d)throw Error("illegal extended field id in "+f.name+": "+c.id+" (not within valid ranges)");}var e=c.name;this.options.convertFieldsToCamelCase&&(e=b.Util.toCamelCase(e));var e=new h.Message.ExtensionField(this,f,c.rule,c.type,this.ptr.fqn()+"."+e,c.id,c.options),
a=new h.Extension(this,this.ptr,c.name,e);e.extension=a;this.ptr.addChild(a);f.addChild(e)},this);else{if(!/\.?google\.protobuf\./.test(e.ref))throw Error("extended message "+e.ref+" is not defined");}else throw Error("not a valid definition: "+JSON.stringify(e));f=e=null}c=null;this.ptr=this.ptr.parent}this.resolved=!1;this.result=null;return this};f["import"]=function(c,d){var e="/";if("string"===typeof d){b.Util.IS_NODE&&(d=require("path").resolve(d));if(!0===this.files[d])return this.reset();
this.files[d]=!0}else if("object"===typeof d){var f=d.root;b.Util.IS_NODE&&(f=require("path").resolve(f));if(0<=f.indexOf("\\")||0<=d.file.indexOf("\\"))e="\\";f=b.Util.IS_NODE?require("path").join(f,d.file):f+e+d.file;if(!0===this.files[f])return this.reset();this.files[f]=!0}if(c.imports&&0<c.imports.length){var h=!1;if("object"===typeof d){if(this.importRoot=d.root,h=!0,f=this.importRoot,d=d.file,0<=f.indexOf("\\")||0<=d.indexOf("\\"))e="\\"}else"string"===typeof d?this.importRoot?f=this.importRoot:
0<=d.indexOf("/")?(f=d.replace(/\/[^\/]*$/,""),""===f&&(f="/")):0<=d.indexOf("\\")?(f=d.replace(/\\[^\\]*$/,""),e="\\"):f=".":f=null;for(var k=0;k<c.imports.length;k++)if("string"===typeof c.imports[k]){if(!f)throw Error("cannot determine import root");var q=c.imports[k];if("google/protobuf/descriptor.proto"!==q&&(q=b.Util.IS_NODE?require("path").join(f,q):f+e+q,!0!==this.files[q])){/\.proto$/i.test(q)&&!b.DotProto&&(q=q.replace(/\.proto$/,".json"));var t=b.Util.fetch(q);if(null===t)throw Error("failed to import '"+
q+"' in '"+d+"': file not found");if(/\.json$/i.test(q))this["import"](JSON.parse(t+""),q);else this["import"](b.DotProto.Parser.parse(t),q)}}else if(d)if(/\.(\w+)$/.test(d))this["import"](c.imports[k],d.replace(/^(.+)\.(\w+)$/,function(a,c,b){return c+"_import"+k+"."+b}));else this["import"](c.imports[k],d+"_import"+k);else this["import"](c.imports[k]);h&&(this.importRoot=null)}c["package"]&&this.define(c["package"]);c.syntax&&p(c);var u=this.ptr;c.options&&Object.keys(c.options).forEach(function(a){u.options[a]=
c.options[a]});c.messages&&(this.create(c.messages),this.ptr=u);c.enums&&(this.create(c.enums),this.ptr=u);c.services&&(this.create(c.services),this.ptr=u);c["extends"]&&this.create(c["extends"]);return this.reset()};f.resolveAll=function(){var c;if(null==this.ptr||"object"===typeof this.ptr.type)return this;if(this.ptr instanceof h.Namespace)this.ptr.children.forEach(function(c){this.ptr=c;this.resolveAll()},this);else if(this.ptr instanceof h.Message.Field){if(d.TYPE.test(this.ptr.type))this.ptr.type=
b.TYPES[this.ptr.type];else{if(!d.TYPEREF.test(this.ptr.type))throw Error("illegal type reference in "+this.ptr.toString(!0)+": "+this.ptr.type);c=(this.ptr instanceof h.Message.ExtensionField?this.ptr.extension.parent:this.ptr.parent).resolve(this.ptr.type,!0);if(!c)throw Error("unresolvable type reference in "+this.ptr.toString(!0)+": "+this.ptr.type);this.ptr.resolvedType=c;if(c instanceof h.Enum){if(this.ptr.type=b.TYPES["enum"],"proto3"===this.ptr.syntax&&"proto3"!==c.syntax)throw Error("proto3 message cannot reference proto2 enum");
}else if(c instanceof h.Message)this.ptr.type=c.isGroup?b.TYPES.group:b.TYPES.message;else throw Error("illegal type reference in "+this.ptr.toString(!0)+": "+this.ptr.type);}if(this.ptr.map){if(!d.TYPE.test(this.ptr.keyType))throw Error("illegal key type for map field in "+this.ptr.toString(!0)+": "+this.ptr.keyType);this.ptr.keyType=b.TYPES[this.ptr.keyType]}"proto3"===this.ptr.syntax&&this.ptr.repeated&&void 0===this.ptr.options.packed&&-1!==b.PACKABLE_WIRE_TYPES.indexOf(this.ptr.type.wireType)&&
(this.ptr.options.packed=!0)}else if(this.ptr instanceof b.Reflect.Service.Method)if(this.ptr instanceof b.Reflect.Service.RPCMethod){c=this.ptr.parent.resolve(this.ptr.requestName,!0);if(!(c&&c instanceof b.Reflect.Message))throw Error("Illegal type reference in "+this.ptr.toString(!0)+": "+this.ptr.requestName);this.ptr.resolvedRequestType=c;c=this.ptr.parent.resolve(this.ptr.responseName,!0);if(!(c&&c instanceof b.Reflect.Message))throw Error("Illegal type reference in "+this.ptr.toString(!0)+
": "+this.ptr.responseName);this.ptr.resolvedResponseType=c}else throw Error("illegal service type in "+this.ptr.toString(!0));else if(!(this.ptr instanceof b.Reflect.Message.OneOf||this.ptr instanceof b.Reflect.Extension||this.ptr instanceof b.Reflect.Enum.Value))throw Error("illegal object in namespace: "+typeof this.ptr+": "+this.ptr);return this.reset()};f.build=function(c){this.reset();this.resolved||(this.resolveAll(),this.resolved=!0,this.result=null);null===this.result&&(this.result=this.ns.build());
if(!c)return this.result;c="string"===typeof c?c.split("."):c;for(var b=this.result,d=0;d<c.length;d++)if(b[c[d]])b=b[c[d]];else{b=null;break}return b};f.lookup=function(c,b){return c?this.ns.resolve(c,b):this.ns};f.toString=function(){return"Builder"};k.Message=function(){};k.Enum=function(){};k.Service=function(){};return k}(d,d.Lang,d.Reflect);d.Map=function(b,d){function h(b){var c=0;return{next:function(){return c<b.length?{done:!1,value:b[c++]}:{done:!0}}}}var p=function(b,c){if(!b.map)throw Error("field is not a map");
this.field=b;this.keyElem=new d.Element(b.keyType,null,!0,b.syntax);this.valueElem=new d.Element(b.type,b.resolvedType,!1,b.syntax);this.map={};Object.defineProperty(this,"size",{get:function(){return Object.keys(this.map).length}});if(c)for(var h=Object.keys(c),e=0;e<h.length;e++){var k=this.keyElem.valueFromString(h[e]),p=this.valueElem.verifyValue(c[h[e]]);this.map[this.keyElem.valueToString(k)]={key:k,value:p}}},k=p.prototype;k.clear=function(){this.map={}};k["delete"]=function(b){b=this.keyElem.valueToString(this.keyElem.verifyValue(b));
var c=b in this.map;delete this.map[b];return c};k.entries=function(){for(var b=[],c=Object.keys(this.map),d=0,e;d<c.length;d++)b.push([(e=this.map[c[d]]).key,e.value]);return h(b)};k.keys=function(){for(var b=[],c=Object.keys(this.map),d=0;d<c.length;d++)b.push(this.map[c[d]].key);return h(b)};k.values=function(){for(var b=[],c=Object.keys(this.map),d=0;d<c.length;d++)b.push(this.map[c[d]].value);return h(b)};k.forEach=function(b,c){for(var d=Object.keys(this.map),e=0,h;e<d.length;e++)b.call(c,(h=
this.map[d[e]]).value,h.key,this)};k.set=function(b,c){var d=this.keyElem.verifyValue(b),e=this.valueElem.verifyValue(c);this.map[this.keyElem.valueToString(d)]={key:d,value:e};return this};k.get=function(b){b=this.keyElem.valueToString(this.keyElem.verifyValue(b));return b in this.map?this.map[b].value:void 0};k.has=function(b){return this.keyElem.valueToString(this.keyElem.verifyValue(b))in this.map};return p}(d,d.Reflect);d.newBuilder=function(b){b=b||{};"undefined"===typeof b.convertFieldsToCamelCase&&
(b.convertFieldsToCamelCase=d.convertFieldsToCamelCase);"undefined"===typeof b.populateAccessors&&(b.populateAccessors=d.populateAccessors);return new d.Builder(b)};d.loadJson=function(b,h,t){if("string"===typeof h||h&&"string"===typeof h.file&&"string"===typeof h.root)t=h,h=null;h&&"object"===typeof h||(h=d.newBuilder());"string"===typeof b&&(b=JSON.parse(b));h["import"](b,t);h.resolveAll();return h};d.loadJsonFile=function(b,h,t){h&&"object"===typeof h?(t=h,h=null):h&&"function"===typeof h||(h=
null);if(h)return d.Util.fetch("string"===typeof b?b:b.root+"/"+b.file,function(k){if(null===k)h(Error("Failed to fetch file"));else try{h(null,d.loadJson(JSON.parse(k),t,b))}catch(f){h(f)}});var p=d.Util.fetch("object"===typeof b?b.root+"/"+b.file:b);return null===p?null:d.loadJson(JSON.parse(p),t,b)};return d});