protobufjs 6.8.5 → 6.8.9

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.
Files changed (103) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/LICENSE +39 -39
  3. package/README.md +879 -879
  4. package/cli/LICENSE +33 -33
  5. package/cli/README.md +11 -11
  6. package/cli/index.d.ts +3 -3
  7. package/cli/index.js +3 -3
  8. package/cli/lib/tsd-jsdoc/LICENSE +20 -20
  9. package/cli/lib/tsd-jsdoc/README.md +23 -23
  10. package/cli/lib/tsd-jsdoc/plugin.js +21 -21
  11. package/cli/lib/tsd-jsdoc/publish.js +693 -693
  12. package/cli/lib/tsd-jsdoc.json +18 -18
  13. package/cli/package.standalone.json +31 -31
  14. package/cli/pbjs.d.ts +9 -9
  15. package/cli/pbjs.js +329 -319
  16. package/cli/pbts.d.ts +9 -9
  17. package/cli/pbts.js +197 -168
  18. package/cli/targets/json-module.js +38 -38
  19. package/cli/targets/json.js +8 -8
  20. package/cli/targets/proto.js +326 -326
  21. package/cli/targets/proto2.js +10 -10
  22. package/cli/targets/proto3.js +10 -10
  23. package/cli/targets/static-module.js +29 -29
  24. package/cli/targets/static.js +702 -705
  25. package/cli/util.js +183 -183
  26. package/cli/wrappers/amd.js +7 -7
  27. package/cli/wrappers/closure.js +7 -7
  28. package/cli/wrappers/commonjs.js +7 -7
  29. package/cli/wrappers/default.js +15 -15
  30. package/cli/wrappers/es6.js +5 -5
  31. package/dist/README.md +31 -31
  32. package/dist/light/README.md +31 -31
  33. package/dist/light/protobuf.js +6031 -6011
  34. package/dist/light/protobuf.js.map +1 -1
  35. package/dist/light/protobuf.min.js +3 -3
  36. package/dist/light/protobuf.min.js.map +1 -1
  37. package/dist/minimal/README.md +31 -31
  38. package/dist/minimal/protobuf.js +1877 -1868
  39. package/dist/minimal/protobuf.js.map +1 -1
  40. package/dist/minimal/protobuf.min.js +3 -3
  41. package/dist/minimal/protobuf.min.js.map +1 -1
  42. package/dist/protobuf.js +7594 -7573
  43. package/dist/protobuf.js.map +1 -1
  44. package/dist/protobuf.min.js +3 -3
  45. package/dist/protobuf.min.js.map +1 -1
  46. package/ext/debug/README.md +4 -4
  47. package/ext/debug/index.js +71 -71
  48. package/ext/descriptor/README.md +72 -72
  49. package/ext/descriptor/index.d.ts +0 -1
  50. package/ext/descriptor/index.js +1052 -1049
  51. package/ext/descriptor/test.js +54 -54
  52. package/google/LICENSE +27 -27
  53. package/google/README.md +1 -1
  54. package/google/api/annotations.proto +10 -10
  55. package/google/protobuf/descriptor.proto +286 -286
  56. package/google/protobuf/source_context.proto +7 -7
  57. package/index.d.ts +3 -1
  58. package/index.js +4 -4
  59. package/light.d.ts +2 -2
  60. package/light.js +3 -3
  61. package/minimal.d.ts +2 -2
  62. package/minimal.js +4 -4
  63. package/package-lock.json +5810 -3344
  64. package/package.json +24 -30
  65. package/scripts/changelog.js +150 -150
  66. package/scripts/postinstall.js +35 -35
  67. package/src/common.js +399 -399
  68. package/src/converter.js +293 -287
  69. package/src/decoder.js +106 -106
  70. package/src/encoder.js +99 -99
  71. package/src/enum.js +181 -181
  72. package/src/field.js +371 -370
  73. package/src/index-light.js +104 -104
  74. package/src/index-minimal.js +36 -36
  75. package/src/index.js +12 -12
  76. package/src/mapfield.js +126 -126
  77. package/src/message.js +138 -138
  78. package/src/method.js +151 -151
  79. package/src/namespace.js +433 -431
  80. package/src/object.js +200 -199
  81. package/src/oneof.js +203 -203
  82. package/src/parse.js +758 -757
  83. package/src/reader.js +405 -407
  84. package/src/reader_buffer.js +44 -44
  85. package/src/root.js +351 -350
  86. package/src/roots.js +18 -18
  87. package/src/rpc/service.js +142 -142
  88. package/src/rpc.js +36 -36
  89. package/src/service.js +167 -167
  90. package/src/tokenize.js +397 -397
  91. package/src/type.js +589 -589
  92. package/src/types.js +196 -196
  93. package/src/typescript.jsdoc +15 -15
  94. package/src/util/longbits.js +200 -200
  95. package/src/util/minimal.js +414 -405
  96. package/src/util.js +178 -178
  97. package/src/verifier.js +176 -176
  98. package/src/wrappers.js +83 -83
  99. package/src/writer.js +459 -459
  100. package/src/writer_buffer.js +81 -81
  101. package/tsconfig.json +6 -6
  102. package/google/protobuf/field_mask.json +0 -21
  103. package/google/protobuf/field_mask.proto +0 -7
@@ -1,40 +1,42 @@
1
1
  /*!
2
- * protobuf.js v6.8.5 (c) 2016, daniel wirtz
3
- * compiled mon, 19 feb 2018 11:50:08 utc
2
+ * protobuf.js v6.8.8 (c) 2016, daniel wirtz
3
+ * compiled tue, 10 mar 2020 18:44:49 utc
4
4
  * licensed under the bsd-3-clause license
5
5
  * see: https://github.com/dcodeio/protobuf.js for details
6
6
  */
7
- (function(global,undefined){"use strict";(function prelude(modules, cache, entries) {
8
-
9
- // This is the prelude used to bundle protobuf.js for the browser. Wraps up the CommonJS
10
- // sources through a conflict-free require shim and is again wrapped within an iife that
11
- // provides a unified `global` and a minification-friendly `undefined` var plus a global
12
- // "use strict" directive so that minification can remove the directives of each module.
13
-
14
- function $require(name) {
15
- var $module = cache[name];
16
- if (!$module)
17
- modules[name][0].call($module = cache[name] = { exports: {} }, $require, $module, $module.exports);
18
- return $module.exports;
19
- }
20
-
21
- // Expose globally
22
- var protobuf = global.protobuf = $require(entries[0]);
23
-
24
- // Be nice to AMD
25
- if (typeof define === "function" && define.amd)
26
- define(["long"], function(Long) {
27
- if (Long && Long.isLong) {
28
- protobuf.util.Long = Long;
29
- protobuf.configure();
30
- }
31
- return protobuf;
32
- });
33
-
34
- // Be nice to CommonJS
35
- if (typeof module === "object" && module && module.exports)
36
- module.exports = protobuf;
37
-
7
+ (function(undefined){"use strict";(function prelude(modules, cache, entries) {
8
+
9
+ // This is the prelude used to bundle protobuf.js for the browser. Wraps up the CommonJS
10
+ // sources through a conflict-free require shim and is again wrapped within an iife that
11
+ // provides a minification-friendly `undefined` var plus a global "use strict" directive
12
+ // so that minification can remove the directives of each module.
13
+
14
+ function $require(name) {
15
+ var $module = cache[name];
16
+ if (!$module)
17
+ modules[name][0].call($module = cache[name] = { exports: {} }, $require, $module, $module.exports);
18
+ return $module.exports;
19
+ }
20
+
21
+ var protobuf = $require(entries[0]);
22
+
23
+ // Expose globally
24
+ protobuf.util.global.protobuf = protobuf;
25
+
26
+ // Be nice to AMD
27
+ if (typeof define === "function" && define.amd)
28
+ define(["long"], function(Long) {
29
+ if (Long && Long.isLong) {
30
+ protobuf.util.Long = Long;
31
+ protobuf.configure();
32
+ }
33
+ return protobuf;
34
+ });
35
+
36
+ // Be nice to CommonJS
37
+ if (typeof module === "object" && module && module.exports)
38
+ module.exports = protobuf;
39
+
38
40
  })/* end of prelude */({1:[function(require,module,exports){
39
41
  "use strict";
40
42
  module.exports = asPromise;
@@ -822,1854 +824,1861 @@ utf8.write = function utf8_write(string, buffer, offset) {
822
824
  };
823
825
 
824
826
  },{}],8:[function(require,module,exports){
825
- "use strict";
826
- var protobuf = exports;
827
-
828
- /**
829
- * Build type, one of `"full"`, `"light"` or `"minimal"`.
830
- * @name build
831
- * @type {string}
832
- * @const
833
- */
834
- protobuf.build = "minimal";
835
-
836
- // Serialization
837
- protobuf.Writer = require(16);
838
- protobuf.BufferWriter = require(17);
839
- protobuf.Reader = require(9);
840
- protobuf.BufferReader = require(10);
841
-
842
- // Utility
843
- protobuf.util = require(15);
844
- protobuf.rpc = require(12);
845
- protobuf.roots = require(11);
846
- protobuf.configure = configure;
847
-
848
- /* istanbul ignore next */
849
- /**
850
- * Reconfigures the library according to the environment.
851
- * @returns {undefined}
852
- */
853
- function configure() {
854
- protobuf.Reader._configure(protobuf.BufferReader);
855
- protobuf.util._configure();
856
- }
857
-
858
- // Configure serialization
859
- protobuf.Writer._configure(protobuf.BufferWriter);
860
- configure();
827
+ "use strict";
828
+ var protobuf = exports;
829
+
830
+ /**
831
+ * Build type, one of `"full"`, `"light"` or `"minimal"`.
832
+ * @name build
833
+ * @type {string}
834
+ * @const
835
+ */
836
+ protobuf.build = "minimal";
837
+
838
+ // Serialization
839
+ protobuf.Writer = require(16);
840
+ protobuf.BufferWriter = require(17);
841
+ protobuf.Reader = require(9);
842
+ protobuf.BufferReader = require(10);
843
+
844
+ // Utility
845
+ protobuf.util = require(15);
846
+ protobuf.rpc = require(12);
847
+ protobuf.roots = require(11);
848
+ protobuf.configure = configure;
849
+
850
+ /* istanbul ignore next */
851
+ /**
852
+ * Reconfigures the library according to the environment.
853
+ * @returns {undefined}
854
+ */
855
+ function configure() {
856
+ protobuf.Reader._configure(protobuf.BufferReader);
857
+ protobuf.util._configure();
858
+ }
859
+
860
+ // Set up buffer utility according to the environment
861
+ protobuf.Writer._configure(protobuf.BufferWriter);
862
+ configure();
861
863
 
862
864
  },{"10":10,"11":11,"12":12,"15":15,"16":16,"17":17,"9":9}],9:[function(require,module,exports){
863
- "use strict";
864
- module.exports = Reader;
865
-
866
- var util = require(15);
867
-
868
- var BufferReader; // cyclic
869
-
870
- var LongBits = util.LongBits,
871
- utf8 = util.utf8;
872
-
873
- /* istanbul ignore next */
874
- function indexOutOfRange(reader, writeLength) {
875
- return RangeError("index out of range: " + reader.pos + " + " + (writeLength || 1) + " > " + reader.len);
876
- }
877
-
878
- /**
879
- * Constructs a new reader instance using the specified buffer.
880
- * @classdesc Wire format reader using `Uint8Array` if available, otherwise `Array`.
881
- * @constructor
882
- * @param {Uint8Array} buffer Buffer to read from
883
- */
884
- function Reader(buffer) {
885
-
886
- /**
887
- * Read buffer.
888
- * @type {Uint8Array}
889
- */
890
- this.buf = buffer;
891
-
892
- /**
893
- * Read buffer position.
894
- * @type {number}
895
- */
896
- this.pos = 0;
897
-
898
- /**
899
- * Read buffer length.
900
- * @type {number}
901
- */
902
- this.len = buffer.length;
903
- }
904
-
905
- var create_array = typeof Uint8Array !== "undefined"
906
- ? function create_typed_array(buffer) {
907
- if (buffer instanceof Uint8Array || Array.isArray(buffer))
908
- return new Reader(buffer);
909
- throw Error("illegal buffer");
910
- }
911
- /* istanbul ignore next */
912
- : function create_array(buffer) {
913
- if (Array.isArray(buffer))
914
- return new Reader(buffer);
915
- throw Error("illegal buffer");
916
- };
917
-
918
- /**
919
- * Creates a new reader using the specified buffer.
920
- * @function
921
- * @param {Uint8Array|Buffer} buffer Buffer to read from
922
- * @returns {Reader|BufferReader} A {@link BufferReader} if `buffer` is a Buffer, otherwise a {@link Reader}
923
- * @throws {Error} If `buffer` is not a valid buffer
924
- */
925
- Reader.create = util.Buffer
926
- ? function create_buffer_setup(buffer) {
927
- return (Reader.create = function create_buffer(buffer) {
928
- return util.Buffer.isBuffer(buffer)
929
- ? new BufferReader(buffer)
930
- /* istanbul ignore next */
931
- : create_array(buffer);
932
- })(buffer);
933
- }
934
- /* istanbul ignore next */
935
- : create_array;
936
-
937
- Reader.prototype._slice = util.Array.prototype.subarray || /* istanbul ignore next */ util.Array.prototype.slice;
938
-
939
- /**
940
- * Reads a varint as an unsigned 32 bit value.
941
- * @function
942
- * @returns {number} Value read
943
- */
944
- Reader.prototype.uint32 = (function read_uint32_setup() {
945
- var value = 4294967295; // optimizer type-hint, tends to deopt otherwise (?!)
946
- return function read_uint32() {
947
- value = ( this.buf[this.pos] & 127 ) >>> 0; if (this.buf[this.pos++] < 128) return value;
948
- value = (value | (this.buf[this.pos] & 127) << 7) >>> 0; if (this.buf[this.pos++] < 128) return value;
949
- value = (value | (this.buf[this.pos] & 127) << 14) >>> 0; if (this.buf[this.pos++] < 128) return value;
950
- value = (value | (this.buf[this.pos] & 127) << 21) >>> 0; if (this.buf[this.pos++] < 128) return value;
951
- value = (value | (this.buf[this.pos] & 15) << 28) >>> 0; if (this.buf[this.pos++] < 128) return value;
952
-
953
- /* istanbul ignore if */
954
- if ((this.pos += 5) > this.len) {
955
- this.pos = this.len;
956
- throw indexOutOfRange(this, 10);
957
- }
958
- return value;
959
- };
960
- })();
961
-
962
- /**
963
- * Reads a varint as a signed 32 bit value.
964
- * @returns {number} Value read
965
- */
966
- Reader.prototype.int32 = function read_int32() {
967
- return this.uint32() | 0;
968
- };
969
-
970
- /**
971
- * Reads a zig-zag encoded varint as a signed 32 bit value.
972
- * @returns {number} Value read
973
- */
974
- Reader.prototype.sint32 = function read_sint32() {
975
- var value = this.uint32();
976
- return value >>> 1 ^ -(value & 1) | 0;
977
- };
978
-
979
- /* eslint-disable no-invalid-this */
980
-
981
- function readLongVarint() {
982
- // tends to deopt with local vars for octet etc.
983
- var bits = new LongBits(0, 0);
984
- var i = 0;
985
- if (this.len - this.pos > 4) { // fast route (lo)
986
- for (; i < 4; ++i) {
987
- // 1st..4th
988
- bits.lo = (bits.lo | (this.buf[this.pos] & 127) << i * 7) >>> 0;
989
- if (this.buf[this.pos++] < 128)
990
- return bits;
991
- }
992
- // 5th
993
- bits.lo = (bits.lo | (this.buf[this.pos] & 127) << 28) >>> 0;
994
- bits.hi = (bits.hi | (this.buf[this.pos] & 127) >> 4) >>> 0;
995
- if (this.buf[this.pos++] < 128)
996
- return bits;
997
- i = 0;
998
- } else {
999
- for (; i < 3; ++i) {
1000
- /* istanbul ignore if */
1001
- if (this.pos >= this.len)
1002
- throw indexOutOfRange(this);
1003
- // 1st..3th
1004
- bits.lo = (bits.lo | (this.buf[this.pos] & 127) << i * 7) >>> 0;
1005
- if (this.buf[this.pos++] < 128)
1006
- return bits;
1007
- }
1008
- // 4th
1009
- bits.lo = (bits.lo | (this.buf[this.pos++] & 127) << i * 7) >>> 0;
1010
- return bits;
1011
- }
1012
- if (this.len - this.pos > 4) { // fast route (hi)
1013
- for (; i < 5; ++i) {
1014
- // 6th..10th
1015
- bits.hi = (bits.hi | (this.buf[this.pos] & 127) << i * 7 + 3) >>> 0;
1016
- if (this.buf[this.pos++] < 128)
1017
- return bits;
1018
- }
1019
- } else {
1020
- for (; i < 5; ++i) {
1021
- /* istanbul ignore if */
1022
- if (this.pos >= this.len)
1023
- throw indexOutOfRange(this);
1024
- // 6th..10th
1025
- bits.hi = (bits.hi | (this.buf[this.pos] & 127) << i * 7 + 3) >>> 0;
1026
- if (this.buf[this.pos++] < 128)
1027
- return bits;
1028
- }
1029
- }
1030
- /* istanbul ignore next */
1031
- throw Error("invalid varint encoding");
1032
- }
1033
-
1034
- /* eslint-enable no-invalid-this */
1035
-
1036
- /**
1037
- * Reads a varint as a signed 64 bit value.
1038
- * @name Reader#int64
1039
- * @function
1040
- * @returns {Long} Value read
1041
- */
1042
-
1043
- /**
1044
- * Reads a varint as an unsigned 64 bit value.
1045
- * @name Reader#uint64
1046
- * @function
1047
- * @returns {Long} Value read
1048
- */
1049
-
1050
- /**
1051
- * Reads a zig-zag encoded varint as a signed 64 bit value.
1052
- * @name Reader#sint64
1053
- * @function
1054
- * @returns {Long} Value read
1055
- */
1056
-
1057
- /**
1058
- * Reads a varint as a boolean.
1059
- * @returns {boolean} Value read
1060
- */
1061
- Reader.prototype.bool = function read_bool() {
1062
- return this.uint32() !== 0;
1063
- };
1064
-
1065
- function readFixed32_end(buf, end) { // note that this uses `end`, not `pos`
1066
- return (buf[end - 4]
1067
- | buf[end - 3] << 8
1068
- | buf[end - 2] << 16
1069
- | buf[end - 1] << 24) >>> 0;
1070
- }
1071
-
1072
- /**
1073
- * Reads fixed 32 bits as an unsigned 32 bit integer.
1074
- * @returns {number} Value read
1075
- */
1076
- Reader.prototype.fixed32 = function read_fixed32() {
1077
-
1078
- /* istanbul ignore if */
1079
- if (this.pos + 4 > this.len)
1080
- throw indexOutOfRange(this, 4);
1081
-
1082
- return readFixed32_end(this.buf, this.pos += 4);
1083
- };
1084
-
1085
- /**
1086
- * Reads fixed 32 bits as a signed 32 bit integer.
1087
- * @returns {number} Value read
1088
- */
1089
- Reader.prototype.sfixed32 = function read_sfixed32() {
1090
-
1091
- /* istanbul ignore if */
1092
- if (this.pos + 4 > this.len)
1093
- throw indexOutOfRange(this, 4);
1094
-
1095
- return readFixed32_end(this.buf, this.pos += 4) | 0;
1096
- };
1097
-
1098
- /* eslint-disable no-invalid-this */
1099
-
1100
- function readFixed64(/* this: Reader */) {
1101
-
1102
- /* istanbul ignore if */
1103
- if (this.pos + 8 > this.len)
1104
- throw indexOutOfRange(this, 8);
1105
-
1106
- return new LongBits(readFixed32_end(this.buf, this.pos += 4), readFixed32_end(this.buf, this.pos += 4));
1107
- }
1108
-
1109
- /* eslint-enable no-invalid-this */
1110
-
1111
- /**
1112
- * Reads fixed 64 bits.
1113
- * @name Reader#fixed64
1114
- * @function
1115
- * @returns {Long} Value read
1116
- */
1117
-
1118
- /**
1119
- * Reads zig-zag encoded fixed 64 bits.
1120
- * @name Reader#sfixed64
1121
- * @function
1122
- * @returns {Long} Value read
1123
- */
1124
-
1125
- /**
1126
- * Reads a float (32 bit) as a number.
1127
- * @function
1128
- * @returns {number} Value read
1129
- */
1130
- Reader.prototype.float = function read_float() {
1131
-
1132
- /* istanbul ignore if */
1133
- if (this.pos + 4 > this.len)
1134
- throw indexOutOfRange(this, 4);
1135
-
1136
- var value = util.float.readFloatLE(this.buf, this.pos);
1137
- this.pos += 4;
1138
- return value;
1139
- };
1140
-
1141
- /**
1142
- * Reads a double (64 bit float) as a number.
1143
- * @function
1144
- * @returns {number} Value read
1145
- */
1146
- Reader.prototype.double = function read_double() {
1147
-
1148
- /* istanbul ignore if */
1149
- if (this.pos + 8 > this.len)
1150
- throw indexOutOfRange(this, 4);
1151
-
1152
- var value = util.float.readDoubleLE(this.buf, this.pos);
1153
- this.pos += 8;
1154
- return value;
1155
- };
1156
-
1157
- /**
1158
- * Reads a sequence of bytes preceeded by its length as a varint.
1159
- * @returns {Uint8Array} Value read
1160
- */
1161
- Reader.prototype.bytes = function read_bytes() {
1162
- var length = this.uint32(),
1163
- start = this.pos,
1164
- end = this.pos + length;
1165
-
1166
- /* istanbul ignore if */
1167
- if (end > this.len)
1168
- throw indexOutOfRange(this, length);
1169
-
1170
- this.pos += length;
1171
- if (Array.isArray(this.buf)) // plain array
1172
- return this.buf.slice(start, end);
1173
- return start === end // fix for IE 10/Win8 and others' subarray returning array of size 1
1174
- ? new this.buf.constructor(0)
1175
- : this._slice.call(this.buf, start, end);
1176
- };
1177
-
1178
- /**
1179
- * Reads a string preceeded by its byte length as a varint.
1180
- * @returns {string} Value read
1181
- */
1182
- Reader.prototype.string = function read_string() {
1183
- var bytes = this.bytes();
1184
- return utf8.read(bytes, 0, bytes.length);
1185
- };
1186
-
1187
- /**
1188
- * Skips the specified number of bytes if specified, otherwise skips a varint.
1189
- * @param {number} [length] Length if known, otherwise a varint is assumed
1190
- * @returns {Reader} `this`
1191
- */
1192
- Reader.prototype.skip = function skip(length) {
1193
- if (typeof length === "number") {
1194
- /* istanbul ignore if */
1195
- if (this.pos + length > this.len)
1196
- throw indexOutOfRange(this, length);
1197
- this.pos += length;
1198
- } else {
1199
- do {
1200
- /* istanbul ignore if */
1201
- if (this.pos >= this.len)
1202
- throw indexOutOfRange(this);
1203
- } while (this.buf[this.pos++] & 128);
1204
- }
1205
- return this;
1206
- };
1207
-
1208
- /**
1209
- * Skips the next element of the specified wire type.
1210
- * @param {number} wireType Wire type received
1211
- * @returns {Reader} `this`
1212
- */
1213
- Reader.prototype.skipType = function(wireType) {
1214
- switch (wireType) {
1215
- case 0:
1216
- this.skip();
1217
- break;
1218
- case 1:
1219
- this.skip(8);
1220
- break;
1221
- case 2:
1222
- this.skip(this.uint32());
1223
- break;
1224
- case 3:
1225
- do { // eslint-disable-line no-constant-condition
1226
- if ((wireType = this.uint32() & 7) === 4)
1227
- break;
1228
- this.skipType(wireType);
1229
- } while (true);
1230
- break;
1231
- case 5:
1232
- this.skip(4);
1233
- break;
1234
-
1235
- /* istanbul ignore next */
1236
- default:
1237
- throw Error("invalid wire type " + wireType + " at offset " + this.pos);
1238
- }
1239
- return this;
1240
- };
1241
-
1242
- Reader._configure = function(BufferReader_) {
1243
- BufferReader = BufferReader_;
1244
-
1245
- var fn = util.Long ? "toLong" : /* istanbul ignore next */ "toNumber";
1246
- util.merge(Reader.prototype, {
1247
-
1248
- int64: function read_int64() {
1249
- return readLongVarint.call(this)[fn](false);
1250
- },
1251
-
1252
- uint64: function read_uint64() {
1253
- return readLongVarint.call(this)[fn](true);
1254
- },
1255
-
1256
- sint64: function read_sint64() {
1257
- return readLongVarint.call(this).zzDecode()[fn](false);
1258
- },
1259
-
1260
- fixed64: function read_fixed64() {
1261
- return readFixed64.call(this)[fn](true);
1262
- },
1263
-
1264
- sfixed64: function read_sfixed64() {
1265
- return readFixed64.call(this)[fn](false);
1266
- }
1267
-
1268
- });
1269
- };
865
+ "use strict";
866
+ module.exports = Reader;
1270
867
 
1271
- },{"15":15}],10:[function(require,module,exports){
1272
- "use strict";
1273
- module.exports = BufferReader;
1274
-
1275
- // extends Reader
1276
- var Reader = require(9);
1277
- (BufferReader.prototype = Object.create(Reader.prototype)).constructor = BufferReader;
1278
-
1279
- var util = require(15);
1280
-
1281
- /**
1282
- * Constructs a new buffer reader instance.
1283
- * @classdesc Wire format reader using node buffers.
1284
- * @extends Reader
1285
- * @constructor
1286
- * @param {Buffer} buffer Buffer to read from
1287
- */
1288
- function BufferReader(buffer) {
1289
- Reader.call(this, buffer);
1290
-
1291
- /**
1292
- * Read buffer.
1293
- * @name BufferReader#buf
1294
- * @type {Buffer}
1295
- */
1296
- }
1297
-
1298
- /* istanbul ignore else */
1299
- if (util.Buffer)
1300
- BufferReader.prototype._slice = util.Buffer.prototype.slice;
1301
-
1302
- /**
1303
- * @override
1304
- */
1305
- BufferReader.prototype.string = function read_string_buffer() {
1306
- var len = this.uint32(); // modifies pos
1307
- return this.buf.utf8Slice(this.pos, this.pos = Math.min(this.pos + len, this.len));
1308
- };
1309
-
1310
- /**
1311
- * Reads a sequence of bytes preceeded by its length as a varint.
1312
- * @name BufferReader#bytes
1313
- * @function
1314
- * @returns {Buffer} Value read
1315
- */
868
+ var util = require(15);
1316
869
 
1317
- },{"15":15,"9":9}],11:[function(require,module,exports){
1318
- "use strict";
1319
- module.exports = {};
1320
-
1321
- /**
1322
- * Named roots.
1323
- * This is where pbjs stores generated structures (the option `-r, --root` specifies a name).
1324
- * Can also be used manually to make roots available accross modules.
1325
- * @name roots
1326
- * @type {Object.<string,Root>}
1327
- * @example
1328
- * // pbjs -r myroot -o compiled.js ...
1329
- *
1330
- * // in another module:
1331
- * require("./compiled.js");
1332
- *
1333
- * // in any subsequent module:
1334
- * var root = protobuf.roots["myroot"];
1335
- */
870
+ var BufferReader; // cyclic
1336
871
 
1337
- },{}],12:[function(require,module,exports){
1338
- "use strict";
1339
-
1340
- /**
1341
- * Streaming RPC helpers.
1342
- * @namespace
1343
- */
1344
- var rpc = exports;
1345
-
1346
- /**
1347
- * RPC implementation passed to {@link Service#create} performing a service request on network level, i.e. by utilizing http requests or websockets.
1348
- * @typedef RPCImpl
1349
- * @type {function}
1350
- * @param {Method|rpc.ServiceMethod<Message<{}>,Message<{}>>} method Reflected or static method being called
1351
- * @param {Uint8Array} requestData Request data
1352
- * @param {RPCImplCallback} callback Callback function
1353
- * @returns {undefined}
1354
- * @example
1355
- * function rpcImpl(method, requestData, callback) {
1356
- * if (protobuf.util.lcFirst(method.name) !== "myMethod") // compatible with static code
1357
- * throw Error("no such method");
1358
- * asynchronouslyObtainAResponse(requestData, function(err, responseData) {
1359
- * callback(err, responseData);
1360
- * });
1361
- * }
1362
- */
1363
-
1364
- /**
1365
- * Node-style callback as used by {@link RPCImpl}.
1366
- * @typedef RPCImplCallback
1367
- * @type {function}
1368
- * @param {Error|null} error Error, if any, otherwise `null`
1369
- * @param {Uint8Array|null} [response] Response data or `null` to signal end of stream, if there hasn't been an error
1370
- * @returns {undefined}
1371
- */
1372
-
1373
- rpc.Service = require(13);
872
+ var LongBits = util.LongBits,
873
+ utf8 = util.utf8;
1374
874
 
1375
- },{"13":13}],13:[function(require,module,exports){
1376
- "use strict";
1377
- module.exports = Service;
1378
-
1379
- var util = require(15);
1380
-
1381
- // Extends EventEmitter
1382
- (Service.prototype = Object.create(util.EventEmitter.prototype)).constructor = Service;
1383
-
1384
- /**
1385
- * A service method callback as used by {@link rpc.ServiceMethod|ServiceMethod}.
1386
- *
1387
- * Differs from {@link RPCImplCallback} in that it is an actual callback of a service method which may not return `response = null`.
1388
- * @typedef rpc.ServiceMethodCallback
1389
- * @template TRes extends Message<TRes>
1390
- * @type {function}
1391
- * @param {Error|null} error Error, if any
1392
- * @param {TRes} [response] Response message
1393
- * @returns {undefined}
1394
- */
1395
-
1396
- /**
1397
- * A service method part of a {@link rpc.Service} as created by {@link Service.create}.
1398
- * @typedef rpc.ServiceMethod
1399
- * @template TReq extends Message<TReq>
1400
- * @template TRes extends Message<TRes>
1401
- * @type {function}
1402
- * @param {TReq|Properties<TReq>} request Request message or plain object
1403
- * @param {rpc.ServiceMethodCallback<TRes>} [callback] Node-style callback called with the error, if any, and the response message
1404
- * @returns {Promise<Message<TRes>>} Promise if `callback` has been omitted, otherwise `undefined`
1405
- */
1406
-
1407
- /**
1408
- * Constructs a new RPC service instance.
1409
- * @classdesc An RPC service as returned by {@link Service#create}.
1410
- * @exports rpc.Service
1411
- * @extends util.EventEmitter
1412
- * @constructor
1413
- * @param {RPCImpl} rpcImpl RPC implementation
1414
- * @param {boolean} [requestDelimited=false] Whether requests are length-delimited
1415
- * @param {boolean} [responseDelimited=false] Whether responses are length-delimited
1416
- */
1417
- function Service(rpcImpl, requestDelimited, responseDelimited) {
1418
-
1419
- if (typeof rpcImpl !== "function")
1420
- throw TypeError("rpcImpl must be a function");
1421
-
1422
- util.EventEmitter.call(this);
1423
-
1424
- /**
1425
- * RPC implementation. Becomes `null` once the service is ended.
1426
- * @type {RPCImpl|null}
1427
- */
1428
- this.rpcImpl = rpcImpl;
1429
-
1430
- /**
1431
- * Whether requests are length-delimited.
1432
- * @type {boolean}
1433
- */
1434
- this.requestDelimited = Boolean(requestDelimited);
1435
-
1436
- /**
1437
- * Whether responses are length-delimited.
1438
- * @type {boolean}
1439
- */
1440
- this.responseDelimited = Boolean(responseDelimited);
1441
- }
1442
-
1443
- /**
1444
- * Calls a service method through {@link rpc.Service#rpcImpl|rpcImpl}.
1445
- * @param {Method|rpc.ServiceMethod<TReq,TRes>} method Reflected or static method
1446
- * @param {Constructor<TReq>} requestCtor Request constructor
1447
- * @param {Constructor<TRes>} responseCtor Response constructor
1448
- * @param {TReq|Properties<TReq>} request Request message or plain object
1449
- * @param {rpc.ServiceMethodCallback<TRes>} callback Service callback
1450
- * @returns {undefined}
1451
- * @template TReq extends Message<TReq>
1452
- * @template TRes extends Message<TRes>
1453
- */
1454
- Service.prototype.rpcCall = function rpcCall(method, requestCtor, responseCtor, request, callback) {
1455
-
1456
- if (!request)
1457
- throw TypeError("request must be specified");
1458
-
1459
- var self = this;
1460
- if (!callback)
1461
- return util.asPromise(rpcCall, self, method, requestCtor, responseCtor, request);
1462
-
1463
- if (!self.rpcImpl) {
1464
- setTimeout(function() { callback(Error("already ended")); }, 0);
1465
- return undefined;
1466
- }
1467
-
1468
- try {
1469
- return self.rpcImpl(
1470
- method,
1471
- requestCtor[self.requestDelimited ? "encodeDelimited" : "encode"](request).finish(),
1472
- function rpcCallback(err, response) {
1473
-
1474
- if (err) {
1475
- self.emit("error", err, method);
1476
- return callback(err);
1477
- }
1478
-
1479
- if (response === null) {
1480
- self.end(/* endedByRPC */ true);
1481
- return undefined;
1482
- }
1483
-
1484
- if (!(response instanceof responseCtor)) {
1485
- try {
1486
- response = responseCtor[self.responseDelimited ? "decodeDelimited" : "decode"](response);
1487
- } catch (err) {
1488
- self.emit("error", err, method);
1489
- return callback(err);
1490
- }
1491
- }
1492
-
1493
- self.emit("data", response, method);
1494
- return callback(null, response);
1495
- }
1496
- );
1497
- } catch (err) {
1498
- self.emit("error", err, method);
1499
- setTimeout(function() { callback(err); }, 0);
1500
- return undefined;
1501
- }
1502
- };
1503
-
1504
- /**
1505
- * Ends this service and emits the `end` event.
1506
- * @param {boolean} [endedByRPC=false] Whether the service has been ended by the RPC implementation.
1507
- * @returns {rpc.Service} `this`
1508
- */
1509
- Service.prototype.end = function end(endedByRPC) {
1510
- if (this.rpcImpl) {
1511
- if (!endedByRPC) // signal end to rpcImpl
1512
- this.rpcImpl(null, null, null);
1513
- this.rpcImpl = null;
1514
- this.emit("end").off();
1515
- }
1516
- return this;
1517
- };
875
+ /* istanbul ignore next */
876
+ function indexOutOfRange(reader, writeLength) {
877
+ return RangeError("index out of range: " + reader.pos + " + " + (writeLength || 1) + " > " + reader.len);
878
+ }
879
+
880
+ /**
881
+ * Constructs a new reader instance using the specified buffer.
882
+ * @classdesc Wire format reader using `Uint8Array` if available, otherwise `Array`.
883
+ * @constructor
884
+ * @param {Uint8Array} buffer Buffer to read from
885
+ */
886
+ function Reader(buffer) {
887
+
888
+ /**
889
+ * Read buffer.
890
+ * @type {Uint8Array}
891
+ */
892
+ this.buf = buffer;
893
+
894
+ /**
895
+ * Read buffer position.
896
+ * @type {number}
897
+ */
898
+ this.pos = 0;
899
+
900
+ /**
901
+ * Read buffer length.
902
+ * @type {number}
903
+ */
904
+ this.len = buffer.length;
905
+ }
906
+
907
+ var create_array = typeof Uint8Array !== "undefined"
908
+ ? function create_typed_array(buffer) {
909
+ if (buffer instanceof Uint8Array || Array.isArray(buffer))
910
+ return new Reader(buffer);
911
+ throw Error("illegal buffer");
912
+ }
913
+ /* istanbul ignore next */
914
+ : function create_array(buffer) {
915
+ if (Array.isArray(buffer))
916
+ return new Reader(buffer);
917
+ throw Error("illegal buffer");
918
+ };
919
+
920
+ /**
921
+ * Creates a new reader using the specified buffer.
922
+ * @function
923
+ * @param {Uint8Array|Buffer} buffer Buffer to read from
924
+ * @returns {Reader|BufferReader} A {@link BufferReader} if `buffer` is a Buffer, otherwise a {@link Reader}
925
+ * @throws {Error} If `buffer` is not a valid buffer
926
+ */
927
+ Reader.create = util.Buffer
928
+ ? function create_buffer_setup(buffer) {
929
+ return (Reader.create = function create_buffer(buffer) {
930
+ return util.Buffer.isBuffer(buffer)
931
+ ? new BufferReader(buffer)
932
+ /* istanbul ignore next */
933
+ : create_array(buffer);
934
+ })(buffer);
935
+ }
936
+ /* istanbul ignore next */
937
+ : create_array;
938
+
939
+ Reader.prototype._slice = util.Array.prototype.subarray || /* istanbul ignore next */ util.Array.prototype.slice;
940
+
941
+ /**
942
+ * Reads a varint as an unsigned 32 bit value.
943
+ * @function
944
+ * @returns {number} Value read
945
+ */
946
+ Reader.prototype.uint32 = (function read_uint32_setup() {
947
+ var value = 4294967295; // optimizer type-hint, tends to deopt otherwise (?!)
948
+ return function read_uint32() {
949
+ value = ( this.buf[this.pos] & 127 ) >>> 0; if (this.buf[this.pos++] < 128) return value;
950
+ value = (value | (this.buf[this.pos] & 127) << 7) >>> 0; if (this.buf[this.pos++] < 128) return value;
951
+ value = (value | (this.buf[this.pos] & 127) << 14) >>> 0; if (this.buf[this.pos++] < 128) return value;
952
+ value = (value | (this.buf[this.pos] & 127) << 21) >>> 0; if (this.buf[this.pos++] < 128) return value;
953
+ value = (value | (this.buf[this.pos] & 15) << 28) >>> 0; if (this.buf[this.pos++] < 128) return value;
954
+
955
+ /* istanbul ignore if */
956
+ if ((this.pos += 5) > this.len) {
957
+ this.pos = this.len;
958
+ throw indexOutOfRange(this, 10);
959
+ }
960
+ return value;
961
+ };
962
+ })();
963
+
964
+ /**
965
+ * Reads a varint as a signed 32 bit value.
966
+ * @returns {number} Value read
967
+ */
968
+ Reader.prototype.int32 = function read_int32() {
969
+ return this.uint32() | 0;
970
+ };
971
+
972
+ /**
973
+ * Reads a zig-zag encoded varint as a signed 32 bit value.
974
+ * @returns {number} Value read
975
+ */
976
+ Reader.prototype.sint32 = function read_sint32() {
977
+ var value = this.uint32();
978
+ return value >>> 1 ^ -(value & 1) | 0;
979
+ };
980
+
981
+ /* eslint-disable no-invalid-this */
982
+
983
+ function readLongVarint() {
984
+ // tends to deopt with local vars for octet etc.
985
+ var bits = new LongBits(0, 0);
986
+ var i = 0;
987
+ if (this.len - this.pos > 4) { // fast route (lo)
988
+ for (; i < 4; ++i) {
989
+ // 1st..4th
990
+ bits.lo = (bits.lo | (this.buf[this.pos] & 127) << i * 7) >>> 0;
991
+ if (this.buf[this.pos++] < 128)
992
+ return bits;
993
+ }
994
+ // 5th
995
+ bits.lo = (bits.lo | (this.buf[this.pos] & 127) << 28) >>> 0;
996
+ bits.hi = (bits.hi | (this.buf[this.pos] & 127) >> 4) >>> 0;
997
+ if (this.buf[this.pos++] < 128)
998
+ return bits;
999
+ i = 0;
1000
+ } else {
1001
+ for (; i < 3; ++i) {
1002
+ /* istanbul ignore if */
1003
+ if (this.pos >= this.len)
1004
+ throw indexOutOfRange(this);
1005
+ // 1st..3th
1006
+ bits.lo = (bits.lo | (this.buf[this.pos] & 127) << i * 7) >>> 0;
1007
+ if (this.buf[this.pos++] < 128)
1008
+ return bits;
1009
+ }
1010
+ // 4th
1011
+ bits.lo = (bits.lo | (this.buf[this.pos++] & 127) << i * 7) >>> 0;
1012
+ return bits;
1013
+ }
1014
+ if (this.len - this.pos > 4) { // fast route (hi)
1015
+ for (; i < 5; ++i) {
1016
+ // 6th..10th
1017
+ bits.hi = (bits.hi | (this.buf[this.pos] & 127) << i * 7 + 3) >>> 0;
1018
+ if (this.buf[this.pos++] < 128)
1019
+ return bits;
1020
+ }
1021
+ } else {
1022
+ for (; i < 5; ++i) {
1023
+ /* istanbul ignore if */
1024
+ if (this.pos >= this.len)
1025
+ throw indexOutOfRange(this);
1026
+ // 6th..10th
1027
+ bits.hi = (bits.hi | (this.buf[this.pos] & 127) << i * 7 + 3) >>> 0;
1028
+ if (this.buf[this.pos++] < 128)
1029
+ return bits;
1030
+ }
1031
+ }
1032
+ /* istanbul ignore next */
1033
+ throw Error("invalid varint encoding");
1034
+ }
1035
+
1036
+ /* eslint-enable no-invalid-this */
1037
+
1038
+ /**
1039
+ * Reads a varint as a signed 64 bit value.
1040
+ * @name Reader#int64
1041
+ * @function
1042
+ * @returns {Long} Value read
1043
+ */
1044
+
1045
+ /**
1046
+ * Reads a varint as an unsigned 64 bit value.
1047
+ * @name Reader#uint64
1048
+ * @function
1049
+ * @returns {Long} Value read
1050
+ */
1051
+
1052
+ /**
1053
+ * Reads a zig-zag encoded varint as a signed 64 bit value.
1054
+ * @name Reader#sint64
1055
+ * @function
1056
+ * @returns {Long} Value read
1057
+ */
1058
+
1059
+ /**
1060
+ * Reads a varint as a boolean.
1061
+ * @returns {boolean} Value read
1062
+ */
1063
+ Reader.prototype.bool = function read_bool() {
1064
+ return this.uint32() !== 0;
1065
+ };
1066
+
1067
+ function readFixed32_end(buf, end) { // note that this uses `end`, not `pos`
1068
+ return (buf[end - 4]
1069
+ | buf[end - 3] << 8
1070
+ | buf[end - 2] << 16
1071
+ | buf[end - 1] << 24) >>> 0;
1072
+ }
1073
+
1074
+ /**
1075
+ * Reads fixed 32 bits as an unsigned 32 bit integer.
1076
+ * @returns {number} Value read
1077
+ */
1078
+ Reader.prototype.fixed32 = function read_fixed32() {
1079
+
1080
+ /* istanbul ignore if */
1081
+ if (this.pos + 4 > this.len)
1082
+ throw indexOutOfRange(this, 4);
1083
+
1084
+ return readFixed32_end(this.buf, this.pos += 4);
1085
+ };
1086
+
1087
+ /**
1088
+ * Reads fixed 32 bits as a signed 32 bit integer.
1089
+ * @returns {number} Value read
1090
+ */
1091
+ Reader.prototype.sfixed32 = function read_sfixed32() {
1092
+
1093
+ /* istanbul ignore if */
1094
+ if (this.pos + 4 > this.len)
1095
+ throw indexOutOfRange(this, 4);
1096
+
1097
+ return readFixed32_end(this.buf, this.pos += 4) | 0;
1098
+ };
1099
+
1100
+ /* eslint-disable no-invalid-this */
1101
+
1102
+ function readFixed64(/* this: Reader */) {
1103
+
1104
+ /* istanbul ignore if */
1105
+ if (this.pos + 8 > this.len)
1106
+ throw indexOutOfRange(this, 8);
1107
+
1108
+ return new LongBits(readFixed32_end(this.buf, this.pos += 4), readFixed32_end(this.buf, this.pos += 4));
1109
+ }
1110
+
1111
+ /* eslint-enable no-invalid-this */
1112
+
1113
+ /**
1114
+ * Reads fixed 64 bits.
1115
+ * @name Reader#fixed64
1116
+ * @function
1117
+ * @returns {Long} Value read
1118
+ */
1119
+
1120
+ /**
1121
+ * Reads zig-zag encoded fixed 64 bits.
1122
+ * @name Reader#sfixed64
1123
+ * @function
1124
+ * @returns {Long} Value read
1125
+ */
1126
+
1127
+ /**
1128
+ * Reads a float (32 bit) as a number.
1129
+ * @function
1130
+ * @returns {number} Value read
1131
+ */
1132
+ Reader.prototype.float = function read_float() {
1133
+
1134
+ /* istanbul ignore if */
1135
+ if (this.pos + 4 > this.len)
1136
+ throw indexOutOfRange(this, 4);
1137
+
1138
+ var value = util.float.readFloatLE(this.buf, this.pos);
1139
+ this.pos += 4;
1140
+ return value;
1141
+ };
1142
+
1143
+ /**
1144
+ * Reads a double (64 bit float) as a number.
1145
+ * @function
1146
+ * @returns {number} Value read
1147
+ */
1148
+ Reader.prototype.double = function read_double() {
1149
+
1150
+ /* istanbul ignore if */
1151
+ if (this.pos + 8 > this.len)
1152
+ throw indexOutOfRange(this, 4);
1153
+
1154
+ var value = util.float.readDoubleLE(this.buf, this.pos);
1155
+ this.pos += 8;
1156
+ return value;
1157
+ };
1158
+
1159
+ /**
1160
+ * Reads a sequence of bytes preceeded by its length as a varint.
1161
+ * @returns {Uint8Array} Value read
1162
+ */
1163
+ Reader.prototype.bytes = function read_bytes() {
1164
+ var length = this.uint32(),
1165
+ start = this.pos,
1166
+ end = this.pos + length;
1167
+
1168
+ /* istanbul ignore if */
1169
+ if (end > this.len)
1170
+ throw indexOutOfRange(this, length);
1171
+
1172
+ this.pos += length;
1173
+ if (Array.isArray(this.buf)) // plain array
1174
+ return this.buf.slice(start, end);
1175
+ return start === end // fix for IE 10/Win8 and others' subarray returning array of size 1
1176
+ ? new this.buf.constructor(0)
1177
+ : this._slice.call(this.buf, start, end);
1178
+ };
1179
+
1180
+ /**
1181
+ * Reads a string preceeded by its byte length as a varint.
1182
+ * @returns {string} Value read
1183
+ */
1184
+ Reader.prototype.string = function read_string() {
1185
+ var bytes = this.bytes();
1186
+ return utf8.read(bytes, 0, bytes.length);
1187
+ };
1188
+
1189
+ /**
1190
+ * Skips the specified number of bytes if specified, otherwise skips a varint.
1191
+ * @param {number} [length] Length if known, otherwise a varint is assumed
1192
+ * @returns {Reader} `this`
1193
+ */
1194
+ Reader.prototype.skip = function skip(length) {
1195
+ if (typeof length === "number") {
1196
+ /* istanbul ignore if */
1197
+ if (this.pos + length > this.len)
1198
+ throw indexOutOfRange(this, length);
1199
+ this.pos += length;
1200
+ } else {
1201
+ do {
1202
+ /* istanbul ignore if */
1203
+ if (this.pos >= this.len)
1204
+ throw indexOutOfRange(this);
1205
+ } while (this.buf[this.pos++] & 128);
1206
+ }
1207
+ return this;
1208
+ };
1209
+
1210
+ /**
1211
+ * Skips the next element of the specified wire type.
1212
+ * @param {number} wireType Wire type received
1213
+ * @returns {Reader} `this`
1214
+ */
1215
+ Reader.prototype.skipType = function(wireType) {
1216
+ switch (wireType) {
1217
+ case 0:
1218
+ this.skip();
1219
+ break;
1220
+ case 1:
1221
+ this.skip(8);
1222
+ break;
1223
+ case 2:
1224
+ this.skip(this.uint32());
1225
+ break;
1226
+ case 3:
1227
+ while ((wireType = this.uint32() & 7) !== 4) {
1228
+ this.skipType(wireType);
1229
+ }
1230
+ break;
1231
+ case 5:
1232
+ this.skip(4);
1233
+ break;
1234
+
1235
+ /* istanbul ignore next */
1236
+ default:
1237
+ throw Error("invalid wire type " + wireType + " at offset " + this.pos);
1238
+ }
1239
+ return this;
1240
+ };
1241
+
1242
+ Reader._configure = function(BufferReader_) {
1243
+ BufferReader = BufferReader_;
1244
+
1245
+ var fn = util.Long ? "toLong" : /* istanbul ignore next */ "toNumber";
1246
+ util.merge(Reader.prototype, {
1247
+
1248
+ int64: function read_int64() {
1249
+ return readLongVarint.call(this)[fn](false);
1250
+ },
1251
+
1252
+ uint64: function read_uint64() {
1253
+ return readLongVarint.call(this)[fn](true);
1254
+ },
1255
+
1256
+ sint64: function read_sint64() {
1257
+ return readLongVarint.call(this).zzDecode()[fn](false);
1258
+ },
1259
+
1260
+ fixed64: function read_fixed64() {
1261
+ return readFixed64.call(this)[fn](true);
1262
+ },
1263
+
1264
+ sfixed64: function read_sfixed64() {
1265
+ return readFixed64.call(this)[fn](false);
1266
+ }
1267
+
1268
+ });
1269
+ };
1270
+
1271
+ },{"15":15}],10:[function(require,module,exports){
1272
+ "use strict";
1273
+ module.exports = BufferReader;
1274
+
1275
+ // extends Reader
1276
+ var Reader = require(9);
1277
+ (BufferReader.prototype = Object.create(Reader.prototype)).constructor = BufferReader;
1278
+
1279
+ var util = require(15);
1280
+
1281
+ /**
1282
+ * Constructs a new buffer reader instance.
1283
+ * @classdesc Wire format reader using node buffers.
1284
+ * @extends Reader
1285
+ * @constructor
1286
+ * @param {Buffer} buffer Buffer to read from
1287
+ */
1288
+ function BufferReader(buffer) {
1289
+ Reader.call(this, buffer);
1290
+
1291
+ /**
1292
+ * Read buffer.
1293
+ * @name BufferReader#buf
1294
+ * @type {Buffer}
1295
+ */
1296
+ }
1297
+
1298
+ /* istanbul ignore else */
1299
+ if (util.Buffer)
1300
+ BufferReader.prototype._slice = util.Buffer.prototype.slice;
1301
+
1302
+ /**
1303
+ * @override
1304
+ */
1305
+ BufferReader.prototype.string = function read_string_buffer() {
1306
+ var len = this.uint32(); // modifies pos
1307
+ return this.buf.utf8Slice(this.pos, this.pos = Math.min(this.pos + len, this.len));
1308
+ };
1309
+
1310
+ /**
1311
+ * Reads a sequence of bytes preceeded by its length as a varint.
1312
+ * @name BufferReader#bytes
1313
+ * @function
1314
+ * @returns {Buffer} Value read
1315
+ */
1316
+
1317
+ },{"15":15,"9":9}],11:[function(require,module,exports){
1318
+ "use strict";
1319
+ module.exports = {};
1320
+
1321
+ /**
1322
+ * Named roots.
1323
+ * This is where pbjs stores generated structures (the option `-r, --root` specifies a name).
1324
+ * Can also be used manually to make roots available accross modules.
1325
+ * @name roots
1326
+ * @type {Object.<string,Root>}
1327
+ * @example
1328
+ * // pbjs -r myroot -o compiled.js ...
1329
+ *
1330
+ * // in another module:
1331
+ * require("./compiled.js");
1332
+ *
1333
+ * // in any subsequent module:
1334
+ * var root = protobuf.roots["myroot"];
1335
+ */
1336
+
1337
+ },{}],12:[function(require,module,exports){
1338
+ "use strict";
1339
+
1340
+ /**
1341
+ * Streaming RPC helpers.
1342
+ * @namespace
1343
+ */
1344
+ var rpc = exports;
1345
+
1346
+ /**
1347
+ * RPC implementation passed to {@link Service#create} performing a service request on network level, i.e. by utilizing http requests or websockets.
1348
+ * @typedef RPCImpl
1349
+ * @type {function}
1350
+ * @param {Method|rpc.ServiceMethod<Message<{}>,Message<{}>>} method Reflected or static method being called
1351
+ * @param {Uint8Array} requestData Request data
1352
+ * @param {RPCImplCallback} callback Callback function
1353
+ * @returns {undefined}
1354
+ * @example
1355
+ * function rpcImpl(method, requestData, callback) {
1356
+ * if (protobuf.util.lcFirst(method.name) !== "myMethod") // compatible with static code
1357
+ * throw Error("no such method");
1358
+ * asynchronouslyObtainAResponse(requestData, function(err, responseData) {
1359
+ * callback(err, responseData);
1360
+ * });
1361
+ * }
1362
+ */
1363
+
1364
+ /**
1365
+ * Node-style callback as used by {@link RPCImpl}.
1366
+ * @typedef RPCImplCallback
1367
+ * @type {function}
1368
+ * @param {Error|null} error Error, if any, otherwise `null`
1369
+ * @param {Uint8Array|null} [response] Response data or `null` to signal end of stream, if there hasn't been an error
1370
+ * @returns {undefined}
1371
+ */
1372
+
1373
+ rpc.Service = require(13);
1374
+
1375
+ },{"13":13}],13:[function(require,module,exports){
1376
+ "use strict";
1377
+ module.exports = Service;
1378
+
1379
+ var util = require(15);
1380
+
1381
+ // Extends EventEmitter
1382
+ (Service.prototype = Object.create(util.EventEmitter.prototype)).constructor = Service;
1383
+
1384
+ /**
1385
+ * A service method callback as used by {@link rpc.ServiceMethod|ServiceMethod}.
1386
+ *
1387
+ * Differs from {@link RPCImplCallback} in that it is an actual callback of a service method which may not return `response = null`.
1388
+ * @typedef rpc.ServiceMethodCallback
1389
+ * @template TRes extends Message<TRes>
1390
+ * @type {function}
1391
+ * @param {Error|null} error Error, if any
1392
+ * @param {TRes} [response] Response message
1393
+ * @returns {undefined}
1394
+ */
1395
+
1396
+ /**
1397
+ * A service method part of a {@link rpc.Service} as created by {@link Service.create}.
1398
+ * @typedef rpc.ServiceMethod
1399
+ * @template TReq extends Message<TReq>
1400
+ * @template TRes extends Message<TRes>
1401
+ * @type {function}
1402
+ * @param {TReq|Properties<TReq>} request Request message or plain object
1403
+ * @param {rpc.ServiceMethodCallback<TRes>} [callback] Node-style callback called with the error, if any, and the response message
1404
+ * @returns {Promise<Message<TRes>>} Promise if `callback` has been omitted, otherwise `undefined`
1405
+ */
1406
+
1407
+ /**
1408
+ * Constructs a new RPC service instance.
1409
+ * @classdesc An RPC service as returned by {@link Service#create}.
1410
+ * @exports rpc.Service
1411
+ * @extends util.EventEmitter
1412
+ * @constructor
1413
+ * @param {RPCImpl} rpcImpl RPC implementation
1414
+ * @param {boolean} [requestDelimited=false] Whether requests are length-delimited
1415
+ * @param {boolean} [responseDelimited=false] Whether responses are length-delimited
1416
+ */
1417
+ function Service(rpcImpl, requestDelimited, responseDelimited) {
1418
+
1419
+ if (typeof rpcImpl !== "function")
1420
+ throw TypeError("rpcImpl must be a function");
1421
+
1422
+ util.EventEmitter.call(this);
1423
+
1424
+ /**
1425
+ * RPC implementation. Becomes `null` once the service is ended.
1426
+ * @type {RPCImpl|null}
1427
+ */
1428
+ this.rpcImpl = rpcImpl;
1429
+
1430
+ /**
1431
+ * Whether requests are length-delimited.
1432
+ * @type {boolean}
1433
+ */
1434
+ this.requestDelimited = Boolean(requestDelimited);
1435
+
1436
+ /**
1437
+ * Whether responses are length-delimited.
1438
+ * @type {boolean}
1439
+ */
1440
+ this.responseDelimited = Boolean(responseDelimited);
1441
+ }
1442
+
1443
+ /**
1444
+ * Calls a service method through {@link rpc.Service#rpcImpl|rpcImpl}.
1445
+ * @param {Method|rpc.ServiceMethod<TReq,TRes>} method Reflected or static method
1446
+ * @param {Constructor<TReq>} requestCtor Request constructor
1447
+ * @param {Constructor<TRes>} responseCtor Response constructor
1448
+ * @param {TReq|Properties<TReq>} request Request message or plain object
1449
+ * @param {rpc.ServiceMethodCallback<TRes>} callback Service callback
1450
+ * @returns {undefined}
1451
+ * @template TReq extends Message<TReq>
1452
+ * @template TRes extends Message<TRes>
1453
+ */
1454
+ Service.prototype.rpcCall = function rpcCall(method, requestCtor, responseCtor, request, callback) {
1455
+
1456
+ if (!request)
1457
+ throw TypeError("request must be specified");
1458
+
1459
+ var self = this;
1460
+ if (!callback)
1461
+ return util.asPromise(rpcCall, self, method, requestCtor, responseCtor, request);
1462
+
1463
+ if (!self.rpcImpl) {
1464
+ setTimeout(function() { callback(Error("already ended")); }, 0);
1465
+ return undefined;
1466
+ }
1467
+
1468
+ try {
1469
+ return self.rpcImpl(
1470
+ method,
1471
+ requestCtor[self.requestDelimited ? "encodeDelimited" : "encode"](request).finish(),
1472
+ function rpcCallback(err, response) {
1473
+
1474
+ if (err) {
1475
+ self.emit("error", err, method);
1476
+ return callback(err);
1477
+ }
1478
+
1479
+ if (response === null) {
1480
+ self.end(/* endedByRPC */ true);
1481
+ return undefined;
1482
+ }
1483
+
1484
+ if (!(response instanceof responseCtor)) {
1485
+ try {
1486
+ response = responseCtor[self.responseDelimited ? "decodeDelimited" : "decode"](response);
1487
+ } catch (err) {
1488
+ self.emit("error", err, method);
1489
+ return callback(err);
1490
+ }
1491
+ }
1492
+
1493
+ self.emit("data", response, method);
1494
+ return callback(null, response);
1495
+ }
1496
+ );
1497
+ } catch (err) {
1498
+ self.emit("error", err, method);
1499
+ setTimeout(function() { callback(err); }, 0);
1500
+ return undefined;
1501
+ }
1502
+ };
1503
+
1504
+ /**
1505
+ * Ends this service and emits the `end` event.
1506
+ * @param {boolean} [endedByRPC=false] Whether the service has been ended by the RPC implementation.
1507
+ * @returns {rpc.Service} `this`
1508
+ */
1509
+ Service.prototype.end = function end(endedByRPC) {
1510
+ if (this.rpcImpl) {
1511
+ if (!endedByRPC) // signal end to rpcImpl
1512
+ this.rpcImpl(null, null, null);
1513
+ this.rpcImpl = null;
1514
+ this.emit("end").off();
1515
+ }
1516
+ return this;
1517
+ };
1518
1518
 
1519
1519
  },{"15":15}],14:[function(require,module,exports){
1520
- "use strict";
1521
- module.exports = LongBits;
1522
-
1523
- var util = require(15);
1524
-
1525
- /**
1526
- * Constructs new long bits.
1527
- * @classdesc Helper class for working with the low and high bits of a 64 bit value.
1528
- * @memberof util
1529
- * @constructor
1530
- * @param {number} lo Low 32 bits, unsigned
1531
- * @param {number} hi High 32 bits, unsigned
1532
- */
1533
- function LongBits(lo, hi) {
1534
-
1535
- // note that the casts below are theoretically unnecessary as of today, but older statically
1536
- // generated converter code might still call the ctor with signed 32bits. kept for compat.
1537
-
1538
- /**
1539
- * Low bits.
1540
- * @type {number}
1541
- */
1542
- this.lo = lo >>> 0;
1543
-
1544
- /**
1545
- * High bits.
1546
- * @type {number}
1547
- */
1548
- this.hi = hi >>> 0;
1549
- }
1550
-
1551
- /**
1552
- * Zero bits.
1553
- * @memberof util.LongBits
1554
- * @type {util.LongBits}
1555
- */
1556
- var zero = LongBits.zero = new LongBits(0, 0);
1557
-
1558
- zero.toNumber = function() { return 0; };
1559
- zero.zzEncode = zero.zzDecode = function() { return this; };
1560
- zero.length = function() { return 1; };
1561
-
1562
- /**
1563
- * Zero hash.
1564
- * @memberof util.LongBits
1565
- * @type {string}
1566
- */
1567
- var zeroHash = LongBits.zeroHash = "\0\0\0\0\0\0\0\0";
1568
-
1569
- /**
1570
- * Constructs new long bits from the specified number.
1571
- * @param {number} value Value
1572
- * @returns {util.LongBits} Instance
1573
- */
1574
- LongBits.fromNumber = function fromNumber(value) {
1575
- if (value === 0)
1576
- return zero;
1577
- var sign = value < 0;
1578
- if (sign)
1579
- value = -value;
1580
- var lo = value >>> 0,
1581
- hi = (value - lo) / 4294967296 >>> 0;
1582
- if (sign) {
1583
- hi = ~hi >>> 0;
1584
- lo = ~lo >>> 0;
1585
- if (++lo > 4294967295) {
1586
- lo = 0;
1587
- if (++hi > 4294967295)
1588
- hi = 0;
1589
- }
1590
- }
1591
- return new LongBits(lo, hi);
1592
- };
1593
-
1594
- /**
1595
- * Constructs new long bits from a number, long or string.
1596
- * @param {Long|number|string} value Value
1597
- * @returns {util.LongBits} Instance
1598
- */
1599
- LongBits.from = function from(value) {
1600
- if (typeof value === "number")
1601
- return LongBits.fromNumber(value);
1602
- if (util.isString(value)) {
1603
- /* istanbul ignore else */
1604
- if (util.Long)
1605
- value = util.Long.fromString(value);
1606
- else
1607
- return LongBits.fromNumber(parseInt(value, 10));
1608
- }
1609
- return value.low || value.high ? new LongBits(value.low >>> 0, value.high >>> 0) : zero;
1610
- };
1611
-
1612
- /**
1613
- * Converts this long bits to a possibly unsafe JavaScript number.
1614
- * @param {boolean} [unsigned=false] Whether unsigned or not
1615
- * @returns {number} Possibly unsafe number
1616
- */
1617
- LongBits.prototype.toNumber = function toNumber(unsigned) {
1618
- if (!unsigned && this.hi >>> 31) {
1619
- var lo = ~this.lo + 1 >>> 0,
1620
- hi = ~this.hi >>> 0;
1621
- if (!lo)
1622
- hi = hi + 1 >>> 0;
1623
- return -(lo + hi * 4294967296);
1624
- }
1625
- return this.lo + this.hi * 4294967296;
1626
- };
1627
-
1628
- /**
1629
- * Converts this long bits to a long.
1630
- * @param {boolean} [unsigned=false] Whether unsigned or not
1631
- * @returns {Long} Long
1632
- */
1633
- LongBits.prototype.toLong = function toLong(unsigned) {
1634
- return util.Long
1635
- ? new util.Long(this.lo | 0, this.hi | 0, Boolean(unsigned))
1636
- /* istanbul ignore next */
1637
- : { low: this.lo | 0, high: this.hi | 0, unsigned: Boolean(unsigned) };
1638
- };
1639
-
1640
- var charCodeAt = String.prototype.charCodeAt;
1641
-
1642
- /**
1643
- * Constructs new long bits from the specified 8 characters long hash.
1644
- * @param {string} hash Hash
1645
- * @returns {util.LongBits} Bits
1646
- */
1647
- LongBits.fromHash = function fromHash(hash) {
1648
- if (hash === zeroHash)
1649
- return zero;
1650
- return new LongBits(
1651
- ( charCodeAt.call(hash, 0)
1652
- | charCodeAt.call(hash, 1) << 8
1653
- | charCodeAt.call(hash, 2) << 16
1654
- | charCodeAt.call(hash, 3) << 24) >>> 0
1655
- ,
1656
- ( charCodeAt.call(hash, 4)
1657
- | charCodeAt.call(hash, 5) << 8
1658
- | charCodeAt.call(hash, 6) << 16
1659
- | charCodeAt.call(hash, 7) << 24) >>> 0
1660
- );
1661
- };
1662
-
1663
- /**
1664
- * Converts this long bits to a 8 characters long hash.
1665
- * @returns {string} Hash
1666
- */
1667
- LongBits.prototype.toHash = function toHash() {
1668
- return String.fromCharCode(
1669
- this.lo & 255,
1670
- this.lo >>> 8 & 255,
1671
- this.lo >>> 16 & 255,
1672
- this.lo >>> 24 ,
1673
- this.hi & 255,
1674
- this.hi >>> 8 & 255,
1675
- this.hi >>> 16 & 255,
1676
- this.hi >>> 24
1677
- );
1678
- };
1679
-
1680
- /**
1681
- * Zig-zag encodes this long bits.
1682
- * @returns {util.LongBits} `this`
1683
- */
1684
- LongBits.prototype.zzEncode = function zzEncode() {
1685
- var mask = this.hi >> 31;
1686
- this.hi = ((this.hi << 1 | this.lo >>> 31) ^ mask) >>> 0;
1687
- this.lo = ( this.lo << 1 ^ mask) >>> 0;
1688
- return this;
1689
- };
1690
-
1691
- /**
1692
- * Zig-zag decodes this long bits.
1693
- * @returns {util.LongBits} `this`
1694
- */
1695
- LongBits.prototype.zzDecode = function zzDecode() {
1696
- var mask = -(this.lo & 1);
1697
- this.lo = ((this.lo >>> 1 | this.hi << 31) ^ mask) >>> 0;
1698
- this.hi = ( this.hi >>> 1 ^ mask) >>> 0;
1699
- return this;
1700
- };
1701
-
1702
- /**
1703
- * Calculates the length of this longbits when encoded as a varint.
1704
- * @returns {number} Length
1705
- */
1706
- LongBits.prototype.length = function length() {
1707
- var part0 = this.lo,
1708
- part1 = (this.lo >>> 28 | this.hi << 4) >>> 0,
1709
- part2 = this.hi >>> 24;
1710
- return part2 === 0
1711
- ? part1 === 0
1712
- ? part0 < 16384
1713
- ? part0 < 128 ? 1 : 2
1714
- : part0 < 2097152 ? 3 : 4
1715
- : part1 < 16384
1716
- ? part1 < 128 ? 5 : 6
1717
- : part1 < 2097152 ? 7 : 8
1718
- : part2 < 128 ? 9 : 10;
1719
- };
1520
+ "use strict";
1521
+ module.exports = LongBits;
1522
+
1523
+ var util = require(15);
1524
+
1525
+ /**
1526
+ * Constructs new long bits.
1527
+ * @classdesc Helper class for working with the low and high bits of a 64 bit value.
1528
+ * @memberof util
1529
+ * @constructor
1530
+ * @param {number} lo Low 32 bits, unsigned
1531
+ * @param {number} hi High 32 bits, unsigned
1532
+ */
1533
+ function LongBits(lo, hi) {
1534
+
1535
+ // note that the casts below are theoretically unnecessary as of today, but older statically
1536
+ // generated converter code might still call the ctor with signed 32bits. kept for compat.
1537
+
1538
+ /**
1539
+ * Low bits.
1540
+ * @type {number}
1541
+ */
1542
+ this.lo = lo >>> 0;
1543
+
1544
+ /**
1545
+ * High bits.
1546
+ * @type {number}
1547
+ */
1548
+ this.hi = hi >>> 0;
1549
+ }
1550
+
1551
+ /**
1552
+ * Zero bits.
1553
+ * @memberof util.LongBits
1554
+ * @type {util.LongBits}
1555
+ */
1556
+ var zero = LongBits.zero = new LongBits(0, 0);
1557
+
1558
+ zero.toNumber = function() { return 0; };
1559
+ zero.zzEncode = zero.zzDecode = function() { return this; };
1560
+ zero.length = function() { return 1; };
1561
+
1562
+ /**
1563
+ * Zero hash.
1564
+ * @memberof util.LongBits
1565
+ * @type {string}
1566
+ */
1567
+ var zeroHash = LongBits.zeroHash = "\0\0\0\0\0\0\0\0";
1568
+
1569
+ /**
1570
+ * Constructs new long bits from the specified number.
1571
+ * @param {number} value Value
1572
+ * @returns {util.LongBits} Instance
1573
+ */
1574
+ LongBits.fromNumber = function fromNumber(value) {
1575
+ if (value === 0)
1576
+ return zero;
1577
+ var sign = value < 0;
1578
+ if (sign)
1579
+ value = -value;
1580
+ var lo = value >>> 0,
1581
+ hi = (value - lo) / 4294967296 >>> 0;
1582
+ if (sign) {
1583
+ hi = ~hi >>> 0;
1584
+ lo = ~lo >>> 0;
1585
+ if (++lo > 4294967295) {
1586
+ lo = 0;
1587
+ if (++hi > 4294967295)
1588
+ hi = 0;
1589
+ }
1590
+ }
1591
+ return new LongBits(lo, hi);
1592
+ };
1593
+
1594
+ /**
1595
+ * Constructs new long bits from a number, long or string.
1596
+ * @param {Long|number|string} value Value
1597
+ * @returns {util.LongBits} Instance
1598
+ */
1599
+ LongBits.from = function from(value) {
1600
+ if (typeof value === "number")
1601
+ return LongBits.fromNumber(value);
1602
+ if (util.isString(value)) {
1603
+ /* istanbul ignore else */
1604
+ if (util.Long)
1605
+ value = util.Long.fromString(value);
1606
+ else
1607
+ return LongBits.fromNumber(parseInt(value, 10));
1608
+ }
1609
+ return value.low || value.high ? new LongBits(value.low >>> 0, value.high >>> 0) : zero;
1610
+ };
1611
+
1612
+ /**
1613
+ * Converts this long bits to a possibly unsafe JavaScript number.
1614
+ * @param {boolean} [unsigned=false] Whether unsigned or not
1615
+ * @returns {number} Possibly unsafe number
1616
+ */
1617
+ LongBits.prototype.toNumber = function toNumber(unsigned) {
1618
+ if (!unsigned && this.hi >>> 31) {
1619
+ var lo = ~this.lo + 1 >>> 0,
1620
+ hi = ~this.hi >>> 0;
1621
+ if (!lo)
1622
+ hi = hi + 1 >>> 0;
1623
+ return -(lo + hi * 4294967296);
1624
+ }
1625
+ return this.lo + this.hi * 4294967296;
1626
+ };
1627
+
1628
+ /**
1629
+ * Converts this long bits to a long.
1630
+ * @param {boolean} [unsigned=false] Whether unsigned or not
1631
+ * @returns {Long} Long
1632
+ */
1633
+ LongBits.prototype.toLong = function toLong(unsigned) {
1634
+ return util.Long
1635
+ ? new util.Long(this.lo | 0, this.hi | 0, Boolean(unsigned))
1636
+ /* istanbul ignore next */
1637
+ : { low: this.lo | 0, high: this.hi | 0, unsigned: Boolean(unsigned) };
1638
+ };
1639
+
1640
+ var charCodeAt = String.prototype.charCodeAt;
1641
+
1642
+ /**
1643
+ * Constructs new long bits from the specified 8 characters long hash.
1644
+ * @param {string} hash Hash
1645
+ * @returns {util.LongBits} Bits
1646
+ */
1647
+ LongBits.fromHash = function fromHash(hash) {
1648
+ if (hash === zeroHash)
1649
+ return zero;
1650
+ return new LongBits(
1651
+ ( charCodeAt.call(hash, 0)
1652
+ | charCodeAt.call(hash, 1) << 8
1653
+ | charCodeAt.call(hash, 2) << 16
1654
+ | charCodeAt.call(hash, 3) << 24) >>> 0
1655
+ ,
1656
+ ( charCodeAt.call(hash, 4)
1657
+ | charCodeAt.call(hash, 5) << 8
1658
+ | charCodeAt.call(hash, 6) << 16
1659
+ | charCodeAt.call(hash, 7) << 24) >>> 0
1660
+ );
1661
+ };
1662
+
1663
+ /**
1664
+ * Converts this long bits to a 8 characters long hash.
1665
+ * @returns {string} Hash
1666
+ */
1667
+ LongBits.prototype.toHash = function toHash() {
1668
+ return String.fromCharCode(
1669
+ this.lo & 255,
1670
+ this.lo >>> 8 & 255,
1671
+ this.lo >>> 16 & 255,
1672
+ this.lo >>> 24 ,
1673
+ this.hi & 255,
1674
+ this.hi >>> 8 & 255,
1675
+ this.hi >>> 16 & 255,
1676
+ this.hi >>> 24
1677
+ );
1678
+ };
1679
+
1680
+ /**
1681
+ * Zig-zag encodes this long bits.
1682
+ * @returns {util.LongBits} `this`
1683
+ */
1684
+ LongBits.prototype.zzEncode = function zzEncode() {
1685
+ var mask = this.hi >> 31;
1686
+ this.hi = ((this.hi << 1 | this.lo >>> 31) ^ mask) >>> 0;
1687
+ this.lo = ( this.lo << 1 ^ mask) >>> 0;
1688
+ return this;
1689
+ };
1690
+
1691
+ /**
1692
+ * Zig-zag decodes this long bits.
1693
+ * @returns {util.LongBits} `this`
1694
+ */
1695
+ LongBits.prototype.zzDecode = function zzDecode() {
1696
+ var mask = -(this.lo & 1);
1697
+ this.lo = ((this.lo >>> 1 | this.hi << 31) ^ mask) >>> 0;
1698
+ this.hi = ( this.hi >>> 1 ^ mask) >>> 0;
1699
+ return this;
1700
+ };
1701
+
1702
+ /**
1703
+ * Calculates the length of this longbits when encoded as a varint.
1704
+ * @returns {number} Length
1705
+ */
1706
+ LongBits.prototype.length = function length() {
1707
+ var part0 = this.lo,
1708
+ part1 = (this.lo >>> 28 | this.hi << 4) >>> 0,
1709
+ part2 = this.hi >>> 24;
1710
+ return part2 === 0
1711
+ ? part1 === 0
1712
+ ? part0 < 16384
1713
+ ? part0 < 128 ? 1 : 2
1714
+ : part0 < 2097152 ? 3 : 4
1715
+ : part1 < 16384
1716
+ ? part1 < 128 ? 5 : 6
1717
+ : part1 < 2097152 ? 7 : 8
1718
+ : part2 < 128 ? 9 : 10;
1719
+ };
1720
1720
 
1721
1721
  },{"15":15}],15:[function(require,module,exports){
1722
- "use strict";
1723
- var util = exports;
1724
-
1725
- // used to return a Promise where callback is omitted
1726
- util.asPromise = require(1);
1727
-
1728
- // converts to / from base64 encoded strings
1729
- util.base64 = require(2);
1730
-
1731
- // base class of rpc.Service
1732
- util.EventEmitter = require(3);
1733
-
1734
- // float handling accross browsers
1735
- util.float = require(4);
1736
-
1737
- // requires modules optionally and hides the call from bundlers
1738
- util.inquire = require(5);
1739
-
1740
- // converts to / from utf8 encoded strings
1741
- util.utf8 = require(7);
1742
-
1743
- // provides a node-like buffer pool in the browser
1744
- util.pool = require(6);
1745
-
1746
- // utility to work with the low and high bits of a 64 bit value
1747
- util.LongBits = require(14);
1748
-
1749
- /**
1750
- * An immuable empty array.
1751
- * @memberof util
1752
- * @type {Array.<*>}
1753
- * @const
1754
- */
1755
- util.emptyArray = Object.freeze ? Object.freeze([]) : /* istanbul ignore next */ []; // used on prototypes
1756
-
1757
- /**
1758
- * An immutable empty object.
1759
- * @type {Object}
1760
- * @const
1761
- */
1762
- util.emptyObject = Object.freeze ? Object.freeze({}) : /* istanbul ignore next */ {}; // used on prototypes
1763
-
1764
- /**
1765
- * Whether running within node or not.
1766
- * @memberof util
1767
- * @type {boolean}
1768
- * @const
1769
- */
1770
- util.isNode = Boolean(global.process && global.process.versions && global.process.versions.node);
1771
-
1772
- /**
1773
- * Tests if the specified value is an integer.
1774
- * @function
1775
- * @param {*} value Value to test
1776
- * @returns {boolean} `true` if the value is an integer
1777
- */
1778
- util.isInteger = Number.isInteger || /* istanbul ignore next */ function isInteger(value) {
1779
- return typeof value === "number" && isFinite(value) && Math.floor(value) === value;
1780
- };
1781
-
1782
- /**
1783
- * Tests if the specified value is a string.
1784
- * @param {*} value Value to test
1785
- * @returns {boolean} `true` if the value is a string
1786
- */
1787
- util.isString = function isString(value) {
1788
- return typeof value === "string" || value instanceof String;
1789
- };
1790
-
1791
- /**
1792
- * Tests if the specified value is a non-null object.
1793
- * @param {*} value Value to test
1794
- * @returns {boolean} `true` if the value is a non-null object
1795
- */
1796
- util.isObject = function isObject(value) {
1797
- return value && typeof value === "object";
1798
- };
1799
-
1800
- /**
1801
- * Checks if a property on a message is considered to be present.
1802
- * This is an alias of {@link util.isSet}.
1803
- * @function
1804
- * @param {Object} obj Plain object or message instance
1805
- * @param {string} prop Property name
1806
- * @returns {boolean} `true` if considered to be present, otherwise `false`
1807
- */
1808
- util.isset =
1809
-
1810
- /**
1811
- * Checks if a property on a message is considered to be present.
1812
- * @param {Object} obj Plain object or message instance
1813
- * @param {string} prop Property name
1814
- * @returns {boolean} `true` if considered to be present, otherwise `false`
1815
- */
1816
- util.isSet = function isSet(obj, prop) {
1817
- var value = obj[prop];
1818
- if (value != null && obj.hasOwnProperty(prop)) // eslint-disable-line eqeqeq, no-prototype-builtins
1819
- return typeof value !== "object" || (Array.isArray(value) ? value.length : Object.keys(value).length) > 0;
1820
- return false;
1821
- };
1822
-
1823
- /**
1824
- * Any compatible Buffer instance.
1825
- * This is a minimal stand-alone definition of a Buffer instance. The actual type is that exported by node's typings.
1826
- * @interface Buffer
1827
- * @extends Uint8Array
1828
- */
1829
-
1830
- /**
1831
- * Node's Buffer class if available.
1832
- * @type {Constructor<Buffer>}
1833
- */
1834
- util.Buffer = (function() {
1835
- try {
1836
- var Buffer = util.inquire("buffer").Buffer;
1837
- // refuse to use non-node buffers if not explicitly assigned (perf reasons):
1838
- return Buffer.prototype.utf8Write ? Buffer : /* istanbul ignore next */ null;
1839
- } catch (e) {
1840
- /* istanbul ignore next */
1841
- return null;
1842
- }
1843
- })();
1844
-
1845
- // Internal alias of or polyfull for Buffer.from.
1846
- util._Buffer_from = null;
1847
-
1848
- // Internal alias of or polyfill for Buffer.allocUnsafe.
1849
- util._Buffer_allocUnsafe = null;
1850
-
1851
- /**
1852
- * Creates a new buffer of whatever type supported by the environment.
1853
- * @param {number|number[]} [sizeOrArray=0] Buffer size or number array
1854
- * @returns {Uint8Array|Buffer} Buffer
1855
- */
1856
- util.newBuffer = function newBuffer(sizeOrArray) {
1857
- /* istanbul ignore next */
1858
- return typeof sizeOrArray === "number"
1859
- ? util.Buffer
1860
- ? util._Buffer_allocUnsafe(sizeOrArray)
1861
- : new util.Array(sizeOrArray)
1862
- : util.Buffer
1863
- ? util._Buffer_from(sizeOrArray)
1864
- : typeof Uint8Array === "undefined"
1865
- ? sizeOrArray
1866
- : new Uint8Array(sizeOrArray);
1867
- };
1868
-
1869
- /**
1870
- * Array implementation used in the browser. `Uint8Array` if supported, otherwise `Array`.
1871
- * @type {Constructor<Uint8Array>}
1872
- */
1873
- util.Array = typeof Uint8Array !== "undefined" ? Uint8Array /* istanbul ignore next */ : Array;
1874
-
1875
- /**
1876
- * Any compatible Long instance.
1877
- * This is a minimal stand-alone definition of a Long instance. The actual type is that exported by long.js.
1878
- * @interface Long
1879
- * @property {number} low Low bits
1880
- * @property {number} high High bits
1881
- * @property {boolean} unsigned Whether unsigned or not
1882
- */
1883
-
1884
- /**
1885
- * Long.js's Long class if available.
1886
- * @type {Constructor<Long>}
1887
- */
1888
- util.Long = /* istanbul ignore next */ global.dcodeIO && /* istanbul ignore next */ global.dcodeIO.Long || util.inquire("long");
1889
-
1890
- /**
1891
- * Regular expression used to verify 2 bit (`bool`) map keys.
1892
- * @type {RegExp}
1893
- * @const
1894
- */
1895
- util.key2Re = /^true|false|0|1$/;
1896
-
1897
- /**
1898
- * Regular expression used to verify 32 bit (`int32` etc.) map keys.
1899
- * @type {RegExp}
1900
- * @const
1901
- */
1902
- util.key32Re = /^-?(?:0|[1-9][0-9]*)$/;
1903
-
1904
- /**
1905
- * Regular expression used to verify 64 bit (`int64` etc.) map keys.
1906
- * @type {RegExp}
1907
- * @const
1908
- */
1909
- util.key64Re = /^(?:[\\x00-\\xff]{8}|-?(?:0|[1-9][0-9]*))$/;
1910
-
1911
- /**
1912
- * Converts a number or long to an 8 characters long hash string.
1913
- * @param {Long|number} value Value to convert
1914
- * @returns {string} Hash
1915
- */
1916
- util.longToHash = function longToHash(value) {
1917
- return value
1918
- ? util.LongBits.from(value).toHash()
1919
- : util.LongBits.zeroHash;
1920
- };
1921
-
1922
- /**
1923
- * Converts an 8 characters long hash string to a long or number.
1924
- * @param {string} hash Hash
1925
- * @param {boolean} [unsigned=false] Whether unsigned or not
1926
- * @returns {Long|number} Original value
1927
- */
1928
- util.longFromHash = function longFromHash(hash, unsigned) {
1929
- var bits = util.LongBits.fromHash(hash);
1930
- if (util.Long)
1931
- return util.Long.fromBits(bits.lo, bits.hi, unsigned);
1932
- return bits.toNumber(Boolean(unsigned));
1933
- };
1934
-
1935
- /**
1936
- * Merges the properties of the source object into the destination object.
1937
- * @memberof util
1938
- * @param {Object.<string,*>} dst Destination object
1939
- * @param {Object.<string,*>} src Source object
1940
- * @param {boolean} [ifNotSet=false] Merges only if the key is not already set
1941
- * @returns {Object.<string,*>} Destination object
1942
- */
1943
- function merge(dst, src, ifNotSet) { // used by converters
1944
- for (var keys = Object.keys(src), i = 0; i < keys.length; ++i)
1945
- if (dst[keys[i]] === undefined || !ifNotSet)
1946
- dst[keys[i]] = src[keys[i]];
1947
- return dst;
1948
- }
1949
-
1950
- util.merge = merge;
1951
-
1952
- /**
1953
- * Converts the first character of a string to lower case.
1954
- * @param {string} str String to convert
1955
- * @returns {string} Converted string
1956
- */
1957
- util.lcFirst = function lcFirst(str) {
1958
- return str.charAt(0).toLowerCase() + str.substring(1);
1959
- };
1960
-
1961
- /**
1962
- * Creates a custom error constructor.
1963
- * @memberof util
1964
- * @param {string} name Error name
1965
- * @returns {Constructor<Error>} Custom error constructor
1966
- */
1967
- function newError(name) {
1968
-
1969
- function CustomError(message, properties) {
1970
-
1971
- if (!(this instanceof CustomError))
1972
- return new CustomError(message, properties);
1973
-
1974
- // Error.call(this, message);
1975
- // ^ just returns a new error instance because the ctor can be called as a function
1976
-
1977
- Object.defineProperty(this, "message", { get: function() { return message; } });
1978
-
1979
- /* istanbul ignore next */
1980
- if (Error.captureStackTrace) // node
1981
- Error.captureStackTrace(this, CustomError);
1982
- else
1983
- Object.defineProperty(this, "stack", { value: (new Error()).stack || "" });
1984
-
1985
- if (properties)
1986
- merge(this, properties);
1987
- }
1988
-
1989
- (CustomError.prototype = Object.create(Error.prototype)).constructor = CustomError;
1990
-
1991
- Object.defineProperty(CustomError.prototype, "name", { get: function() { return name; } });
1992
-
1993
- CustomError.prototype.toString = function toString() {
1994
- return this.name + ": " + this.message;
1995
- };
1996
-
1997
- return CustomError;
1998
- }
1999
-
2000
- util.newError = newError;
2001
-
2002
- /**
2003
- * Constructs a new protocol error.
2004
- * @classdesc Error subclass indicating a protocol specifc error.
2005
- * @memberof util
2006
- * @extends Error
2007
- * @template T extends Message<T>
2008
- * @constructor
2009
- * @param {string} message Error message
2010
- * @param {Object.<string,*>} [properties] Additional properties
2011
- * @example
2012
- * try {
2013
- * MyMessage.decode(someBuffer); // throws if required fields are missing
2014
- * } catch (e) {
2015
- * if (e instanceof ProtocolError && e.instance)
2016
- * console.log("decoded so far: " + JSON.stringify(e.instance));
2017
- * }
2018
- */
2019
- util.ProtocolError = newError("ProtocolError");
2020
-
2021
- /**
2022
- * So far decoded message instance.
2023
- * @name util.ProtocolError#instance
2024
- * @type {Message<T>}
2025
- */
2026
-
2027
- /**
2028
- * A OneOf getter as returned by {@link util.oneOfGetter}.
2029
- * @typedef OneOfGetter
2030
- * @type {function}
2031
- * @returns {string|undefined} Set field name, if any
2032
- */
2033
-
2034
- /**
2035
- * Builds a getter for a oneof's present field name.
2036
- * @param {string[]} fieldNames Field names
2037
- * @returns {OneOfGetter} Unbound getter
2038
- */
2039
- util.oneOfGetter = function getOneOf(fieldNames) {
2040
- var fieldMap = {};
2041
- for (var i = 0; i < fieldNames.length; ++i)
2042
- fieldMap[fieldNames[i]] = 1;
2043
-
2044
- /**
2045
- * @returns {string|undefined} Set field name, if any
2046
- * @this Object
2047
- * @ignore
2048
- */
2049
- return function() { // eslint-disable-line consistent-return
2050
- for (var keys = Object.keys(this), i = keys.length - 1; i > -1; --i)
2051
- if (fieldMap[keys[i]] === 1 && this[keys[i]] !== undefined && this[keys[i]] !== null)
2052
- return keys[i];
2053
- };
2054
- };
2055
-
2056
- /**
2057
- * A OneOf setter as returned by {@link util.oneOfSetter}.
2058
- * @typedef OneOfSetter
2059
- * @type {function}
2060
- * @param {string|undefined} value Field name
2061
- * @returns {undefined}
2062
- */
2063
-
2064
- /**
2065
- * Builds a setter for a oneof's present field name.
2066
- * @param {string[]} fieldNames Field names
2067
- * @returns {OneOfSetter} Unbound setter
2068
- */
2069
- util.oneOfSetter = function setOneOf(fieldNames) {
2070
-
2071
- /**
2072
- * @param {string} name Field name
2073
- * @returns {undefined}
2074
- * @this Object
2075
- * @ignore
2076
- */
2077
- return function(name) {
2078
- for (var i = 0; i < fieldNames.length; ++i)
2079
- if (fieldNames[i] !== name)
2080
- delete this[fieldNames[i]];
2081
- };
2082
- };
2083
-
2084
- /**
2085
- * Default conversion options used for {@link Message#toJSON} implementations.
2086
- *
2087
- * These options are close to proto3's JSON mapping with the exception that internal types like Any are handled just like messages. More precisely:
2088
- *
2089
- * - Longs become strings
2090
- * - Enums become string keys
2091
- * - Bytes become base64 encoded strings
2092
- * - (Sub-)Messages become plain objects
2093
- * - Maps become plain objects with all string keys
2094
- * - Repeated fields become arrays
2095
- * - NaN and Infinity for float and double fields become strings
2096
- *
2097
- * @type {IConversionOptions}
2098
- * @see https://developers.google.com/protocol-buffers/docs/proto3?hl=en#json
2099
- */
2100
- util.toJSONOptions = {
2101
- longs: String,
2102
- enums: String,
2103
- bytes: String,
2104
- json: true
2105
- };
2106
-
2107
- util._configure = function() {
2108
- var Buffer = util.Buffer;
2109
- /* istanbul ignore if */
2110
- if (!Buffer) {
2111
- util._Buffer_from = util._Buffer_allocUnsafe = null;
2112
- return;
2113
- }
2114
- // because node 4.x buffers are incompatible & immutable
2115
- // see: https://github.com/dcodeIO/protobuf.js/pull/665
2116
- util._Buffer_from = Buffer.from !== Uint8Array.from && Buffer.from ||
2117
- /* istanbul ignore next */
2118
- function Buffer_from(value, encoding) {
2119
- return new Buffer(value, encoding);
2120
- };
2121
- util._Buffer_allocUnsafe = Buffer.allocUnsafe ||
2122
- /* istanbul ignore next */
2123
- function Buffer_allocUnsafe(size) {
2124
- return new Buffer(size);
2125
- };
2126
- };
1722
+ "use strict";
1723
+ var util = exports;
1724
+
1725
+ // used to return a Promise where callback is omitted
1726
+ util.asPromise = require(1);
1727
+
1728
+ // converts to / from base64 encoded strings
1729
+ util.base64 = require(2);
1730
+
1731
+ // base class of rpc.Service
1732
+ util.EventEmitter = require(3);
1733
+
1734
+ // float handling accross browsers
1735
+ util.float = require(4);
1736
+
1737
+ // requires modules optionally and hides the call from bundlers
1738
+ util.inquire = require(5);
1739
+
1740
+ // converts to / from utf8 encoded strings
1741
+ util.utf8 = require(7);
1742
+
1743
+ // provides a node-like buffer pool in the browser
1744
+ util.pool = require(6);
1745
+
1746
+ // utility to work with the low and high bits of a 64 bit value
1747
+ util.LongBits = require(14);
1748
+
1749
+ // global object reference
1750
+ util.global = typeof window !== "undefined" && window
1751
+ || typeof global !== "undefined" && global
1752
+ || typeof self !== "undefined" && self
1753
+ || this; // eslint-disable-line no-invalid-this
1754
+
1755
+ /**
1756
+ * An immuable empty array.
1757
+ * @memberof util
1758
+ * @type {Array.<*>}
1759
+ * @const
1760
+ */
1761
+ util.emptyArray = Object.freeze ? Object.freeze([]) : /* istanbul ignore next */ []; // used on prototypes
1762
+
1763
+ /**
1764
+ * An immutable empty object.
1765
+ * @type {Object}
1766
+ * @const
1767
+ */
1768
+ util.emptyObject = Object.freeze ? Object.freeze({}) : /* istanbul ignore next */ {}; // used on prototypes
1769
+
1770
+ /**
1771
+ * Whether running within node or not.
1772
+ * @memberof util
1773
+ * @type {boolean}
1774
+ * @const
1775
+ */
1776
+ util.isNode = Boolean(util.global.process && util.global.process.versions && util.global.process.versions.node);
1777
+
1778
+ /**
1779
+ * Tests if the specified value is an integer.
1780
+ * @function
1781
+ * @param {*} value Value to test
1782
+ * @returns {boolean} `true` if the value is an integer
1783
+ */
1784
+ util.isInteger = Number.isInteger || /* istanbul ignore next */ function isInteger(value) {
1785
+ return typeof value === "number" && isFinite(value) && Math.floor(value) === value;
1786
+ };
1787
+
1788
+ /**
1789
+ * Tests if the specified value is a string.
1790
+ * @param {*} value Value to test
1791
+ * @returns {boolean} `true` if the value is a string
1792
+ */
1793
+ util.isString = function isString(value) {
1794
+ return typeof value === "string" || value instanceof String;
1795
+ };
1796
+
1797
+ /**
1798
+ * Tests if the specified value is a non-null object.
1799
+ * @param {*} value Value to test
1800
+ * @returns {boolean} `true` if the value is a non-null object
1801
+ */
1802
+ util.isObject = function isObject(value) {
1803
+ return value && typeof value === "object";
1804
+ };
1805
+
1806
+ /**
1807
+ * Checks if a property on a message is considered to be present.
1808
+ * This is an alias of {@link util.isSet}.
1809
+ * @function
1810
+ * @param {Object} obj Plain object or message instance
1811
+ * @param {string} prop Property name
1812
+ * @returns {boolean} `true` if considered to be present, otherwise `false`
1813
+ */
1814
+ util.isset =
1815
+
1816
+ /**
1817
+ * Checks if a property on a message is considered to be present.
1818
+ * @param {Object} obj Plain object or message instance
1819
+ * @param {string} prop Property name
1820
+ * @returns {boolean} `true` if considered to be present, otherwise `false`
1821
+ */
1822
+ util.isSet = function isSet(obj, prop) {
1823
+ var value = obj[prop];
1824
+ if (value != null && obj.hasOwnProperty(prop)) // eslint-disable-line eqeqeq, no-prototype-builtins
1825
+ return typeof value !== "object" || (Array.isArray(value) ? value.length : Object.keys(value).length) > 0;
1826
+ return false;
1827
+ };
1828
+
1829
+ /**
1830
+ * Any compatible Buffer instance.
1831
+ * This is a minimal stand-alone definition of a Buffer instance. The actual type is that exported by node's typings.
1832
+ * @interface Buffer
1833
+ * @extends Uint8Array
1834
+ */
1835
+
1836
+ /**
1837
+ * Node's Buffer class if available.
1838
+ * @type {Constructor<Buffer>}
1839
+ */
1840
+ util.Buffer = (function() {
1841
+ try {
1842
+ var Buffer = util.inquire("buffer").Buffer;
1843
+ // refuse to use non-node buffers if not explicitly assigned (perf reasons):
1844
+ return Buffer.prototype.utf8Write ? Buffer : /* istanbul ignore next */ null;
1845
+ } catch (e) {
1846
+ /* istanbul ignore next */
1847
+ return null;
1848
+ }
1849
+ })();
1850
+
1851
+ // Internal alias of or polyfull for Buffer.from.
1852
+ util._Buffer_from = null;
1853
+
1854
+ // Internal alias of or polyfill for Buffer.allocUnsafe.
1855
+ util._Buffer_allocUnsafe = null;
1856
+
1857
+ /**
1858
+ * Creates a new buffer of whatever type supported by the environment.
1859
+ * @param {number|number[]} [sizeOrArray=0] Buffer size or number array
1860
+ * @returns {Uint8Array|Buffer} Buffer
1861
+ */
1862
+ util.newBuffer = function newBuffer(sizeOrArray) {
1863
+ /* istanbul ignore next */
1864
+ return typeof sizeOrArray === "number"
1865
+ ? util.Buffer
1866
+ ? util._Buffer_allocUnsafe(sizeOrArray)
1867
+ : new util.Array(sizeOrArray)
1868
+ : util.Buffer
1869
+ ? util._Buffer_from(sizeOrArray)
1870
+ : typeof Uint8Array === "undefined"
1871
+ ? sizeOrArray
1872
+ : new Uint8Array(sizeOrArray);
1873
+ };
1874
+
1875
+ /**
1876
+ * Array implementation used in the browser. `Uint8Array` if supported, otherwise `Array`.
1877
+ * @type {Constructor<Uint8Array>}
1878
+ */
1879
+ util.Array = typeof Uint8Array !== "undefined" ? Uint8Array /* istanbul ignore next */ : Array;
1880
+
1881
+ /**
1882
+ * Any compatible Long instance.
1883
+ * This is a minimal stand-alone definition of a Long instance. The actual type is that exported by long.js.
1884
+ * @interface Long
1885
+ * @property {number} low Low bits
1886
+ * @property {number} high High bits
1887
+ * @property {boolean} unsigned Whether unsigned or not
1888
+ */
1889
+
1890
+ /**
1891
+ * Long.js's Long class if available.
1892
+ * @type {Constructor<Long>}
1893
+ */
1894
+ util.Long = /* istanbul ignore next */ util.global.dcodeIO && /* istanbul ignore next */ util.global.dcodeIO.Long
1895
+ || /* istanbul ignore next */ util.global.Long
1896
+ || util.inquire("long");
1897
+
1898
+ /**
1899
+ * Regular expression used to verify 2 bit (`bool`) map keys.
1900
+ * @type {RegExp}
1901
+ * @const
1902
+ */
1903
+ util.key2Re = /^true|false|0|1$/;
1904
+
1905
+ /**
1906
+ * Regular expression used to verify 32 bit (`int32` etc.) map keys.
1907
+ * @type {RegExp}
1908
+ * @const
1909
+ */
1910
+ util.key32Re = /^-?(?:0|[1-9][0-9]*)$/;
1911
+
1912
+ /**
1913
+ * Regular expression used to verify 64 bit (`int64` etc.) map keys.
1914
+ * @type {RegExp}
1915
+ * @const
1916
+ */
1917
+ util.key64Re = /^(?:[\\x00-\\xff]{8}|-?(?:0|[1-9][0-9]*))$/;
1918
+
1919
+ /**
1920
+ * Converts a number or long to an 8 characters long hash string.
1921
+ * @param {Long|number} value Value to convert
1922
+ * @returns {string} Hash
1923
+ */
1924
+ util.longToHash = function longToHash(value) {
1925
+ return value
1926
+ ? util.LongBits.from(value).toHash()
1927
+ : util.LongBits.zeroHash;
1928
+ };
1929
+
1930
+ /**
1931
+ * Converts an 8 characters long hash string to a long or number.
1932
+ * @param {string} hash Hash
1933
+ * @param {boolean} [unsigned=false] Whether unsigned or not
1934
+ * @returns {Long|number} Original value
1935
+ */
1936
+ util.longFromHash = function longFromHash(hash, unsigned) {
1937
+ var bits = util.LongBits.fromHash(hash);
1938
+ if (util.Long)
1939
+ return util.Long.fromBits(bits.lo, bits.hi, unsigned);
1940
+ return bits.toNumber(Boolean(unsigned));
1941
+ };
1942
+
1943
+ /**
1944
+ * Merges the properties of the source object into the destination object.
1945
+ * @memberof util
1946
+ * @param {Object.<string,*>} dst Destination object
1947
+ * @param {Object.<string,*>} src Source object
1948
+ * @param {boolean} [ifNotSet=false] Merges only if the key is not already set
1949
+ * @returns {Object.<string,*>} Destination object
1950
+ */
1951
+ function merge(dst, src, ifNotSet) { // used by converters
1952
+ for (var keys = Object.keys(src), i = 0; i < keys.length; ++i)
1953
+ if (dst[keys[i]] === undefined || !ifNotSet)
1954
+ dst[keys[i]] = src[keys[i]];
1955
+ return dst;
1956
+ }
1957
+
1958
+ util.merge = merge;
1959
+
1960
+ /**
1961
+ * Converts the first character of a string to lower case.
1962
+ * @param {string} str String to convert
1963
+ * @returns {string} Converted string
1964
+ */
1965
+ util.lcFirst = function lcFirst(str) {
1966
+ return str.charAt(0).toLowerCase() + str.substring(1);
1967
+ };
1968
+
1969
+ /**
1970
+ * Creates a custom error constructor.
1971
+ * @memberof util
1972
+ * @param {string} name Error name
1973
+ * @returns {Constructor<Error>} Custom error constructor
1974
+ */
1975
+ function newError(name) {
1976
+
1977
+ function CustomError(message, properties) {
1978
+
1979
+ if (!(this instanceof CustomError))
1980
+ return new CustomError(message, properties);
1981
+
1982
+ // Error.call(this, message);
1983
+ // ^ just returns a new error instance because the ctor can be called as a function
1984
+
1985
+ Object.defineProperty(this, "message", { get: function() { return message; } });
1986
+
1987
+ /* istanbul ignore next */
1988
+ if (Error.captureStackTrace) // node
1989
+ Error.captureStackTrace(this, CustomError);
1990
+ else
1991
+ Object.defineProperty(this, "stack", { value: (new Error()).stack || "" });
1992
+
1993
+ if (properties)
1994
+ merge(this, properties);
1995
+ }
1996
+
1997
+ (CustomError.prototype = Object.create(Error.prototype)).constructor = CustomError;
1998
+
1999
+ Object.defineProperty(CustomError.prototype, "name", { get: function() { return name; } });
2000
+
2001
+ CustomError.prototype.toString = function toString() {
2002
+ return this.name + ": " + this.message;
2003
+ };
2004
+
2005
+ return CustomError;
2006
+ }
2007
+
2008
+ util.newError = newError;
2009
+
2010
+ /**
2011
+ * Constructs a new protocol error.
2012
+ * @classdesc Error subclass indicating a protocol specifc error.
2013
+ * @memberof util
2014
+ * @extends Error
2015
+ * @template T extends Message<T>
2016
+ * @constructor
2017
+ * @param {string} message Error message
2018
+ * @param {Object.<string,*>} [properties] Additional properties
2019
+ * @example
2020
+ * try {
2021
+ * MyMessage.decode(someBuffer); // throws if required fields are missing
2022
+ * } catch (e) {
2023
+ * if (e instanceof ProtocolError && e.instance)
2024
+ * console.log("decoded so far: " + JSON.stringify(e.instance));
2025
+ * }
2026
+ */
2027
+ util.ProtocolError = newError("ProtocolError");
2028
+
2029
+ /**
2030
+ * So far decoded message instance.
2031
+ * @name util.ProtocolError#instance
2032
+ * @type {Message<T>}
2033
+ */
2034
+
2035
+ /**
2036
+ * A OneOf getter as returned by {@link util.oneOfGetter}.
2037
+ * @typedef OneOfGetter
2038
+ * @type {function}
2039
+ * @returns {string|undefined} Set field name, if any
2040
+ */
2041
+
2042
+ /**
2043
+ * Builds a getter for a oneof's present field name.
2044
+ * @param {string[]} fieldNames Field names
2045
+ * @returns {OneOfGetter} Unbound getter
2046
+ */
2047
+ util.oneOfGetter = function getOneOf(fieldNames) {
2048
+ var fieldMap = {};
2049
+ for (var i = 0; i < fieldNames.length; ++i)
2050
+ fieldMap[fieldNames[i]] = 1;
2051
+
2052
+ /**
2053
+ * @returns {string|undefined} Set field name, if any
2054
+ * @this Object
2055
+ * @ignore
2056
+ */
2057
+ return function() { // eslint-disable-line consistent-return
2058
+ for (var keys = Object.keys(this), i = keys.length - 1; i > -1; --i)
2059
+ if (fieldMap[keys[i]] === 1 && this[keys[i]] !== undefined && this[keys[i]] !== null)
2060
+ return keys[i];
2061
+ };
2062
+ };
2063
+
2064
+ /**
2065
+ * A OneOf setter as returned by {@link util.oneOfSetter}.
2066
+ * @typedef OneOfSetter
2067
+ * @type {function}
2068
+ * @param {string|undefined} value Field name
2069
+ * @returns {undefined}
2070
+ */
2071
+
2072
+ /**
2073
+ * Builds a setter for a oneof's present field name.
2074
+ * @param {string[]} fieldNames Field names
2075
+ * @returns {OneOfSetter} Unbound setter
2076
+ */
2077
+ util.oneOfSetter = function setOneOf(fieldNames) {
2078
+
2079
+ /**
2080
+ * @param {string} name Field name
2081
+ * @returns {undefined}
2082
+ * @this Object
2083
+ * @ignore
2084
+ */
2085
+ return function(name) {
2086
+ for (var i = 0; i < fieldNames.length; ++i)
2087
+ if (fieldNames[i] !== name)
2088
+ delete this[fieldNames[i]];
2089
+ };
2090
+ };
2091
+
2092
+ /**
2093
+ * Default conversion options used for {@link Message#toJSON} implementations.
2094
+ *
2095
+ * These options are close to proto3's JSON mapping with the exception that internal types like Any are handled just like messages. More precisely:
2096
+ *
2097
+ * - Longs become strings
2098
+ * - Enums become string keys
2099
+ * - Bytes become base64 encoded strings
2100
+ * - (Sub-)Messages become plain objects
2101
+ * - Maps become plain objects with all string keys
2102
+ * - Repeated fields become arrays
2103
+ * - NaN and Infinity for float and double fields become strings
2104
+ *
2105
+ * @type {IConversionOptions}
2106
+ * @see https://developers.google.com/protocol-buffers/docs/proto3?hl=en#json
2107
+ */
2108
+ util.toJSONOptions = {
2109
+ longs: String,
2110
+ enums: String,
2111
+ bytes: String,
2112
+ json: true
2113
+ };
2114
+
2115
+ // Sets up buffer utility according to the environment (called in index-minimal)
2116
+ util._configure = function() {
2117
+ var Buffer = util.Buffer;
2118
+ /* istanbul ignore if */
2119
+ if (!Buffer) {
2120
+ util._Buffer_from = util._Buffer_allocUnsafe = null;
2121
+ return;
2122
+ }
2123
+ // because node 4.x buffers are incompatible & immutable
2124
+ // see: https://github.com/dcodeIO/protobuf.js/pull/665
2125
+ util._Buffer_from = Buffer.from !== Uint8Array.from && Buffer.from ||
2126
+ /* istanbul ignore next */
2127
+ function Buffer_from(value, encoding) {
2128
+ return new Buffer(value, encoding);
2129
+ };
2130
+ util._Buffer_allocUnsafe = Buffer.allocUnsafe ||
2131
+ /* istanbul ignore next */
2132
+ function Buffer_allocUnsafe(size) {
2133
+ return new Buffer(size);
2134
+ };
2135
+ };
2136
+
2137
+ },{"1":1,"14":14,"2":2,"3":3,"4":4,"5":5,"6":6,"7":7}],16:[function(require,module,exports){
2138
+ "use strict";
2139
+ module.exports = Writer;
2140
+
2141
+ var util = require(15);
2142
+
2143
+ var BufferWriter; // cyclic
2144
+
2145
+ var LongBits = util.LongBits,
2146
+ base64 = util.base64,
2147
+ utf8 = util.utf8;
2148
+
2149
+ /**
2150
+ * Constructs a new writer operation instance.
2151
+ * @classdesc Scheduled writer operation.
2152
+ * @constructor
2153
+ * @param {function(*, Uint8Array, number)} fn Function to call
2154
+ * @param {number} len Value byte length
2155
+ * @param {*} val Value to write
2156
+ * @ignore
2157
+ */
2158
+ function Op(fn, len, val) {
2159
+
2160
+ /**
2161
+ * Function to call.
2162
+ * @type {function(Uint8Array, number, *)}
2163
+ */
2164
+ this.fn = fn;
2165
+
2166
+ /**
2167
+ * Value byte length.
2168
+ * @type {number}
2169
+ */
2170
+ this.len = len;
2171
+
2172
+ /**
2173
+ * Next operation.
2174
+ * @type {Writer.Op|undefined}
2175
+ */
2176
+ this.next = undefined;
2177
+
2178
+ /**
2179
+ * Value to write.
2180
+ * @type {*}
2181
+ */
2182
+ this.val = val; // type varies
2183
+ }
2184
+
2185
+ /* istanbul ignore next */
2186
+ function noop() {} // eslint-disable-line no-empty-function
2187
+
2188
+ /**
2189
+ * Constructs a new writer state instance.
2190
+ * @classdesc Copied writer state.
2191
+ * @memberof Writer
2192
+ * @constructor
2193
+ * @param {Writer} writer Writer to copy state from
2194
+ * @ignore
2195
+ */
2196
+ function State(writer) {
2197
+
2198
+ /**
2199
+ * Current head.
2200
+ * @type {Writer.Op}
2201
+ */
2202
+ this.head = writer.head;
2203
+
2204
+ /**
2205
+ * Current tail.
2206
+ * @type {Writer.Op}
2207
+ */
2208
+ this.tail = writer.tail;
2209
+
2210
+ /**
2211
+ * Current buffer length.
2212
+ * @type {number}
2213
+ */
2214
+ this.len = writer.len;
2215
+
2216
+ /**
2217
+ * Next state.
2218
+ * @type {State|null}
2219
+ */
2220
+ this.next = writer.states;
2221
+ }
2222
+
2223
+ /**
2224
+ * Constructs a new writer instance.
2225
+ * @classdesc Wire format writer using `Uint8Array` if available, otherwise `Array`.
2226
+ * @constructor
2227
+ */
2228
+ function Writer() {
2229
+
2230
+ /**
2231
+ * Current length.
2232
+ * @type {number}
2233
+ */
2234
+ this.len = 0;
2235
+
2236
+ /**
2237
+ * Operations head.
2238
+ * @type {Object}
2239
+ */
2240
+ this.head = new Op(noop, 0, 0);
2241
+
2242
+ /**
2243
+ * Operations tail
2244
+ * @type {Object}
2245
+ */
2246
+ this.tail = this.head;
2247
+
2248
+ /**
2249
+ * Linked forked states.
2250
+ * @type {Object|null}
2251
+ */
2252
+ this.states = null;
2253
+
2254
+ // When a value is written, the writer calculates its byte length and puts it into a linked
2255
+ // list of operations to perform when finish() is called. This both allows us to allocate
2256
+ // buffers of the exact required size and reduces the amount of work we have to do compared
2257
+ // to first calculating over objects and then encoding over objects. In our case, the encoding
2258
+ // part is just a linked list walk calling operations with already prepared values.
2259
+ }
2260
+
2261
+ /**
2262
+ * Creates a new writer.
2263
+ * @function
2264
+ * @returns {BufferWriter|Writer} A {@link BufferWriter} when Buffers are supported, otherwise a {@link Writer}
2265
+ */
2266
+ Writer.create = util.Buffer
2267
+ ? function create_buffer_setup() {
2268
+ return (Writer.create = function create_buffer() {
2269
+ return new BufferWriter();
2270
+ })();
2271
+ }
2272
+ /* istanbul ignore next */
2273
+ : function create_array() {
2274
+ return new Writer();
2275
+ };
2276
+
2277
+ /**
2278
+ * Allocates a buffer of the specified size.
2279
+ * @param {number} size Buffer size
2280
+ * @returns {Uint8Array} Buffer
2281
+ */
2282
+ Writer.alloc = function alloc(size) {
2283
+ return new util.Array(size);
2284
+ };
2285
+
2286
+ // Use Uint8Array buffer pool in the browser, just like node does with buffers
2287
+ /* istanbul ignore else */
2288
+ if (util.Array !== Array)
2289
+ Writer.alloc = util.pool(Writer.alloc, util.Array.prototype.subarray);
2290
+
2291
+ /**
2292
+ * Pushes a new operation to the queue.
2293
+ * @param {function(Uint8Array, number, *)} fn Function to call
2294
+ * @param {number} len Value byte length
2295
+ * @param {number} val Value to write
2296
+ * @returns {Writer} `this`
2297
+ * @private
2298
+ */
2299
+ Writer.prototype._push = function push(fn, len, val) {
2300
+ this.tail = this.tail.next = new Op(fn, len, val);
2301
+ this.len += len;
2302
+ return this;
2303
+ };
2304
+
2305
+ function writeByte(val, buf, pos) {
2306
+ buf[pos] = val & 255;
2307
+ }
2308
+
2309
+ function writeVarint32(val, buf, pos) {
2310
+ while (val > 127) {
2311
+ buf[pos++] = val & 127 | 128;
2312
+ val >>>= 7;
2313
+ }
2314
+ buf[pos] = val;
2315
+ }
2316
+
2317
+ /**
2318
+ * Constructs a new varint writer operation instance.
2319
+ * @classdesc Scheduled varint writer operation.
2320
+ * @extends Op
2321
+ * @constructor
2322
+ * @param {number} len Value byte length
2323
+ * @param {number} val Value to write
2324
+ * @ignore
2325
+ */
2326
+ function VarintOp(len, val) {
2327
+ this.len = len;
2328
+ this.next = undefined;
2329
+ this.val = val;
2330
+ }
2331
+
2332
+ VarintOp.prototype = Object.create(Op.prototype);
2333
+ VarintOp.prototype.fn = writeVarint32;
2334
+
2335
+ /**
2336
+ * Writes an unsigned 32 bit value as a varint.
2337
+ * @param {number} value Value to write
2338
+ * @returns {Writer} `this`
2339
+ */
2340
+ Writer.prototype.uint32 = function write_uint32(value) {
2341
+ // here, the call to this.push has been inlined and a varint specific Op subclass is used.
2342
+ // uint32 is by far the most frequently used operation and benefits significantly from this.
2343
+ this.len += (this.tail = this.tail.next = new VarintOp(
2344
+ (value = value >>> 0)
2345
+ < 128 ? 1
2346
+ : value < 16384 ? 2
2347
+ : value < 2097152 ? 3
2348
+ : value < 268435456 ? 4
2349
+ : 5,
2350
+ value)).len;
2351
+ return this;
2352
+ };
2353
+
2354
+ /**
2355
+ * Writes a signed 32 bit value as a varint.
2356
+ * @function
2357
+ * @param {number} value Value to write
2358
+ * @returns {Writer} `this`
2359
+ */
2360
+ Writer.prototype.int32 = function write_int32(value) {
2361
+ return value < 0
2362
+ ? this._push(writeVarint64, 10, LongBits.fromNumber(value)) // 10 bytes per spec
2363
+ : this.uint32(value);
2364
+ };
2365
+
2366
+ /**
2367
+ * Writes a 32 bit value as a varint, zig-zag encoded.
2368
+ * @param {number} value Value to write
2369
+ * @returns {Writer} `this`
2370
+ */
2371
+ Writer.prototype.sint32 = function write_sint32(value) {
2372
+ return this.uint32((value << 1 ^ value >> 31) >>> 0);
2373
+ };
2374
+
2375
+ function writeVarint64(val, buf, pos) {
2376
+ while (val.hi) {
2377
+ buf[pos++] = val.lo & 127 | 128;
2378
+ val.lo = (val.lo >>> 7 | val.hi << 25) >>> 0;
2379
+ val.hi >>>= 7;
2380
+ }
2381
+ while (val.lo > 127) {
2382
+ buf[pos++] = val.lo & 127 | 128;
2383
+ val.lo = val.lo >>> 7;
2384
+ }
2385
+ buf[pos++] = val.lo;
2386
+ }
2387
+
2388
+ /**
2389
+ * Writes an unsigned 64 bit value as a varint.
2390
+ * @param {Long|number|string} value Value to write
2391
+ * @returns {Writer} `this`
2392
+ * @throws {TypeError} If `value` is a string and no long library is present.
2393
+ */
2394
+ Writer.prototype.uint64 = function write_uint64(value) {
2395
+ var bits = LongBits.from(value);
2396
+ return this._push(writeVarint64, bits.length(), bits);
2397
+ };
2398
+
2399
+ /**
2400
+ * Writes a signed 64 bit value as a varint.
2401
+ * @function
2402
+ * @param {Long|number|string} value Value to write
2403
+ * @returns {Writer} `this`
2404
+ * @throws {TypeError} If `value` is a string and no long library is present.
2405
+ */
2406
+ Writer.prototype.int64 = Writer.prototype.uint64;
2407
+
2408
+ /**
2409
+ * Writes a signed 64 bit value as a varint, zig-zag encoded.
2410
+ * @param {Long|number|string} value Value to write
2411
+ * @returns {Writer} `this`
2412
+ * @throws {TypeError} If `value` is a string and no long library is present.
2413
+ */
2414
+ Writer.prototype.sint64 = function write_sint64(value) {
2415
+ var bits = LongBits.from(value).zzEncode();
2416
+ return this._push(writeVarint64, bits.length(), bits);
2417
+ };
2418
+
2419
+ /**
2420
+ * Writes a boolish value as a varint.
2421
+ * @param {boolean} value Value to write
2422
+ * @returns {Writer} `this`
2423
+ */
2424
+ Writer.prototype.bool = function write_bool(value) {
2425
+ return this._push(writeByte, 1, value ? 1 : 0);
2426
+ };
2427
+
2428
+ function writeFixed32(val, buf, pos) {
2429
+ buf[pos ] = val & 255;
2430
+ buf[pos + 1] = val >>> 8 & 255;
2431
+ buf[pos + 2] = val >>> 16 & 255;
2432
+ buf[pos + 3] = val >>> 24;
2433
+ }
2434
+
2435
+ /**
2436
+ * Writes an unsigned 32 bit value as fixed 32 bits.
2437
+ * @param {number} value Value to write
2438
+ * @returns {Writer} `this`
2439
+ */
2440
+ Writer.prototype.fixed32 = function write_fixed32(value) {
2441
+ return this._push(writeFixed32, 4, value >>> 0);
2442
+ };
2443
+
2444
+ /**
2445
+ * Writes a signed 32 bit value as fixed 32 bits.
2446
+ * @function
2447
+ * @param {number} value Value to write
2448
+ * @returns {Writer} `this`
2449
+ */
2450
+ Writer.prototype.sfixed32 = Writer.prototype.fixed32;
2451
+
2452
+ /**
2453
+ * Writes an unsigned 64 bit value as fixed 64 bits.
2454
+ * @param {Long|number|string} value Value to write
2455
+ * @returns {Writer} `this`
2456
+ * @throws {TypeError} If `value` is a string and no long library is present.
2457
+ */
2458
+ Writer.prototype.fixed64 = function write_fixed64(value) {
2459
+ var bits = LongBits.from(value);
2460
+ return this._push(writeFixed32, 4, bits.lo)._push(writeFixed32, 4, bits.hi);
2461
+ };
2462
+
2463
+ /**
2464
+ * Writes a signed 64 bit value as fixed 64 bits.
2465
+ * @function
2466
+ * @param {Long|number|string} value Value to write
2467
+ * @returns {Writer} `this`
2468
+ * @throws {TypeError} If `value` is a string and no long library is present.
2469
+ */
2470
+ Writer.prototype.sfixed64 = Writer.prototype.fixed64;
2127
2471
 
2128
- },{"1":1,"14":14,"2":2,"3":3,"4":4,"5":5,"6":6,"7":7}],16:[function(require,module,exports){
2129
- "use strict";
2130
- module.exports = Writer;
2131
-
2132
- var util = require(15);
2133
-
2134
- var BufferWriter; // cyclic
2135
-
2136
- var LongBits = util.LongBits,
2137
- base64 = util.base64,
2138
- utf8 = util.utf8;
2139
-
2140
- /**
2141
- * Constructs a new writer operation instance.
2142
- * @classdesc Scheduled writer operation.
2143
- * @constructor
2144
- * @param {function(*, Uint8Array, number)} fn Function to call
2145
- * @param {number} len Value byte length
2146
- * @param {*} val Value to write
2147
- * @ignore
2148
- */
2149
- function Op(fn, len, val) {
2150
-
2151
- /**
2152
- * Function to call.
2153
- * @type {function(Uint8Array, number, *)}
2154
- */
2155
- this.fn = fn;
2156
-
2157
- /**
2158
- * Value byte length.
2159
- * @type {number}
2160
- */
2161
- this.len = len;
2162
-
2163
- /**
2164
- * Next operation.
2165
- * @type {Writer.Op|undefined}
2166
- */
2167
- this.next = undefined;
2168
-
2169
- /**
2170
- * Value to write.
2171
- * @type {*}
2172
- */
2173
- this.val = val; // type varies
2174
- }
2175
-
2176
- /* istanbul ignore next */
2177
- function noop() {} // eslint-disable-line no-empty-function
2178
-
2179
- /**
2180
- * Constructs a new writer state instance.
2181
- * @classdesc Copied writer state.
2182
- * @memberof Writer
2183
- * @constructor
2184
- * @param {Writer} writer Writer to copy state from
2185
- * @ignore
2186
- */
2187
- function State(writer) {
2188
-
2189
- /**
2190
- * Current head.
2191
- * @type {Writer.Op}
2192
- */
2193
- this.head = writer.head;
2194
-
2195
- /**
2196
- * Current tail.
2197
- * @type {Writer.Op}
2198
- */
2199
- this.tail = writer.tail;
2200
-
2201
- /**
2202
- * Current buffer length.
2203
- * @type {number}
2204
- */
2205
- this.len = writer.len;
2206
-
2207
- /**
2208
- * Next state.
2209
- * @type {State|null}
2210
- */
2211
- this.next = writer.states;
2212
- }
2213
-
2214
- /**
2215
- * Constructs a new writer instance.
2216
- * @classdesc Wire format writer using `Uint8Array` if available, otherwise `Array`.
2217
- * @constructor
2218
- */
2219
- function Writer() {
2220
-
2221
- /**
2222
- * Current length.
2223
- * @type {number}
2224
- */
2225
- this.len = 0;
2226
-
2227
- /**
2228
- * Operations head.
2229
- * @type {Object}
2230
- */
2231
- this.head = new Op(noop, 0, 0);
2232
-
2233
- /**
2234
- * Operations tail
2235
- * @type {Object}
2236
- */
2237
- this.tail = this.head;
2238
-
2239
- /**
2240
- * Linked forked states.
2241
- * @type {Object|null}
2242
- */
2243
- this.states = null;
2244
-
2245
- // When a value is written, the writer calculates its byte length and puts it into a linked
2246
- // list of operations to perform when finish() is called. This both allows us to allocate
2247
- // buffers of the exact required size and reduces the amount of work we have to do compared
2248
- // to first calculating over objects and then encoding over objects. In our case, the encoding
2249
- // part is just a linked list walk calling operations with already prepared values.
2250
- }
2251
-
2252
- /**
2253
- * Creates a new writer.
2254
- * @function
2255
- * @returns {BufferWriter|Writer} A {@link BufferWriter} when Buffers are supported, otherwise a {@link Writer}
2256
- */
2257
- Writer.create = util.Buffer
2258
- ? function create_buffer_setup() {
2259
- return (Writer.create = function create_buffer() {
2260
- return new BufferWriter();
2261
- })();
2262
- }
2263
- /* istanbul ignore next */
2264
- : function create_array() {
2265
- return new Writer();
2266
- };
2267
-
2268
- /**
2269
- * Allocates a buffer of the specified size.
2270
- * @param {number} size Buffer size
2271
- * @returns {Uint8Array} Buffer
2272
- */
2273
- Writer.alloc = function alloc(size) {
2274
- return new util.Array(size);
2275
- };
2276
-
2277
- // Use Uint8Array buffer pool in the browser, just like node does with buffers
2278
- /* istanbul ignore else */
2279
- if (util.Array !== Array)
2280
- Writer.alloc = util.pool(Writer.alloc, util.Array.prototype.subarray);
2281
-
2282
- /**
2283
- * Pushes a new operation to the queue.
2284
- * @param {function(Uint8Array, number, *)} fn Function to call
2285
- * @param {number} len Value byte length
2286
- * @param {number} val Value to write
2287
- * @returns {Writer} `this`
2288
- * @private
2289
- */
2290
- Writer.prototype._push = function push(fn, len, val) {
2291
- this.tail = this.tail.next = new Op(fn, len, val);
2292
- this.len += len;
2293
- return this;
2294
- };
2295
-
2296
- function writeByte(val, buf, pos) {
2297
- buf[pos] = val & 255;
2298
- }
2299
-
2300
- function writeVarint32(val, buf, pos) {
2301
- while (val > 127) {
2302
- buf[pos++] = val & 127 | 128;
2303
- val >>>= 7;
2304
- }
2305
- buf[pos] = val;
2306
- }
2307
-
2308
- /**
2309
- * Constructs a new varint writer operation instance.
2310
- * @classdesc Scheduled varint writer operation.
2311
- * @extends Op
2312
- * @constructor
2313
- * @param {number} len Value byte length
2314
- * @param {number} val Value to write
2315
- * @ignore
2316
- */
2317
- function VarintOp(len, val) {
2318
- this.len = len;
2319
- this.next = undefined;
2320
- this.val = val;
2321
- }
2322
-
2323
- VarintOp.prototype = Object.create(Op.prototype);
2324
- VarintOp.prototype.fn = writeVarint32;
2325
-
2326
- /**
2327
- * Writes an unsigned 32 bit value as a varint.
2328
- * @param {number} value Value to write
2329
- * @returns {Writer} `this`
2330
- */
2331
- Writer.prototype.uint32 = function write_uint32(value) {
2332
- // here, the call to this.push has been inlined and a varint specific Op subclass is used.
2333
- // uint32 is by far the most frequently used operation and benefits significantly from this.
2334
- this.len += (this.tail = this.tail.next = new VarintOp(
2335
- (value = value >>> 0)
2336
- < 128 ? 1
2337
- : value < 16384 ? 2
2338
- : value < 2097152 ? 3
2339
- : value < 268435456 ? 4
2340
- : 5,
2341
- value)).len;
2342
- return this;
2343
- };
2344
-
2345
- /**
2346
- * Writes a signed 32 bit value as a varint.
2347
- * @function
2348
- * @param {number} value Value to write
2349
- * @returns {Writer} `this`
2350
- */
2351
- Writer.prototype.int32 = function write_int32(value) {
2352
- return value < 0
2353
- ? this._push(writeVarint64, 10, LongBits.fromNumber(value)) // 10 bytes per spec
2354
- : this.uint32(value);
2355
- };
2356
-
2357
- /**
2358
- * Writes a 32 bit value as a varint, zig-zag encoded.
2359
- * @param {number} value Value to write
2360
- * @returns {Writer} `this`
2361
- */
2362
- Writer.prototype.sint32 = function write_sint32(value) {
2363
- return this.uint32((value << 1 ^ value >> 31) >>> 0);
2364
- };
2365
-
2366
- function writeVarint64(val, buf, pos) {
2367
- while (val.hi) {
2368
- buf[pos++] = val.lo & 127 | 128;
2369
- val.lo = (val.lo >>> 7 | val.hi << 25) >>> 0;
2370
- val.hi >>>= 7;
2371
- }
2372
- while (val.lo > 127) {
2373
- buf[pos++] = val.lo & 127 | 128;
2374
- val.lo = val.lo >>> 7;
2375
- }
2376
- buf[pos++] = val.lo;
2377
- }
2378
-
2379
- /**
2380
- * Writes an unsigned 64 bit value as a varint.
2381
- * @param {Long|number|string} value Value to write
2382
- * @returns {Writer} `this`
2383
- * @throws {TypeError} If `value` is a string and no long library is present.
2384
- */
2385
- Writer.prototype.uint64 = function write_uint64(value) {
2386
- var bits = LongBits.from(value);
2387
- return this._push(writeVarint64, bits.length(), bits);
2388
- };
2389
-
2390
- /**
2391
- * Writes a signed 64 bit value as a varint.
2392
- * @function
2393
- * @param {Long|number|string} value Value to write
2394
- * @returns {Writer} `this`
2395
- * @throws {TypeError} If `value` is a string and no long library is present.
2396
- */
2397
- Writer.prototype.int64 = Writer.prototype.uint64;
2398
-
2399
- /**
2400
- * Writes a signed 64 bit value as a varint, zig-zag encoded.
2401
- * @param {Long|number|string} value Value to write
2402
- * @returns {Writer} `this`
2403
- * @throws {TypeError} If `value` is a string and no long library is present.
2404
- */
2405
- Writer.prototype.sint64 = function write_sint64(value) {
2406
- var bits = LongBits.from(value).zzEncode();
2407
- return this._push(writeVarint64, bits.length(), bits);
2408
- };
2409
-
2410
- /**
2411
- * Writes a boolish value as a varint.
2412
- * @param {boolean} value Value to write
2413
- * @returns {Writer} `this`
2414
- */
2415
- Writer.prototype.bool = function write_bool(value) {
2416
- return this._push(writeByte, 1, value ? 1 : 0);
2417
- };
2418
-
2419
- function writeFixed32(val, buf, pos) {
2420
- buf[pos ] = val & 255;
2421
- buf[pos + 1] = val >>> 8 & 255;
2422
- buf[pos + 2] = val >>> 16 & 255;
2423
- buf[pos + 3] = val >>> 24;
2424
- }
2425
-
2426
- /**
2427
- * Writes an unsigned 32 bit value as fixed 32 bits.
2428
- * @param {number} value Value to write
2429
- * @returns {Writer} `this`
2430
- */
2431
- Writer.prototype.fixed32 = function write_fixed32(value) {
2432
- return this._push(writeFixed32, 4, value >>> 0);
2433
- };
2434
-
2435
- /**
2436
- * Writes a signed 32 bit value as fixed 32 bits.
2437
- * @function
2438
- * @param {number} value Value to write
2439
- * @returns {Writer} `this`
2440
- */
2441
- Writer.prototype.sfixed32 = Writer.prototype.fixed32;
2442
-
2443
- /**
2444
- * Writes an unsigned 64 bit value as fixed 64 bits.
2445
- * @param {Long|number|string} value Value to write
2446
- * @returns {Writer} `this`
2447
- * @throws {TypeError} If `value` is a string and no long library is present.
2448
- */
2449
- Writer.prototype.fixed64 = function write_fixed64(value) {
2450
- var bits = LongBits.from(value);
2451
- return this._push(writeFixed32, 4, bits.lo)._push(writeFixed32, 4, bits.hi);
2452
- };
2453
-
2454
- /**
2455
- * Writes a signed 64 bit value as fixed 64 bits.
2456
- * @function
2457
- * @param {Long|number|string} value Value to write
2458
- * @returns {Writer} `this`
2459
- * @throws {TypeError} If `value` is a string and no long library is present.
2460
- */
2461
- Writer.prototype.sfixed64 = Writer.prototype.fixed64;
2462
-
2463
- /**
2464
- * Writes a float (32 bit).
2465
- * @function
2466
- * @param {number} value Value to write
2467
- * @returns {Writer} `this`
2468
- */
2469
- Writer.prototype.float = function write_float(value) {
2470
- return this._push(util.float.writeFloatLE, 4, value);
2471
- };
2472
-
2473
- /**
2474
- * Writes a double (64 bit float).
2475
- * @function
2476
- * @param {number} value Value to write
2477
- * @returns {Writer} `this`
2478
- */
2479
- Writer.prototype.double = function write_double(value) {
2480
- return this._push(util.float.writeDoubleLE, 8, value);
2481
- };
2482
-
2483
- var writeBytes = util.Array.prototype.set
2484
- ? function writeBytes_set(val, buf, pos) {
2485
- buf.set(val, pos); // also works for plain array values
2486
- }
2487
- /* istanbul ignore next */
2488
- : function writeBytes_for(val, buf, pos) {
2489
- for (var i = 0; i < val.length; ++i)
2490
- buf[pos + i] = val[i];
2491
- };
2492
-
2493
- /**
2494
- * Writes a sequence of bytes.
2495
- * @param {Uint8Array|string} value Buffer or base64 encoded string to write
2496
- * @returns {Writer} `this`
2497
- */
2498
- Writer.prototype.bytes = function write_bytes(value) {
2499
- var len = value.length >>> 0;
2500
- if (!len)
2501
- return this._push(writeByte, 1, 0);
2502
- if (util.isString(value)) {
2503
- var buf = Writer.alloc(len = base64.length(value));
2504
- base64.decode(value, buf, 0);
2505
- value = buf;
2506
- }
2507
- return this.uint32(len)._push(writeBytes, len, value);
2508
- };
2509
-
2510
- /**
2511
- * Writes a string.
2512
- * @param {string} value Value to write
2513
- * @returns {Writer} `this`
2514
- */
2515
- Writer.prototype.string = function write_string(value) {
2516
- var len = utf8.length(value);
2517
- return len
2518
- ? this.uint32(len)._push(utf8.write, len, value)
2519
- : this._push(writeByte, 1, 0);
2520
- };
2521
-
2522
- /**
2523
- * Forks this writer's state by pushing it to a stack.
2524
- * Calling {@link Writer#reset|reset} or {@link Writer#ldelim|ldelim} resets the writer to the previous state.
2525
- * @returns {Writer} `this`
2526
- */
2527
- Writer.prototype.fork = function fork() {
2528
- this.states = new State(this);
2529
- this.head = this.tail = new Op(noop, 0, 0);
2530
- this.len = 0;
2531
- return this;
2532
- };
2533
-
2534
- /**
2535
- * Resets this instance to the last state.
2536
- * @returns {Writer} `this`
2537
- */
2538
- Writer.prototype.reset = function reset() {
2539
- if (this.states) {
2540
- this.head = this.states.head;
2541
- this.tail = this.states.tail;
2542
- this.len = this.states.len;
2543
- this.states = this.states.next;
2544
- } else {
2545
- this.head = this.tail = new Op(noop, 0, 0);
2546
- this.len = 0;
2547
- }
2548
- return this;
2549
- };
2550
-
2551
- /**
2552
- * Resets to the last state and appends the fork state's current write length as a varint followed by its operations.
2553
- * @returns {Writer} `this`
2554
- */
2555
- Writer.prototype.ldelim = function ldelim() {
2556
- var head = this.head,
2557
- tail = this.tail,
2558
- len = this.len;
2559
- this.reset().uint32(len);
2560
- if (len) {
2561
- this.tail.next = head.next; // skip noop
2562
- this.tail = tail;
2563
- this.len += len;
2564
- }
2565
- return this;
2566
- };
2567
-
2568
- /**
2569
- * Finishes the write operation.
2570
- * @returns {Uint8Array} Finished buffer
2571
- */
2572
- Writer.prototype.finish = function finish() {
2573
- var head = this.head.next, // skip noop
2574
- buf = this.constructor.alloc(this.len),
2575
- pos = 0;
2576
- while (head) {
2577
- head.fn(head.val, buf, pos);
2578
- pos += head.len;
2579
- head = head.next;
2580
- }
2581
- // this.head = this.tail = null;
2582
- return buf;
2583
- };
2584
-
2585
- Writer._configure = function(BufferWriter_) {
2586
- BufferWriter = BufferWriter_;
2587
- };
2472
+ /**
2473
+ * Writes a float (32 bit).
2474
+ * @function
2475
+ * @param {number} value Value to write
2476
+ * @returns {Writer} `this`
2477
+ */
2478
+ Writer.prototype.float = function write_float(value) {
2479
+ return this._push(util.float.writeFloatLE, 4, value);
2480
+ };
2481
+
2482
+ /**
2483
+ * Writes a double (64 bit float).
2484
+ * @function
2485
+ * @param {number} value Value to write
2486
+ * @returns {Writer} `this`
2487
+ */
2488
+ Writer.prototype.double = function write_double(value) {
2489
+ return this._push(util.float.writeDoubleLE, 8, value);
2490
+ };
2491
+
2492
+ var writeBytes = util.Array.prototype.set
2493
+ ? function writeBytes_set(val, buf, pos) {
2494
+ buf.set(val, pos); // also works for plain array values
2495
+ }
2496
+ /* istanbul ignore next */
2497
+ : function writeBytes_for(val, buf, pos) {
2498
+ for (var i = 0; i < val.length; ++i)
2499
+ buf[pos + i] = val[i];
2500
+ };
2501
+
2502
+ /**
2503
+ * Writes a sequence of bytes.
2504
+ * @param {Uint8Array|string} value Buffer or base64 encoded string to write
2505
+ * @returns {Writer} `this`
2506
+ */
2507
+ Writer.prototype.bytes = function write_bytes(value) {
2508
+ var len = value.length >>> 0;
2509
+ if (!len)
2510
+ return this._push(writeByte, 1, 0);
2511
+ if (util.isString(value)) {
2512
+ var buf = Writer.alloc(len = base64.length(value));
2513
+ base64.decode(value, buf, 0);
2514
+ value = buf;
2515
+ }
2516
+ return this.uint32(len)._push(writeBytes, len, value);
2517
+ };
2518
+
2519
+ /**
2520
+ * Writes a string.
2521
+ * @param {string} value Value to write
2522
+ * @returns {Writer} `this`
2523
+ */
2524
+ Writer.prototype.string = function write_string(value) {
2525
+ var len = utf8.length(value);
2526
+ return len
2527
+ ? this.uint32(len)._push(utf8.write, len, value)
2528
+ : this._push(writeByte, 1, 0);
2529
+ };
2530
+
2531
+ /**
2532
+ * Forks this writer's state by pushing it to a stack.
2533
+ * Calling {@link Writer#reset|reset} or {@link Writer#ldelim|ldelim} resets the writer to the previous state.
2534
+ * @returns {Writer} `this`
2535
+ */
2536
+ Writer.prototype.fork = function fork() {
2537
+ this.states = new State(this);
2538
+ this.head = this.tail = new Op(noop, 0, 0);
2539
+ this.len = 0;
2540
+ return this;
2541
+ };
2542
+
2543
+ /**
2544
+ * Resets this instance to the last state.
2545
+ * @returns {Writer} `this`
2546
+ */
2547
+ Writer.prototype.reset = function reset() {
2548
+ if (this.states) {
2549
+ this.head = this.states.head;
2550
+ this.tail = this.states.tail;
2551
+ this.len = this.states.len;
2552
+ this.states = this.states.next;
2553
+ } else {
2554
+ this.head = this.tail = new Op(noop, 0, 0);
2555
+ this.len = 0;
2556
+ }
2557
+ return this;
2558
+ };
2559
+
2560
+ /**
2561
+ * Resets to the last state and appends the fork state's current write length as a varint followed by its operations.
2562
+ * @returns {Writer} `this`
2563
+ */
2564
+ Writer.prototype.ldelim = function ldelim() {
2565
+ var head = this.head,
2566
+ tail = this.tail,
2567
+ len = this.len;
2568
+ this.reset().uint32(len);
2569
+ if (len) {
2570
+ this.tail.next = head.next; // skip noop
2571
+ this.tail = tail;
2572
+ this.len += len;
2573
+ }
2574
+ return this;
2575
+ };
2576
+
2577
+ /**
2578
+ * Finishes the write operation.
2579
+ * @returns {Uint8Array} Finished buffer
2580
+ */
2581
+ Writer.prototype.finish = function finish() {
2582
+ var head = this.head.next, // skip noop
2583
+ buf = this.constructor.alloc(this.len),
2584
+ pos = 0;
2585
+ while (head) {
2586
+ head.fn(head.val, buf, pos);
2587
+ pos += head.len;
2588
+ head = head.next;
2589
+ }
2590
+ // this.head = this.tail = null;
2591
+ return buf;
2592
+ };
2593
+
2594
+ Writer._configure = function(BufferWriter_) {
2595
+ BufferWriter = BufferWriter_;
2596
+ };
2588
2597
 
2589
2598
  },{"15":15}],17:[function(require,module,exports){
2590
- "use strict";
2591
- module.exports = BufferWriter;
2592
-
2593
- // extends Writer
2594
- var Writer = require(16);
2595
- (BufferWriter.prototype = Object.create(Writer.prototype)).constructor = BufferWriter;
2596
-
2597
- var util = require(15);
2598
-
2599
- var Buffer = util.Buffer;
2600
-
2601
- /**
2602
- * Constructs a new buffer writer instance.
2603
- * @classdesc Wire format writer using node buffers.
2604
- * @extends Writer
2605
- * @constructor
2606
- */
2607
- function BufferWriter() {
2608
- Writer.call(this);
2609
- }
2610
-
2611
- /**
2612
- * Allocates a buffer of the specified size.
2613
- * @param {number} size Buffer size
2614
- * @returns {Buffer} Buffer
2615
- */
2616
- BufferWriter.alloc = function alloc_buffer(size) {
2617
- return (BufferWriter.alloc = util._Buffer_allocUnsafe)(size);
2618
- };
2619
-
2620
- var writeBytesBuffer = Buffer && Buffer.prototype instanceof Uint8Array && Buffer.prototype.set.name === "set"
2621
- ? function writeBytesBuffer_set(val, buf, pos) {
2622
- buf.set(val, pos); // faster than copy (requires node >= 4 where Buffers extend Uint8Array and set is properly inherited)
2623
- // also works for plain array values
2624
- }
2625
- /* istanbul ignore next */
2626
- : function writeBytesBuffer_copy(val, buf, pos) {
2627
- if (val.copy) // Buffer values
2628
- val.copy(buf, pos, 0, val.length);
2629
- else for (var i = 0; i < val.length;) // plain array values
2630
- buf[pos++] = val[i++];
2631
- };
2632
-
2633
- /**
2634
- * @override
2635
- */
2636
- BufferWriter.prototype.bytes = function write_bytes_buffer(value) {
2637
- if (util.isString(value))
2638
- value = util._Buffer_from(value, "base64");
2639
- var len = value.length >>> 0;
2640
- this.uint32(len);
2641
- if (len)
2642
- this._push(writeBytesBuffer, len, value);
2643
- return this;
2644
- };
2645
-
2646
- function writeStringBuffer(val, buf, pos) {
2647
- if (val.length < 40) // plain js is faster for short strings (probably due to redundant assertions)
2648
- util.utf8.write(val, buf, pos);
2649
- else
2650
- buf.utf8Write(val, pos);
2651
- }
2652
-
2653
- /**
2654
- * @override
2655
- */
2656
- BufferWriter.prototype.string = function write_string_buffer(value) {
2657
- var len = Buffer.byteLength(value);
2658
- this.uint32(len);
2659
- if (len)
2660
- this._push(writeStringBuffer, len, value);
2661
- return this;
2662
- };
2663
-
2664
-
2665
- /**
2666
- * Finishes the write operation.
2667
- * @name BufferWriter#finish
2668
- * @function
2669
- * @returns {Buffer} Finished buffer
2670
- */
2599
+ "use strict";
2600
+ module.exports = BufferWriter;
2601
+
2602
+ // extends Writer
2603
+ var Writer = require(16);
2604
+ (BufferWriter.prototype = Object.create(Writer.prototype)).constructor = BufferWriter;
2605
+
2606
+ var util = require(15);
2607
+
2608
+ var Buffer = util.Buffer;
2609
+
2610
+ /**
2611
+ * Constructs a new buffer writer instance.
2612
+ * @classdesc Wire format writer using node buffers.
2613
+ * @extends Writer
2614
+ * @constructor
2615
+ */
2616
+ function BufferWriter() {
2617
+ Writer.call(this);
2618
+ }
2619
+
2620
+ /**
2621
+ * Allocates a buffer of the specified size.
2622
+ * @param {number} size Buffer size
2623
+ * @returns {Buffer} Buffer
2624
+ */
2625
+ BufferWriter.alloc = function alloc_buffer(size) {
2626
+ return (BufferWriter.alloc = util._Buffer_allocUnsafe)(size);
2627
+ };
2628
+
2629
+ var writeBytesBuffer = Buffer && Buffer.prototype instanceof Uint8Array && Buffer.prototype.set.name === "set"
2630
+ ? function writeBytesBuffer_set(val, buf, pos) {
2631
+ buf.set(val, pos); // faster than copy (requires node >= 4 where Buffers extend Uint8Array and set is properly inherited)
2632
+ // also works for plain array values
2633
+ }
2634
+ /* istanbul ignore next */
2635
+ : function writeBytesBuffer_copy(val, buf, pos) {
2636
+ if (val.copy) // Buffer values
2637
+ val.copy(buf, pos, 0, val.length);
2638
+ else for (var i = 0; i < val.length;) // plain array values
2639
+ buf[pos++] = val[i++];
2640
+ };
2641
+
2642
+ /**
2643
+ * @override
2644
+ */
2645
+ BufferWriter.prototype.bytes = function write_bytes_buffer(value) {
2646
+ if (util.isString(value))
2647
+ value = util._Buffer_from(value, "base64");
2648
+ var len = value.length >>> 0;
2649
+ this.uint32(len);
2650
+ if (len)
2651
+ this._push(writeBytesBuffer, len, value);
2652
+ return this;
2653
+ };
2654
+
2655
+ function writeStringBuffer(val, buf, pos) {
2656
+ if (val.length < 40) // plain js is faster for short strings (probably due to redundant assertions)
2657
+ util.utf8.write(val, buf, pos);
2658
+ else
2659
+ buf.utf8Write(val, pos);
2660
+ }
2661
+
2662
+ /**
2663
+ * @override
2664
+ */
2665
+ BufferWriter.prototype.string = function write_string_buffer(value) {
2666
+ var len = Buffer.byteLength(value);
2667
+ this.uint32(len);
2668
+ if (len)
2669
+ this._push(writeStringBuffer, len, value);
2670
+ return this;
2671
+ };
2672
+
2673
+
2674
+ /**
2675
+ * Finishes the write operation.
2676
+ * @name BufferWriter#finish
2677
+ * @function
2678
+ * @returns {Buffer} Finished buffer
2679
+ */
2671
2680
 
2672
2681
  },{"15":15,"16":16}]},{},[8])
2673
2682
 
2674
- })(typeof window==="object"&&window||typeof self==="object"&&self||this);
2675
- //# sourceMappingURL=protobuf.js.map
2683
+ })();
2684
+ //# sourceMappingURL=protobuf.js.map