protobufjs 6.8.8 → 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 (104) hide show
  1. package/LICENSE +39 -39
  2. package/README.md +879 -879
  3. package/cli/LICENSE +33 -33
  4. package/cli/README.md +11 -11
  5. package/cli/index.d.ts +3 -3
  6. package/cli/index.js +3 -3
  7. package/cli/lib/tsd-jsdoc/LICENSE +20 -20
  8. package/cli/lib/tsd-jsdoc/README.md +23 -23
  9. package/cli/lib/tsd-jsdoc/plugin.js +21 -21
  10. package/cli/lib/tsd-jsdoc/publish.js +693 -693
  11. package/cli/lib/tsd-jsdoc.json +18 -18
  12. package/cli/package.standalone.json +31 -31
  13. package/cli/pbjs.d.ts +9 -9
  14. package/cli/pbjs.js +329 -329
  15. package/cli/pbts.d.ts +9 -9
  16. package/cli/pbts.js +197 -197
  17. package/cli/targets/json-module.js +38 -38
  18. package/cli/targets/json.js +8 -8
  19. package/cli/targets/proto.js +326 -326
  20. package/cli/targets/proto2.js +10 -10
  21. package/cli/targets/proto3.js +10 -10
  22. package/cli/targets/static-module.js +29 -29
  23. package/cli/targets/static.js +702 -702
  24. package/cli/util.js +183 -183
  25. package/cli/wrappers/amd.js +7 -7
  26. package/cli/wrappers/closure.js +7 -7
  27. package/cli/wrappers/commonjs.js +7 -7
  28. package/cli/wrappers/default.js +15 -15
  29. package/cli/wrappers/es6.js +5 -5
  30. package/dist/README.md +31 -31
  31. package/dist/light/README.md +31 -31
  32. package/dist/light/protobuf.js +6030 -6030
  33. package/dist/light/protobuf.js.map +1 -1
  34. package/dist/light/protobuf.min.js +1 -1
  35. package/dist/light/protobuf.min.js.map +1 -1
  36. package/dist/minimal/README.md +31 -31
  37. package/dist/minimal/protobuf.js +1876 -1876
  38. package/dist/minimal/protobuf.js.map +1 -1
  39. package/dist/minimal/protobuf.min.js +1 -1
  40. package/dist/minimal/protobuf.min.js.map +1 -1
  41. package/dist/protobuf.js +7595 -7595
  42. package/dist/protobuf.js.map +1 -1
  43. package/dist/protobuf.min.js +1 -1
  44. package/dist/protobuf.min.js.map +1 -1
  45. package/ext/debug/README.md +4 -4
  46. package/ext/debug/index.js +71 -71
  47. package/ext/descriptor/README.md +72 -72
  48. package/ext/descriptor/index.js +1052 -1052
  49. package/ext/descriptor/test.js +54 -54
  50. package/google/LICENSE +27 -27
  51. package/google/README.md +1 -1
  52. package/google/api/annotations.proto +10 -10
  53. package/google/protobuf/descriptor.proto +286 -286
  54. package/google/protobuf/source_context.proto +7 -7
  55. package/index.js +4 -4
  56. package/light.d.ts +2 -2
  57. package/light.js +3 -3
  58. package/minimal.d.ts +2 -2
  59. package/minimal.js +4 -4
  60. package/package-lock.json +1748 -642
  61. package/package.json +119 -122
  62. package/scripts/changelog.js +150 -150
  63. package/scripts/postinstall.js +35 -35
  64. package/src/common.js +399 -399
  65. package/src/converter.js +293 -293
  66. package/src/decoder.js +106 -106
  67. package/src/encoder.js +99 -99
  68. package/src/enum.js +181 -181
  69. package/src/field.js +371 -371
  70. package/src/index-light.js +104 -104
  71. package/src/index-minimal.js +36 -36
  72. package/src/index.js +12 -12
  73. package/src/mapfield.js +126 -126
  74. package/src/message.js +138 -138
  75. package/src/method.js +151 -151
  76. package/src/namespace.js +433 -433
  77. package/src/object.js +200 -200
  78. package/src/oneof.js +203 -203
  79. package/src/parse.js +758 -758
  80. package/src/reader.js +405 -405
  81. package/src/reader_buffer.js +44 -44
  82. package/src/root.js +351 -351
  83. package/src/roots.js +18 -18
  84. package/src/rpc/service.js +142 -142
  85. package/src/rpc.js +36 -36
  86. package/src/service.js +167 -167
  87. package/src/tokenize.js +397 -397
  88. package/src/type.js +589 -589
  89. package/src/types.js +196 -196
  90. package/src/typescript.jsdoc +15 -15
  91. package/src/util/longbits.js +200 -200
  92. package/src/util/minimal.js +414 -414
  93. package/src/util.js +178 -178
  94. package/src/verifier.js +176 -176
  95. package/src/wrappers.js +83 -83
  96. package/src/writer.js +459 -459
  97. package/src/writer_buffer.js +81 -81
  98. package/tsconfig.json +6 -6
  99. package/cli/node_modules/os-tmpdir/index.js +0 -25
  100. package/cli/node_modules/os-tmpdir/license +0 -21
  101. package/cli/node_modules/os-tmpdir/readme.md +0 -32
  102. package/cli/node_modules/tmp/LICENSE +0 -21
  103. package/cli/node_modules/tmp/README.md +0 -314
  104. package/cli/node_modules/tmp/lib/tmp.js +0 -611
package/src/reader.js CHANGED
@@ -1,405 +1,405 @@
1
- "use strict";
2
- module.exports = Reader;
3
-
4
- var util = require("./util/minimal");
5
-
6
- var BufferReader; // cyclic
7
-
8
- var LongBits = util.LongBits,
9
- utf8 = util.utf8;
10
-
11
- /* istanbul ignore next */
12
- function indexOutOfRange(reader, writeLength) {
13
- return RangeError("index out of range: " + reader.pos + " + " + (writeLength || 1) + " > " + reader.len);
14
- }
15
-
16
- /**
17
- * Constructs a new reader instance using the specified buffer.
18
- * @classdesc Wire format reader using `Uint8Array` if available, otherwise `Array`.
19
- * @constructor
20
- * @param {Uint8Array} buffer Buffer to read from
21
- */
22
- function Reader(buffer) {
23
-
24
- /**
25
- * Read buffer.
26
- * @type {Uint8Array}
27
- */
28
- this.buf = buffer;
29
-
30
- /**
31
- * Read buffer position.
32
- * @type {number}
33
- */
34
- this.pos = 0;
35
-
36
- /**
37
- * Read buffer length.
38
- * @type {number}
39
- */
40
- this.len = buffer.length;
41
- }
42
-
43
- var create_array = typeof Uint8Array !== "undefined"
44
- ? function create_typed_array(buffer) {
45
- if (buffer instanceof Uint8Array || Array.isArray(buffer))
46
- return new Reader(buffer);
47
- throw Error("illegal buffer");
48
- }
49
- /* istanbul ignore next */
50
- : function create_array(buffer) {
51
- if (Array.isArray(buffer))
52
- return new Reader(buffer);
53
- throw Error("illegal buffer");
54
- };
55
-
56
- /**
57
- * Creates a new reader using the specified buffer.
58
- * @function
59
- * @param {Uint8Array|Buffer} buffer Buffer to read from
60
- * @returns {Reader|BufferReader} A {@link BufferReader} if `buffer` is a Buffer, otherwise a {@link Reader}
61
- * @throws {Error} If `buffer` is not a valid buffer
62
- */
63
- Reader.create = util.Buffer
64
- ? function create_buffer_setup(buffer) {
65
- return (Reader.create = function create_buffer(buffer) {
66
- return util.Buffer.isBuffer(buffer)
67
- ? new BufferReader(buffer)
68
- /* istanbul ignore next */
69
- : create_array(buffer);
70
- })(buffer);
71
- }
72
- /* istanbul ignore next */
73
- : create_array;
74
-
75
- Reader.prototype._slice = util.Array.prototype.subarray || /* istanbul ignore next */ util.Array.prototype.slice;
76
-
77
- /**
78
- * Reads a varint as an unsigned 32 bit value.
79
- * @function
80
- * @returns {number} Value read
81
- */
82
- Reader.prototype.uint32 = (function read_uint32_setup() {
83
- var value = 4294967295; // optimizer type-hint, tends to deopt otherwise (?!)
84
- return function read_uint32() {
85
- value = ( this.buf[this.pos] & 127 ) >>> 0; if (this.buf[this.pos++] < 128) return value;
86
- value = (value | (this.buf[this.pos] & 127) << 7) >>> 0; if (this.buf[this.pos++] < 128) return value;
87
- value = (value | (this.buf[this.pos] & 127) << 14) >>> 0; if (this.buf[this.pos++] < 128) return value;
88
- value = (value | (this.buf[this.pos] & 127) << 21) >>> 0; if (this.buf[this.pos++] < 128) return value;
89
- value = (value | (this.buf[this.pos] & 15) << 28) >>> 0; if (this.buf[this.pos++] < 128) return value;
90
-
91
- /* istanbul ignore if */
92
- if ((this.pos += 5) > this.len) {
93
- this.pos = this.len;
94
- throw indexOutOfRange(this, 10);
95
- }
96
- return value;
97
- };
98
- })();
99
-
100
- /**
101
- * Reads a varint as a signed 32 bit value.
102
- * @returns {number} Value read
103
- */
104
- Reader.prototype.int32 = function read_int32() {
105
- return this.uint32() | 0;
106
- };
107
-
108
- /**
109
- * Reads a zig-zag encoded varint as a signed 32 bit value.
110
- * @returns {number} Value read
111
- */
112
- Reader.prototype.sint32 = function read_sint32() {
113
- var value = this.uint32();
114
- return value >>> 1 ^ -(value & 1) | 0;
115
- };
116
-
117
- /* eslint-disable no-invalid-this */
118
-
119
- function readLongVarint() {
120
- // tends to deopt with local vars for octet etc.
121
- var bits = new LongBits(0, 0);
122
- var i = 0;
123
- if (this.len - this.pos > 4) { // fast route (lo)
124
- for (; i < 4; ++i) {
125
- // 1st..4th
126
- bits.lo = (bits.lo | (this.buf[this.pos] & 127) << i * 7) >>> 0;
127
- if (this.buf[this.pos++] < 128)
128
- return bits;
129
- }
130
- // 5th
131
- bits.lo = (bits.lo | (this.buf[this.pos] & 127) << 28) >>> 0;
132
- bits.hi = (bits.hi | (this.buf[this.pos] & 127) >> 4) >>> 0;
133
- if (this.buf[this.pos++] < 128)
134
- return bits;
135
- i = 0;
136
- } else {
137
- for (; i < 3; ++i) {
138
- /* istanbul ignore if */
139
- if (this.pos >= this.len)
140
- throw indexOutOfRange(this);
141
- // 1st..3th
142
- bits.lo = (bits.lo | (this.buf[this.pos] & 127) << i * 7) >>> 0;
143
- if (this.buf[this.pos++] < 128)
144
- return bits;
145
- }
146
- // 4th
147
- bits.lo = (bits.lo | (this.buf[this.pos++] & 127) << i * 7) >>> 0;
148
- return bits;
149
- }
150
- if (this.len - this.pos > 4) { // fast route (hi)
151
- for (; i < 5; ++i) {
152
- // 6th..10th
153
- bits.hi = (bits.hi | (this.buf[this.pos] & 127) << i * 7 + 3) >>> 0;
154
- if (this.buf[this.pos++] < 128)
155
- return bits;
156
- }
157
- } else {
158
- for (; i < 5; ++i) {
159
- /* istanbul ignore if */
160
- if (this.pos >= this.len)
161
- throw indexOutOfRange(this);
162
- // 6th..10th
163
- bits.hi = (bits.hi | (this.buf[this.pos] & 127) << i * 7 + 3) >>> 0;
164
- if (this.buf[this.pos++] < 128)
165
- return bits;
166
- }
167
- }
168
- /* istanbul ignore next */
169
- throw Error("invalid varint encoding");
170
- }
171
-
172
- /* eslint-enable no-invalid-this */
173
-
174
- /**
175
- * Reads a varint as a signed 64 bit value.
176
- * @name Reader#int64
177
- * @function
178
- * @returns {Long} Value read
179
- */
180
-
181
- /**
182
- * Reads a varint as an unsigned 64 bit value.
183
- * @name Reader#uint64
184
- * @function
185
- * @returns {Long} Value read
186
- */
187
-
188
- /**
189
- * Reads a zig-zag encoded varint as a signed 64 bit value.
190
- * @name Reader#sint64
191
- * @function
192
- * @returns {Long} Value read
193
- */
194
-
195
- /**
196
- * Reads a varint as a boolean.
197
- * @returns {boolean} Value read
198
- */
199
- Reader.prototype.bool = function read_bool() {
200
- return this.uint32() !== 0;
201
- };
202
-
203
- function readFixed32_end(buf, end) { // note that this uses `end`, not `pos`
204
- return (buf[end - 4]
205
- | buf[end - 3] << 8
206
- | buf[end - 2] << 16
207
- | buf[end - 1] << 24) >>> 0;
208
- }
209
-
210
- /**
211
- * Reads fixed 32 bits as an unsigned 32 bit integer.
212
- * @returns {number} Value read
213
- */
214
- Reader.prototype.fixed32 = function read_fixed32() {
215
-
216
- /* istanbul ignore if */
217
- if (this.pos + 4 > this.len)
218
- throw indexOutOfRange(this, 4);
219
-
220
- return readFixed32_end(this.buf, this.pos += 4);
221
- };
222
-
223
- /**
224
- * Reads fixed 32 bits as a signed 32 bit integer.
225
- * @returns {number} Value read
226
- */
227
- Reader.prototype.sfixed32 = function read_sfixed32() {
228
-
229
- /* istanbul ignore if */
230
- if (this.pos + 4 > this.len)
231
- throw indexOutOfRange(this, 4);
232
-
233
- return readFixed32_end(this.buf, this.pos += 4) | 0;
234
- };
235
-
236
- /* eslint-disable no-invalid-this */
237
-
238
- function readFixed64(/* this: Reader */) {
239
-
240
- /* istanbul ignore if */
241
- if (this.pos + 8 > this.len)
242
- throw indexOutOfRange(this, 8);
243
-
244
- return new LongBits(readFixed32_end(this.buf, this.pos += 4), readFixed32_end(this.buf, this.pos += 4));
245
- }
246
-
247
- /* eslint-enable no-invalid-this */
248
-
249
- /**
250
- * Reads fixed 64 bits.
251
- * @name Reader#fixed64
252
- * @function
253
- * @returns {Long} Value read
254
- */
255
-
256
- /**
257
- * Reads zig-zag encoded fixed 64 bits.
258
- * @name Reader#sfixed64
259
- * @function
260
- * @returns {Long} Value read
261
- */
262
-
263
- /**
264
- * Reads a float (32 bit) as a number.
265
- * @function
266
- * @returns {number} Value read
267
- */
268
- Reader.prototype.float = function read_float() {
269
-
270
- /* istanbul ignore if */
271
- if (this.pos + 4 > this.len)
272
- throw indexOutOfRange(this, 4);
273
-
274
- var value = util.float.readFloatLE(this.buf, this.pos);
275
- this.pos += 4;
276
- return value;
277
- };
278
-
279
- /**
280
- * Reads a double (64 bit float) as a number.
281
- * @function
282
- * @returns {number} Value read
283
- */
284
- Reader.prototype.double = function read_double() {
285
-
286
- /* istanbul ignore if */
287
- if (this.pos + 8 > this.len)
288
- throw indexOutOfRange(this, 4);
289
-
290
- var value = util.float.readDoubleLE(this.buf, this.pos);
291
- this.pos += 8;
292
- return value;
293
- };
294
-
295
- /**
296
- * Reads a sequence of bytes preceeded by its length as a varint.
297
- * @returns {Uint8Array} Value read
298
- */
299
- Reader.prototype.bytes = function read_bytes() {
300
- var length = this.uint32(),
301
- start = this.pos,
302
- end = this.pos + length;
303
-
304
- /* istanbul ignore if */
305
- if (end > this.len)
306
- throw indexOutOfRange(this, length);
307
-
308
- this.pos += length;
309
- if (Array.isArray(this.buf)) // plain array
310
- return this.buf.slice(start, end);
311
- return start === end // fix for IE 10/Win8 and others' subarray returning array of size 1
312
- ? new this.buf.constructor(0)
313
- : this._slice.call(this.buf, start, end);
314
- };
315
-
316
- /**
317
- * Reads a string preceeded by its byte length as a varint.
318
- * @returns {string} Value read
319
- */
320
- Reader.prototype.string = function read_string() {
321
- var bytes = this.bytes();
322
- return utf8.read(bytes, 0, bytes.length);
323
- };
324
-
325
- /**
326
- * Skips the specified number of bytes if specified, otherwise skips a varint.
327
- * @param {number} [length] Length if known, otherwise a varint is assumed
328
- * @returns {Reader} `this`
329
- */
330
- Reader.prototype.skip = function skip(length) {
331
- if (typeof length === "number") {
332
- /* istanbul ignore if */
333
- if (this.pos + length > this.len)
334
- throw indexOutOfRange(this, length);
335
- this.pos += length;
336
- } else {
337
- do {
338
- /* istanbul ignore if */
339
- if (this.pos >= this.len)
340
- throw indexOutOfRange(this);
341
- } while (this.buf[this.pos++] & 128);
342
- }
343
- return this;
344
- };
345
-
346
- /**
347
- * Skips the next element of the specified wire type.
348
- * @param {number} wireType Wire type received
349
- * @returns {Reader} `this`
350
- */
351
- Reader.prototype.skipType = function(wireType) {
352
- switch (wireType) {
353
- case 0:
354
- this.skip();
355
- break;
356
- case 1:
357
- this.skip(8);
358
- break;
359
- case 2:
360
- this.skip(this.uint32());
361
- break;
362
- case 3:
363
- while ((wireType = this.uint32() & 7) !== 4) {
364
- this.skipType(wireType);
365
- }
366
- break;
367
- case 5:
368
- this.skip(4);
369
- break;
370
-
371
- /* istanbul ignore next */
372
- default:
373
- throw Error("invalid wire type " + wireType + " at offset " + this.pos);
374
- }
375
- return this;
376
- };
377
-
378
- Reader._configure = function(BufferReader_) {
379
- BufferReader = BufferReader_;
380
-
381
- var fn = util.Long ? "toLong" : /* istanbul ignore next */ "toNumber";
382
- util.merge(Reader.prototype, {
383
-
384
- int64: function read_int64() {
385
- return readLongVarint.call(this)[fn](false);
386
- },
387
-
388
- uint64: function read_uint64() {
389
- return readLongVarint.call(this)[fn](true);
390
- },
391
-
392
- sint64: function read_sint64() {
393
- return readLongVarint.call(this).zzDecode()[fn](false);
394
- },
395
-
396
- fixed64: function read_fixed64() {
397
- return readFixed64.call(this)[fn](true);
398
- },
399
-
400
- sfixed64: function read_sfixed64() {
401
- return readFixed64.call(this)[fn](false);
402
- }
403
-
404
- });
405
- };
1
+ "use strict";
2
+ module.exports = Reader;
3
+
4
+ var util = require("./util/minimal");
5
+
6
+ var BufferReader; // cyclic
7
+
8
+ var LongBits = util.LongBits,
9
+ utf8 = util.utf8;
10
+
11
+ /* istanbul ignore next */
12
+ function indexOutOfRange(reader, writeLength) {
13
+ return RangeError("index out of range: " + reader.pos + " + " + (writeLength || 1) + " > " + reader.len);
14
+ }
15
+
16
+ /**
17
+ * Constructs a new reader instance using the specified buffer.
18
+ * @classdesc Wire format reader using `Uint8Array` if available, otherwise `Array`.
19
+ * @constructor
20
+ * @param {Uint8Array} buffer Buffer to read from
21
+ */
22
+ function Reader(buffer) {
23
+
24
+ /**
25
+ * Read buffer.
26
+ * @type {Uint8Array}
27
+ */
28
+ this.buf = buffer;
29
+
30
+ /**
31
+ * Read buffer position.
32
+ * @type {number}
33
+ */
34
+ this.pos = 0;
35
+
36
+ /**
37
+ * Read buffer length.
38
+ * @type {number}
39
+ */
40
+ this.len = buffer.length;
41
+ }
42
+
43
+ var create_array = typeof Uint8Array !== "undefined"
44
+ ? function create_typed_array(buffer) {
45
+ if (buffer instanceof Uint8Array || Array.isArray(buffer))
46
+ return new Reader(buffer);
47
+ throw Error("illegal buffer");
48
+ }
49
+ /* istanbul ignore next */
50
+ : function create_array(buffer) {
51
+ if (Array.isArray(buffer))
52
+ return new Reader(buffer);
53
+ throw Error("illegal buffer");
54
+ };
55
+
56
+ /**
57
+ * Creates a new reader using the specified buffer.
58
+ * @function
59
+ * @param {Uint8Array|Buffer} buffer Buffer to read from
60
+ * @returns {Reader|BufferReader} A {@link BufferReader} if `buffer` is a Buffer, otherwise a {@link Reader}
61
+ * @throws {Error} If `buffer` is not a valid buffer
62
+ */
63
+ Reader.create = util.Buffer
64
+ ? function create_buffer_setup(buffer) {
65
+ return (Reader.create = function create_buffer(buffer) {
66
+ return util.Buffer.isBuffer(buffer)
67
+ ? new BufferReader(buffer)
68
+ /* istanbul ignore next */
69
+ : create_array(buffer);
70
+ })(buffer);
71
+ }
72
+ /* istanbul ignore next */
73
+ : create_array;
74
+
75
+ Reader.prototype._slice = util.Array.prototype.subarray || /* istanbul ignore next */ util.Array.prototype.slice;
76
+
77
+ /**
78
+ * Reads a varint as an unsigned 32 bit value.
79
+ * @function
80
+ * @returns {number} Value read
81
+ */
82
+ Reader.prototype.uint32 = (function read_uint32_setup() {
83
+ var value = 4294967295; // optimizer type-hint, tends to deopt otherwise (?!)
84
+ return function read_uint32() {
85
+ value = ( this.buf[this.pos] & 127 ) >>> 0; if (this.buf[this.pos++] < 128) return value;
86
+ value = (value | (this.buf[this.pos] & 127) << 7) >>> 0; if (this.buf[this.pos++] < 128) return value;
87
+ value = (value | (this.buf[this.pos] & 127) << 14) >>> 0; if (this.buf[this.pos++] < 128) return value;
88
+ value = (value | (this.buf[this.pos] & 127) << 21) >>> 0; if (this.buf[this.pos++] < 128) return value;
89
+ value = (value | (this.buf[this.pos] & 15) << 28) >>> 0; if (this.buf[this.pos++] < 128) return value;
90
+
91
+ /* istanbul ignore if */
92
+ if ((this.pos += 5) > this.len) {
93
+ this.pos = this.len;
94
+ throw indexOutOfRange(this, 10);
95
+ }
96
+ return value;
97
+ };
98
+ })();
99
+
100
+ /**
101
+ * Reads a varint as a signed 32 bit value.
102
+ * @returns {number} Value read
103
+ */
104
+ Reader.prototype.int32 = function read_int32() {
105
+ return this.uint32() | 0;
106
+ };
107
+
108
+ /**
109
+ * Reads a zig-zag encoded varint as a signed 32 bit value.
110
+ * @returns {number} Value read
111
+ */
112
+ Reader.prototype.sint32 = function read_sint32() {
113
+ var value = this.uint32();
114
+ return value >>> 1 ^ -(value & 1) | 0;
115
+ };
116
+
117
+ /* eslint-disable no-invalid-this */
118
+
119
+ function readLongVarint() {
120
+ // tends to deopt with local vars for octet etc.
121
+ var bits = new LongBits(0, 0);
122
+ var i = 0;
123
+ if (this.len - this.pos > 4) { // fast route (lo)
124
+ for (; i < 4; ++i) {
125
+ // 1st..4th
126
+ bits.lo = (bits.lo | (this.buf[this.pos] & 127) << i * 7) >>> 0;
127
+ if (this.buf[this.pos++] < 128)
128
+ return bits;
129
+ }
130
+ // 5th
131
+ bits.lo = (bits.lo | (this.buf[this.pos] & 127) << 28) >>> 0;
132
+ bits.hi = (bits.hi | (this.buf[this.pos] & 127) >> 4) >>> 0;
133
+ if (this.buf[this.pos++] < 128)
134
+ return bits;
135
+ i = 0;
136
+ } else {
137
+ for (; i < 3; ++i) {
138
+ /* istanbul ignore if */
139
+ if (this.pos >= this.len)
140
+ throw indexOutOfRange(this);
141
+ // 1st..3th
142
+ bits.lo = (bits.lo | (this.buf[this.pos] & 127) << i * 7) >>> 0;
143
+ if (this.buf[this.pos++] < 128)
144
+ return bits;
145
+ }
146
+ // 4th
147
+ bits.lo = (bits.lo | (this.buf[this.pos++] & 127) << i * 7) >>> 0;
148
+ return bits;
149
+ }
150
+ if (this.len - this.pos > 4) { // fast route (hi)
151
+ for (; i < 5; ++i) {
152
+ // 6th..10th
153
+ bits.hi = (bits.hi | (this.buf[this.pos] & 127) << i * 7 + 3) >>> 0;
154
+ if (this.buf[this.pos++] < 128)
155
+ return bits;
156
+ }
157
+ } else {
158
+ for (; i < 5; ++i) {
159
+ /* istanbul ignore if */
160
+ if (this.pos >= this.len)
161
+ throw indexOutOfRange(this);
162
+ // 6th..10th
163
+ bits.hi = (bits.hi | (this.buf[this.pos] & 127) << i * 7 + 3) >>> 0;
164
+ if (this.buf[this.pos++] < 128)
165
+ return bits;
166
+ }
167
+ }
168
+ /* istanbul ignore next */
169
+ throw Error("invalid varint encoding");
170
+ }
171
+
172
+ /* eslint-enable no-invalid-this */
173
+
174
+ /**
175
+ * Reads a varint as a signed 64 bit value.
176
+ * @name Reader#int64
177
+ * @function
178
+ * @returns {Long} Value read
179
+ */
180
+
181
+ /**
182
+ * Reads a varint as an unsigned 64 bit value.
183
+ * @name Reader#uint64
184
+ * @function
185
+ * @returns {Long} Value read
186
+ */
187
+
188
+ /**
189
+ * Reads a zig-zag encoded varint as a signed 64 bit value.
190
+ * @name Reader#sint64
191
+ * @function
192
+ * @returns {Long} Value read
193
+ */
194
+
195
+ /**
196
+ * Reads a varint as a boolean.
197
+ * @returns {boolean} Value read
198
+ */
199
+ Reader.prototype.bool = function read_bool() {
200
+ return this.uint32() !== 0;
201
+ };
202
+
203
+ function readFixed32_end(buf, end) { // note that this uses `end`, not `pos`
204
+ return (buf[end - 4]
205
+ | buf[end - 3] << 8
206
+ | buf[end - 2] << 16
207
+ | buf[end - 1] << 24) >>> 0;
208
+ }
209
+
210
+ /**
211
+ * Reads fixed 32 bits as an unsigned 32 bit integer.
212
+ * @returns {number} Value read
213
+ */
214
+ Reader.prototype.fixed32 = function read_fixed32() {
215
+
216
+ /* istanbul ignore if */
217
+ if (this.pos + 4 > this.len)
218
+ throw indexOutOfRange(this, 4);
219
+
220
+ return readFixed32_end(this.buf, this.pos += 4);
221
+ };
222
+
223
+ /**
224
+ * Reads fixed 32 bits as a signed 32 bit integer.
225
+ * @returns {number} Value read
226
+ */
227
+ Reader.prototype.sfixed32 = function read_sfixed32() {
228
+
229
+ /* istanbul ignore if */
230
+ if (this.pos + 4 > this.len)
231
+ throw indexOutOfRange(this, 4);
232
+
233
+ return readFixed32_end(this.buf, this.pos += 4) | 0;
234
+ };
235
+
236
+ /* eslint-disable no-invalid-this */
237
+
238
+ function readFixed64(/* this: Reader */) {
239
+
240
+ /* istanbul ignore if */
241
+ if (this.pos + 8 > this.len)
242
+ throw indexOutOfRange(this, 8);
243
+
244
+ return new LongBits(readFixed32_end(this.buf, this.pos += 4), readFixed32_end(this.buf, this.pos += 4));
245
+ }
246
+
247
+ /* eslint-enable no-invalid-this */
248
+
249
+ /**
250
+ * Reads fixed 64 bits.
251
+ * @name Reader#fixed64
252
+ * @function
253
+ * @returns {Long} Value read
254
+ */
255
+
256
+ /**
257
+ * Reads zig-zag encoded fixed 64 bits.
258
+ * @name Reader#sfixed64
259
+ * @function
260
+ * @returns {Long} Value read
261
+ */
262
+
263
+ /**
264
+ * Reads a float (32 bit) as a number.
265
+ * @function
266
+ * @returns {number} Value read
267
+ */
268
+ Reader.prototype.float = function read_float() {
269
+
270
+ /* istanbul ignore if */
271
+ if (this.pos + 4 > this.len)
272
+ throw indexOutOfRange(this, 4);
273
+
274
+ var value = util.float.readFloatLE(this.buf, this.pos);
275
+ this.pos += 4;
276
+ return value;
277
+ };
278
+
279
+ /**
280
+ * Reads a double (64 bit float) as a number.
281
+ * @function
282
+ * @returns {number} Value read
283
+ */
284
+ Reader.prototype.double = function read_double() {
285
+
286
+ /* istanbul ignore if */
287
+ if (this.pos + 8 > this.len)
288
+ throw indexOutOfRange(this, 4);
289
+
290
+ var value = util.float.readDoubleLE(this.buf, this.pos);
291
+ this.pos += 8;
292
+ return value;
293
+ };
294
+
295
+ /**
296
+ * Reads a sequence of bytes preceeded by its length as a varint.
297
+ * @returns {Uint8Array} Value read
298
+ */
299
+ Reader.prototype.bytes = function read_bytes() {
300
+ var length = this.uint32(),
301
+ start = this.pos,
302
+ end = this.pos + length;
303
+
304
+ /* istanbul ignore if */
305
+ if (end > this.len)
306
+ throw indexOutOfRange(this, length);
307
+
308
+ this.pos += length;
309
+ if (Array.isArray(this.buf)) // plain array
310
+ return this.buf.slice(start, end);
311
+ return start === end // fix for IE 10/Win8 and others' subarray returning array of size 1
312
+ ? new this.buf.constructor(0)
313
+ : this._slice.call(this.buf, start, end);
314
+ };
315
+
316
+ /**
317
+ * Reads a string preceeded by its byte length as a varint.
318
+ * @returns {string} Value read
319
+ */
320
+ Reader.prototype.string = function read_string() {
321
+ var bytes = this.bytes();
322
+ return utf8.read(bytes, 0, bytes.length);
323
+ };
324
+
325
+ /**
326
+ * Skips the specified number of bytes if specified, otherwise skips a varint.
327
+ * @param {number} [length] Length if known, otherwise a varint is assumed
328
+ * @returns {Reader} `this`
329
+ */
330
+ Reader.prototype.skip = function skip(length) {
331
+ if (typeof length === "number") {
332
+ /* istanbul ignore if */
333
+ if (this.pos + length > this.len)
334
+ throw indexOutOfRange(this, length);
335
+ this.pos += length;
336
+ } else {
337
+ do {
338
+ /* istanbul ignore if */
339
+ if (this.pos >= this.len)
340
+ throw indexOutOfRange(this);
341
+ } while (this.buf[this.pos++] & 128);
342
+ }
343
+ return this;
344
+ };
345
+
346
+ /**
347
+ * Skips the next element of the specified wire type.
348
+ * @param {number} wireType Wire type received
349
+ * @returns {Reader} `this`
350
+ */
351
+ Reader.prototype.skipType = function(wireType) {
352
+ switch (wireType) {
353
+ case 0:
354
+ this.skip();
355
+ break;
356
+ case 1:
357
+ this.skip(8);
358
+ break;
359
+ case 2:
360
+ this.skip(this.uint32());
361
+ break;
362
+ case 3:
363
+ while ((wireType = this.uint32() & 7) !== 4) {
364
+ this.skipType(wireType);
365
+ }
366
+ break;
367
+ case 5:
368
+ this.skip(4);
369
+ break;
370
+
371
+ /* istanbul ignore next */
372
+ default:
373
+ throw Error("invalid wire type " + wireType + " at offset " + this.pos);
374
+ }
375
+ return this;
376
+ };
377
+
378
+ Reader._configure = function(BufferReader_) {
379
+ BufferReader = BufferReader_;
380
+
381
+ var fn = util.Long ? "toLong" : /* istanbul ignore next */ "toNumber";
382
+ util.merge(Reader.prototype, {
383
+
384
+ int64: function read_int64() {
385
+ return readLongVarint.call(this)[fn](false);
386
+ },
387
+
388
+ uint64: function read_uint64() {
389
+ return readLongVarint.call(this)[fn](true);
390
+ },
391
+
392
+ sint64: function read_sint64() {
393
+ return readLongVarint.call(this).zzDecode()[fn](false);
394
+ },
395
+
396
+ fixed64: function read_fixed64() {
397
+ return readFixed64.call(this)[fn](true);
398
+ },
399
+
400
+ sfixed64: function read_sfixed64() {
401
+ return readFixed64.call(this)[fn](false);
402
+ }
403
+
404
+ });
405
+ };