protobufjs 3.6.0 → 3.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/proto2js +16 -4
- package/bower.json +1 -1
- package/dist/ProtoBuf.js +645 -441
- package/dist/ProtoBuf.min.js +96 -96
- package/dist/ProtoBuf.min.js.gz +0 -0
- package/dist/ProtoBuf.min.map +2 -2
- package/dist/ProtoBuf.noparse.js +520 -357
- package/dist/ProtoBuf.noparse.min.js +68 -66
- package/dist/ProtoBuf.noparse.min.js.gz +0 -0
- package/dist/ProtoBuf.noparse.min.map +3 -3
- package/docs/ProtoBuf.Builder.Message.html +673 -135
- package/docs/ProtoBuf.Builder.Service.html +58 -19
- package/docs/ProtoBuf.Builder.html +374 -46
- package/docs/ProtoBuf.DotProto.Parser.html +58 -19
- package/docs/ProtoBuf.DotProto.Tokenizer.html +104 -19
- package/docs/ProtoBuf.DotProto.html +16 -10
- package/docs/ProtoBuf.Reflect.Enum.Value.html +207 -33
- package/docs/ProtoBuf.Reflect.Enum.html +318 -56
- package/docs/ProtoBuf.Reflect.Extension.html +53 -13
- package/docs/ProtoBuf.Reflect.Message.ExtensionField.html +450 -68
- package/docs/ProtoBuf.Reflect.Message.Field.html +454 -51
- package/docs/ProtoBuf.Reflect.Message.OneOf.html +1044 -0
- package/docs/ProtoBuf.Reflect.Message.html +378 -64
- package/docs/ProtoBuf.Reflect.Namespace.html +333 -51
- package/docs/ProtoBuf.Reflect.Service.Method.html +228 -35
- package/docs/ProtoBuf.Reflect.Service.RPCMethod.html +262 -41
- package/docs/ProtoBuf.Reflect.Service.html +318 -56
- package/docs/ProtoBuf.Reflect.T.html +210 -25
- package/docs/ProtoBuf.Reflect.html +17 -11
- package/docs/ProtoBuf.Util.html +59 -13
- package/docs/ProtoBuf.html +235 -67
- package/docs/ProtoBuf.js.html +648 -443
- package/docs/index.html +4 -2
- package/docs/styles/jsdoc-default.css +2 -2
- package/examples/protoify/.npmignore +2 -0
- package/examples/protoify/README.md +28 -0
- package/examples/protoify/index.js +147 -0
- package/examples/protoify/json.js +123 -0
- package/examples/protoify/json.json +123 -0
- package/examples/protoify/json.proto +30 -0
- package/examples/protoify/package.json +15 -0
- package/examples/protoify/test.js +56 -0
- package/examples/websocket/README.md +1 -0
- package/examples/websocket/package.json +1 -1
- package/externs/ProtoBuf.js +922 -922
- package/package.json +3 -3
- package/scripts/build.js +58 -58
- package/src/ProtoBuf/Builder/Message.js +107 -77
- package/src/ProtoBuf/Builder/Service.js +8 -5
- package/src/ProtoBuf/Builder.js +71 -37
- package/src/ProtoBuf/DotProto/Parser.js +108 -72
- package/src/ProtoBuf/DotProto/Tokenizer.js +17 -11
- package/src/ProtoBuf/Lang.js +1 -1
- package/src/ProtoBuf/Reflect/Enum/Value.js +3 -2
- package/src/ProtoBuf/Reflect/Enum.js +9 -5
- package/src/ProtoBuf/Reflect/Extension.js +4 -3
- package/src/ProtoBuf/Reflect/Message/ExtensionField.js +4 -3
- package/src/ProtoBuf/Reflect/Message/Field.js +45 -26
- package/src/ProtoBuf/Reflect/Message/OneOf.js +19 -0
- package/src/ProtoBuf/Reflect/Message.js +36 -19
- package/src/ProtoBuf/Reflect/Namespace.js +19 -15
- package/src/ProtoBuf/Reflect/Service/Method.js +9 -5
- package/src/ProtoBuf/Reflect/Service/RPCMethod.js +3 -2
- package/src/ProtoBuf/Reflect/Service.js +9 -5
- package/src/ProtoBuf/Reflect/T.js +20 -6
- package/src/ProtoBuf/Reflect.js +9 -0
- package/src/ProtoBuf/Util.js +132 -132
- package/src/ProtoBuf.js +15 -17
- package/src/google/protobuf/descriptor.json +33 -13
- package/tests/bench.txt +373 -373
- package/tests/complex.json +8 -4
- package/tests/custom-options.json +169 -169
- package/tests/extend.json +71 -71
- package/tests/nodeunit-browser/nodeunit.css +70 -70
- package/tests/nodeunit-browser/nodeunit.js +2108 -2108
- package/tests/oneof.proto +6 -0
- package/tests/options.json +32 -32
- package/tests/options.proto +2 -0
- package/tests/proto2js/Bar.json +46 -46
- package/tests/suite.js +83 -12
- package/.idea/.name +0 -1
- package/.idea/ProtoBuf.iml +0 -9
- package/.idea/dictionaries/Daniel.xml +0 -7
- package/.idea/encodings.xml +0 -5
- package/.idea/misc.xml +0 -5
- package/.idea/modules.xml +0 -9
- package/.idea/scopes/scope_settings.xml +0 -5
- package/.idea/vcs.xml +0 -7
- package/.idea/workspace.xml +0 -551
- package/NOTICE +0 -2
- package/sandbox/issue146/MyOptions.proto +0 -28
- package/sandbox/issue146/Sample.proto +0 -21
- package/sandbox/issue146/main.js +0 -3
- package/sandbox/issue147/enum.proto +0 -8
- package/sandbox/issue147/main.js +0 -3
- package/sandbox/issue42/innerextend.proto +0 -18
- package/sandbox/issue42/main.js +0 -8
- package/sandbox/issue42/outerextend.proto +0 -17
- package/v8.log +0 -3828
|
@@ -3,71 +3,73 @@
|
|
|
3
3
|
Released under the Apache License, Version 2.0
|
|
4
4
|
see: https://github.com/dcodeIO/ProtoBuf.js for details
|
|
5
5
|
*/
|
|
6
|
-
(function(
|
|
6
|
+
(function(w){function x(k){var g={VERSION:"3.8.2",WIRE_TYPES:{}};g.WIRE_TYPES.VARINT=0;g.WIRE_TYPES.BITS64=1;g.WIRE_TYPES.LDELIM=2;g.WIRE_TYPES.STARTGROUP=3;g.WIRE_TYPES.ENDGROUP=4;g.WIRE_TYPES.BITS32=5;g.PACKABLE_WIRE_TYPES=[g.WIRE_TYPES.VARINT,g.WIRE_TYPES.BITS64,g.WIRE_TYPES.BITS32];g.TYPES={int32:{name:"int32",wireType:g.WIRE_TYPES.VARINT},uint32:{name:"uint32",wireType:g.WIRE_TYPES.VARINT},sint32:{name:"sint32",wireType:g.WIRE_TYPES.VARINT},int64:{name:"int64",wireType:g.WIRE_TYPES.VARINT},uint64:{name:"uint64",
|
|
7
7
|
wireType:g.WIRE_TYPES.VARINT},sint64:{name:"sint64",wireType:g.WIRE_TYPES.VARINT},bool:{name:"bool",wireType:g.WIRE_TYPES.VARINT},"double":{name:"double",wireType:g.WIRE_TYPES.BITS64},string:{name:"string",wireType:g.WIRE_TYPES.LDELIM},bytes:{name:"bytes",wireType:g.WIRE_TYPES.LDELIM},fixed32:{name:"fixed32",wireType:g.WIRE_TYPES.BITS32},sfixed32:{name:"sfixed32",wireType:g.WIRE_TYPES.BITS32},fixed64:{name:"fixed64",wireType:g.WIRE_TYPES.BITS64},sfixed64:{name:"sfixed64",wireType:g.WIRE_TYPES.BITS64},
|
|
8
|
-
"float":{name:"float",wireType:g.WIRE_TYPES.BITS32},"enum":{name:"enum",wireType:g.WIRE_TYPES.VARINT},message:{name:"message",wireType:g.WIRE_TYPES.LDELIM},group:{name:"group",wireType:g.WIRE_TYPES.STARTGROUP}};g.ID_MIN=1;g.ID_MAX=536870911;g.ByteBuffer=
|
|
9
|
-
|
|
10
|
-
return
|
|
11
|
-
|
|
8
|
+
"float":{name:"float",wireType:g.WIRE_TYPES.BITS32},"enum":{name:"enum",wireType:g.WIRE_TYPES.VARINT},message:{name:"message",wireType:g.WIRE_TYPES.LDELIM},group:{name:"group",wireType:g.WIRE_TYPES.STARTGROUP}};g.ID_MIN=1;g.ID_MAX=536870911;g.ByteBuffer=k;g.Long=k.Long||null;g.convertFieldsToCamelCase=!1;g.populateAccessors=!0;g.Util=function(){Object.create||(Object.create=function(c){function g(){}if(1<arguments.length)throw Error("Object.create polyfill only accepts the first parameter.");g.prototype=
|
|
9
|
+
c;return new g});var c={IS_NODE:!1};try{c.IS_NODE="function"===typeof require&&"function"===typeof require("fs").readFileSync&&"function"===typeof require("path").resolve}catch(g){}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")}],g=null,s=0;s<c.length;s++){try{g=c[s]()}catch(b){continue}break}if(!g)throw Error("XMLHttpRequest is not supported");
|
|
10
|
+
return g};c.fetch=function(g,p){p&&"function"!=typeof p&&(p=null);if(c.IS_NODE)if(p)require("fs").readFile(g,function(b,c){b?p(null):p(""+c)});else try{return require("fs").readFileSync(g)}catch(s){return null}else{var b=c.XHR();b.open("GET",g,p?!0:!1);b.setRequestHeader("Accept","text/plain");"function"===typeof b.overrideMimeType&&b.overrideMimeType("text/plain");if(p)b.onreadystatechange=function(){4==b.readyState&&(200==b.status||0==b.status&&"string"===typeof b.responseText?p(b.responseText):
|
|
11
|
+
p(null))},4!=b.readyState&&b.send(null);else return b.send(null),200==b.status||0==b.status&&"string"===typeof b.responseText?b.responseText:null}};c.isArray=Array.isArray||function(c){return"[object Array]"===Object.prototype.toString.call(c)};return c}();g.Lang={OPEN:"{",CLOSE:"}",OPTOPEN:"[",OPTCLOSE:"]",OPTEND:",",EQUAL:"=",END:";",STRINGOPEN:'"',STRINGCLOSE:'"',STRINGOPEN_SQ:"'",STRINGCLOSE_SQ:"'",COPTOPEN:"(",COPTCLOSE:")",DELIM:/[\s\{\}=;\[\],'"\(\)]/g,RULE:/^(?:required|optional|repeated)$/,
|
|
12
12
|
TYPE:/^(?:double|float|int32|uint32|sint32|int64|uint64|sint64|fixed32|sfixed32|fixed64|sfixed64|bool|string|bytes)$/,NAME:/^[a-zA-Z_][a-zA-Z_0-9]*$/,TYPEDEF:/^[a-zA-Z][a-zA-Z_0-9]*$/,TYPEREF:/^(?:\.?[a-zA-Z_][a-zA-Z_0-9]*)+$/,FQTYPEREF:/^(?:\.[a-zA-Z][a-zA-Z_0-9]*)+$/,NUMBER:/^-?(?:[1-9][0-9]*|0|0x[0-9a-fA-F]+|0[0-7]+|([0-9]*\.[0-9]+([Ee][+-]?[0-9]+)?))$/,NUMBER_DEC:/^(?:[1-9][0-9]*|0)$/,NUMBER_HEX:/^0x[0-9a-fA-F]+$/,NUMBER_OCT:/^0[0-7]+$/,NUMBER_FLT:/^[0-9]*\.[0-9]+([Ee][+-]?[0-9]+)?$/,ID:/^(?:[1-9][0-9]*|0|0x[0-9a-fA-F]+|0[0-7]+)$/,
|
|
13
|
-
NEGID:/^\-?(?:[1-9][0-9]*|0|0x[0-9a-fA-F]+|0[0-7]+)$/,WHITESPACE:/\s/,STRING:/
|
|
14
|
-
b+" ("+a+" expected)");case
|
|
15
|
-
}var
|
|
16
|
-
function(a){a=a||null;if(null==a)return this.children.slice();for(var
|
|
17
|
-
this.toString(!0)+": "+a.name);this.children.push(a)};
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
b[
|
|
22
|
-
this.$set(
|
|
23
|
-
"#"+
|
|
24
|
-
|
|
25
|
-
c.
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
"hex")};
|
|
29
|
-
n))throw Error("Illegal reflect child of "+this.toString(!0)+": "+children[b].toString(!0));return this.clazz=a};
|
|
30
|
-
this._fields[
|
|
31
|
-
this._fieldsById[
|
|
32
|
-
this._fields[a],null===f[
|
|
33
|
-
c.ExtensionField||(this.name=this.name.replace(/_([a-zA-Z])/g,function(a,
|
|
34
|
-
"required"),null;var e;if(this.repeated&&!b){
|
|
35
|
-
a>>>0:a;case
|
|
36
|
-
typeof a||a&&a instanceof String||
|
|
37
|
-
a[e]);a=
|
|
38
|
-
b.ensureCapacity(b.offset+=1);var e=b.offset;for(
|
|
39
|
-
function(a,b){if(null===a)return b;switch(this.type){case
|
|
40
|
-
break;case
|
|
41
|
-
break;case
|
|
42
|
-
": "+this.type);if(null===a||this.repeated&&0==a.length)return 0;var b=0;try{if(this.repeated){var
|
|
43
|
-
this.toString(!0)+": "+a+" ("+f+")");}return b};
|
|
44
|
-
case
|
|
45
|
-
a;case
|
|
46
|
-
|
|
47
|
-
case
|
|
48
|
-
b.offset+=a;return
|
|
49
|
-
function(){for(var a={},b=this.getChildren(
|
|
50
|
-
this.
|
|
51
|
-
"$options",{value:c.$options}));for(var
|
|
52
|
-
b.name+"#"+a.name)),0)}catch(e){setTimeout(d.bind(this,e),0)}};c[a.name]=function(b,d,
|
|
53
|
-
|
|
54
|
-
!g.TYPEREF.test(b))throw Error("Illegal package: "+b);var
|
|
55
|
-
var c=[],
|
|
56
|
-
typeof b.extensions||
|
|
57
|
-
0,f
|
|
58
|
-
b.values[
|
|
59
|
-
Object.keys(
|
|
60
|
-
|
|
61
|
-
for(
|
|
62
|
-
f.name
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
13
|
+
NEGID:/^\-?(?:[1-9][0-9]*|0|0x[0-9a-fA-F]+|0[0-7]+)$/,WHITESPACE:/\s/,STRING:/(?:"([^"\\]*(?:\\.[^"\\]*)*)")|(?:'([^'\\]*(?:\\.[^'\\]*)*)')/g,BOOL:/^(?:true|false)$/i};g.Reflect=function(c){function g(a,h){var b=h.readVarint32(),e=b&7,b=b>>3;switch(e){case c.WIRE_TYPES.VARINT:do b=h.readUint8();while(128===(b&128));break;case c.WIRE_TYPES.BITS64:h.offset+=8;break;case c.WIRE_TYPES.LDELIM:b=h.readVarint32();h.offset+=b;break;case c.WIRE_TYPES.STARTGROUP:g(b,h);break;case c.WIRE_TYPES.ENDGROUP:if(b===
|
|
14
|
+
a)return!1;throw Error("Illegal GROUPEND after unknown group: "+b+" ("+a+" expected)");case c.WIRE_TYPES.BITS32:h.offset+=4;break;default:throw Error("Illegal wire type in unknown group "+a+": "+e);}return!0}function t(a,h){if(a&&"number"===typeof a.low&&"number"===typeof a.high&&"boolean"===typeof a.unsigned&&a.low===a.low&&a.high===a.high)return new c.Long(a.low,a.high,"undefined"===typeof h?a.unsigned:h);if("string"===typeof a)return c.Long.fromString(a,h||!1,10);if("number"===typeof a)return c.Long.fromNumber(a,
|
|
15
|
+
h||!1);throw Error("not convertible to Long");}var p={},r=function(a,h,b){this.builder=a;this.parent=h;this.name=b},b=r.prototype;b.fqn=function(){var a=this.name,h=this;do{h=h.parent;if(null==h)break;a=h.name+"."+a}while(1);return a};b.toString=function(a){return(a?this.className+" ":"")+this.fqn()};b.build=function(){throw Error(this.toString(!0)+" cannot be built directly");};p.T=r;var m=function(a,h,b,c){r.call(this,a,h,b);this.className="Namespace";this.children=[];this.options=c||{}},b=m.prototype=
|
|
16
|
+
Object.create(r.prototype);b.getChildren=function(a){a=a||null;if(null==a)return this.children.slice();for(var h=[],b=0,c=this.children.length;b<c;++b)this.children[b]instanceof a&&h.push(this.children[b]);return h};b.addChild=function(a){var h;if(h=this.getChild(a.name))if(h instanceof f.Field&&h.name!==h.originalName&&null===this.getChild(h.originalName))h.name=h.originalName;else if(a instanceof f.Field&&a.name!==a.originalName&&null===this.getChild(a.originalName))a.name=a.originalName;else throw Error("Duplicate name in namespace "+
|
|
17
|
+
this.toString(!0)+": "+a.name);this.children.push(a)};b.getChild=function(a){for(var h="number"===typeof a?"id":"name",b=0,c=this.children.length;b<c;++b)if(this.children[b][h]===a)return this.children[b];return null};b.resolve=function(a,b){var c=a.split("."),e=this,f=0;if(""===c[f]){for(;null!==e.parent;)e=e.parent;f++}do{do{e=e.getChild(c[f]);if(!(e&&e instanceof p.T)||b&&e instanceof p.Message.Field){e=null;break}f++}while(f<c.length);if(null!=e)break;if(null!==this.parent)return this.parent.resolve(a,
|
|
18
|
+
b)}while(null!=e);return e};b.build=function(){for(var a={},b=this.children,c=0,f=b.length,d;c<f;++c)d=b[c],d instanceof m&&(a[d.name]=d.build());Object.defineProperty&&Object.defineProperty(a,"$options",{value:this.buildOpt()});return a};b.buildOpt=function(){for(var a={},b=Object.keys(this.options),c=0,f=b.length;c<f;++c)a[b[c]]=this.options[b[c]];return a};b.getOption=function(a){return"undefined"===typeof a?this.options:"undefined"!==typeof this.options[a]?this.options[a]:null};p.Namespace=m;
|
|
19
|
+
var f=function(a,b,f,e,d){m.call(this,a,b,f,e);this.className="Message";this.extensions=[c.ID_MIN,c.ID_MAX];this.clazz=null;this.isGroup=!!d;this._fieldsByName=this._fieldsById=this._fields=null},d=f.prototype=Object.create(m.prototype);d.build=function(a){if(this.clazz&&!a)return this.clazz;a=function(a,b){function c(a,b){var h={},e;for(e in a)a.hasOwnProperty(e)&&(null===a[e]||"object"!==typeof a[e]?h[e]=a[e]:a[e]instanceof k?b&&(h[e]=a[e].toBase64()):h[e]=c(a[e],b));return h}var h=b.getChildren(a.Reflect.Message.Field),
|
|
20
|
+
f=b.getChildren(a.Reflect.Message.OneOf),l=function(b,c){a.Builder.Message.call(this);for(var e=0,l=f.length;e<l;++e)this[f[e].name]=null;e=0;for(l=h.length;e<l;++e){var d=h[e];this[d.name]=d.repeated?[]:null;d.required&&null!==d.defaultValue&&(this[d.name]=d.defaultValue)}if(0<arguments.length)if(1!==arguments.length||"object"!==typeof b||"function"===typeof b.encode||a.Util.isArray(b)||b instanceof k||b instanceof ArrayBuffer||a.Long&&b instanceof a.Long)for(e=0,l=arguments.length;e<l;++e)this.$set(h[e].name,
|
|
21
|
+
arguments[e]);else for(d=Object.keys(b),e=0,l=d.length;e<l;++e)this.$set(d[e],b[d[e]])},e=l.prototype=Object.create(a.Builder.Message.prototype);e.add=function(c,h,e){var l=b._fieldsByName[c];if(!e){if(!l)throw Error(this+"#"+c+" is undefined");if(!(l instanceof a.Reflect.Message.Field))throw Error(this+"#"+c+" is not a field: "+l.toString(!0));if(!l.repeated)throw Error(this+"#"+c+" is not a repeated field");}null===this[l.name]&&(this[l.name]=[]);this[l.name].push(e?h:l.verifyValue(h,!0))};e.$add=
|
|
22
|
+
e.add;e.set=function(c,h,e){if(c&&"object"===typeof c){for(var l in c)c.hasOwnProperty(l)&&this.$set(l,c[l],e);return this}l=b._fieldsByName[c];if(e)this[l.name]=h;else{if(!l)throw Error(this+"#"+c+" is not a field: undefined");if(!(l instanceof a.Reflect.Message.Field))throw Error(this+"#"+c+" is not a field: "+l.toString(!0));this[l.name]=h=l.verifyValue(h)}l.oneof&&(null!==h?(null!==this[l.oneof.name]&&(this[this[l.oneof.name]]=null),this[l.oneof.name]=l.name):l.oneof.name===c&&(this[l.oneof.name]=
|
|
23
|
+
null));return this};e.$set=e.set;e.get=function(c,h){if(h)return this[c];var e=b._fieldsByName[c];if(!(e&&e instanceof a.Reflect.Message.Field))throw Error(this+"#"+c+" is not a field: undefined");if(!(e instanceof a.Reflect.Message.Field))throw Error(this+"#"+c+" is not a field: "+e.toString(!0));return this[e.name]};e.$get=e.get;for(var d=0;d<h.length;d++){var m=h[d];m instanceof a.Reflect.Message.ExtensionField||b.builder.options.populateAccessors&&function(a){var c=a.originalName.replace(/(_[a-zA-Z])/g,
|
|
24
|
+
function(a){return a.toUpperCase().replace("_","")}),c=c.substring(0,1).toUpperCase()+c.substring(1),h=a.originalName.replace(/([A-Z])/g,function(a){return"_"+a}),l=function(b,c){this[a.name]=c?b:a.verifyValue(b);return this},f=function(){return this[a.name]};null===b.getChild("set"+c)&&(e["set"+c]=l);null===b.getChild("set_"+h)&&(e["set_"+h]=l);null===b.getChild("get"+c)&&(e["get"+c]=f);null===b.getChild("get_"+h)&&(e["get_"+h]=f)}(m)}e.encode=function(a,c){"boolean"===typeof a&&(c=a,a=void 0);var h=
|
|
25
|
+
!1;a||(a=new k,h=!0);var e=a.littleEndian;try{return b.encode(this,a.LE(),c),(h?a.flip():a).LE(e)}catch(l){throw a.LE(e),l;}};e.calculate=function(){return b.calculate(this)};e.encodeDelimited=function(a){var c=!1;a||(a=new k,c=!0);var h=(new k).LE();b.encode(this,h).flip();a.writeVarint32(h.remaining());a.append(h);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=
|
|
26
|
+
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){return c(this,!!a)};l.decode=function(a,c){"string"===typeof a&&(a=
|
|
27
|
+
k.wrap(a,c?c:"base64"));a=a instanceof k?a:k.wrap(a);var h=a.littleEndian;try{var e=b.decode(a.LE());a.LE(h);return e}catch(l){throw a.LE(h),l;}};l.decodeDelimited=function(a,c){"string"===typeof a&&(a=k.wrap(a,c?c:"base64"));a=a instanceof k?a:k.wrap(a);if(1>a.remaining())return null;var h=a.offset,e=a.readVarint32();if(a.remaining()<e)return a.offset=h,null;try{var l=b.decode(a.slice(a.offset,a.offset+e).LE());a.offset+=e;return l}catch(f){throw a.offset+=e,f;}};l.decode64=function(a){return l.decode(a,
|
|
28
|
+
"base64")};l.decodeHex=function(a){return l.decode(a,"hex")};e.toString=function(){return b.toString()};Object.defineProperty&&(Object.defineProperty(l,"$options",{value:b.buildOpt()}),Object.defineProperty(e,"$type",{get:function(){return b}}));return l}(c,this);this._fields=[];this._fieldsById={};this._fieldsByName={};for(var b=0,l=this.children.length,e;b<l;b++)if(e=this.children[b],e instanceof q)a[e.name]=e.build();else if(e instanceof f)a[e.name]=e.build();else if(e instanceof f.Field)e.build(),
|
|
29
|
+
this._fields.push(e),this._fieldsById[e.id]=e,this._fieldsByName[e.name]=e;else if(!(e instanceof f.OneOf||e instanceof n))throw Error("Illegal reflect child of "+this.toString(!0)+": "+children[b].toString(!0));return this.clazz=a};d.encode=function(a,b,c){for(var e=null,f,d=0,m=this._fields.length,g;d<m;++d)f=this._fields[d],g=a[f.name],f.required&&null===g?null===e&&(e=f):f.encode(c?g:f.verifyValue(g),b);if(null!==e)throw a=Error("Missing at least one required field for "+this.toString(!0)+": "+
|
|
30
|
+
e),a.encoded=b,a;return b};d.calculate=function(a){for(var b=0,c=0,e=this._fields.length,f,d;c<e;++c){f=this._fields[c];d=a[f.name];if(f.required&&null===d)throw Error("Missing at least one required field for "+this.toString(!0)+": "+f);b+=f.calculate(d)}return b};d.decode=function(a,b,l){b="number"===typeof b?b:-1;for(var e=a.offset,f=new this.clazz,d,m,n;a.offset<e+b||-1===b&&0<a.remaining();){d=a.readVarint32();m=d&7;n=d>>3;if(m===c.WIRE_TYPES.ENDGROUP){if(n!==l)throw Error("Illegal group end indicator for "+
|
|
31
|
+
this.toString(!0)+": "+n+" ("+(l?l+" expected":"not a group")+")");break}if(d=this._fieldsById[n])d.repeated&&!d.options.packed?f[d.name].push(d.decode(m,a)):(f[d.name]=d.decode(m,a),d.oneof&&(null!==this[d.oneof.name]&&(this[this[d.oneof.name]]=null),f[d.oneof.name]=d.name));else switch(m){case c.WIRE_TYPES.VARINT:a.readVarint32();break;case c.WIRE_TYPES.BITS32:a.offset+=4;break;case c.WIRE_TYPES.BITS64:a.offset+=8;break;case c.WIRE_TYPES.LDELIM:d=a.readVarint32();a.offset+=d;break;case c.WIRE_TYPES.STARTGROUP:for(;g(n,
|
|
32
|
+
a););break;default:throw Error("Illegal wire type for unknown field "+n+" in "+this.toString(!0)+"#decode: "+m);}}a=0;for(b=this._fields.length;a<b;++a)if(d=this._fields[a],null===f[d.name]){if(d.required)throw a=Error("Missing at least one required field for "+this.toString(!0)+": "+d.name),a.decoded=f,a;null!==d.defaultValue&&(f[d.name]=d.defaultValue)}return f};p.Message=f;var u=function(a,b,c,e,d,m,g,n){r.call(this,a,b,d);this.className="Message.Field";this.required="required"===c;this.repeated=
|
|
33
|
+
"repeated"===c;this.type=e;this.resolvedType=null;this.id=m;this.options=g||{};this.defaultValue=null;this.oneof=n||null;this.originalName=this.name;!this.builder.options.convertFieldsToCamelCase||this instanceof f.ExtensionField||(this.name=u._toCamelCase(this.name))};u._toCamelCase=function(a){return a.replace(/_([a-zA-Z])/g,function(a,b){return b.toUpperCase()})};d=u.prototype=Object.create(r.prototype);d.build=function(){this.defaultValue="undefined"!==typeof this.options["default"]?this.verifyValue(this.options["default"]):
|
|
34
|
+
null};d.verifyValue=function(a,b){b=b||!1;var l=function(a,b){throw Error("Illegal value for "+this.toString(!0)+" of type "+this.type.name+": "+a+" ("+b+")");}.bind(this);if(null===a)return this.required&&l(typeof a,"required"),null;var e;if(this.repeated&&!b){c.Util.isArray(a)||(a=[a]);l=[];for(e=0;e<a.length;e++)l.push(this.verifyValue(a[e],!0));return l}!this.repeated&&c.Util.isArray(a)&&l(typeof a,"no array expected");switch(this.type){case c.TYPES.int32:case c.TYPES.sint32:case c.TYPES.sfixed32:return("number"!==
|
|
35
|
+
typeof a||a===a&&0!==a%1)&&l(typeof a,"not an integer"),4294967295<a?a|0:a;case c.TYPES.uint32:case c.TYPES.fixed32:return("number"!==typeof a||a===a&&0!==a%1)&&l(typeof a,"not an integer"),0>a?a>>>0:a;case c.TYPES.int64:case c.TYPES.sint64:case c.TYPES.sfixed64:if(c.Long)try{return t(a,!1)}catch(d){l(typeof a,d.message)}else l(typeof a,"requires Long.js");case c.TYPES.uint64:case c.TYPES.fixed64:if(c.Long)try{return t(a,!0)}catch(f){l(typeof a,f.message)}else l(typeof a,"requires Long.js");case c.TYPES.bool:return"boolean"!==
|
|
36
|
+
typeof a&&l(typeof a,"not a boolean"),a;case c.TYPES["float"]:case c.TYPES["double"]:return"number"!==typeof a&&l(typeof a,"not a number"),a;case c.TYPES.string:return"string"===typeof a||a&&a instanceof String||l(typeof a,"not a string"),""+a;case c.TYPES.bytes:return k.isByteBuffer(a)?a:k.wrap(a,"base64");case c.TYPES["enum"]:var m=this.resolvedType.getChildren(q.Value);for(e=0;e<m.length;e++)if(m[e].name==a||m[e].id==a)return m[e].id;l(a,"not a valid enum value");case c.TYPES.group:case c.TYPES.message:a&&
|
|
37
|
+
"object"===typeof a||l(typeof a,"object expected");if(a instanceof this.resolvedType.clazz)return a;if(a instanceof c.Builder.Message){l={};for(e in a)a.hasOwnProperty(e)&&(l[e]=a[e]);a=l}return new this.resolvedType.clazz(a)}throw Error("[INTERNAL] Illegal value for "+this.toString(!0)+": "+a+" (undefined type "+this.type+")");};d.encode=function(a,b){if(null===this.type||"object"!==typeof this.type)throw Error("[INTERNAL] Unresolved type in "+this.toString(!0)+": "+this.type);if(null===a||this.repeated&&
|
|
38
|
+
0==a.length)return b;try{if(this.repeated){var d;if(this.options.packed&&0<=c.PACKABLE_WIRE_TYPES.indexOf(this.type.wireType)){b.writeVarint32(this.id<<3|c.WIRE_TYPES.LDELIM);b.ensureCapacity(b.offset+=1);var e=b.offset;for(d=0;d<a.length;d++)this.encodeValue(a[d],b);var f=b.offset-e,m=k.calculateVarint32(f);if(1<m){var g=b.slice(e,b.offset),e=e+(m-1);b.offset=e;b.append(g)}b.writeVarint32(f,e-m)}else for(d=0;d<a.length;d++)b.writeVarint32(this.id<<3|this.type.wireType),this.encodeValue(a[d],b)}else b.writeVarint32(this.id<<
|
|
39
|
+
3|this.type.wireType),this.encodeValue(a,b)}catch(n){throw Error("Illegal value for "+this.toString(!0)+": "+a+" ("+n+")");}return b};d.encodeValue=function(a,b){if(null===a)return b;switch(this.type){case c.TYPES.int32:0>a?b.writeVarint64(a):b.writeVarint32(a);break;case c.TYPES.uint32:b.writeVarint32(a);break;case c.TYPES.sint32:b.writeVarint32ZigZag(a);break;case c.TYPES.fixed32:b.writeUint32(a);break;case c.TYPES.sfixed32:b.writeInt32(a);break;case c.TYPES.int64:case c.TYPES.uint64:b.writeVarint64(a);
|
|
40
|
+
break;case c.TYPES.sint64:b.writeVarint64ZigZag(a);break;case c.TYPES.fixed64:b.writeUint64(a);break;case c.TYPES.sfixed64:b.writeInt64(a);break;case c.TYPES.bool:"string"===typeof a?b.writeVarint32("false"===a.toLowerCase()?0:!!a):b.writeVarint32(a?1:0);break;case c.TYPES["enum"]:b.writeVarint32(a);break;case c.TYPES["float"]:b.writeFloat32(a);break;case c.TYPES["double"]:b.writeFloat64(a);break;case c.TYPES.string:b.writeVString(a);break;case c.TYPES.bytes:if(0>a.remaining())throw Error("Illegal value for "+
|
|
41
|
+
this.toString(!0)+": "+a.remaining()+" bytes remaining");var d=a.offset;b.writeVarint32(a.remaining());b.append(a);a.offset=d;break;case c.TYPES.message:d=(new k).LE();this.resolvedType.encode(a,d);b.writeVarint32(d.offset);b.append(d.flip());break;case c.TYPES.group:this.resolvedType.encode(a,b);b.writeVarint32(this.id<<3|c.WIRE_TYPES.ENDGROUP);break;default:throw Error("[INTERNAL] Illegal value to encode in "+this.toString(!0)+": "+a+" (unknown type)");}return b};d.calculate=function(a){a=this.verifyValue(a);
|
|
42
|
+
if(null===this.type||"object"!==typeof this.type)throw Error("[INTERNAL] Unresolved type in "+this.toString(!0)+": "+this.type);if(null===a||this.repeated&&0==a.length)return 0;var b=0;try{if(this.repeated){var d,e;if(this.options.packed&&0<=c.PACKABLE_WIRE_TYPES.indexOf(this.type.wireType)){b+=k.calculateVarint32(this.id<<3|c.WIRE_TYPES.LDELIM);for(d=e=0;d<a.length;d++)e+=this.calculateValue(a[d]);b+=k.calculateVarint32(e);b+=e}else for(d=0;d<a.length;d++)b+=k.calculateVarint32(this.id<<3|this.type.wireType),
|
|
43
|
+
b+=this.calculateValue(a[d])}else b+=k.calculateVarint32(this.id<<3|this.type.wireType),b+=this.calculateValue(a)}catch(f){throw Error("Illegal value for "+this.toString(!0)+": "+a+" ("+f+")");}return b};d.calculateValue=function(a){if(null===a)return 0;switch(this.type){case c.TYPES.int32:return 0>a?k.calculateVarint64(a):k.calculateVarint32(a);case c.TYPES.uint32:return k.calculateVarint32(a);case c.TYPES.sint32:return k.calculateVarint32(k.zigZagEncode32(a));case c.TYPES.fixed32:case c.TYPES.sfixed32:case c.TYPES["float"]:return 4;
|
|
44
|
+
case c.TYPES.int64:case c.TYPES.uint64:return k.calculateVarint64(a);case c.TYPES.sint64:return k.calculateVarint64(k.zigZagEncode64(a));case c.TYPES.fixed64:case c.TYPES.sfixed64:return 8;case c.TYPES.bool:return 1;case c.TYPES["enum"]:return k.calculateVarint32(a);case c.TYPES["double"]:return 8;case c.TYPES.string:return a=k.calculateUTF8Bytes(a),k.calculateVarint32(a)+a;case c.TYPES.bytes:if(0>a.remaining())throw Error("Illegal value for "+this.toString(!0)+": "+a.remaining()+" bytes remaining");
|
|
45
|
+
return k.calculateVarint32(a.remaining())+a.remaining();case c.TYPES.message:return a=this.resolvedType.calculate(a),k.calculateVarint32(a)+a;case c.TYPES.group:return a=this.resolvedType.calculate(a),a+k.calculateVarint32(this.id<<3|c.WIRE_TYPES.ENDGROUP)}throw Error("[INTERNAL] Illegal value to encode in "+this.toString(!0)+": "+a+" (unknown type)");};d.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)+
|
|
46
|
+
": "+a+" ("+this.type.wireType+" expected)");if(a==c.WIRE_TYPES.LDELIM&&this.repeated&&this.options.packed&&0<=c.PACKABLE_WIRE_TYPES.indexOf(this.type.wireType)&&!d){a=b.readVarint32();a=b.offset+a;for(d=[];b.offset<a;)d.push(this.decode(this.type.wireType,b,!0));return d}switch(this.type){case c.TYPES.int32:return b.readVarint32()|0;case c.TYPES.uint32:return b.readVarint32()>>>0;case c.TYPES.sint32:return b.readVarint32ZigZag()|0;case c.TYPES.fixed32:return b.readUint32()>>>0;case c.TYPES.sfixed32:return b.readInt32()|
|
|
47
|
+
0;case c.TYPES.int64:return b.readVarint64();case c.TYPES.uint64:return b.readVarint64().toUnsigned();case c.TYPES.sint64:return b.readVarint64ZigZag();case c.TYPES.fixed64:return b.readUint64();case c.TYPES.sfixed64:return b.readInt64();case c.TYPES.bool:return!!b.readVarint32();case c.TYPES["enum"]:return b.readVarint32();case c.TYPES["float"]:return b.readFloat();case c.TYPES["double"]:return b.readDouble();case c.TYPES.string:return b.readVString();case c.TYPES.bytes:a=b.readVarint32();if(b.remaining()<
|
|
48
|
+
a)throw Error("Illegal number of bytes for "+this.toString(!0)+": "+a+" required but got only "+b.remaining());d=b.clone();d.limit=d.offset+a;b.offset+=a;return d;case c.TYPES.message:return a=b.readVarint32(),this.resolvedType.decode(b,a);case c.TYPES.group:return this.resolvedType.decode(b,-1,this.id)}throw Error("[INTERNAL] Illegal wire type for "+this.toString(!0)+": "+a);};p.Message.Field=u;d=function(a,b,c,e,d,f,m){u.call(this,a,b,c,e,d,f,m)};d.prototype=Object.create(u.prototype);p.Message.ExtensionField=
|
|
49
|
+
d;p.Message.OneOf=function(a,b,c){r.call(this,a,b,c);this.fields=[]};var q=function(a,b,c,e){m.call(this,a,b,c,e);this.className="Enum";this.object=null};(q.prototype=Object.create(m.prototype)).build=function(){for(var a={},b=this.getChildren(q.Value),c=0,e=b.length;c<e;++c)a[b[c].name]=b[c].id;Object.defineProperty&&Object.defineProperty(a,"$options",{value:this.buildOpt()});return this.object=a};p.Enum=q;d=function(a,b,c,e){r.call(this,a,b,c);this.className="Enum.Value";this.id=e};d.prototype=
|
|
50
|
+
Object.create(r.prototype);p.Enum.Value=d;var n=function(a,b,c,e){r.call(this,a,b,c);this.field=e};n.prototype=Object.create(r.prototype);p.Extension=n;d=function(a,b,c,e){m.call(this,a,b,c,e);this.className="Service";this.clazz=null};(d.prototype=Object.create(m.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")),
|
|
51
|
+
0)}},d=c.prototype=Object.create(a.Builder.Service.prototype);Object.defineProperty&&(Object.defineProperty(c,"$options",{value:b.buildOpt()}),Object.defineProperty(d,"$options",{value:c.$options}));for(var f=b.getChildren(a.Reflect.Service.RPCMethod),m=0;m<f.length;m++)(function(a){d[a.name]=function(c,d){try{c&&c instanceof a.resolvedRequestType.clazz?this.rpcImpl(a.fqn(),c,function(c,e){if(c)d(c);else{try{e=a.resolvedResponseType.clazz.decode(e)}catch(f){}e&&e instanceof a.resolvedResponseType.clazz?
|
|
52
|
+
d(null,e):d(Error("Illegal response type received in service method "+b.name+"#"+a.name))}}):setTimeout(d.bind(this,Error("Illegal request type provided to service method "+b.name+"#"+a.name)),0)}catch(e){setTimeout(d.bind(this,e),0)}};c[a.name]=function(b,d,f){(new c(b))[a.name](d,f)};Object.defineProperty&&(Object.defineProperty(c[a.name],"$options",{value:a.buildOpt()}),Object.defineProperty(d[a.name],"$options",{value:c[a.name].$options}))})(f[m]);return c}(c,this)};p.Service=d;var v=function(a,
|
|
53
|
+
b,c,d){r.call(this,a,b,c);this.className="Service.Method";this.options=d||{}};(v.prototype=Object.create(r.prototype)).buildOpt=b.buildOpt;p.Service.Method=v;b=function(a,b,c,d,f,m){v.call(this,a,b,c,m);this.className="Service.RPCMethod";this.requestName=d;this.responseName=f;this.resolvedResponseType=this.resolvedRequestType=null};b.prototype=Object.create(v.prototype);p.Service.RPCMethod=b;return p}(g);g.Builder=function(c,g,k){var p=function(b){this.ptr=this.ns=new k.Namespace(this,null,"");this.resolved=
|
|
54
|
+
!1;this.result=null;this.files={};this.importRoot=null;this.options=b||{}},r=p.prototype;r.reset=function(){this.ptr=this.ns};r.define=function(b,c){if("string"!==typeof b||!g.TYPEREF.test(b))throw Error("Illegal package: "+b);var f=b.split("."),d;for(d=0;d<f.length;d++)if(!g.NAME.test(f[d]))throw Error("Illegal package: "+f[d]);for(d=0;d<f.length;d++)null===this.ptr.getChild(f[d])&&this.ptr.addChild(new k.Namespace(this,this.ptr,f[d],c)),this.ptr=this.ptr.getChild(f[d]);return this};p.isValidMessage=
|
|
55
|
+
function(b){if("string"!==typeof b.name||!g.NAME.test(b.name)||"undefined"!==typeof b.values||"undefined"!==typeof b.rpc)return!1;var m;if("undefined"!==typeof b.fields){if(!c.Util.isArray(b.fields))return!1;var f=[],d;for(m=0;m<b.fields.length;m++){if(!p.isValidMessageField(b.fields[m]))return!1;d=parseInt(b.fields[m].id,10);if(0<=f.indexOf(d))return!1;f.push(d)}}if("undefined"!==typeof b.enums){if(!c.Util.isArray(b.enums))return!1;for(m=0;m<b.enums.length;m++)if(!p.isValidEnum(b.enums[m]))return!1}if("undefined"!==
|
|
56
|
+
typeof b.messages){if(!c.Util.isArray(b.messages))return!1;for(m=0;m<b.messages.length;m++)if(!p.isValidMessage(b.messages[m])&&!p.isValidExtend(b.messages[m]))return!1}return"undefined"===typeof b.extensions||c.Util.isArray(b.extensions)&&2===b.extensions.length&&"number"===typeof b.extensions[0]&&"number"===typeof b.extensions[1]?!0:!1};p.isValidMessageField=function(b){if("string"!==typeof b.rule||"string"!==typeof b.name||"string"!==typeof b.type||"undefined"===typeof b.id||!(g.RULE.test(b.rule)&&
|
|
57
|
+
g.NAME.test(b.name)&&g.TYPEREF.test(b.type)&&g.ID.test(""+b.id)))return!1;if("undefined"!==typeof b.options){if("object"!==typeof b.options)return!1;for(var c=Object.keys(b.options),f=0,d;f<c.length;f++)if("string"!==typeof(d=c[f])||"string"!==typeof b.options[d]&&"number"!==typeof b.options[d]&&"boolean"!==typeof b.options[d])return!1}return!0};p.isValidEnum=function(b){if("string"!==typeof b.name||!g.NAME.test(b.name)||"undefined"===typeof b.values||!c.Util.isArray(b.values)||0==b.values.length)return!1;
|
|
58
|
+
for(var m=0;m<b.values.length;m++)if("object"!=typeof b.values[m]||"string"!==typeof b.values[m].name||"undefined"===typeof b.values[m].id||!g.NAME.test(b.values[m].name)||!g.NEGID.test(""+b.values[m].id))return!1;return!0};r.create=function(b){if(!b)return this;c.Util.isArray(b)||(b=[b]);if(0==b.length)return this;var m=[];for(m.push(b);0<m.length;){b=m.pop();if(c.Util.isArray(b))for(;0<b.length;){var f=b.shift();if(p.isValidMessage(f)){var d=new k.Message(this,this.ptr,f.name,f.options,f.isGroup),
|
|
59
|
+
g={};if(f.oneofs)for(var q=Object.keys(f.oneofs),n=0,s=q.length;n<s;++n)d.addChild(g[q[n]]=new k.Message.OneOf(this,d,q[n]));if(f.fields&&0<f.fields.length)for(n=0,s=f.fields.length;n<s;++n){q=f.fields[n];if(null!==d.getChild(q.id))throw Error("Duplicate field id in message "+d.name+": "+q.id);if(q.options)for(var a=Object.keys(q.options),h=0,l=a.length;h<l;++h){if("string"!==typeof a[h])throw Error("Illegal field option name in message "+d.name+"#"+q.name+": "+a[h]);if("string"!==typeof q.options[a[h]]&&
|
|
60
|
+
"number"!==typeof q.options[a[h]]&&"boolean"!==typeof q.options[a[h]])throw Error("Illegal field option value in message "+d.name+"#"+q.name+"#"+a[h]+": "+q.options[a[h]]);}a=null;if("string"===typeof q.oneof&&(a=g[q.oneof],"undefined"===typeof a))throw Error("Illegal oneof in message "+d.name+"#"+q.name+": "+q.oneof);q=new k.Message.Field(this,d,q.rule,q.type,q.name,q.id,q.options,a);a&&a.fields.push(q);d.addChild(q)}g=[];if("undefined"!==typeof f.enums&&0<f.enums.length)for(n=0;n<f.enums.length;n++)g.push(f.enums[n]);
|
|
61
|
+
if(f.messages&&0<f.messages.length)for(n=0;n<f.messages.length;n++)g.push(f.messages[n]);f.extensions&&(d.extensions=f.extensions,d.extensions[0]<c.ID_MIN&&(d.extensions[0]=c.ID_MIN),d.extensions[1]>c.ID_MAX&&(d.extensions[1]=c.ID_MAX));this.ptr.addChild(d);0<g.length&&(m.push(b),b=g,this.ptr=d)}else if(p.isValidEnum(f)){d=new k.Enum(this,this.ptr,f.name,f.options);for(n=0;n<f.values.length;n++)d.addChild(new k.Enum.Value(this,d,f.values[n].name,f.values[n].id));this.ptr.addChild(d)}else if(p.isValidService(f)){d=
|
|
62
|
+
new k.Service(this,this.ptr,f.name,f.options);for(n in f.rpc)f.rpc.hasOwnProperty(n)&&d.addChild(new k.Service.RPCMethod(this,d,n,f.rpc[n].request,f.rpc[n].response,f.rpc[n].options));this.ptr.addChild(d)}else if(p.isValidExtend(f))if(d=this.ptr.resolve(f.ref))for(n=0;n<f.fields.length;n++){if(null!==d.getChild(f.fields[n].id))throw Error("Duplicate extended field id in message "+d.name+": "+f.fields[n].id);if(f.fields[n].id<d.extensions[0]||f.fields[n].id>d.extensions[1])throw Error("Illegal extended field id in message "+
|
|
63
|
+
d.name+": "+f.fields[n].id+" ("+d.extensions.join(" to ")+" expected)");g=f.fields[n].name;this.options.convertFieldsToCamelCase&&(g=k.Message.Field._toCamelCase(f.fields[n].name));q=new k.Message.ExtensionField(this,d,f.fields[n].rule,f.fields[n].type,this.ptr.fqn()+"."+g,f.fields[n].id,f.fields[n].options);g=new k.Extension(this,this.ptr,f.fields[n].name,q);q.extension=g;this.ptr.addChild(g);d.addChild(q)}else{if(!/\.?google\.protobuf\./.test(f.ref))throw Error("Extended message "+f.ref+" is not defined");
|
|
64
|
+
}else throw Error("Not a valid definition: "+JSON.stringify(f));}else throw Error("Not a valid namespace: "+JSON.stringify(b));this.ptr=this.ptr.parent}this.resolved=!1;this.result=null;return this};r["import"]=function(b,g){if("string"===typeof g){c.Util.IS_NODE&&(g=require("path").resolve(g));if(!0===this.files[g])return this.reset(),this;this.files[g]=!0}if(b.imports&&0<b.imports.length){var f,d="/",k=!1;if("object"===typeof g){if(this.importRoot=g.root,k=!0,f=this.importRoot,g=g.file,0<=f.indexOf("\\")||
|
|
65
|
+
0<=g.indexOf("\\"))d="\\"}else"string"===typeof g?this.importRoot?f=this.importRoot:0<=g.indexOf("/")?(f=g.replace(/\/[^\/]*$/,""),""===f&&(f="/")):0<=g.indexOf("\\")?(f=g.replace(/\\[^\\]*$/,""),d="\\"):f=".":f=null;for(var p=0;p<b.imports.length;p++)if("string"===typeof b.imports[p]){if(!f)throw Error("Cannot determine import root: File name is unknown");var n=b.imports[p];if(!/^google\/protobuf\//.test(n)&&(n=f+d+n,!0!==this.files[n])){/\.proto$/i.test(n)&&!c.DotProto&&(n=n.replace(/\.proto$/,
|
|
66
|
+
".json"));var s=c.Util.fetch(n);if(null===s)throw Error("Failed to import '"+n+"' in '"+g+"': File not found");if(/\.json$/i.test(n))this["import"](JSON.parse(s+""),n);else this["import"]((new c.DotProto.Parser(s+"")).parse(),n)}}else if(g)if(/\.(\w+)$/.test(g))this["import"](b.imports[p],g.replace(/^(.+)\.(\w+)$/,function(a,b,c){return b+"_import"+p+"."+c}));else this["import"](b.imports[p],g+"_import"+p);else this["import"](b.imports[p]);k&&(this.importRoot=null)}b.messages&&(b["package"]&&this.define(b["package"],
|
|
67
|
+
b.options),this.create(b.messages),this.reset());b.enums&&(b["package"]&&this.define(b["package"],b.options),this.create(b.enums),this.reset());b.services&&(b["package"]&&this.define(b["package"],b.options),this.create(b.services),this.reset());b["extends"]&&(b["package"]&&this.define(b["package"],b.options),this.create(b["extends"]),this.reset());return this};p.isValidService=function(b){return!("string"!==typeof b.name||!g.NAME.test(b.name)||"object"!==typeof b.rpc)};p.isValidExtend=function(b){if("string"!==
|
|
68
|
+
typeof b.ref||!g.TYPEREF.test(b.ref))return!1;var m;if("undefined"!==typeof b.fields){if(!c.Util.isArray(b.fields))return!1;var f=[],d;for(m=0;m<b.fields.length;m++){if(!p.isValidMessageField(b.fields[m]))return!1;d=parseInt(b.id,10);if(0<=f.indexOf(d))return!1;f.push(d)}}return!0};r.resolveAll=function(){var b;if(null!=this.ptr&&"object"!==typeof this.ptr.type){if(this.ptr instanceof k.Namespace){b=this.ptr.children;for(var m=0,f=b.length;m<f;++m)this.ptr=b[m],this.resolveAll()}else if(this.ptr instanceof
|
|
69
|
+
k.Message.Field)if(g.TYPE.test(this.ptr.type))this.ptr.type=c.TYPES[this.ptr.type];else{if(!g.TYPEREF.test(this.ptr.type))throw Error("Illegal type reference in "+this.ptr.toString(!0)+": "+this.ptr.type);b=(this.ptr instanceof k.Message.ExtensionField?this.ptr.extension.parent:this.ptr.parent).resolve(this.ptr.type,!0);if(!b)throw Error("Unresolvable type reference in "+this.ptr.toString(!0)+": "+this.ptr.type);this.ptr.resolvedType=b;if(b instanceof k.Enum)this.ptr.type=c.TYPES["enum"];else if(b instanceof
|
|
70
|
+
k.Message)this.ptr.type=b.isGroup?c.TYPES.group: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){b=this.ptr.parent.resolve(this.ptr.requestName);if(!(b&&b instanceof c.Reflect.Message))throw Error("Illegal type reference in "+this.ptr.toString(!0)+": "+this.ptr.requestName);this.ptr.resolvedRequestType=
|
|
71
|
+
b;b=this.ptr.parent.resolve(this.ptr.responseName);if(!(b&&b instanceof c.Reflect.Message))throw Error("Illegal type reference in "+this.ptr.toString(!0)+": "+this.ptr.responseName);this.ptr.resolvedResponseType=b}else throw Error("Illegal service type in "+this.ptr.toString(!0));else if(!(this.ptr instanceof c.Reflect.Message.OneOf||this.ptr instanceof c.Reflect.Extension))throw Error("Illegal object in namespace: "+typeof this.ptr+":"+this.ptr);this.reset()}};r.build=function(b){this.reset();this.resolved||
|
|
72
|
+
(this.resolveAll(),this.resolved=!0,this.result=null);null==this.result&&(this.result=this.ns.build());if(b){b=b.split(".");for(var c=this.result,f=0;f<b.length;f++)if(c[b[f]])c=c[b[f]];else{c=null;break}return c}return this.result};r.lookup=function(b){return b?this.ns.resolve(b):this.ns};r.toString=function(){return"Builder"};p.Message=function(){};p.Service=function(){};return p}(g,g.Lang,g.Reflect);g.newBuilder=function(c){c=c||{};"undefined"===typeof c.convertFieldsToCamelCase&&(c.convertFieldsToCamelCase=
|
|
73
|
+
g.convertFieldsToCamelCase);"undefined"===typeof c.populateAccessors&&(c.populateAccessors=g.populateAccessors);return new g.Builder(c)};g.loadJson=function(c,k,t){if("string"===typeof k||k&&"string"===typeof k.file&&"string"===typeof k.root)t=k,k=null;k&&"object"===typeof k||(k=g.newBuilder());"string"===typeof c&&(c=JSON.parse(c));k["import"](c,t);k.resolveAll();return k};g.loadJsonFile=function(c,k,t){k&&"object"===typeof k?(t=k,k=null):k&&"function"===typeof k||(k=null);if(k)return g.Util.fetch("string"===
|
|
74
|
+
typeof c?c:c.root+"/"+c.file,function(p){if(null===p)k(Error("Failed to fetch file"));else try{k(null,g.loadJson(JSON.parse(p),t,c))}catch(b){k(b)}});var p=g.Util.fetch("object"===typeof c?c.root+"/"+c.file:c);return null===p?null:g.loadJson(JSON.parse(p),t,c)};return g}"function"===typeof require&&"object"===typeof module&&module&&"object"===typeof exports&&exports?module.exports=x(require("bytebuffer")):"function"===typeof define&&define.amd?define(["ByteBuffer"],x):(w.dcodeIO=w.dcodeIO||{}).ProtoBuf=
|
|
75
|
+
x(w.dcodeIO.ByteBuffer)})(this);
|
|
Binary file
|