protobufjs 8.6.6 → 8.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +53 -54
- package/dist/light/protobuf.js +745 -341
- package/dist/light/protobuf.js.map +1 -1
- package/dist/light/protobuf.min.js +3 -3
- package/dist/light/protobuf.min.js.map +1 -1
- package/dist/minimal/protobuf.js +729 -327
- package/dist/minimal/protobuf.js.map +1 -1
- package/dist/minimal/protobuf.min.js +3 -3
- package/dist/minimal/protobuf.min.js.map +1 -1
- package/dist/protobuf.js +824 -376
- package/dist/protobuf.js.map +1 -1
- package/dist/protobuf.min.js +3 -3
- package/dist/protobuf.min.js.map +1 -1
- package/ext/protojson.js +5 -1
- package/google/api/annotations.json +3 -1
- package/google/api/http.json +2 -1
- package/google/protobuf/api.json +12 -6
- package/google/protobuf/descriptor.json +170 -87
- package/google/protobuf/descriptor.proto +0 -8
- package/google/protobuf/source_context.json +2 -1
- package/google/protobuf/type.json +14 -7
- package/index.d.ts +211 -23
- package/package.json +5 -5
- package/src/common.js +12 -6
- package/src/converter.js +1 -1
- package/src/decoder.js +5 -8
- package/src/encoder.js +1 -4
- package/src/index-minimal.js +1 -1
- package/src/parse.js +67 -29
- package/src/reader.js +251 -21
- package/src/reader_buffer.js +1 -3
- package/src/type.js +9 -1
- package/src/util/longbits.js +10 -6
- package/src/util/minimal.js +12 -40
- package/src/util/utf8.js +19 -17
- package/src/writer.js +399 -194
- package/src/writer_buffer.js +33 -42
package/dist/light/protobuf.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* protobuf.js v8.
|
|
3
|
-
* compiled
|
|
2
|
+
* protobuf.js v8.7.1 (c) 2016, daniel wirtz
|
|
3
|
+
* compiled mon, 13 jul 2026 11:04:12 utc
|
|
4
4
|
* licensed under the bsd-3-clause license
|
|
5
5
|
* see: https://github.com/dcodeio/protobuf.js for details
|
|
6
6
|
*/
|
|
@@ -340,7 +340,7 @@ converter.toObject = function toObject(mtype) {
|
|
|
340
340
|
else if (field.bytes) {
|
|
341
341
|
var arrayDefault = Array.prototype.slice.call(field.typeDefault);
|
|
342
342
|
gen
|
|
343
|
-
("if(o.bytes===String)d%s=%j", prop,
|
|
343
|
+
("if(o.bytes===String)d%s=%j", prop, util.base64.encode(field.typeDefault, 0, field.typeDefault.length))
|
|
344
344
|
("else{")
|
|
345
345
|
("d%s=%j", prop, arrayDefault)
|
|
346
346
|
("if(o.bytes!==Array)d%s=util.newBuffer(d%s)", prop, prop)
|
|
@@ -498,7 +498,7 @@ function decoder(mtype) {
|
|
|
498
498
|
("break");
|
|
499
499
|
|
|
500
500
|
if (types.basic[type] === undefined) gen
|
|
501
|
-
("v=types[%i].decode(r,r.uint32(),undefined,q+1)", i); // can't be groups
|
|
501
|
+
("v=types[%i].decode(r,r.uint32(),undefined,q+1,v)", i); // can't be groups
|
|
502
502
|
else gen
|
|
503
503
|
("v=r.%s()", type === "string" ? stringMethod(field) : type);
|
|
504
504
|
|
|
@@ -537,13 +537,9 @@ function decoder(mtype) {
|
|
|
537
537
|
if (types.packed[type] !== undefined) {
|
|
538
538
|
gen
|
|
539
539
|
("if(u===2){");
|
|
540
|
-
if (!closed) gen
|
|
541
|
-
("if(!(%s&&%s.length))", ref, ref)
|
|
542
|
-
("%s=[]", ref);
|
|
543
|
-
gen
|
|
544
|
-
("var c2=r.uint32()+r.pos");
|
|
545
540
|
if (closed) {
|
|
546
541
|
gen
|
|
542
|
+
("var c2=r.uint32()+r.pos")
|
|
547
543
|
("while(r.pos<c2){")
|
|
548
544
|
("s=r.pos")
|
|
549
545
|
("v=r.%s()", type)
|
|
@@ -555,8 +551,9 @@ function decoder(mtype) {
|
|
|
555
551
|
genPreserveUnknown(gen, "util.rawField(" + field.id + ",0,r.raw(s,r.pos))")
|
|
556
552
|
("}");
|
|
557
553
|
} else gen
|
|
558
|
-
("
|
|
559
|
-
("%s
|
|
554
|
+
("if(!(%s&&%s.length))", ref, ref)
|
|
555
|
+
("%s=[]", ref)
|
|
556
|
+
("r.%ss(%s)", type, ref);
|
|
560
557
|
gen
|
|
561
558
|
("continue")
|
|
562
559
|
("}");
|
|
@@ -752,10 +749,7 @@ function encoder(mtype) {
|
|
|
752
749
|
// Packed repeated
|
|
753
750
|
if (field.packed && types.packed[type] !== undefined) { gen
|
|
754
751
|
|
|
755
|
-
("w.uint32(%i)
|
|
756
|
-
("for(var i=0;i<%s.length;++i)", ref)
|
|
757
|
-
("w.%s(%s[i])", type, ref)
|
|
758
|
-
("w.ldelim()");
|
|
752
|
+
("w.uint32(%i).%ss(%s)", (field.id << 3 | 2) >>> 0, type, ref);
|
|
759
753
|
|
|
760
754
|
// Non-packed
|
|
761
755
|
} else { gen
|
|
@@ -1688,7 +1682,7 @@ exports.configure = configure;
|
|
|
1688
1682
|
* @returns {undefined}
|
|
1689
1683
|
*/
|
|
1690
1684
|
function configure() {
|
|
1691
|
-
exports.util._configure();
|
|
1685
|
+
exports.util.LongBits._configure(exports.util.Long);
|
|
1692
1686
|
exports.Writer._configure(exports.BufferWriter);
|
|
1693
1687
|
exports.Reader._configure(exports.BufferReader);
|
|
1694
1688
|
}
|
|
@@ -3389,7 +3383,7 @@ function indexOutOfRange(reader, writeLength) {
|
|
|
3389
3383
|
|
|
3390
3384
|
/**
|
|
3391
3385
|
* Constructs a new reader instance using the specified buffer.
|
|
3392
|
-
* @classdesc Wire format reader using `Uint8Array
|
|
3386
|
+
* @classdesc Wire format reader using `Uint8Array`.
|
|
3393
3387
|
* @constructor
|
|
3394
3388
|
* @param {Uint8Array} buffer Buffer to read from
|
|
3395
3389
|
*/
|
|
@@ -3413,6 +3407,12 @@ function Reader(buffer) {
|
|
|
3413
3407
|
*/
|
|
3414
3408
|
this.len = buffer.length;
|
|
3415
3409
|
|
|
3410
|
+
/**
|
|
3411
|
+
* Cached DataView for packed reads.
|
|
3412
|
+
* @type {DataView|null}
|
|
3413
|
+
*/
|
|
3414
|
+
this.view = null;
|
|
3415
|
+
|
|
3416
3416
|
/**
|
|
3417
3417
|
* Whether to discard unknown fields while decoding.
|
|
3418
3418
|
* @type {boolean}
|
|
@@ -3420,18 +3420,14 @@ function Reader(buffer) {
|
|
|
3420
3420
|
this.discardUnknown = Reader.discardUnknown;
|
|
3421
3421
|
}
|
|
3422
3422
|
|
|
3423
|
-
|
|
3424
|
-
|
|
3425
|
-
|
|
3426
|
-
|
|
3427
|
-
|
|
3428
|
-
|
|
3429
|
-
|
|
3430
|
-
|
|
3431
|
-
if (Array.isArray(buffer))
|
|
3432
|
-
return new Reader(buffer);
|
|
3433
|
-
throw Error("illegal buffer");
|
|
3434
|
-
};
|
|
3423
|
+
function create_array(buffer) {
|
|
3424
|
+
// TODO: Remove plain array reader support in the next major release.
|
|
3425
|
+
if (Array.isArray(buffer))
|
|
3426
|
+
buffer = new Uint8Array(buffer);
|
|
3427
|
+
if (buffer instanceof Uint8Array)
|
|
3428
|
+
return new Reader(buffer);
|
|
3429
|
+
throw Error("illegal buffer");
|
|
3430
|
+
}
|
|
3435
3431
|
|
|
3436
3432
|
var create = function create() {
|
|
3437
3433
|
return util.Buffer
|
|
@@ -3456,8 +3452,6 @@ var create = function create() {
|
|
|
3456
3452
|
*/
|
|
3457
3453
|
Reader.create = create();
|
|
3458
3454
|
|
|
3459
|
-
Reader.prototype._slice = util.Array.prototype.subarray || /* istanbul ignore next */ util.Array.prototype.slice;
|
|
3460
|
-
|
|
3461
3455
|
/**
|
|
3462
3456
|
* Returns raw bytes from the backing buffer without advancing the reader.
|
|
3463
3457
|
* @param {number} start Start offset
|
|
@@ -3465,12 +3459,7 @@ Reader.prototype._slice = util.Array.prototype.subarray || /* istanbul ignore ne
|
|
|
3465
3459
|
* @returns {Uint8Array} Raw bytes
|
|
3466
3460
|
*/
|
|
3467
3461
|
Reader.prototype.raw = function read_raw(start, end) {
|
|
3468
|
-
|
|
3469
|
-
return this.buf.slice(start, end);
|
|
3470
|
-
|
|
3471
|
-
if (start === end) // fix for IE 10/Win8 and others' subarray returning array of size 1
|
|
3472
|
-
return new this.buf.constructor(0);
|
|
3473
|
-
return this._slice.call(this.buf, start, end);
|
|
3462
|
+
return this.buf.subarray(start, end);
|
|
3474
3463
|
};
|
|
3475
3464
|
|
|
3476
3465
|
/**
|
|
@@ -3767,6 +3756,241 @@ Reader.prototype.double = function read_double() {
|
|
|
3767
3756
|
return value;
|
|
3768
3757
|
};
|
|
3769
3758
|
|
|
3759
|
+
/**
|
|
3760
|
+
* Reads a packed repeated field of unsigned 32 bit varints.
|
|
3761
|
+
* @param {number[]} [array] Array to read into; a new one is created if omitted
|
|
3762
|
+
* @returns {number[]} Array read into
|
|
3763
|
+
*/
|
|
3764
|
+
Reader.prototype.uint32s = function read_uint32s(array) {
|
|
3765
|
+
if (array === undefined) array = [];
|
|
3766
|
+
var end = this.uint32() + this.pos;
|
|
3767
|
+
while (this.pos < end)
|
|
3768
|
+
array.push(this.uint32());
|
|
3769
|
+
return array;
|
|
3770
|
+
};
|
|
3771
|
+
|
|
3772
|
+
/**
|
|
3773
|
+
* Reads a packed repeated field of signed 32 bit varints.
|
|
3774
|
+
* @param {number[]} [array] Array to read into; a new one is created if omitted
|
|
3775
|
+
* @returns {number[]} Array read into
|
|
3776
|
+
*/
|
|
3777
|
+
Reader.prototype.int32s = function read_int32s(array) {
|
|
3778
|
+
if (array === undefined) array = [];
|
|
3779
|
+
var end = this.uint32() + this.pos;
|
|
3780
|
+
while (this.pos < end)
|
|
3781
|
+
array.push(this.int32());
|
|
3782
|
+
return array;
|
|
3783
|
+
};
|
|
3784
|
+
|
|
3785
|
+
/**
|
|
3786
|
+
* Reads a packed repeated field of zig-zag encoded signed 32 bit varints.
|
|
3787
|
+
* @param {number[]} [array] Array to read into; a new one is created if omitted
|
|
3788
|
+
* @returns {number[]} Array read into
|
|
3789
|
+
*/
|
|
3790
|
+
Reader.prototype.sint32s = function read_sint32s(array) {
|
|
3791
|
+
if (array === undefined) array = [];
|
|
3792
|
+
var end = this.uint32() + this.pos;
|
|
3793
|
+
while (this.pos < end)
|
|
3794
|
+
array.push(this.sint32());
|
|
3795
|
+
return array;
|
|
3796
|
+
};
|
|
3797
|
+
|
|
3798
|
+
/**
|
|
3799
|
+
* Reads a packed repeated field of booleans.
|
|
3800
|
+
* @param {boolean[]} [array] Array to read into; a new one is created if omitted
|
|
3801
|
+
* @returns {boolean[]} Array read into
|
|
3802
|
+
*/
|
|
3803
|
+
Reader.prototype.bools = function read_bools(array) {
|
|
3804
|
+
if (array === undefined) array = [];
|
|
3805
|
+
var end = this.uint32() + this.pos;
|
|
3806
|
+
while (this.pos < end)
|
|
3807
|
+
array.push(this.bool());
|
|
3808
|
+
return array;
|
|
3809
|
+
};
|
|
3810
|
+
|
|
3811
|
+
// The view allocation only pays off when amortized over enough reads
|
|
3812
|
+
var VIEW_THRESHOLD_FLOAT = 8,
|
|
3813
|
+
VIEW_THRESHOLD_INT = 128;
|
|
3814
|
+
|
|
3815
|
+
function getLazyView(reader, count, threshold) {
|
|
3816
|
+
var view = reader.view;
|
|
3817
|
+
if (view || count < threshold)
|
|
3818
|
+
return view;
|
|
3819
|
+
var buf = reader.buf;
|
|
3820
|
+
return reader.view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
3821
|
+
}
|
|
3822
|
+
|
|
3823
|
+
/**
|
|
3824
|
+
* Reads a packed repeated field of unsigned 32 bit fixed values.
|
|
3825
|
+
* @param {number[]} [array] Array to read into; a new one is created if omitted
|
|
3826
|
+
* @returns {number[]} Array read into
|
|
3827
|
+
*/
|
|
3828
|
+
Reader.prototype.fixed32s = function read_fixed32s(array) {
|
|
3829
|
+
if (array === undefined) array = [];
|
|
3830
|
+
var len = this.uint32(), end = this.pos + len;
|
|
3831
|
+
/* istanbul ignore if */
|
|
3832
|
+
if (end > this.len) throw indexOutOfRange(this, len);
|
|
3833
|
+
var count = len >>> 2, i = array.length, pos = this.pos;
|
|
3834
|
+
array.length = i + count;
|
|
3835
|
+
var dv = getLazyView(this, count, VIEW_THRESHOLD_INT);
|
|
3836
|
+
if (dv)
|
|
3837
|
+
for (var k = 0; k < count; ++k, pos += 4) array[i++] = dv.getUint32(pos, true);
|
|
3838
|
+
else {
|
|
3839
|
+
var buf = this.buf;
|
|
3840
|
+
for (var j = 0; j < count; ++j, pos += 4) array[i++] = readFixed32_end(buf, pos + 4);
|
|
3841
|
+
}
|
|
3842
|
+
this.pos = pos;
|
|
3843
|
+
if (pos !== end) throw indexOutOfRange(this, 4);
|
|
3844
|
+
return array;
|
|
3845
|
+
};
|
|
3846
|
+
|
|
3847
|
+
/**
|
|
3848
|
+
* Reads a packed repeated field of signed 32 bit fixed values.
|
|
3849
|
+
* @param {number[]} [array] Array to read into; a new one is created if omitted
|
|
3850
|
+
* @returns {number[]} Array read into
|
|
3851
|
+
*/
|
|
3852
|
+
Reader.prototype.sfixed32s = function read_sfixed32s(array) {
|
|
3853
|
+
if (array === undefined) array = [];
|
|
3854
|
+
var len = this.uint32(), end = this.pos + len;
|
|
3855
|
+
/* istanbul ignore if */
|
|
3856
|
+
if (end > this.len) throw indexOutOfRange(this, len);
|
|
3857
|
+
var count = len >>> 2, i = array.length, pos = this.pos;
|
|
3858
|
+
array.length = i + count;
|
|
3859
|
+
var dv = getLazyView(this, count, VIEW_THRESHOLD_INT);
|
|
3860
|
+
if (dv)
|
|
3861
|
+
for (var k = 0; k < count; ++k, pos += 4) array[i++] = dv.getInt32(pos, true);
|
|
3862
|
+
else {
|
|
3863
|
+
var buf = this.buf;
|
|
3864
|
+
for (var j = 0; j < count; ++j, pos += 4) array[i++] = readFixed32_end(buf, pos + 4) | 0;
|
|
3865
|
+
}
|
|
3866
|
+
this.pos = pos;
|
|
3867
|
+
if (pos !== end) throw indexOutOfRange(this, 4);
|
|
3868
|
+
return array;
|
|
3869
|
+
};
|
|
3870
|
+
|
|
3871
|
+
/**
|
|
3872
|
+
* Reads a packed repeated field of floats (32 bit).
|
|
3873
|
+
* @param {number[]} [array] Array to read into; a new one is created if omitted
|
|
3874
|
+
* @returns {number[]} Array read into
|
|
3875
|
+
*/
|
|
3876
|
+
Reader.prototype.floats = function read_floats(array) {
|
|
3877
|
+
if (array === undefined) array = [];
|
|
3878
|
+
var len = this.uint32(), end = this.pos + len;
|
|
3879
|
+
/* istanbul ignore if */
|
|
3880
|
+
if (end > this.len) throw indexOutOfRange(this, len);
|
|
3881
|
+
var count = len >>> 2, i = array.length, pos = this.pos;
|
|
3882
|
+
array.length = i + count;
|
|
3883
|
+
var dv = getLazyView(this, count, VIEW_THRESHOLD_FLOAT);
|
|
3884
|
+
if (dv)
|
|
3885
|
+
for (var k = 0; k < count; ++k, pos += 4) array[i++] = dv.getFloat32(pos, true);
|
|
3886
|
+
else {
|
|
3887
|
+
var buf = this.buf;
|
|
3888
|
+
for (var j = 0; j < count; ++j, pos += 4) array[i++] = util.float.readFloatLE(buf, pos);
|
|
3889
|
+
}
|
|
3890
|
+
this.pos = pos;
|
|
3891
|
+
if (pos !== end) throw indexOutOfRange(this, 4);
|
|
3892
|
+
return array;
|
|
3893
|
+
};
|
|
3894
|
+
|
|
3895
|
+
/**
|
|
3896
|
+
* Reads a packed repeated field of doubles (64 bit float).
|
|
3897
|
+
* @param {number[]} [array] Array to read into; a new one is created if omitted
|
|
3898
|
+
* @returns {number[]} Array read into
|
|
3899
|
+
*/
|
|
3900
|
+
Reader.prototype.doubles = function read_doubles(array) {
|
|
3901
|
+
if (array === undefined) array = [];
|
|
3902
|
+
var len = this.uint32(), end = this.pos + len;
|
|
3903
|
+
/* istanbul ignore if */
|
|
3904
|
+
if (end > this.len) throw indexOutOfRange(this, len);
|
|
3905
|
+
var count = len >>> 3, i = array.length, pos = this.pos;
|
|
3906
|
+
array.length = i + count;
|
|
3907
|
+
var dv = getLazyView(this, count, VIEW_THRESHOLD_FLOAT);
|
|
3908
|
+
if (dv)
|
|
3909
|
+
for (var k = 0; k < count; ++k, pos += 8) array[i++] = dv.getFloat64(pos, true);
|
|
3910
|
+
else {
|
|
3911
|
+
var buf = this.buf;
|
|
3912
|
+
for (var j = 0; j < count; ++j, pos += 8) array[i++] = util.float.readDoubleLE(buf, pos);
|
|
3913
|
+
}
|
|
3914
|
+
this.pos = pos;
|
|
3915
|
+
if (pos !== end) throw indexOutOfRange(this, 8);
|
|
3916
|
+
return array;
|
|
3917
|
+
};
|
|
3918
|
+
|
|
3919
|
+
/**
|
|
3920
|
+
* Reads a packed repeated field of unsigned 64 bit varints.
|
|
3921
|
+
* @param {Array.<Long|number>} [array] Array to read into; a new one is created if omitted
|
|
3922
|
+
* @returns {Array.<Long|number>} Array read into
|
|
3923
|
+
*/
|
|
3924
|
+
Reader.prototype.uint64s = function read_uint64s(array) {
|
|
3925
|
+
if (array === undefined) array = [];
|
|
3926
|
+
var end = this.uint32() + this.pos;
|
|
3927
|
+
while (this.pos < end)
|
|
3928
|
+
array.push(this.uint64());
|
|
3929
|
+
return array;
|
|
3930
|
+
};
|
|
3931
|
+
|
|
3932
|
+
/**
|
|
3933
|
+
* Reads a packed repeated field of signed 64 bit varints.
|
|
3934
|
+
* @param {Array.<Long|number>} [array] Array to read into; a new one is created if omitted
|
|
3935
|
+
* @returns {Array.<Long|number>} Array read into
|
|
3936
|
+
*/
|
|
3937
|
+
Reader.prototype.int64s = function read_int64s(array) {
|
|
3938
|
+
if (array === undefined) array = [];
|
|
3939
|
+
var end = this.uint32() + this.pos;
|
|
3940
|
+
while (this.pos < end)
|
|
3941
|
+
array.push(this.int64());
|
|
3942
|
+
return array;
|
|
3943
|
+
};
|
|
3944
|
+
|
|
3945
|
+
/**
|
|
3946
|
+
* Reads a packed repeated field of zig-zag encoded signed 64 bit varints.
|
|
3947
|
+
* @param {Array.<Long|number>} [array] Array to read into; a new one is created if omitted
|
|
3948
|
+
* @returns {Array.<Long|number>} Array read into
|
|
3949
|
+
*/
|
|
3950
|
+
Reader.prototype.sint64s = function read_sint64s(array) {
|
|
3951
|
+
if (array === undefined) array = [];
|
|
3952
|
+
var end = this.uint32() + this.pos;
|
|
3953
|
+
while (this.pos < end)
|
|
3954
|
+
array.push(this.sint64());
|
|
3955
|
+
return array;
|
|
3956
|
+
};
|
|
3957
|
+
|
|
3958
|
+
/**
|
|
3959
|
+
* Reads a packed repeated field of unsigned 64 bit fixed values.
|
|
3960
|
+
* @param {Array.<Long|number>} [array] Array to read into; a new one is created if omitted
|
|
3961
|
+
* @returns {Array.<Long|number>} Array read into
|
|
3962
|
+
*/
|
|
3963
|
+
Reader.prototype.fixed64s = function read_fixed64s(array) {
|
|
3964
|
+
if (array === undefined) array = [];
|
|
3965
|
+
var len = this.uint32(), end = this.pos + len, i = array.length;
|
|
3966
|
+
/* istanbul ignore if */
|
|
3967
|
+
if (end > this.len) throw indexOutOfRange(this, len);
|
|
3968
|
+
var count = len >>> 3;
|
|
3969
|
+
array.length = i + count; // 8 bytes per value, count is known
|
|
3970
|
+
for (var j = 0; j < count; ++j)
|
|
3971
|
+
array[i++] = this.fixed64();
|
|
3972
|
+
if (this.pos !== end) throw indexOutOfRange(this, 8);
|
|
3973
|
+
return array;
|
|
3974
|
+
};
|
|
3975
|
+
|
|
3976
|
+
/**
|
|
3977
|
+
* Reads a packed repeated field of signed 64 bit fixed values.
|
|
3978
|
+
* @param {Array.<Long|number>} [array] Array to read into; a new one is created if omitted
|
|
3979
|
+
* @returns {Array.<Long|number>} Array read into
|
|
3980
|
+
*/
|
|
3981
|
+
Reader.prototype.sfixed64s = function read_sfixed64s(array) {
|
|
3982
|
+
if (array === undefined) array = [];
|
|
3983
|
+
var len = this.uint32(), end = this.pos + len, i = array.length;
|
|
3984
|
+
/* istanbul ignore if */
|
|
3985
|
+
if (end > this.len) throw indexOutOfRange(this, len);
|
|
3986
|
+
var count = len >>> 3;
|
|
3987
|
+
array.length = i + count; // 8 bytes per value, count is known
|
|
3988
|
+
for (var j = 0; j < count; ++j)
|
|
3989
|
+
array[i++] = this.sfixed64();
|
|
3990
|
+
if (this.pos !== end) throw indexOutOfRange(this, 8);
|
|
3991
|
+
return array;
|
|
3992
|
+
};
|
|
3993
|
+
|
|
3770
3994
|
/**
|
|
3771
3995
|
* Reads a sequence of bytes preceeded by its length as a varint.
|
|
3772
3996
|
* @returns {Uint8Array} Value read
|
|
@@ -3962,7 +4186,7 @@ function BufferReader(buffer) {
|
|
|
3962
4186
|
* Read buffer.
|
|
3963
4187
|
* @name BufferReader#buf
|
|
3964
4188
|
* @type {Buffer}
|
|
3965
|
-
|
|
4189
|
+
*/
|
|
3966
4190
|
}
|
|
3967
4191
|
|
|
3968
4192
|
BufferReader._configure = function () {
|
|
@@ -3980,8 +4204,6 @@ BufferReader._configure = function () {
|
|
|
3980
4204
|
* @returns {Buffer} Raw bytes
|
|
3981
4205
|
*/
|
|
3982
4206
|
BufferReader.prototype.raw = function read_raw_buffer(start, end) {
|
|
3983
|
-
if (start === end)
|
|
3984
|
-
return util.Buffer.alloc(0);
|
|
3985
4207
|
return this._slice.call(this.buf, start, end);
|
|
3986
4208
|
};
|
|
3987
4209
|
|
|
@@ -5358,6 +5580,14 @@ Type.prototype.setup = function setup() {
|
|
|
5358
5580
|
// Sets up everything at once so that the prototype chain does not have to be re-evaluated
|
|
5359
5581
|
// multiple times (V8, soft-deopt prototype-check).
|
|
5360
5582
|
|
|
5583
|
+
// Resolve feature defaults incl. field presence before generating codecs
|
|
5584
|
+
var root = this.root;
|
|
5585
|
+
if (root && root._needsRecursiveFeatureResolution) {
|
|
5586
|
+
var edition = root._edition || this._edition;
|
|
5587
|
+
if (edition)
|
|
5588
|
+
root._resolveFeaturesRecursive(edition);
|
|
5589
|
+
}
|
|
5590
|
+
|
|
5361
5591
|
var fullName = this.fullName,
|
|
5362
5592
|
types = [];
|
|
5363
5593
|
for (var i = 0; i < /* initializes */ this.fieldsArray.length; ++i)
|
|
@@ -5421,7 +5651,7 @@ Type.prototype.encode = function encode_setup(message, writer) { // eslint-disab
|
|
|
5421
5651
|
* @returns {Writer} writer
|
|
5422
5652
|
*/
|
|
5423
5653
|
Type.prototype.encodeDelimited = function encodeDelimited(message, writer) {
|
|
5424
|
-
return this.encode(message, writer
|
|
5654
|
+
return this.encode(message, (writer || Writer.create()).fork()).ldelim();
|
|
5425
5655
|
};
|
|
5426
5656
|
|
|
5427
5657
|
/**
|
|
@@ -6873,7 +7103,7 @@ module.exports = fs;
|
|
|
6873
7103
|
"use strict";
|
|
6874
7104
|
module.exports = LongBits;
|
|
6875
7105
|
|
|
6876
|
-
var
|
|
7106
|
+
var Long;
|
|
6877
7107
|
|
|
6878
7108
|
/**
|
|
6879
7109
|
* Constructs new long bits.
|
|
@@ -6952,10 +7182,10 @@ LongBits.fromNumber = function fromNumber(value) {
|
|
|
6952
7182
|
LongBits.from = function from(value) {
|
|
6953
7183
|
if (typeof value === "number")
|
|
6954
7184
|
return LongBits.fromNumber(value);
|
|
6955
|
-
if (
|
|
7185
|
+
if (typeof value === "string" || value instanceof String) {
|
|
6956
7186
|
/* istanbul ignore else */
|
|
6957
|
-
if (
|
|
6958
|
-
value =
|
|
7187
|
+
if (Long)
|
|
7188
|
+
value = Long.fromString(value);
|
|
6959
7189
|
else
|
|
6960
7190
|
return LongBits.fromNumber(parseInt(value, 10));
|
|
6961
7191
|
}
|
|
@@ -6984,8 +7214,8 @@ LongBits.prototype.toNumber = function toNumber(unsigned) {
|
|
|
6984
7214
|
* @returns {Long} Long
|
|
6985
7215
|
*/
|
|
6986
7216
|
LongBits.prototype.toLong = function toLong(unsigned) {
|
|
6987
|
-
return
|
|
6988
|
-
? new
|
|
7217
|
+
return Long
|
|
7218
|
+
? new Long(this.lo | 0, this.hi | 0, Boolean(unsigned))
|
|
6989
7219
|
/* istanbul ignore next */
|
|
6990
7220
|
: { low: this.lo | 0, high: this.hi | 0, unsigned: Boolean(unsigned) };
|
|
6991
7221
|
};
|
|
@@ -7071,7 +7301,11 @@ LongBits.prototype.length = function length() {
|
|
|
7071
7301
|
: part2 < 128 ? 9 : 10;
|
|
7072
7302
|
};
|
|
7073
7303
|
|
|
7074
|
-
|
|
7304
|
+
LongBits._configure = function(Long_) {
|
|
7305
|
+
Long = Long_;
|
|
7306
|
+
};
|
|
7307
|
+
|
|
7308
|
+
},{}],33:[function(require,module,exports){
|
|
7075
7309
|
"use strict";
|
|
7076
7310
|
/* global globalThis */
|
|
7077
7311
|
var util = exports;
|
|
@@ -7211,36 +7445,29 @@ util.isSet = function isSet(obj, prop) {
|
|
|
7211
7445
|
util.Buffer = (function() {
|
|
7212
7446
|
try {
|
|
7213
7447
|
var Buffer = util.global.Buffer;
|
|
7214
|
-
// refuse to use non-node buffers if not explicitly assigned (perf reasons)
|
|
7215
|
-
return Buffer.prototype.utf8Write ? Buffer : /* istanbul ignore next */ null;
|
|
7448
|
+
// refuse to use non-node buffers if not explicitly assigned (perf reasons)
|
|
7449
|
+
return Buffer.prototype.utf8Write || util.isNode ? Buffer : /* istanbul ignore next */ null;
|
|
7216
7450
|
} catch (e) {
|
|
7217
7451
|
/* istanbul ignore next */
|
|
7218
7452
|
return null;
|
|
7219
7453
|
}
|
|
7220
7454
|
})();
|
|
7221
7455
|
|
|
7222
|
-
// Internal alias of or polyfull for Buffer.from.
|
|
7223
|
-
util._Buffer_from = null;
|
|
7224
|
-
|
|
7225
|
-
// Internal alias of or polyfill for Buffer.allocUnsafe.
|
|
7226
|
-
util._Buffer_allocUnsafe = null;
|
|
7227
|
-
|
|
7228
7456
|
/**
|
|
7229
7457
|
* Creates a new buffer of whatever type supported by the environment.
|
|
7230
7458
|
* @param {number|number[]} [sizeOrArray=0] Buffer size or number array
|
|
7231
7459
|
* @returns {Uint8Array|Buffer} Buffer
|
|
7232
7460
|
*/
|
|
7233
7461
|
util.newBuffer = function newBuffer(sizeOrArray) {
|
|
7462
|
+
var Buffer = util.Buffer;
|
|
7234
7463
|
/* istanbul ignore next */
|
|
7235
7464
|
return typeof sizeOrArray === "number"
|
|
7236
|
-
?
|
|
7237
|
-
?
|
|
7238
|
-
: new
|
|
7239
|
-
:
|
|
7240
|
-
?
|
|
7241
|
-
:
|
|
7242
|
-
? sizeOrArray
|
|
7243
|
-
: new Uint8Array(sizeOrArray);
|
|
7465
|
+
? Buffer
|
|
7466
|
+
? Buffer.allocUnsafe(sizeOrArray)
|
|
7467
|
+
: new Uint8Array(sizeOrArray)
|
|
7468
|
+
: Buffer
|
|
7469
|
+
? Buffer.from(sizeOrArray)
|
|
7470
|
+
: new Uint8Array(sizeOrArray);
|
|
7244
7471
|
};
|
|
7245
7472
|
|
|
7246
7473
|
/**
|
|
@@ -7266,10 +7493,11 @@ util.rawField = function rawField(id, wireType, data) {
|
|
|
7266
7493
|
};
|
|
7267
7494
|
|
|
7268
7495
|
/**
|
|
7269
|
-
* Array implementation used in the browser.
|
|
7496
|
+
* Array implementation used in the browser.
|
|
7270
7497
|
* @type {Constructor<Uint8Array>}
|
|
7498
|
+
* @deprecated Use `Uint8Array` instead.
|
|
7271
7499
|
*/
|
|
7272
|
-
util.Array =
|
|
7500
|
+
util.Array = Uint8Array;
|
|
7273
7501
|
|
|
7274
7502
|
/**
|
|
7275
7503
|
* Any compatible Long instance.
|
|
@@ -7590,28 +7818,6 @@ util.toJSONOptions = {
|
|
|
7590
7818
|
json: true
|
|
7591
7819
|
};
|
|
7592
7820
|
|
|
7593
|
-
// Sets up buffer utility according to the environment (called in index-minimal)
|
|
7594
|
-
util._configure = function() {
|
|
7595
|
-
var Buffer = util.Buffer;
|
|
7596
|
-
/* istanbul ignore if */
|
|
7597
|
-
if (!Buffer) {
|
|
7598
|
-
util._Buffer_from = util._Buffer_allocUnsafe = null;
|
|
7599
|
-
return;
|
|
7600
|
-
}
|
|
7601
|
-
// because node 4.x buffers are incompatible & immutable
|
|
7602
|
-
// see: https://github.com/dcodeIO/protobuf.js/pull/665
|
|
7603
|
-
util._Buffer_from = Buffer.from !== Uint8Array.from && Buffer.from ||
|
|
7604
|
-
/* istanbul ignore next */
|
|
7605
|
-
function Buffer_from(value, encoding) {
|
|
7606
|
-
return new Buffer(value, encoding);
|
|
7607
|
-
};
|
|
7608
|
-
util._Buffer_allocUnsafe = Buffer.allocUnsafe ||
|
|
7609
|
-
/* istanbul ignore next */
|
|
7610
|
-
function Buffer_allocUnsafe(size) {
|
|
7611
|
-
return new Buffer(size);
|
|
7612
|
-
};
|
|
7613
|
-
};
|
|
7614
|
-
|
|
7615
7821
|
},{"25":25,"26":26,"28":28,"30":30,"32":32,"36":36,"37":37,"long":"long"}],34:[function(require,module,exports){
|
|
7616
7822
|
"use strict";
|
|
7617
7823
|
|
|
@@ -7777,19 +7983,21 @@ function pool(alloc, slice, size) {
|
|
|
7777
7983
|
"use strict";
|
|
7778
7984
|
|
|
7779
7985
|
/**
|
|
7780
|
-
* A minimal UTF8 implementation
|
|
7986
|
+
* A minimal UTF8 implementation.
|
|
7781
7987
|
* @memberof util
|
|
7782
7988
|
* @namespace
|
|
7783
7989
|
*/
|
|
7784
7990
|
var utf8 = exports,
|
|
7785
7991
|
replacementChar = "\ufffd",
|
|
7992
|
+
looseDecoder = new TextDecoder("utf-8", { ignoreBOM: true }),
|
|
7786
7993
|
strictDecoder;
|
|
7994
|
+
var TEXT_DECODER_MIN_LENGTH = 64;
|
|
7787
7995
|
|
|
7788
7996
|
try {
|
|
7789
7997
|
strictDecoder = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
|
|
7790
7998
|
} catch (err) {
|
|
7791
7999
|
// "fatal" option is not supported on Node.js compiled without ICU
|
|
7792
|
-
strictDecoder =
|
|
8000
|
+
strictDecoder = looseDecoder;
|
|
7793
8001
|
}
|
|
7794
8002
|
|
|
7795
8003
|
/**
|
|
@@ -7840,6 +8048,13 @@ function utf8_read_js(buffer, start, end, str) {
|
|
|
7840
8048
|
return str;
|
|
7841
8049
|
}
|
|
7842
8050
|
|
|
8051
|
+
function utf8_read_decoder(decoder, buffer, start, end) {
|
|
8052
|
+
var source = start === 0 && end === buffer.length
|
|
8053
|
+
? buffer
|
|
8054
|
+
: buffer.subarray(start, end);
|
|
8055
|
+
return decoder.decode(source);
|
|
8056
|
+
}
|
|
8057
|
+
|
|
7843
8058
|
/**
|
|
7844
8059
|
* Reads UTF8 bytes as a string.
|
|
7845
8060
|
* @param {Uint8Array} buffer Source buffer
|
|
@@ -7847,9 +8062,11 @@ function utf8_read_js(buffer, start, end, str) {
|
|
|
7847
8062
|
* @param {number} end Source end
|
|
7848
8063
|
* @returns {string} String read
|
|
7849
8064
|
*/
|
|
7850
|
-
utf8.read = function
|
|
8065
|
+
utf8.read = function utf8_read_loose(buffer, start, end) {
|
|
7851
8066
|
if (end - start < 1)
|
|
7852
8067
|
return "";
|
|
8068
|
+
if (end - start >= TEXT_DECODER_MIN_LENGTH)
|
|
8069
|
+
return utf8_read_decoder(looseDecoder, buffer, start, end);
|
|
7853
8070
|
|
|
7854
8071
|
var str = "",
|
|
7855
8072
|
i = start,
|
|
@@ -7879,17 +8096,6 @@ utf8.read = function utf8_read_ascii(buffer, start, end) {
|
|
|
7879
8096
|
return str;
|
|
7880
8097
|
};
|
|
7881
8098
|
|
|
7882
|
-
function utf8_read_strict(buffer, start, end) {
|
|
7883
|
-
var source = start === 0 && end === buffer.length
|
|
7884
|
-
? buffer
|
|
7885
|
-
: buffer.subarray
|
|
7886
|
-
? buffer.subarray(start, end)
|
|
7887
|
-
: buffer.slice(start, end);
|
|
7888
|
-
if (Array.isArray(source))
|
|
7889
|
-
source = Uint8Array.from(source);
|
|
7890
|
-
return strictDecoder.decode(source);
|
|
7891
|
-
}
|
|
7892
|
-
|
|
7893
8099
|
/**
|
|
7894
8100
|
* Reads UTF8 bytes as a string, rejecting invalid UTF8.
|
|
7895
8101
|
* @param {Uint8Array} buffer Source buffer
|
|
@@ -7897,9 +8103,11 @@ function utf8_read_strict(buffer, start, end) {
|
|
|
7897
8103
|
* @param {number} end Source end
|
|
7898
8104
|
* @returns {string} String read
|
|
7899
8105
|
*/
|
|
7900
|
-
utf8.readStrict = function
|
|
8106
|
+
utf8.readStrict = function utf8_read_strict(buffer, start, end) {
|
|
7901
8107
|
if (end - start < 1)
|
|
7902
8108
|
return "";
|
|
8109
|
+
if (end - start >= TEXT_DECODER_MIN_LENGTH)
|
|
8110
|
+
return utf8_read_decoder(strictDecoder, buffer, start, end);
|
|
7903
8111
|
|
|
7904
8112
|
var str = "",
|
|
7905
8113
|
i = start,
|
|
@@ -7915,14 +8123,14 @@ utf8.readStrict = function utf8_read_strict_ascii(buffer, start, end) {
|
|
|
7915
8123
|
c7 = buffer[i + 6];
|
|
7916
8124
|
c8 = buffer[i + 7];
|
|
7917
8125
|
if ((c1 | c2 | c3 | c4 | c5 | c6 | c7 | c8) & 0x80)
|
|
7918
|
-
return str +
|
|
8126
|
+
return str + utf8_read_decoder(strictDecoder, buffer, i, end);
|
|
7919
8127
|
str += String.fromCharCode(c1, c2, c3, c4, c5, c6, c7, c8);
|
|
7920
8128
|
}
|
|
7921
8129
|
|
|
7922
8130
|
for (; i < end; ++i) {
|
|
7923
8131
|
c1 = buffer[i];
|
|
7924
8132
|
if (c1 & 0x80)
|
|
7925
|
-
return str +
|
|
8133
|
+
return str + utf8_read_decoder(strictDecoder, buffer, i, end);
|
|
7926
8134
|
str += String.fromCharCode(c1);
|
|
7927
8135
|
}
|
|
7928
8136
|
|
|
@@ -8270,118 +8478,52 @@ var LongBits = util.LongBits,
|
|
|
8270
8478
|
base64 = util.base64,
|
|
8271
8479
|
utf8 = util.utf8;
|
|
8272
8480
|
|
|
8273
|
-
/**
|
|
8274
|
-
* Constructs a new writer operation instance.
|
|
8275
|
-
* @classdesc Scheduled writer operation.
|
|
8276
|
-
* @constructor
|
|
8277
|
-
* @param {function(*, Uint8Array, number)} fn Function to call
|
|
8278
|
-
* @param {number} len Value byte length
|
|
8279
|
-
* @param {*} val Value to write
|
|
8280
|
-
* @ignore
|
|
8281
|
-
*/
|
|
8282
|
-
function Op(fn, len, val) {
|
|
8283
|
-
|
|
8284
|
-
/**
|
|
8285
|
-
* Function to call.
|
|
8286
|
-
* @type {function(Uint8Array, number, *)}
|
|
8287
|
-
*/
|
|
8288
|
-
this.fn = fn;
|
|
8289
|
-
|
|
8290
|
-
/**
|
|
8291
|
-
* Value byte length.
|
|
8292
|
-
* @type {number}
|
|
8293
|
-
*/
|
|
8294
|
-
this.len = len;
|
|
8295
|
-
|
|
8296
|
-
/**
|
|
8297
|
-
* Next operation.
|
|
8298
|
-
* @type {Writer.Op|undefined}
|
|
8299
|
-
*/
|
|
8300
|
-
this.next = undefined;
|
|
8301
|
-
|
|
8302
|
-
/**
|
|
8303
|
-
* Value to write.
|
|
8304
|
-
* @type {*}
|
|
8305
|
-
*/
|
|
8306
|
-
this.val = val; // type varies
|
|
8307
|
-
}
|
|
8308
|
-
|
|
8309
|
-
/* istanbul ignore next */
|
|
8310
|
-
function noop() {} // eslint-disable-line no-empty-function
|
|
8311
|
-
|
|
8312
|
-
/**
|
|
8313
|
-
* Constructs a new writer state instance.
|
|
8314
|
-
* @classdesc Copied writer state.
|
|
8315
|
-
* @memberof Writer
|
|
8316
|
-
* @constructor
|
|
8317
|
-
* @param {Writer} writer Writer to copy state from
|
|
8318
|
-
* @ignore
|
|
8319
|
-
*/
|
|
8320
|
-
function State(writer) {
|
|
8321
|
-
|
|
8322
|
-
/**
|
|
8323
|
-
* Current head.
|
|
8324
|
-
* @type {Writer.Op}
|
|
8325
|
-
*/
|
|
8326
|
-
this.head = writer.head;
|
|
8327
|
-
|
|
8328
|
-
/**
|
|
8329
|
-
* Current tail.
|
|
8330
|
-
* @type {Writer.Op}
|
|
8331
|
-
*/
|
|
8332
|
-
this.tail = writer.tail;
|
|
8333
|
-
|
|
8334
|
-
/**
|
|
8335
|
-
* Current buffer length.
|
|
8336
|
-
* @type {number}
|
|
8337
|
-
*/
|
|
8338
|
-
this.len = writer.len;
|
|
8339
|
-
|
|
8340
|
-
/**
|
|
8341
|
-
* Next state.
|
|
8342
|
-
* @type {State|null}
|
|
8343
|
-
*/
|
|
8344
|
-
this.next = writer.states;
|
|
8345
|
-
}
|
|
8346
|
-
|
|
8347
8481
|
/**
|
|
8348
8482
|
* Constructs a new writer instance.
|
|
8349
|
-
* @classdesc Wire format writer using `Uint8Array
|
|
8483
|
+
* @classdesc Wire format writer using `Uint8Array`.
|
|
8350
8484
|
* @constructor
|
|
8351
8485
|
*/
|
|
8352
8486
|
function Writer() {
|
|
8353
8487
|
|
|
8354
8488
|
/**
|
|
8355
|
-
*
|
|
8489
|
+
* Write cursor into {@link Writer#buf}.
|
|
8356
8490
|
* @type {number}
|
|
8357
8491
|
*/
|
|
8358
|
-
this.
|
|
8492
|
+
this.pos = 0;
|
|
8359
8493
|
|
|
8360
8494
|
/**
|
|
8361
|
-
*
|
|
8362
|
-
* @type {
|
|
8495
|
+
* Backing buffer.
|
|
8496
|
+
* @type {Uint8Array}
|
|
8363
8497
|
*/
|
|
8364
|
-
this.
|
|
8498
|
+
this.buf = this.constructor.alloc(64);
|
|
8365
8499
|
|
|
8366
8500
|
/**
|
|
8367
|
-
*
|
|
8368
|
-
* @type {
|
|
8501
|
+
* Cached DataView over {@link Writer#buf}.
|
|
8502
|
+
* @type {DataView|null}
|
|
8369
8503
|
*/
|
|
8370
|
-
this.
|
|
8504
|
+
this.view = null;
|
|
8371
8505
|
|
|
8372
8506
|
/**
|
|
8373
|
-
*
|
|
8374
|
-
* @type {
|
|
8507
|
+
* Stack of forked length-prefix positions.
|
|
8508
|
+
* @type {Array<number>|null}
|
|
8375
8509
|
*/
|
|
8376
8510
|
this.states = null;
|
|
8377
|
-
|
|
8378
|
-
// When a value is written, the writer calculates its byte length and puts it into a linked
|
|
8379
|
-
// list of operations to perform when finish() is called. This both allows us to allocate
|
|
8380
|
-
// buffers of the exact required size and reduces the amount of work we have to do compared
|
|
8381
|
-
// to first calculating over objects and then encoding over objects. In our case, the encoding
|
|
8382
|
-
// part is just a linked list walk calling operations with already prepared values.
|
|
8383
8511
|
}
|
|
8384
8512
|
|
|
8513
|
+
/**
|
|
8514
|
+
* Current write position.
|
|
8515
|
+
* @name Writer#len
|
|
8516
|
+
* @type {number}
|
|
8517
|
+
* @deprecated Use {@link Writer#pos} instead.
|
|
8518
|
+
*/
|
|
8519
|
+
Object.defineProperty(Writer.prototype, "len", {
|
|
8520
|
+
configurable: true,
|
|
8521
|
+
enumerable: true,
|
|
8522
|
+
get: function get_len() {
|
|
8523
|
+
return this.pos;
|
|
8524
|
+
}
|
|
8525
|
+
});
|
|
8526
|
+
|
|
8385
8527
|
var create = function create() {
|
|
8386
8528
|
return util.Buffer
|
|
8387
8529
|
? function create_buffer_setup() {
|
|
@@ -8408,32 +8550,45 @@ Writer.create = create();
|
|
|
8408
8550
|
* @returns {Uint8Array} Buffer
|
|
8409
8551
|
*/
|
|
8410
8552
|
Writer.alloc = function alloc(size) {
|
|
8411
|
-
return new
|
|
8553
|
+
return new Uint8Array(size);
|
|
8412
8554
|
};
|
|
8413
8555
|
|
|
8414
8556
|
// Use Uint8Array buffer pool in the browser, just like node does with buffers
|
|
8415
|
-
|
|
8416
|
-
if (util.Array !== Array)
|
|
8417
|
-
Writer.alloc = util.pool(Writer.alloc, util.Array.prototype.subarray);
|
|
8557
|
+
Writer.alloc = util.pool(Writer.alloc, Uint8Array.prototype.subarray);
|
|
8418
8558
|
|
|
8419
8559
|
/**
|
|
8420
|
-
*
|
|
8421
|
-
* @param {
|
|
8422
|
-
* @
|
|
8423
|
-
* @
|
|
8424
|
-
|
|
8560
|
+
* Calculates the number of bytes a value occupies as a varint.
|
|
8561
|
+
* @param {number} value Value to size (unsigned)
|
|
8562
|
+
* @returns {number} Byte length (1..5)
|
|
8563
|
+
* @ignore
|
|
8564
|
+
*/
|
|
8565
|
+
function sizeVarint32(value) {
|
|
8566
|
+
return value < 128 ? 1
|
|
8567
|
+
: value < 16384 ? 2
|
|
8568
|
+
: value < 2097152 ? 3
|
|
8569
|
+
: value < 268435456 ? 4
|
|
8570
|
+
: 5;
|
|
8571
|
+
}
|
|
8572
|
+
|
|
8573
|
+
/**
|
|
8574
|
+
* Ensures that at least `n` more bytes fit into the backing buffer, doubling it if not.
|
|
8575
|
+
* @param {number} n Number of additional bytes required
|
|
8576
|
+
* @returns {undefined}
|
|
8425
8577
|
* @private
|
|
8426
8578
|
*/
|
|
8427
|
-
Writer.prototype.
|
|
8428
|
-
|
|
8429
|
-
this.
|
|
8430
|
-
|
|
8579
|
+
Writer.prototype._reserve = function _reserve(n) {
|
|
8580
|
+
var need = this.pos + n;
|
|
8581
|
+
if (need > this.buf.length) {
|
|
8582
|
+
var size = this.buf.length << 1;
|
|
8583
|
+
if (size < need)
|
|
8584
|
+
size = need;
|
|
8585
|
+
var buf = this.constructor.alloc(size);
|
|
8586
|
+
buf.set(this.buf.subarray(0, this.pos), 0);
|
|
8587
|
+
this.buf = buf;
|
|
8588
|
+
this.view = null; // invalidate
|
|
8589
|
+
}
|
|
8431
8590
|
};
|
|
8432
8591
|
|
|
8433
|
-
function writeByte(val, buf, pos) {
|
|
8434
|
-
buf[pos] = val & 255;
|
|
8435
|
-
}
|
|
8436
|
-
|
|
8437
8592
|
function writeStringAscii(val, buf, pos) {
|
|
8438
8593
|
for (var i = 0; i < val.length;)
|
|
8439
8594
|
buf[pos++] = val.charCodeAt(i++);
|
|
@@ -8445,42 +8600,19 @@ function writeVarint32(val, buf, pos) {
|
|
|
8445
8600
|
val >>>= 7;
|
|
8446
8601
|
}
|
|
8447
8602
|
buf[pos] = val;
|
|
8603
|
+
return pos + 1;
|
|
8448
8604
|
}
|
|
8449
8605
|
|
|
8450
|
-
/**
|
|
8451
|
-
* Constructs a new varint writer operation instance.
|
|
8452
|
-
* @classdesc Scheduled varint writer operation.
|
|
8453
|
-
* @extends Op
|
|
8454
|
-
* @constructor
|
|
8455
|
-
* @param {number} len Value byte length
|
|
8456
|
-
* @param {number} val Value to write
|
|
8457
|
-
* @ignore
|
|
8458
|
-
*/
|
|
8459
|
-
function VarintOp(len, val) {
|
|
8460
|
-
this.len = len;
|
|
8461
|
-
this.next = undefined;
|
|
8462
|
-
this.val = val;
|
|
8463
|
-
}
|
|
8464
|
-
|
|
8465
|
-
VarintOp.prototype = Object.create(Op.prototype);
|
|
8466
|
-
VarintOp.prototype.fn = writeVarint32;
|
|
8467
|
-
|
|
8468
8606
|
/**
|
|
8469
8607
|
* Writes an unsigned 32 bit value as a varint.
|
|
8470
8608
|
* @param {number} value Value to write
|
|
8471
8609
|
* @returns {Writer} `this`
|
|
8472
8610
|
*/
|
|
8473
8611
|
Writer.prototype.uint32 = function write_uint32(value) {
|
|
8474
|
-
|
|
8475
|
-
|
|
8476
|
-
|
|
8477
|
-
|
|
8478
|
-
< 128 ? 1
|
|
8479
|
-
: value < 16384 ? 2
|
|
8480
|
-
: value < 2097152 ? 3
|
|
8481
|
-
: value < 268435456 ? 4
|
|
8482
|
-
: 5,
|
|
8483
|
-
value)).len;
|
|
8612
|
+
value = value >>> 0;
|
|
8613
|
+
this._reserve(5);
|
|
8614
|
+
var pos = this.pos;
|
|
8615
|
+
this.pos = writeVarint32(value, this.buf, pos);
|
|
8484
8616
|
return this;
|
|
8485
8617
|
};
|
|
8486
8618
|
|
|
@@ -8491,9 +8623,13 @@ Writer.prototype.uint32 = function write_uint32(value) {
|
|
|
8491
8623
|
* @returns {Writer} `this`
|
|
8492
8624
|
*/
|
|
8493
8625
|
Writer.prototype.int32 = function write_int32(value) {
|
|
8494
|
-
|
|
8495
|
-
|
|
8496
|
-
|
|
8626
|
+
if ((value |= 0) < 0) { // 10 bytes per spec
|
|
8627
|
+
this._reserve(10);
|
|
8628
|
+
writeVarint64(LongBits.fromNumber(value), this.buf, this.pos);
|
|
8629
|
+
this.pos += 10;
|
|
8630
|
+
return this;
|
|
8631
|
+
}
|
|
8632
|
+
return this.uint32(value);
|
|
8497
8633
|
};
|
|
8498
8634
|
|
|
8499
8635
|
/**
|
|
@@ -8517,7 +8653,8 @@ function writeVarint64(val, buf, pos) {
|
|
|
8517
8653
|
buf[pos++] = lo & 127 | 128;
|
|
8518
8654
|
lo = lo >>> 7;
|
|
8519
8655
|
}
|
|
8520
|
-
buf[pos
|
|
8656
|
+
buf[pos] = lo;
|
|
8657
|
+
return pos + 1;
|
|
8521
8658
|
}
|
|
8522
8659
|
|
|
8523
8660
|
/**
|
|
@@ -8528,7 +8665,10 @@ function writeVarint64(val, buf, pos) {
|
|
|
8528
8665
|
*/
|
|
8529
8666
|
Writer.prototype.uint64 = function write_uint64(value) {
|
|
8530
8667
|
var bits = LongBits.from(value);
|
|
8531
|
-
|
|
8668
|
+
this._reserve(10);
|
|
8669
|
+
var pos = this.pos;
|
|
8670
|
+
this.pos = writeVarint64(bits, this.buf, pos);
|
|
8671
|
+
return this;
|
|
8532
8672
|
};
|
|
8533
8673
|
|
|
8534
8674
|
/**
|
|
@@ -8548,7 +8688,10 @@ Writer.prototype.int64 = Writer.prototype.uint64;
|
|
|
8548
8688
|
*/
|
|
8549
8689
|
Writer.prototype.sint64 = function write_sint64(value) {
|
|
8550
8690
|
var bits = LongBits.from(value).zzEncode();
|
|
8551
|
-
|
|
8691
|
+
this._reserve(10);
|
|
8692
|
+
var pos = this.pos;
|
|
8693
|
+
this.pos = writeVarint64(bits, this.buf, pos);
|
|
8694
|
+
return this;
|
|
8552
8695
|
};
|
|
8553
8696
|
|
|
8554
8697
|
/**
|
|
@@ -8557,7 +8700,9 @@ Writer.prototype.sint64 = function write_sint64(value) {
|
|
|
8557
8700
|
* @returns {Writer} `this`
|
|
8558
8701
|
*/
|
|
8559
8702
|
Writer.prototype.bool = function write_bool(value) {
|
|
8560
|
-
|
|
8703
|
+
this._reserve(1);
|
|
8704
|
+
this.buf[this.pos++] = value ? 1 : 0;
|
|
8705
|
+
return this;
|
|
8561
8706
|
};
|
|
8562
8707
|
|
|
8563
8708
|
function writeFixed32(val, buf, pos) {
|
|
@@ -8573,7 +8718,10 @@ function writeFixed32(val, buf, pos) {
|
|
|
8573
8718
|
* @returns {Writer} `this`
|
|
8574
8719
|
*/
|
|
8575
8720
|
Writer.prototype.fixed32 = function write_fixed32(value) {
|
|
8576
|
-
|
|
8721
|
+
this._reserve(4);
|
|
8722
|
+
writeFixed32(value >>> 0, this.buf, this.pos);
|
|
8723
|
+
this.pos += 4;
|
|
8724
|
+
return this;
|
|
8577
8725
|
};
|
|
8578
8726
|
|
|
8579
8727
|
/**
|
|
@@ -8592,7 +8740,11 @@ Writer.prototype.sfixed32 = Writer.prototype.fixed32;
|
|
|
8592
8740
|
*/
|
|
8593
8741
|
Writer.prototype.fixed64 = function write_fixed64(value) {
|
|
8594
8742
|
var bits = LongBits.from(value);
|
|
8595
|
-
|
|
8743
|
+
this._reserve(8);
|
|
8744
|
+
writeFixed32(bits.lo, this.buf, this.pos);
|
|
8745
|
+
writeFixed32(bits.hi, this.buf, this.pos + 4);
|
|
8746
|
+
this.pos += 8;
|
|
8747
|
+
return this;
|
|
8596
8748
|
};
|
|
8597
8749
|
|
|
8598
8750
|
/**
|
|
@@ -8611,7 +8763,10 @@ Writer.prototype.sfixed64 = Writer.prototype.fixed64;
|
|
|
8611
8763
|
* @returns {Writer} `this`
|
|
8612
8764
|
*/
|
|
8613
8765
|
Writer.prototype.float = function write_float(value) {
|
|
8614
|
-
|
|
8766
|
+
this._reserve(4);
|
|
8767
|
+
util.float.writeFloatLE(value, this.buf, this.pos);
|
|
8768
|
+
this.pos += 4;
|
|
8769
|
+
return this;
|
|
8615
8770
|
};
|
|
8616
8771
|
|
|
8617
8772
|
/**
|
|
@@ -8621,19 +8776,12 @@ Writer.prototype.float = function write_float(value) {
|
|
|
8621
8776
|
* @returns {Writer} `this`
|
|
8622
8777
|
*/
|
|
8623
8778
|
Writer.prototype.double = function write_double(value) {
|
|
8624
|
-
|
|
8779
|
+
this._reserve(8);
|
|
8780
|
+
util.float.writeDoubleLE(value, this.buf, this.pos);
|
|
8781
|
+
this.pos += 8;
|
|
8782
|
+
return this;
|
|
8625
8783
|
};
|
|
8626
8784
|
|
|
8627
|
-
var writeBytes = util.Array.prototype.set
|
|
8628
|
-
? function writeBytes_set(val, buf, pos) {
|
|
8629
|
-
buf.set(val, pos); // also works for plain array values
|
|
8630
|
-
}
|
|
8631
|
-
/* istanbul ignore next */
|
|
8632
|
-
: function writeBytes_for(val, buf, pos) {
|
|
8633
|
-
for (var i = 0; i < val.length; ++i)
|
|
8634
|
-
buf[pos + i] = val[i];
|
|
8635
|
-
};
|
|
8636
|
-
|
|
8637
8785
|
/**
|
|
8638
8786
|
* Writes a sequence of bytes.
|
|
8639
8787
|
* @param {Uint8Array|string} value Buffer or base64 encoded string to write
|
|
@@ -8641,14 +8789,21 @@ var writeBytes = util.Array.prototype.set
|
|
|
8641
8789
|
*/
|
|
8642
8790
|
Writer.prototype.bytes = function write_bytes(value) {
|
|
8643
8791
|
var len = value.length >>> 0;
|
|
8644
|
-
if (!len)
|
|
8645
|
-
|
|
8792
|
+
if (!len) {
|
|
8793
|
+
this._reserve(1);
|
|
8794
|
+
this.buf[this.pos++] = 0;
|
|
8795
|
+
return this;
|
|
8796
|
+
}
|
|
8646
8797
|
if (util.isString(value)) {
|
|
8647
8798
|
var buf = Writer.alloc(len = base64.length(value));
|
|
8648
8799
|
base64.decode(value, buf, 0);
|
|
8649
8800
|
value = buf;
|
|
8650
8801
|
}
|
|
8651
|
-
|
|
8802
|
+
this.uint32(len);
|
|
8803
|
+
this._reserve(len);
|
|
8804
|
+
this.buf.set(value, this.pos);
|
|
8805
|
+
this.pos += len;
|
|
8806
|
+
return this;
|
|
8652
8807
|
};
|
|
8653
8808
|
|
|
8654
8809
|
/**
|
|
@@ -8658,7 +8813,28 @@ Writer.prototype.bytes = function write_bytes(value) {
|
|
|
8658
8813
|
*/
|
|
8659
8814
|
Writer.prototype.raw = function write_raw(value) {
|
|
8660
8815
|
var len = value.length >>> 0;
|
|
8661
|
-
|
|
8816
|
+
if (!len)
|
|
8817
|
+
return this;
|
|
8818
|
+
this._reserve(len);
|
|
8819
|
+
this.buf.set(value, this.pos);
|
|
8820
|
+
this.pos += len;
|
|
8821
|
+
return this;
|
|
8822
|
+
};
|
|
8823
|
+
|
|
8824
|
+
/**
|
|
8825
|
+
* Backfills the length varint.
|
|
8826
|
+
* @param {number} pos Position of reserved length byte
|
|
8827
|
+
* @param {number} len Length of content after length varint
|
|
8828
|
+
* @returns {Writer} `this`
|
|
8829
|
+
* @private
|
|
8830
|
+
*/
|
|
8831
|
+
Writer.prototype._delim = function _delim(pos, len) {
|
|
8832
|
+
var n = sizeVarint32(len);
|
|
8833
|
+
if (n > 1)
|
|
8834
|
+
this.buf.copyWithin(pos + n, pos + 1, pos + 1 + len);
|
|
8835
|
+
writeVarint32(len, this.buf, pos);
|
|
8836
|
+
this.pos = pos + n + len;
|
|
8837
|
+
return this;
|
|
8662
8838
|
};
|
|
8663
8839
|
|
|
8664
8840
|
/**
|
|
@@ -8667,21 +8843,245 @@ Writer.prototype.raw = function write_raw(value) {
|
|
|
8667
8843
|
* @returns {Writer} `this`
|
|
8668
8844
|
*/
|
|
8669
8845
|
Writer.prototype.string = function write_string(value) {
|
|
8846
|
+
var n = value.length;
|
|
8847
|
+
if (!n) {
|
|
8848
|
+
this._reserve(1);
|
|
8849
|
+
this.buf[this.pos++] = 0;
|
|
8850
|
+
return this;
|
|
8851
|
+
}
|
|
8852
|
+
if (n < 0x80) {
|
|
8853
|
+
this._reserve(n * 3 + 5); // worst case
|
|
8854
|
+
var lenPos = this.pos;
|
|
8855
|
+
return this._delim(lenPos, utf8.write(value, this.buf, lenPos + 1));
|
|
8856
|
+
}
|
|
8670
8857
|
var len = utf8.length(value);
|
|
8671
|
-
|
|
8672
|
-
|
|
8673
|
-
|
|
8858
|
+
this.uint32(len);
|
|
8859
|
+
this._reserve(len);
|
|
8860
|
+
if (len === value.length)
|
|
8861
|
+
writeStringAscii(value, this.buf, this.pos);
|
|
8862
|
+
else
|
|
8863
|
+
utf8.write(value, this.buf, this.pos);
|
|
8864
|
+
this.pos += len;
|
|
8865
|
+
return this;
|
|
8866
|
+
};
|
|
8867
|
+
|
|
8868
|
+
/**
|
|
8869
|
+
* Writes an array of unsigned 32 bit values as a packed repeated field.
|
|
8870
|
+
* @param {number[]} value Values to write
|
|
8871
|
+
* @returns {Writer} `this`
|
|
8872
|
+
*/
|
|
8873
|
+
Writer.prototype.uint32s = function write_uint32s(value) {
|
|
8874
|
+
var n = value.length;
|
|
8875
|
+
this._reserve(n * 5 + 5); // worst case: 5 bytes per value + length varint
|
|
8876
|
+
var buf = this.buf, lenPos = this.pos, p = lenPos + 1;
|
|
8877
|
+
for (var i = 0; i < n; ++i)
|
|
8878
|
+
p = writeVarint32(value[i] >>> 0, buf, p);
|
|
8879
|
+
return this._delim(lenPos, p - lenPos - 1);
|
|
8880
|
+
};
|
|
8881
|
+
|
|
8882
|
+
/**
|
|
8883
|
+
* Writes an array of signed 32 bit values as a packed repeated field.
|
|
8884
|
+
* @param {number[]} value Values to write
|
|
8885
|
+
* @returns {Writer} `this`
|
|
8886
|
+
*/
|
|
8887
|
+
Writer.prototype.int32s = function write_int32s(value) {
|
|
8888
|
+
var n = value.length;
|
|
8889
|
+
this._reserve(n * 10 + 5); // worst case: 10 bytes per negative value + length varint
|
|
8890
|
+
var buf = this.buf, lenPos = this.pos, pos = lenPos + 1, val;
|
|
8891
|
+
for (var i = 0; i < n; ++i) {
|
|
8892
|
+
if ((val = value[i] | 0) < 0) { // negatives are 10 bytes per spec
|
|
8893
|
+
pos = writeVarint64(LongBits.fromNumber(val), buf, pos);
|
|
8894
|
+
} else {
|
|
8895
|
+
pos = writeVarint32(val, buf, pos);
|
|
8896
|
+
}
|
|
8897
|
+
}
|
|
8898
|
+
return this._delim(lenPos, pos - lenPos - 1);
|
|
8899
|
+
};
|
|
8900
|
+
|
|
8901
|
+
/**
|
|
8902
|
+
* Writes an array of 32 bit values as packed, zig-zag encoded varints.
|
|
8903
|
+
* @param {number[]} value Values to write
|
|
8904
|
+
* @returns {Writer} `this`
|
|
8905
|
+
*/
|
|
8906
|
+
Writer.prototype.sint32s = function write_sint32s(value) {
|
|
8907
|
+
var n = value.length;
|
|
8908
|
+
this._reserve(n * 5 + 5);
|
|
8909
|
+
var buf = this.buf, lenPos = this.pos, pos = lenPos + 1;
|
|
8910
|
+
for (var i = 0; i < n; ++i)
|
|
8911
|
+
pos = writeVarint32((value[i] << 1 ^ value[i] >> 31) >>> 0, buf, pos);
|
|
8912
|
+
return this._delim(lenPos, pos - lenPos - 1);
|
|
8913
|
+
};
|
|
8914
|
+
|
|
8915
|
+
/**
|
|
8916
|
+
* Writes an array of unsigned 64 bit values as a packed repeated field.
|
|
8917
|
+
* @param {Array.<Long|number|string>} value Values to write
|
|
8918
|
+
* @returns {Writer} `this`
|
|
8919
|
+
*/
|
|
8920
|
+
Writer.prototype.uint64s = function write_uint64s(value) {
|
|
8921
|
+
var n = value.length;
|
|
8922
|
+
this._reserve(n * 10 + 5);
|
|
8923
|
+
var buf = this.buf, lenPos = this.pos, pos = lenPos + 1;
|
|
8924
|
+
for (var i = 0; i < n; ++i) {
|
|
8925
|
+
pos = writeVarint64(LongBits.from(value[i]), buf, pos);
|
|
8926
|
+
}
|
|
8927
|
+
return this._delim(lenPos, pos - lenPos - 1);
|
|
8928
|
+
};
|
|
8929
|
+
|
|
8930
|
+
/**
|
|
8931
|
+
* Writes an array of signed 64 bit values as a packed repeated field.
|
|
8932
|
+
* @function
|
|
8933
|
+
* @param {Array.<Long|number|string>} value Values to write
|
|
8934
|
+
* @returns {Writer} `this`
|
|
8935
|
+
*/
|
|
8936
|
+
Writer.prototype.int64s = Writer.prototype.uint64s;
|
|
8937
|
+
|
|
8938
|
+
/**
|
|
8939
|
+
* Writes an array of 64 bit values as packed, zig-zag encoded varints.
|
|
8940
|
+
* @param {Array.<Long|number|string>} value Values to write
|
|
8941
|
+
* @returns {Writer} `this`
|
|
8942
|
+
*/
|
|
8943
|
+
Writer.prototype.sint64s = function write_sint64s(value) {
|
|
8944
|
+
var n = value.length;
|
|
8945
|
+
this._reserve(n * 10 + 5);
|
|
8946
|
+
var buf = this.buf, lenPos = this.pos, pos = lenPos + 1;
|
|
8947
|
+
for (var i = 0; i < n; ++i) {
|
|
8948
|
+
pos = writeVarint64(LongBits.from(value[i]).zzEncode(), buf, pos);
|
|
8949
|
+
}
|
|
8950
|
+
return this._delim(lenPos, pos - lenPos - 1);
|
|
8951
|
+
};
|
|
8952
|
+
|
|
8953
|
+
/**
|
|
8954
|
+
* Writes an array of boolish values as a packed repeated field.
|
|
8955
|
+
* @param {boolean[]} value Values to write
|
|
8956
|
+
* @returns {Writer} `this`
|
|
8957
|
+
*/
|
|
8958
|
+
Writer.prototype.bools = function write_bools(value) {
|
|
8959
|
+
var n = value.length;
|
|
8960
|
+
this.uint32(n); // one byte per value
|
|
8961
|
+
this._reserve(n);
|
|
8962
|
+
var buf = this.buf, p = this.pos;
|
|
8963
|
+
for (var i = 0; i < n; ++i)
|
|
8964
|
+
buf[p++] = value[i] ? 1 : 0;
|
|
8965
|
+
this.pos += n;
|
|
8966
|
+
return this;
|
|
8967
|
+
};
|
|
8968
|
+
|
|
8969
|
+
// The view allocation only pays off when amortized over enough writes
|
|
8970
|
+
var VIEW_THRESHOLD_FLOAT = 16,
|
|
8971
|
+
VIEW_THRESHOLD_INT = 128;
|
|
8972
|
+
|
|
8973
|
+
function getLazyView(writer, count, threshold) {
|
|
8974
|
+
var view = writer.view;
|
|
8975
|
+
if (view || count < threshold)
|
|
8976
|
+
return view;
|
|
8977
|
+
var buf = writer.buf;
|
|
8978
|
+
return writer.view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
8979
|
+
}
|
|
8980
|
+
|
|
8981
|
+
/**
|
|
8982
|
+
* Writes an array of unsigned 32 bit values as packed, fixed 32 bits.
|
|
8983
|
+
* @param {number[]} value Values to write
|
|
8984
|
+
* @returns {Writer} `this`
|
|
8985
|
+
*/
|
|
8986
|
+
Writer.prototype.fixed32s = function write_fixed32s(value) {
|
|
8987
|
+
var n = value.length, bytes = n * 4;
|
|
8988
|
+
this.uint32(bytes); // length is known exactly
|
|
8989
|
+
this._reserve(bytes);
|
|
8990
|
+
var p = this.pos, i, dv = getLazyView(this, n, VIEW_THRESHOLD_INT);
|
|
8991
|
+
if (dv)
|
|
8992
|
+
for (i = 0; i < n; ++i) { dv.setUint32(p, value[i] >>> 0, true); p += 4; }
|
|
8993
|
+
else {
|
|
8994
|
+
var buf = this.buf;
|
|
8995
|
+
for (i = 0; i < n; ++i) { writeFixed32(value[i] >>> 0, buf, p); p += 4; }
|
|
8996
|
+
}
|
|
8997
|
+
this.pos += bytes;
|
|
8998
|
+
return this;
|
|
8999
|
+
};
|
|
9000
|
+
|
|
9001
|
+
/**
|
|
9002
|
+
* Writes an array of signed 32 bit values as packed, fixed 32 bits.
|
|
9003
|
+
* @function
|
|
9004
|
+
* @param {number[]} value Values to write
|
|
9005
|
+
* @returns {Writer} `this`
|
|
9006
|
+
*/
|
|
9007
|
+
Writer.prototype.sfixed32s = Writer.prototype.fixed32s;
|
|
9008
|
+
|
|
9009
|
+
/**
|
|
9010
|
+
* Writes an array of unsigned 64 bit values as packed, fixed 64 bits.
|
|
9011
|
+
* @param {Array.<Long|number|string>} value Values to write
|
|
9012
|
+
* @returns {Writer} `this`
|
|
9013
|
+
*/
|
|
9014
|
+
Writer.prototype.fixed64s = function write_fixed64s(value) {
|
|
9015
|
+
var n = value.length, bytes = n * 8;
|
|
9016
|
+
this.uint32(bytes);
|
|
9017
|
+
this._reserve(bytes);
|
|
9018
|
+
var p = this.pos, i, bits, dv = getLazyView(this, n, VIEW_THRESHOLD_INT);
|
|
9019
|
+
if (dv)
|
|
9020
|
+
for (i = 0; i < n; ++i) { bits = LongBits.from(value[i]); dv.setUint32(p, bits.lo, true); dv.setUint32(p + 4, bits.hi, true); p += 8; }
|
|
9021
|
+
else {
|
|
9022
|
+
var buf = this.buf;
|
|
9023
|
+
for (i = 0; i < n; ++i) { bits = LongBits.from(value[i]); writeFixed32(bits.lo, buf, p); writeFixed32(bits.hi, buf, p + 4); p += 8; }
|
|
9024
|
+
}
|
|
9025
|
+
this.pos += bytes;
|
|
9026
|
+
return this;
|
|
9027
|
+
};
|
|
9028
|
+
|
|
9029
|
+
/**
|
|
9030
|
+
* Writes an array of signed 64 bit values as packed, fixed 64 bits.
|
|
9031
|
+
* @function
|
|
9032
|
+
* @param {Array.<Long|number|string>} value Values to write
|
|
9033
|
+
* @returns {Writer} `this`
|
|
9034
|
+
*/
|
|
9035
|
+
Writer.prototype.sfixed64s = Writer.prototype.fixed64s;
|
|
9036
|
+
|
|
9037
|
+
/**
|
|
9038
|
+
* Writes an array of floats (32 bit) as a packed repeated field.
|
|
9039
|
+
* @param {number[]} value Values to write
|
|
9040
|
+
* @returns {Writer} `this`
|
|
9041
|
+
*/
|
|
9042
|
+
Writer.prototype.floats = function write_floats(value) {
|
|
9043
|
+
var n = value.length, bytes = n * 4;
|
|
9044
|
+
this.uint32(bytes);
|
|
9045
|
+
this._reserve(bytes);
|
|
9046
|
+
var p = this.pos, i, dv = getLazyView(this, n, VIEW_THRESHOLD_FLOAT);
|
|
9047
|
+
if (dv)
|
|
9048
|
+
for (i = 0; i < n; ++i) { dv.setFloat32(p, value[i], true); p += 4; }
|
|
9049
|
+
else {
|
|
9050
|
+
var buf = this.buf;
|
|
9051
|
+
for (i = 0; i < n; ++i) { util.float.writeFloatLE(value[i], buf, p); p += 4; }
|
|
9052
|
+
}
|
|
9053
|
+
this.pos += bytes;
|
|
9054
|
+
return this;
|
|
9055
|
+
};
|
|
9056
|
+
|
|
9057
|
+
/**
|
|
9058
|
+
* Writes an array of doubles (64 bit float) as a packed repeated field.
|
|
9059
|
+
* @param {number[]} value Values to write
|
|
9060
|
+
* @returns {Writer} `this`
|
|
9061
|
+
*/
|
|
9062
|
+
Writer.prototype.doubles = function write_doubles(value) {
|
|
9063
|
+
var n = value.length, bytes = n * 8;
|
|
9064
|
+
this.uint32(bytes);
|
|
9065
|
+
this._reserve(bytes);
|
|
9066
|
+
var p = this.pos, i, dv = getLazyView(this, n, VIEW_THRESHOLD_FLOAT);
|
|
9067
|
+
if (dv)
|
|
9068
|
+
for (i = 0; i < n; ++i) { dv.setFloat64(p, value[i], true); p += 8; }
|
|
9069
|
+
else {
|
|
9070
|
+
var buf = this.buf;
|
|
9071
|
+
for (i = 0; i < n; ++i) { util.float.writeDoubleLE(value[i], buf, p); p += 8; }
|
|
9072
|
+
}
|
|
9073
|
+
this.pos += bytes;
|
|
9074
|
+
return this;
|
|
8674
9075
|
};
|
|
8675
9076
|
|
|
8676
9077
|
/**
|
|
8677
9078
|
* Forks this writer's state by pushing it to a stack.
|
|
8678
|
-
* Calling {@link Writer#reset|reset} or {@link Writer#ldelim|ldelim} resets the writer to the previous state.
|
|
8679
9079
|
* @returns {Writer} `this`
|
|
8680
9080
|
*/
|
|
8681
9081
|
Writer.prototype.fork = function fork() {
|
|
8682
|
-
this.
|
|
8683
|
-
this.
|
|
8684
|
-
this.
|
|
9082
|
+
this._reserve(1);
|
|
9083
|
+
(this.states || (this.states = [])).push(this.pos);
|
|
9084
|
+
this.pos += 1;
|
|
8685
9085
|
return this;
|
|
8686
9086
|
};
|
|
8687
9087
|
|
|
@@ -8690,47 +9090,66 @@ Writer.prototype.fork = function fork() {
|
|
|
8690
9090
|
* @returns {Writer} `this`
|
|
8691
9091
|
*/
|
|
8692
9092
|
Writer.prototype.reset = function reset() {
|
|
8693
|
-
|
|
8694
|
-
|
|
8695
|
-
this.
|
|
8696
|
-
this.len = this.states.len;
|
|
8697
|
-
this.states = this.states.next;
|
|
9093
|
+
var states = this.states;
|
|
9094
|
+
if (states && states.length) {
|
|
9095
|
+
this.pos = states.pop();
|
|
8698
9096
|
} else {
|
|
8699
|
-
this.
|
|
8700
|
-
this.len = 0;
|
|
9097
|
+
this.pos = 0;
|
|
8701
9098
|
}
|
|
8702
9099
|
return this;
|
|
8703
9100
|
};
|
|
8704
9101
|
|
|
8705
9102
|
/**
|
|
8706
|
-
* Resets to the last state and
|
|
9103
|
+
* Resets to the last state and prepends the fork state's current write length as a varint.
|
|
8707
9104
|
* @returns {Writer} `this`
|
|
8708
9105
|
*/
|
|
8709
9106
|
Writer.prototype.ldelim = function ldelim() {
|
|
8710
|
-
var
|
|
8711
|
-
|
|
8712
|
-
|
|
8713
|
-
|
|
8714
|
-
|
|
8715
|
-
|
|
8716
|
-
|
|
8717
|
-
|
|
9107
|
+
var states = this.states,
|
|
9108
|
+
len,
|
|
9109
|
+
vlen;
|
|
9110
|
+
if (states && states.length) {
|
|
9111
|
+
var lenPos = states.pop();
|
|
9112
|
+
len = this.pos - lenPos - 1;
|
|
9113
|
+
vlen = sizeVarint32(len);
|
|
9114
|
+
if (vlen > 1) { // grow the reserved single byte and shift content forward
|
|
9115
|
+
this._reserve(vlen - 1);
|
|
9116
|
+
this.buf.copyWithin(lenPos + vlen, lenPos + 1, lenPos + 1 + len);
|
|
9117
|
+
this.pos += vlen - 1;
|
|
9118
|
+
writeVarint32(len, this.buf, lenPos);
|
|
9119
|
+
} else {
|
|
9120
|
+
this.buf[lenPos] = len;
|
|
9121
|
+
}
|
|
9122
|
+
} else { // not forked: prefix the entire buffer with its length
|
|
9123
|
+
// TODO: Compatibility with older generated code.
|
|
9124
|
+
// Remove this branch in the next major release.
|
|
9125
|
+
len = this.pos;
|
|
9126
|
+
vlen = sizeVarint32(len);
|
|
9127
|
+
this._reserve(vlen);
|
|
9128
|
+
this.buf.copyWithin(vlen, 0, len);
|
|
9129
|
+
writeVarint32(len, this.buf, 0);
|
|
9130
|
+
this.pos += vlen;
|
|
8718
9131
|
}
|
|
8719
9132
|
return this;
|
|
8720
9133
|
};
|
|
8721
9134
|
|
|
8722
9135
|
/**
|
|
8723
9136
|
* Finishes the write operation.
|
|
9137
|
+
* Returns a buffer sized to the written data by default.
|
|
9138
|
+
* @param {boolean} [shared=false] Whether to return a shared view instead of a unique copy
|
|
8724
9139
|
* @returns {Uint8Array} Finished buffer
|
|
8725
9140
|
*/
|
|
8726
|
-
Writer.prototype.finish = function finish() {
|
|
8727
|
-
|
|
9141
|
+
Writer.prototype.finish = function finish(shared) {
|
|
9142
|
+
if (shared)
|
|
9143
|
+
return this.buf.subarray(0, this.pos);
|
|
9144
|
+
var buf = this.constructor.alloc(this.pos);
|
|
9145
|
+
buf.set(this.buf.subarray(0, this.pos), 0);
|
|
9146
|
+
return buf;
|
|
8728
9147
|
};
|
|
8729
9148
|
|
|
8730
9149
|
/**
|
|
8731
9150
|
* Finishes the write operation, writing into the provided buffer.
|
|
8732
9151
|
* The caller must ensure that `buf` has enough space starting at `offset`
|
|
8733
|
-
* to hold {@link Writer#
|
|
9152
|
+
* to hold {@link Writer#pos} bytes.
|
|
8734
9153
|
* @param {T} buf Target buffer
|
|
8735
9154
|
* @param {number} [offset=0] Offset to start writing at
|
|
8736
9155
|
* @returns {T} The provided buffer
|
|
@@ -8739,13 +9158,7 @@ Writer.prototype.finish = function finish() {
|
|
|
8739
9158
|
Writer.prototype.finishInto = function finishInto(buf, offset) {
|
|
8740
9159
|
if (offset === undefined)
|
|
8741
9160
|
offset = 0;
|
|
8742
|
-
|
|
8743
|
-
pos = offset;
|
|
8744
|
-
while (head) {
|
|
8745
|
-
head.fn(head.val, buf, pos);
|
|
8746
|
-
pos += head.len;
|
|
8747
|
-
head = head.next;
|
|
8748
|
-
}
|
|
9161
|
+
buf.set(this.buf.subarray(0, this.pos), offset);
|
|
8749
9162
|
return buf;
|
|
8750
9163
|
};
|
|
8751
9164
|
|
|
@@ -8782,6 +9195,8 @@ function BufferWriter() {
|
|
|
8782
9195
|
Writer.call(this);
|
|
8783
9196
|
}
|
|
8784
9197
|
|
|
9198
|
+
var writeStringBuffer;
|
|
9199
|
+
|
|
8785
9200
|
BufferWriter._configure = function () {
|
|
8786
9201
|
/**
|
|
8787
9202
|
* Allocates a buffer of the specified size.
|
|
@@ -8789,19 +9204,14 @@ BufferWriter._configure = function () {
|
|
|
8789
9204
|
* @param {number} size Buffer size
|
|
8790
9205
|
* @returns {Buffer} Buffer
|
|
8791
9206
|
*/
|
|
8792
|
-
BufferWriter.alloc = util.
|
|
9207
|
+
BufferWriter.alloc = util.Buffer && util.Buffer.allocUnsafe;
|
|
8793
9208
|
|
|
8794
|
-
|
|
8795
|
-
? function
|
|
8796
|
-
|
|
8797
|
-
// also works for plain array values
|
|
9209
|
+
writeStringBuffer = util.Buffer && util.Buffer.prototype.utf8Write
|
|
9210
|
+
? function writeStringBuffer_utf8Write(val, buf, pos) {
|
|
9211
|
+
return buf.utf8Write(val, pos);
|
|
8798
9212
|
}
|
|
8799
|
-
|
|
8800
|
-
|
|
8801
|
-
if (val.copy) // Buffer values
|
|
8802
|
-
val.copy(buf, pos, 0, val.length);
|
|
8803
|
-
else for (var i = 0; i < val.length;) // plain array values
|
|
8804
|
-
buf[pos++] = val[i++];
|
|
9213
|
+
: function writeStringBuffer_write(val, buf, pos) {
|
|
9214
|
+
return buf.write(val, pos);
|
|
8805
9215
|
};
|
|
8806
9216
|
};
|
|
8807
9217
|
|
|
@@ -8811,48 +9221,42 @@ BufferWriter._configure = function () {
|
|
|
8811
9221
|
*/
|
|
8812
9222
|
BufferWriter.prototype.bytes = function write_bytes_buffer(value) {
|
|
8813
9223
|
if (util.isString(value))
|
|
8814
|
-
value = util.
|
|
9224
|
+
value = util.Buffer.from(value, "base64");
|
|
8815
9225
|
var len = value.length >>> 0;
|
|
8816
9226
|
this.uint32(len);
|
|
8817
|
-
if (len)
|
|
8818
|
-
this.
|
|
9227
|
+
if (len) {
|
|
9228
|
+
this._reserve(len);
|
|
9229
|
+
this.buf.set(value, this.pos);
|
|
9230
|
+
this.pos += len;
|
|
9231
|
+
}
|
|
8819
9232
|
return this;
|
|
8820
9233
|
};
|
|
8821
9234
|
|
|
8822
|
-
/**
|
|
8823
|
-
* Writes raw bytes without a tag or length prefix.
|
|
8824
|
-
* @name BufferWriter#raw
|
|
8825
|
-
* @function
|
|
8826
|
-
* @param {Uint8Array} value Raw bytes
|
|
8827
|
-
* @returns {BufferWriter} `this`
|
|
8828
|
-
*/
|
|
8829
|
-
BufferWriter.prototype.raw = function write_raw_buffer(value) {
|
|
8830
|
-
var len = value.length >>> 0;
|
|
8831
|
-
return len ? this._push(BufferWriter.writeBytesBuffer, len, value) : this;
|
|
8832
|
-
};
|
|
8833
|
-
|
|
8834
|
-
function writeStringBufferAscii(val, buf, pos) {
|
|
8835
|
-
for (var i = 0; i < val.length;)
|
|
8836
|
-
buf[pos++] = val.charCodeAt(i++);
|
|
8837
|
-
}
|
|
8838
|
-
|
|
8839
|
-
function writeStringBuffer(val, buf, pos) {
|
|
8840
|
-
if (val.length < 40) // plain js is faster for short strings (probably due to redundant assertions)
|
|
8841
|
-
util.utf8.write(val, buf, pos);
|
|
8842
|
-
else if (buf.utf8Write)
|
|
8843
|
-
buf.utf8Write(val, pos);
|
|
8844
|
-
else
|
|
8845
|
-
buf.write(val, pos);
|
|
8846
|
-
}
|
|
8847
|
-
|
|
8848
9235
|
/**
|
|
8849
9236
|
* @override
|
|
8850
9237
|
*/
|
|
8851
9238
|
BufferWriter.prototype.string = function write_string_buffer(value) {
|
|
9239
|
+
var n = value.length;
|
|
9240
|
+
if (!n) {
|
|
9241
|
+
this._reserve(1);
|
|
9242
|
+
this.buf[this.pos++] = 0;
|
|
9243
|
+
return this;
|
|
9244
|
+
}
|
|
9245
|
+
if (n < 0x80) {
|
|
9246
|
+
this._reserve(n * 3 + 5); // worst case
|
|
9247
|
+
var pos = this.pos,
|
|
9248
|
+
buf = this.buf;
|
|
9249
|
+
return this._delim(pos,
|
|
9250
|
+
n < 40
|
|
9251
|
+
? util.utf8.write(value, buf, pos + 1)
|
|
9252
|
+
: writeStringBuffer(value, buf, pos + 1)
|
|
9253
|
+
);
|
|
9254
|
+
}
|
|
8852
9255
|
var len = util.Buffer.byteLength(value);
|
|
8853
9256
|
this.uint32(len);
|
|
8854
|
-
|
|
8855
|
-
|
|
9257
|
+
this._reserve(len);
|
|
9258
|
+
writeStringBuffer(value, this.buf, this.pos);
|
|
9259
|
+
this.pos += len;
|
|
8856
9260
|
return this;
|
|
8857
9261
|
};
|
|
8858
9262
|
|