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