forked from protobufjs/protobuf.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProtoBuf.noparse.min.js
64 lines (64 loc) · 29.5 KB
/
ProtoBuf.noparse.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
/*
ProtoBuf.js (c) 2013 Daniel Wirtz <[email protected]>
Released under the Apache License, Version 2.0
see: https://github.com/dcodeIO/ProtoBuf.js for details
*/
(function(q){function r(p){var k={VERSION:"2.0.1",WIRE_TYPES:{}};k.WIRE_TYPES.VARINT=0;k.WIRE_TYPES.BITS64=1;k.WIRE_TYPES.LDELIM=2;k.WIRE_TYPES.STARTGROUP=3;k.WIRE_TYPES.ENDGROUP=4;k.WIRE_TYPES.BITS32=5;k.TYPES={int32:{name:"int32",wireType:k.WIRE_TYPES.VARINT},uint32:{name:"uint32",wireType:k.WIRE_TYPES.VARINT},sint32:{name:"sint32",wireType:k.WIRE_TYPES.VARINT},int64:{name:"int64",wireType:k.WIRE_TYPES.VARINT},uint64:{name:"uint64",wireType:k.WIRE_TYPES.VARINT},sint64:{name:"sint64",wireType:k.WIRE_TYPES.VARINT},
bool:{name:"bool",wireType:k.WIRE_TYPES.VARINT},"double":{name:"double",wireType:k.WIRE_TYPES.BITS64},string:{name:"string",wireType:k.WIRE_TYPES.LDELIM},bytes:{name:"bytes",wireType:k.WIRE_TYPES.LDELIM},fixed32:{name:"fixed32",wireType:k.WIRE_TYPES.BITS32},sfixed32:{name:"sfixed32",wireType:k.WIRE_TYPES.BITS32},fixed64:{name:"fixed64",wireType:k.WIRE_TYPES.BITS64},sfixed64:{name:"sfixed64",wireType:k.WIRE_TYPES.BITS64},"float":{name:"float",wireType:k.WIRE_TYPES.BITS32},"enum":{name:"enum",wireType:k.WIRE_TYPES.VARINT},
message:{name:"message",wireType:k.WIRE_TYPES.LDELIM}};k.Long=p.Long;k.convertFieldsToCamelCase=!1;k.Util=function(){Object.create||(Object.create=function(c){function m(){}if(1<arguments.length)throw Error("Object.create implementation only accepts the first parameter.");m.prototype=c;return new m});var c={};c.IS_NODE=("undefined"==typeof window||!window.window)&&"function"==typeof require&&"undefined"!==typeof process&&"function"===typeof process.nextTick;c.XHR=function(){for(var c=[function(){return new XMLHttpRequest},
function(){return new ActiveXObject("Msxml2.XMLHTTP")},function(){return new ActiveXObject("Msxml3.XMLHTTP")},function(){return new ActiveXObject("Microsoft.XMLHTTP")}],m=null,l=0;l<c.length;l++){try{m=c[l]()}catch(a){continue}break}if(!m)throw Error("XMLHttpRequest is not supported");return m};c.fetch=function(h,m){m&&"function"!=typeof m&&(m=null);if(c.IS_NODE)if(m)require("fs").readFile(h,function(a,c){a?m(null):m(""+c)});else try{return require("fs").readFileSync(h)}catch(l){return null}else{var a=
c.XHR();a.open("GET",h,m?!0:!1);a.setRequestHeader("Accept","text/plain");"function"===typeof a.overrideMimeType&&a.overrideMimeType("text/plain");if(m)a.onreadystatechange=function(){4==a.readyState&&(200==a.status||0==a.status&&"string"===typeof a.responseText?m(a.responseText):m(null))},4!=a.readyState&&a.send(null);else return a.send(null),200==a.status||0==a.status&&"string"===typeof a.responseText?a.responseText:null}};c.isArray=function(c){return c?c instanceof Array?!0:Array.isArray?Array.isArray(c):
"[object Array]"===Object.prototype.toString.call(c):!1};return c}();k.Lang={OPEN:"{",CLOSE:"}",OPTOPEN:"[",OPTCLOSE:"]",OPTEND:",",EQUAL:"=",END:";",STRINGOPEN:'"',STRINGCLOSE:'"',COPTOPEN:"(",COPTCLOSE:")",DELIM:/[\s\{\}=;\[\],"\(\)]/g,KEYWORD:/^(?:package|option|import|message|enum|extend|service|syntax|extensions)$/,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]*$/,
OPTNAME:/^(?:[a-zA-Z][a-zA-Z_0-9]*|\([a-zA-Z][a-zA-Z_0-9]*\))$/,TYPEDEF:/^[a-zA-Z][a-zA-Z_0-9]*$/,TYPEREF:/^(?:\.?[a-zA-Z][a-zA-Z_0-9]*)+$/,FQTYPEREF:/^(?:\.[a-zA-Z][a-zA-Z_0-9]*)+$/,NUMBER:/^-?(?:[1-9][0-9]*|0|0x[0-9a-fA-F]+|0[0-7]+|[0-9]*\.[0-9]+)$/,NUMBER_DEC:/^(?:[1-9][0-9]*|0)$/,NUMBER_HEX:/^0x[0-9a-fA-F]+$/,NUMBER_OCT:/^0[0-7]+$/,NUMBER_FLT:/^[0-9]*\.[0-9]+$/,ID:/^(?:[1-9][0-9]*|0|0x[0-9a-fA-F]+|0[0-7]+)$/,NEGID:/^\-?(?:[1-9][0-9]*|0|0x[0-9a-fA-F]+|0[0-7]+)$/,WHITESPACE:/\s/,STRING:/"([^"\\]*(\\.[^"\\]*)*)"/g,
BOOL:/^(?:true|false)$/i,ID_MIN:1,ID_MAX:536870911};k.Reflect=function(c){var h={},m=function(b,f){this.parent=b;this.name=f};m.prototype.fqn=function(){var b=this.name,f=this;do{f=f.parent;if(null==f)break;b=f.name+"."+b}while(1);return b};m.prototype.toString=function(b){var f=this.fqn();b&&(this instanceof a?f="Message "+f:this instanceof a.Field?f="Message.Field "+f:this instanceof d?f="Enum "+f:this instanceof d.Value?f="Enum.Value "+f:this instanceof g?f="Service "+f:this instanceof g.Method?
f=this instanceof g.RPCMethod?"Service.RPCMethod "+f:"Service.Method "+f:this instanceof l&&(f="Namespace "+f));return f};m.prototype.build=function(){throw Error(this.toString(!0)+" cannot be built directly");};h.T=m;var l=function(b,f,a){m.call(this,b,f);this.children=[];this.options=a||{}};l.prototype=Object.create(m.prototype);l.prototype.getChildren=function(b){b=b||null;if(null==b)return this.children.slice();for(var f=[],a=0;a<this.children.length;a++)this.children[a]instanceof b&&f.push(this.children[a]);
return f};l.prototype.addChild=function(b){var f;if(f=this.getChild(b.name))if(f instanceof a.Field&&f.name!==f.originalName&&!this.hasChild(f.originalName))f.name=f.originalName;else if(b instanceof a.Field&&b.name!==b.originalName&&!this.hasChild(b.originalName))b.name=b.originalName;else throw Error("Duplicate name in namespace "+this.toString(!0)+": "+b.name);this.children.push(b)};l.prototype.hasChild=function(b){var f;if("number"==typeof b)for(f=0;f<this.children.length;f++){if("undefined"!==
typeof this.children[f].id&&this.children[f].id==b)return!0}else for(f=0;f<this.children.length;f++)if("undefined"!==typeof this.children[f].name&&this.children[f].name==b)return!0;return!1};l.prototype.getChild=function(b){var f;if("number"==typeof b)for(f=0;f<this.children.length;f++){if("undefined"!==typeof this.children[f].id&&this.children[f].id==b)return this.children[f]}else for(f=0;f<this.children.length;f++)if("undefined"!==typeof this.children[f].name&&this.children[f].name==b)return this.children[f];
return null};l.prototype.resolve=function(b,f){var a=b.split("."),c=this,d=0;if(""==a[d]){for(;null!=c.parent;)c=c.parent;d++}do{do{c=c.getChild(a[d]);if(!(c&&c instanceof h.T)||f&&c instanceof h.Message.Field){c=null;break}d++}while(d<a.length);if(null!=c)break;if(null!==this.parent)return this.parent.resolve(b,f)}while(null!=c);return c};l.prototype.build=function(){for(var b={},f=this.getChildren(),a,c=0;c<f.length;c++)a=f[c],a instanceof l&&(b[a.name]=a.build());Object.defineProperty&&Object.defineProperty(b,
"$options",{value:this.buildOpt(),enumerable:!1,configurable:!1,writable:!1});return b};l.prototype.buildOpt=function(){for(var b={},f=Object.keys(this.options),a=0;a<f.length;a++)b[f[a]]=this.options[f[a]];return b};l.prototype.getOption=function(b){return"undefined"==typeof b?this.options:"undefined"!=typeof this.options[b]?this.options[b]:null};h.Namespace=l;var a=function(b,f,a){l.call(this,b,f,a);this.extensions=[c.Lang.ID_MIN,c.Lang.ID_MAX];this.clazz=null};a.prototype=Object.create(l.prototype);
a.prototype.build=function(b){if(this.clazz&&!b)return this.clazz;b=function(b,f){var a=f.getChildren(h.Message.Field),c=function(f){b.Builder.Message.call(this);var c,d;for(c=0;c<a.length;c++)d=a[c],this[d.name]=d.repeated?[]:null;for(c=0;c<a.length;c++)if(d=a[c],"undefined"!=typeof d.options["default"])try{this.set(d.name,d.options["default"])}catch(n){throw Error("[INTERNAL] "+n);}if(1!=arguments.length||"object"!=typeof f||"function"==typeof f.encode||b.Util.isArray(f)||f instanceof p||f instanceof
ArrayBuffer||b.Long&&f instanceof b.Long)for(c=0;c<arguments.length;c++)c<a.length&&this.set(a[c].name,arguments[c]);else for(d=Object.keys(f),c=0;c<d.length;c++)this.set(d[c],f[d[c]])};c.prototype=Object.create(b.Builder.Message.prototype);c.prototype.add=function(a,c){var d=f.getChild(a);if(!d)throw Error(this+"#"+a+" is undefined");if(!(d instanceof b.Reflect.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(c,!0))};c.prototype.set=function(a,c){var d=f.getChild(a);if(!d)throw Error(this+"#"+a+" is not a field: undefined");if(!(d instanceof b.Reflect.Message.Field))throw Error(this+"#"+a+" is not a field: "+d.toString(!0));this[d.name]=d.verifyValue(c)};c.prototype.get=function(a){var c=f.getChild(a);if(!(c&&c instanceof b.Reflect.Message.Field))throw Error(this+"#"+a+" is not a field: undefined");if(!(c instanceof b.Reflect.Message.Field))throw Error(this+
"#"+a+" is not a field: "+c.toString(!0));return this[c.name]};for(var d=0;d<a.length;d++)(function(b){var a=b.originalName.replace(/(_[a-zA-Z])/g,function(b){return b.toUpperCase().replace("_","")}),a=a.substring(0,1).toUpperCase()+a.substring(1),d=b.originalName.replace(/([A-Z])/g,function(b){return"_"+b});f.hasChild("set"+a)||(c.prototype["set"+a]=function(a){this.set(b.name,a)});f.hasChild("set_"+d)||(c.prototype["set_"+d]=function(a){this.set(b.name,a)});f.hasChild("get"+a)||(c.prototype["get"+
a]=function(){return this.get(b.name)});f.hasChild("get_"+d)||(c.prototype["get_"+d]=function(){return this.get(b.name)})})(a[d]);c.prototype.encode=function(b){b=b||new p;var a=b.littleEndian;try{return f.encode(this,b.LE()).flip().LE(a)}catch(c){throw b.LE(a),c;}};c.prototype.encodeAB=function(){try{return this.encode().toArrayBuffer()}catch(b){throw b.encoded&&(b.encoded=b.encoded.toArrayBuffer()),b;}};c.prototype.toArrayBuffer=c.prototype.encodeAB;c.prototype.encodeNB=function(){try{return this.encode().toBuffer()}catch(b){throw b.encoded&&
(b.encoded=b.encoded.toBuffer()),b;}};c.prototype.toBuffer=c.prototype.encodeNB;c.prototype.encode64=function(){try{return this.encode().toBase64()}catch(b){throw b.encoded&&(b.encoded=b.encoded.toBase64()),b;}};c.prototype.toBase64=c.prototype.encode64;c.prototype.encodeHex=function(){try{return this.encode().toHex()}catch(b){throw b.encoded&&(b.encoded=b.encoded.toHex()),b;}};c.prototype.toHex=c.prototype.encodeHex;c.decode=function(b,a){if(null===b)throw Error("buffer must not be null");"string"===
typeof b&&(b=p.wrap(b,a?a:"base64"));b=b instanceof p?b:p.wrap(b);var c=b.littleEndian;try{var d=f.decode(b.LE());b.LE(c);return d}catch(n){throw b.LE(c),n;}};c.decode64=function(b){return c.decode(b,"base64")};c.decodeHex=function(b){return c.decode(b,"hex")};c.prototype.toString=function(){return f.toString()};Object.defineProperty&&Object.defineProperty(c,"$options",{value:f.buildOpt(),enumerable:!1,configurable:!1,writable:!1});return c}(c,this);for(var f=this.getChildren(),n=0;n<f.length;n++)if(f[n]instanceof
d)b[f[n].name]=f[n].build();else if(f[n]instanceof a)b[f[n].name]=f[n].build();else if(!(f[n]instanceof a.Field))throw Error("Illegal reflect child of "+this.toString(!0)+": "+f[n].toString(!0));return this.clazz=b};a.prototype.encode=function(b,f){for(var c=this.getChildren(a.Field),d=null,e=0;e<c.length;e++){var h=b.get(c[e].name);c[e].required&&null===h?null===d&&(d=c[e]):c[e].encode(h,f)}if(null!==d)throw c=Error("Missing at least one required field for "+this.toString(!0)+": "+d),c.encoded=f,
c;return f};a.prototype.decode=function(b,a){a="number"===typeof a?a:-1;for(var d=b.offset,e=new this.clazz;b.offset<d+a||-1==a&&0<b.remaining();){var h=b.readVarint32(),g=h&7,h=h>>3,l=this.getChild(h);if(l)l.repeated&&!l.options.packed?e.add(l.name,l.decode(g,b)):e.set(l.name,l.decode(g,b));else switch(g){case c.WIRE_TYPES.VARINT:b.readVarint32();break;case c.WIRE_TYPES.BITS32:b.offset+=4;break;case c.WIRE_TYPES.BITS64:b.offset+=8;break;case c.WIRE_TYPES.LDELIM:g=b.readVarint32();b.offset+=g;break;
default:throw Error("Illegal wire type of unknown field "+h+" in "+this.toString(!0)+"#decode: "+g);}}d=this.getChildren(c.Reflect.Field);for(g=0;g<d.length;g++)if(d[g].required&&null===e[d[g].name])throw d=Error("Missing at least one required field for "+this.toString(!0)+": "+d[g].name),d.decoded=e,d;return e};h.Message=a;var e=function(b,a,d,e,g,h){m.call(this,b,e);this.required="required"==a;this.repeated="repeated"==a;this.type=d;this.resolvedType=null;this.id=g;this.options=h||{};this.originalName=
this.name;c.convertFieldsToCamelCase&&(this.name=this.name.replace(/_([a-zA-Z])/g,function(b,a){return a.toUpperCase()}))};e.prototype=Object.create(m.prototype);e.prototype.verifyValue=function(b,a){a=a||!1;if(null===b){if(this.required)throw Error("Illegal value for "+this.toString(!0)+": "+b+" (required)");return null}var e;if(this.repeated&&!a){c.Util.isArray(b)||(b=[b]);var g=[];for(e=0;e<b.length;e++)g.push(this.verifyValue(b[e],!0));return g}if(!this.repeated&&c.Util.isArray(b))throw Error("Illegal value for "+
this.toString(!0)+": "+b+" (no array expected)");if(this.type==c.TYPES.int32||this.type==c.TYPES.sint32||this.type==c.TYPES.sfixed32)return isNaN(e=parseInt(b,10))?e:e|0;if(this.type==c.TYPES.uint32||this.type==c.TYPES.fixed32)return isNaN(e=parseInt(b,10))?e:e>>>0;if(c.Long){if(this.type==c.TYPES.int64||this.type==c.TYPES.sint64||this.type==c.TYPES.sfixed64)return"object"==typeof b&&b instanceof c.Long?b.unsigned?b.toSigned():b:c.Long.fromNumber(b,!1);if(this.type==c.TYPES.uint64||this.type==c.TYPES.fixed64)return"object"==
typeof b&&b instanceof c.Long?b.unsigned?b:b.toUnsigned():c.Long.fromNumber(b,!0)}if(this.type==c.TYPES.bool)return"string"===typeof b?"true"===b:!!b;if(this.type==c.TYPES["float"]||this.type==c.TYPES["double"])return parseFloat(b);if(this.type==c.TYPES.string)return""+b;if(this.type==c.TYPES.bytes)return"object"==typeof b&&b instanceof p?b:p.wrap(b);if(this.type==c.TYPES["enum"]){g=this.resolvedType.getChildren(d.Value);for(e=0;e<g.length;e++)if(g[e].name==b||g[e].id==b)return g[e].id;throw Error("Illegal value for "+
this.toString(!0)+": "+b+" (not a valid enum value)");}if(this.type==c.TYPES.message){if("object"!==typeof b)throw Error("Illegal value for "+this.toString(!0)+": "+b+" (object expected)");return b instanceof this.resolvedType.clazz?b:new this.resolvedType.clazz(b)}throw Error("[INTERNAL] Illegal value for "+this.toString(!0)+": "+b+" (undefined type "+this.type+")");};e.prototype.encode=function(b,a){b=this.verifyValue(b);if(null==this.type||"object"!=typeof this.type)throw Error("[INTERNAL] Unresolved type in "+
this.toString(!0)+": "+this.type);if(null===b||this.repeated&&0==b.length)return a;try{if(this.repeated){var d;if(this.options.packed){a.writeVarint32(this.id<<3|c.WIRE_TYPES.LDELIM);a.ensureCapacity(a.offset+=1);var e=a.offset;for(d=0;d<b.length;d++)this.encodeValue(b[d],a);var g=a.offset-e,h=p.calculateVarint32(g);if(1<h){var l=a.slice(e,a.offset),e=e+(h-1);a.offset=e;a.append(l)}a.writeVarint32(g,e-h)}else for(d=0;d<b.length;d++)a.writeVarint32(this.id<<3|this.type.wireType),this.encodeValue(b[d],
a)}else a.writeVarint32(this.id<<3|this.type.wireType),this.encodeValue(b,a)}catch(m){throw Error("Illegal value for "+this.toString(!0)+": "+b+" ("+m+")");}return a};e.prototype.encodeValue=function(b,a){if(null!==b){if(this.type==c.TYPES.int32||this.type==c.TYPES.uint32)a.writeVarint32(b);else if(this.type==c.TYPES.sint32)a.writeZigZagVarint32(b);else if(this.type==c.TYPES.fixed32)a.writeUint32(b);else if(this.type==c.TYPES.sfixed32)a.writeInt32(b);else if(this.type==c.TYPES.int64||this.type==c.TYPES.uint64)a.writeVarint64(b);
else if(this.type==c.TYPES.sint64)a.writeZigZagVarint64(b);else if(this.type==c.TYPES.fixed64)a.writeUint64(b);else if(this.type==c.TYPES.sfixed64)a.writeInt64(b);else if(this.type==c.TYPES.bool)"string"===typeof b?a.writeVarint32("false"===b.toLowerCase()?0:!!b):a.writeVarint32(b?1:0);else if(this.type==c.TYPES["enum"])a.writeVarint32(b);else if(this.type==c.TYPES["float"])a.writeFloat32(b);else if(this.type==c.TYPES["double"])a.writeFloat64(b);else if(this.type==c.TYPES.string)a.writeVString(b);
else if(this.type==c.TYPES.bytes)b.offset>b.length&&(a=a.clone().flip()),a.writeVarint32(b.remaining()),a.append(b);else if(this.type==c.TYPES.message){var d=(new p).LE();this.resolvedType.encode(b,d);a.writeVarint32(d.offset);a.append(d.flip())}else throw Error("[INTERNAL] Illegal value to encode in "+this.toString(!0)+": "+b+" (unknown type)");return a}};e.prototype.decode=function(b,a,d){if(b!=this.type.wireType&&(d||b!=c.WIRE_TYPES.LDELIM||!this.repeated))throw Error("Illegal wire type for field "+
this.toString(!0)+": "+b+" ("+this.type.wireType+" expected)");if(b==c.WIRE_TYPES.LDELIM&&this.repeated&&this.options.packed&&!d){b=a.readVarint32();b=a.offset+b;for(d=[];a.offset<b;)d.push(this.decode(this.type.wireType,a,!0));return d}if(this.type==c.TYPES.int32)return a.readVarint32()|0;if(this.type==c.TYPES.uint32)return a.readVarint32()>>>0;if(this.type==c.TYPES.sint32)return a.readZigZagVarint32()|0;if(this.type==c.TYPES.fixed32)return a.readUint32()>>>0;if(this.type==c.TYPES.sfixed32)return a.readInt32()|
0;if(this.type==c.TYPES.int64)return a.readVarint64();if(this.type==c.TYPES.uint64)return a.readVarint64().toUnsigned();if(this.type==c.TYPES.sint64)return a.readZigZagVarint64();if(this.type==c.TYPES.fixed64)return a.readUint64();if(this.type==c.TYPES.sfixed64)return a.readInt64();if(this.type==c.TYPES.bool)return!!a.readVarint32();if(this.type==c.TYPES["enum"])return a.readVarint32();if(this.type==c.TYPES["float"])return a.readFloat();if(this.type==c.TYPES["double"])return a.readDouble();if(this.type==
c.TYPES.string)return a.readVString();if(this.type==c.TYPES.bytes){b=a.readVarint32();if(a.remaining()<b)throw Error("Illegal number of bytes for "+this.toString(!0)+": "+b+" required but got only "+a.remaining());d=a.clone();d.length=d.offset+b;a.offset+=b;return d}if(this.type==c.TYPES.message)return b=a.readVarint32(),this.resolvedType.decode(a,b);throw Error("[INTERNAL] Illegal wire type for "+this.toString(!0)+": "+b);};h.Message.Field=e;var d=function(a,c,d){l.call(this,a,c,d);this.object=null};
d.prototype=Object.create(l.prototype);d.prototype.build=function(){for(var a={},c=this.getChildren(d.Value),e=0;e<c.length;e++)a[c[e].name]=c[e].id;Object.defineProperty&&Object.defineProperty(a,"$options",{value:this.buildOpt(),enumerable:!1,configurable:!1,writable:!1});return this.object=a};h.Enum=d;e=function(a,c,d){m.call(this,a,c);this.id=d};e.prototype=Object.create(m.prototype);h.Enum.Value=e;var g=function(a,c,d){l.call(this,a,c,d);this.clazz=null};g.prototype=Object.create(l.prototype);
g.prototype.build=function(a){return this.clazz&&!a?this.clazz:this.clazz=function(a,b){var c=function(b){a.Builder.Service.call(this);this.rpcImpl=b||function(a,b,c){setTimeout(c.bind(this,Error("Not implemented, see: https://github.com/dcodeIO/ProtoBuf.js/wiki/Services")),0)}};c.prototype=Object.create(a.Builder.Service.prototype);Object.defineProperty&&(Object.defineProperty(c,"$options",{value:b.buildOpt(),enumerable:!1,configurable:!1,writable:!1}),Object.defineProperty(c.prototype,"$options",
{value:c.$options,enumerable:!1,configurable:!1,writable:!1}));for(var d=b.getChildren(h.Service.RPCMethod),e=0;e<d.length;e++)(function(a){c.prototype[a.name]=function(c,d){try{c&&c instanceof a.resolvedRequestType.clazz||setTimeout(d.bind(this,Error("Illegal request type provided to service method "+b.name+"#"+a.name))),this.rpcImpl(a.fqn(),c,function(c,e){if(c)d(c);else{try{e=a.resolvedResponseType.clazz.decode(e)}catch(f){}e&&e instanceof a.resolvedResponseType.clazz?d(null,e):d(Error("Illegal response type received in service method "+
b.name+"#"+a.name))}})}catch(e){setTimeout(d.bind(this,e),0)}};c[a.name]=function(b,d,e){(new c(b))[a.name](d,e)};Object.defineProperty&&(Object.defineProperty(c[a.name],"$options",{value:a.buildOpt(),enumerable:!1,configurable:!1,writable:!1}),Object.defineProperty(c.prototype[a.name],"$options",{value:c[a.name].$options,enumerable:!1,configurable:!1,writable:!1}))})(d[e]);return c}(c,this)};h.Service=g;var k=function(a,c,d){m.call(this,a,c);this.options=d||{}};k.prototype=Object.create(m.prototype);
k.prototype.buildOpt=l.prototype.buildOpt;h.Service.Method=k;e=function(a,c,d,e,g){k.call(this,a,c,g);this.requestName=d;this.responseName=e;this.resolvedResponseType=this.resolvedRequestType=null};e.prototype=Object.create(k.prototype);h.Service.RPCMethod=e;return h}(k);k.Builder=function(c,h,m){var l=function(){this.ptr=this.ns=new m.Namespace(null,"");this.resolved=!1;this.result=null;this.files={};this.importRoot=null};l.prototype.reset=function(){this.ptr=this.ns};l.prototype.define=function(a,
c){if("string"!==typeof a||!h.TYPEREF.test(a))throw Error("Illegal package name: "+a);var d=a.split("."),g;for(g=0;g<d.length;g++)if(!h.NAME.test(d[g]))throw Error("Illegal package name: "+d[g]);for(g=0;g<d.length;g++)this.ptr.hasChild(d[g])||this.ptr.addChild(new m.Namespace(this.ptr,d[g],c)),this.ptr=this.ptr.getChild(d[g]);return this};l.isValidMessage=function(a){if("string"!==typeof a.name||!h.NAME.test(a.name)||"undefined"!==typeof a.values||"undefined"!==typeof a.rpc)return!1;var e;if("undefined"!==
typeof a.fields){if(!c.Util.isArray(a.fields))return!1;var d=[],g;for(e=0;e<a.fields.length;e++){if(!l.isValidMessageField(a.fields[e]))return!1;g=parseInt(a.id,10);if(0<=d.indexOf(g))return!1;d.push(g)}}if("undefined"!==typeof a.enums){if(!c.Util.isArray(a.enums))return!1;for(e=0;e<a.enums.length;e++)if(!l.isValidEnum(a.enums[e]))return!1}if("undefined"!==typeof a.messages){if(!c.Util.isArray(a.messages))return!1;for(e=0;e<a.messages.length;e++)if(!l.isValidMessage(a.messages[e])&&!l.isValidExtend(a.messages[e]))return!1}return"undefined"===
typeof a.extensions||c.Util.isArray(a.extensions)&&2===a.extensions.length&&"number"===typeof a.extensions[0]&&"number"===typeof a.extensions[1]?!0:!1};l.isValidMessageField=function(a){if("string"!==typeof a.rule||"string"!==typeof a.name||"string"!==typeof a.type||"undefined"===typeof a.id||!(h.RULE.test(a.rule)&&h.NAME.test(a.name)&&h.TYPEREF.test(a.type)&&h.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),d=0;d<
c.length;d++)if(!h.OPTNAME.test(c[d])||"string"!==typeof a.options[c[d]]&&"number"!==typeof a.options[c[d]]&&"boolean"!==typeof a.options[c[d]])return!1}return!0};l.isValidEnum=function(a){if("string"!==typeof a.name||!h.NAME.test(a.name)||"undefined"===typeof a.values||!c.Util.isArray(a.values)||0==a.values.length)return!1;for(var e=0;e<a.values.length;e++)if("object"!=typeof a.values[e]||"string"!==typeof a.values[e].name||"undefined"===typeof a.values[e].id||!h.NAME.test(a.values[e].name)||!h.NEGID.test(""+
a.values[e].id))return!1;return!0};l.prototype.create=function(a){if(a&&(c.Util.isArray(a)||(a=[a]),0!=a.length)){var e=[],d,g,k,b,f;for(e.push(a);0<e.length;){a=e.pop();if(c.Util.isArray(a))for(;0<a.length;)if(d=a.shift(),l.isValidMessage(d)){g=new m.Message(this.ptr,d.name,d.options);if(d.fields&&0<d.fields.length)for(b=0;b<d.fields.length;b++){if(g.hasChild(d.fields[b].id))throw Error("Duplicate field id in message "+g.name+": "+d.fields[b].id);if(d.fields[b].options)for(k=Object.keys(d.fields[b].options),
f=0;f<k.length;f++){if(!h.OPTNAME.test(k[f]))throw Error("Illegal field option name in message "+g.name+"#"+d.fields[b].name+": "+k[f]);if("string"!==typeof d.fields[b].options[k[f]]&&"number"!==typeof d.fields[b].options[k[f]]&&"boolean"!==typeof d.fields[b].options[k[f]])throw Error("Illegal field option value in message "+g.name+"#"+d.fields[b].name+"#"+k[f]+": "+d.fields[b].options[k[f]]);}g.addChild(new m.Message.Field(g,d.fields[b].rule,d.fields[b].type,d.fields[b].name,d.fields[b].id,d.fields[b].options))}k=
[];if("undefined"!==typeof d.enums&&0<d.enums.length)for(b=0;b<d.enums.length;b++)k.push(d.enums[b]);if(d.messages&&0<d.messages.length)for(b=0;b<d.messages.length;b++)k.push(d.messages[b]);d.extensions&&(g.extensions=d.extensions,g.extensions[0]<c.Lang.ID_MIN&&(g.extensions[0]=c.Lang.ID_MIN),g.extensions[1]>c.Lang.ID_MAX&&(g.extensions[1]=c.Lang.ID_MAX));this.ptr.addChild(g);0<k.length&&(e.push(a),a=k,this.ptr=g)}else if(l.isValidEnum(d)){g=new m.Enum(this.ptr,d.name,d.options);for(b=0;b<d.values.length;b++)g.addChild(new m.Enum.Value(g,
d.values[b].name,d.values[b].id));this.ptr.addChild(g)}else if(l.isValidService(d)){g=new m.Service(this.ptr,d.name,d.options);for(b in d.rpc)d.rpc.hasOwnProperty(b)&&g.addChild(new m.Service.RPCMethod(g,b,d.rpc[b].request,d.rpc[b].response,d.rpc[b].options));this.ptr.addChild(g)}else if(l.isValidExtend(d))if(g=this.lookup(d.ref))for(b=0;b<d.fields.length;b++){if(g.hasChild(d.fields[b].id))throw Error("Duplicate extended field id in message "+g.name+": "+d.fields[b].id);if(d.fields[b].id<g.extensions[0]||
d.fields[b].id>g.extensions[1])throw Error("Illegal extended field id in message "+g.name+": "+d.fields[b].id+" ("+g.extensions.join(" to ")+" expected)");g.addChild(new m.Message.Field(g,d.fields[b].rule,d.fields[b].type,d.fields[b].name,d.fields[b].id,d.fields[b].options))}else{if(!/\.?google\.protobuf\./.test(d.ref))throw Error("Extended message "+d.ref+" is not defined");}else throw Error("Not a valid message, enum, service or extend definition: "+JSON.stringify(d));else throw Error("Not a valid namespace definition: "+
JSON.stringify(a));this.ptr=this.ptr.parent}this.resolved=!1;this.result=null;return this}};l.isValidImport=function(a){return!/google\/protobuf\//.test(a)};l.prototype["import"]=function(a,e){if("string"===typeof e){c.Util.IS_NODE&&(e=require("path").resolve(e));if(this.files[e])return this.reset(),this;this.files[e]=!0}if(a.imports&&0<a.imports.length){var d,g="/",h=!1;if("object"===typeof e){if(this.importRoot=e.root,h=!0,d=this.importRoot,e=e.file,0<=d.indexOf("\\")||0<=e.indexOf("\\"))g="\\"}else"string"===
typeof e?this.importRoot?d=this.importRoot:0<=e.indexOf("/")?(d=e.replace(/\/[^\/]*$/,""),""===d&&(d="/")):0<=e.indexOf("\\")?(d=e.replace(/\\[^\\]*$/,""),g="\\"):d=".":d=null;for(var b=0;b<a.imports.length;b++)if("string"===typeof a.imports[b]){if(!d)throw Error("Cannot determine import root: File name is unknown");var f=d+g+a.imports[b];if(l.isValidImport(f)){/\.proto$/i.test(f)&&!c.DotProto&&(f=f.replace(/\.proto$/,".json"));var k=c.Util.fetch(f);if(null===k)throw Error("Failed to import '"+f+
"' in '"+e+"': File not found");if(/\.json$/i.test(f))this["import"](JSON.parse(k+""),f);else this["import"]((new c.DotProto.Parser(k+"")).parse(),f)}}else if(e)if(/\.(\w+)$/.test(e))this["import"](a.imports[b],e.replace(/^(.+)\.(\w+)$/,function(a,c,d){return c+"_import"+b+"."+d}));else this["import"](a.imports[b],e+"_import"+b);else this["import"](a.imports[b]);h&&(this.importRoot=null)}a.messages&&(a["package"]&&this.define(a["package"],a.options),this.create(a.messages),this.reset());a.enums&&
(a["package"]&&this.define(a["package"],a.options),this.create(a.enums),this.reset());a.services&&(a["package"]&&this.define(a["package"],a.options),this.create(a.services),this.reset());a["extends"]&&(a["package"]&&this.define(a["package"],a.options),this.create(a["extends"]),this.reset());return this};l.isValidService=function(a){return"string"===typeof a.name&&h.NAME.test(a.name)&&"object"===typeof a.rpc?!0:!1};l.isValidExtend=function(a){if("string"!==typeof a.ref||!h.TYPEREF.test(a.name))return!1;
var e;if("undefined"!==typeof a.fields){if(!c.Util.isArray(a.fields))return!1;var d=[],g;for(e=0;e<a.fields.length;e++){if(!l.isValidMessageField(a.fields[e]))return!1;g=parseInt(a.id,10);if(0<=d.indexOf(g))return!1;d.push(g)}}return!0};l.prototype.resolveAll=function(){var a;if(null!=this.ptr&&"object"!==typeof this.ptr.type){if(this.ptr instanceof m.Namespace){a=this.ptr.getChildren();for(var e=0;e<a.length;e++)this.ptr=a[e],this.resolveAll()}else if(this.ptr instanceof m.Message.Field)if(h.TYPE.test(this.ptr.type))this.ptr.type=
c.TYPES[this.ptr.type];else{if(!h.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,!0);if(!a)throw Error("Unresolvable type reference in "+this.ptr.toString(!0)+": "+this.ptr.type);this.ptr.resolvedType=a;if(a instanceof m.Enum)this.ptr.type=c.TYPES["enum"];else if(a instanceof m.Message)this.ptr.type=c.TYPES.message;else throw Error("Illegal type reference in "+this.ptr.toString(!0)+": "+this.ptr.type);
}else if(!(this.ptr instanceof c.Reflect.Enum.Value))if(this.ptr instanceof c.Reflect.Service.Method)if(this.ptr instanceof c.Reflect.Service.RPCMethod){a=this.ptr.parent.resolve(this.ptr.requestName);if(!(a&&a instanceof c.Reflect.Message))throw Error("Illegal request type reference in "+this.ptr.toString(!0)+": "+this.ptr.requestName);this.ptr.resolvedRequestType=a;a=this.ptr.parent.resolve(this.ptr.responseName);if(!(a&&a instanceof c.Reflect.Message))throw Error("Illegal response type reference in "+
this.ptr.toString(!0)+": "+this.ptr.responseName);this.ptr.resolvedResponseType=a}else throw Error("Illegal service method type in "+this.ptr.toString(!0));else throw Error("Illegal object type in namespace: "+typeof this.ptr+":"+this.ptr);this.reset()}};l.prototype.build=function(a){this.reset();this.resolved||(this.resolveAll(),this.resolved=!0,this.result=null);null==this.result&&(this.result=this.ns.build());if(a){a=a.split(".");for(var c=this.result,d=0;d<a.length;d++)if(c[a[d]])c=c[a[d]];else{c=
null;break}return c}return this.result};l.prototype.lookup=function(a){return a?this.ns.resolve(a):this.ns};l.prototype.toString=function(){return"Builder"};l.Message=function(){};l.Service=function(){};return l}(k,k.Lang,k.Reflect);k.newBuilder=function(c,h){var m=new k.Builder;"undefined"!==typeof c&&null!==c&&m.define(c,h);return m};k.loadJson=function(c,h,m){if("string"===typeof h||h&&"string"===typeof h.file&&"string"===typeof h.root)m=h,h=null;h&&"object"===typeof h||(h=k.newBuilder());"string"===
typeof c&&(c=JSON.parse(c));h["import"](c,m);h.resolveAll();h.build();return h};k.loadJsonFile=function(c,h,m){h&&"object"===typeof h?(m=h,h=null):h&&"function"===typeof h||(h=null);if(h)k.Util.fetch("object"===typeof c?c.root+"/"+c.file:c,function(a){try{h(k.loadJson(JSON.parse(a),m,c))}catch(e){h(e)}});else{var l=k.Util.fetch("object"===typeof c?c.root+"/"+c.file:c);return null!==l?k.loadJson(JSON.parse(l),m,c):null}};return k}"undefined"!=typeof module&&module.exports?module.exports=r(require("bytebuffer")):
"undefined"!=typeof define&&define.amd?define("ProtoBuf",["ByteBuffer"],r):(q.dcodeIO||(q.dcodeIO={}),q.dcodeIO.ProtoBuf=r(q.dcodeIO.ByteBuffer))})(this);