lib0 0.2.86 → 0.2.87
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/buffer.d.ts.map +1 -1
- package/buffer.js +3 -6
- package/coverage/tmp/coverage-29846-1697198852740-0.json +1 -0
- package/decoding.d.ts.map +1 -1
- package/decoding.js +1 -2
- package/dist/aes-gcm.cjs +8 -13
- package/dist/aes-gcm.cjs.map +1 -1
- package/dist/{broadcastchannel-036aba21.cjs → broadcastchannel-554b85cd.cjs} +4 -4
- package/dist/{broadcastchannel-036aba21.cjs.map → broadcastchannel-554b85cd.cjs.map} +1 -1
- package/dist/broadcastchannel.cjs +6 -4
- package/dist/broadcastchannel.cjs.map +1 -1
- package/dist/buffer-f9b1a143.cjs +198 -0
- package/dist/buffer-f9b1a143.cjs.map +1 -0
- package/dist/buffer.cjs +18 -16
- package/dist/buffer.cjs.map +1 -1
- package/dist/buffer.d.ts.map +1 -1
- package/dist/decoding-fca97826.cjs +791 -0
- package/dist/decoding-fca97826.cjs.map +1 -0
- package/dist/decoding.cjs +40 -45
- package/dist/decoding.cjs.map +1 -1
- package/dist/decoding.d.ts.map +1 -1
- package/dist/{buffer-bc255c75.cjs → encoding-5bb79b9b.cjs} +9 -983
- package/dist/encoding-5bb79b9b.cjs.map +1 -0
- package/dist/encoding.cjs +1 -8
- package/dist/encoding.cjs.map +1 -1
- package/dist/encoding.d.ts.map +1 -1
- package/dist/{environment-ad129e4d.cjs → environment-819e9403.cjs} +4 -4
- package/dist/environment-819e9403.cjs.map +1 -0
- package/dist/environment.cjs +1 -1
- package/dist/environment.d.ts.map +1 -1
- package/dist/index.cjs +11 -9
- package/dist/index.cjs.map +1 -1
- package/dist/{indexeddb-2dd34f7d.cjs → indexeddb-8d495848.cjs} +1 -4
- package/dist/indexeddb-8d495848.cjs.map +1 -0
- package/dist/indexeddb.cjs +1 -1
- package/dist/indexeddb.d.ts.map +1 -1
- package/dist/jwt.cjs +9 -7
- package/dist/jwt.cjs.map +1 -1
- package/dist/logging.cjs +1 -1
- package/dist/logging.common.cjs +1 -1
- package/dist/logging.node.cjs +1 -1
- package/dist/observable.cjs +5 -5
- package/dist/observable.cjs.map +1 -1
- package/dist/observable.d.ts +10 -12
- package/dist/observable.d.ts.map +1 -1
- package/dist/{prng-d6655349.cjs → prng-33ae0b2e.cjs} +3 -3
- package/dist/{prng-d6655349.cjs.map → prng-33ae0b2e.cjs.map} +1 -1
- package/dist/prng.cjs +5 -3
- package/dist/prng.cjs.map +1 -1
- package/dist/rabin-gf2-polynomial.cjs +6 -4
- package/dist/rabin-gf2-polynomial.cjs.map +1 -1
- package/dist/rabin-uncached.cjs +6 -4
- package/dist/rabin-uncached.cjs.map +1 -1
- package/dist/rabin.cjs +7 -5
- package/dist/rabin.cjs.map +1 -1
- package/dist/storage.cjs +1 -1
- package/dist/storage.cjs.map +1 -1
- package/dist/testing.cjs +5 -3
- package/dist/testing.cjs.map +1 -1
- package/dist/{websocket-aa53d26d.cjs → websocket-ccb9bf5d.cjs} +1 -1
- package/dist/{websocket-aa53d26d.cjs.map → websocket-ccb9bf5d.cjs.map} +1 -1
- package/dist/websocket.cjs +1 -1
- package/encoding.d.ts.map +1 -1
- package/encoding.js +2 -3
- package/environment.d.ts.map +1 -1
- package/environment.js +3 -3
- package/indexeddb.d.ts.map +1 -1
- package/indexeddb.js +0 -3
- package/observable.d.ts +10 -12
- package/observable.d.ts.map +1 -1
- package/observable.js +5 -5
- package/package.json +21 -2
- package/storage.js +1 -1
- package/coverage/tmp/coverage-12951-1695475540140-0.json +0 -1
- package/dist/buffer-bc255c75.cjs.map +0 -1
- package/dist/environment-ad129e4d.cjs.map +0 -1
- package/dist/indexeddb-2dd34f7d.cjs.map +0 -1
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var string = require('./string-6d104757.cjs');
|
|
4
|
-
var environment = require('./environment-ad129e4d.cjs');
|
|
5
|
-
var array = require('./array-704ca50e.cjs');
|
|
6
3
|
var math = require('./math-08e068f9.cjs');
|
|
7
|
-
var binary = require('./binary-ac8e39e2.cjs');
|
|
8
4
|
var number = require('./number-466d8922.cjs');
|
|
9
|
-
var
|
|
5
|
+
var binary = require('./binary-ac8e39e2.cjs');
|
|
6
|
+
var string = require('./string-6d104757.cjs');
|
|
7
|
+
var array = require('./array-704ca50e.cjs');
|
|
10
8
|
|
|
11
9
|
/**
|
|
12
10
|
* Efficient schema-less binary encoding with support for variable length encoding.
|
|
@@ -87,7 +85,7 @@ const length = encoder => {
|
|
|
87
85
|
* @param {Encoder} encoder
|
|
88
86
|
* @return {boolean}
|
|
89
87
|
*/
|
|
90
|
-
const hasContent
|
|
88
|
+
const hasContent = encoder => encoder.cpos > 0 || encoder.bufs.length > 0;
|
|
91
89
|
|
|
92
90
|
/**
|
|
93
91
|
* Transform to Uint8Array.
|
|
@@ -104,7 +102,7 @@ const toUint8Array = encoder => {
|
|
|
104
102
|
uint8arr.set(d, curPos);
|
|
105
103
|
curPos += d.length;
|
|
106
104
|
}
|
|
107
|
-
uint8arr.set(
|
|
105
|
+
uint8arr.set(new Uint8Array(encoder.cbuf.buffer, 0, encoder.cpos), curPos);
|
|
108
106
|
return uint8arr
|
|
109
107
|
};
|
|
110
108
|
|
|
@@ -118,7 +116,7 @@ const toUint8Array = encoder => {
|
|
|
118
116
|
const verifyLen = (encoder, len) => {
|
|
119
117
|
const bufferLen = encoder.cbuf.length;
|
|
120
118
|
if (bufferLen - encoder.cpos < len) {
|
|
121
|
-
encoder.bufs.push(
|
|
119
|
+
encoder.bufs.push(new Uint8Array(encoder.cbuf.buffer, 0, encoder.cpos));
|
|
122
120
|
encoder.cbuf = new Uint8Array(math.max(bufferLen, len) * 2);
|
|
123
121
|
encoder.cpos = 0;
|
|
124
122
|
}
|
|
@@ -924,7 +922,7 @@ var encoding = /*#__PURE__*/Object.freeze({
|
|
|
924
922
|
createEncoder: createEncoder,
|
|
925
923
|
encode: encode,
|
|
926
924
|
length: length,
|
|
927
|
-
hasContent: hasContent
|
|
925
|
+
hasContent: hasContent,
|
|
928
926
|
toUint8Array: toUint8Array,
|
|
929
927
|
verifyLen: verifyLen,
|
|
930
928
|
write: write,
|
|
@@ -961,997 +959,25 @@ var encoding = /*#__PURE__*/Object.freeze({
|
|
|
961
959
|
StringEncoder: StringEncoder
|
|
962
960
|
});
|
|
963
961
|
|
|
964
|
-
/**
|
|
965
|
-
* Efficient schema-less binary decoding with support for variable length encoding.
|
|
966
|
-
*
|
|
967
|
-
* Use [lib0/decoding] with [lib0/encoding]. Every encoding function has a corresponding decoding function.
|
|
968
|
-
*
|
|
969
|
-
* Encodes numbers in little-endian order (least to most significant byte order)
|
|
970
|
-
* and is compatible with Golang's binary encoding (https://golang.org/pkg/encoding/binary/)
|
|
971
|
-
* which is also used in Protocol Buffers.
|
|
972
|
-
*
|
|
973
|
-
* ```js
|
|
974
|
-
* // encoding step
|
|
975
|
-
* const encoder = encoding.createEncoder()
|
|
976
|
-
* encoding.writeVarUint(encoder, 256)
|
|
977
|
-
* encoding.writeVarString(encoder, 'Hello world!')
|
|
978
|
-
* const buf = encoding.toUint8Array(encoder)
|
|
979
|
-
* ```
|
|
980
|
-
*
|
|
981
|
-
* ```js
|
|
982
|
-
* // decoding step
|
|
983
|
-
* const decoder = decoding.createDecoder(buf)
|
|
984
|
-
* decoding.readVarUint(decoder) // => 256
|
|
985
|
-
* decoding.readVarString(decoder) // => 'Hello world!'
|
|
986
|
-
* decoding.hasContent(decoder) // => false - all data is read
|
|
987
|
-
* ```
|
|
988
|
-
*
|
|
989
|
-
* @module decoding
|
|
990
|
-
*/
|
|
991
|
-
|
|
992
|
-
const errorUnexpectedEndOfArray = error.create('Unexpected end of array');
|
|
993
|
-
const errorIntegerOutOfRange = error.create('Integer out of Range');
|
|
994
|
-
|
|
995
|
-
/**
|
|
996
|
-
* A Decoder handles the decoding of an Uint8Array.
|
|
997
|
-
*/
|
|
998
|
-
class Decoder {
|
|
999
|
-
/**
|
|
1000
|
-
* @param {Uint8Array} uint8Array Binary data to decode
|
|
1001
|
-
*/
|
|
1002
|
-
constructor (uint8Array) {
|
|
1003
|
-
/**
|
|
1004
|
-
* Decoding target.
|
|
1005
|
-
*
|
|
1006
|
-
* @type {Uint8Array}
|
|
1007
|
-
*/
|
|
1008
|
-
this.arr = uint8Array;
|
|
1009
|
-
/**
|
|
1010
|
-
* Current decoding position.
|
|
1011
|
-
*
|
|
1012
|
-
* @type {number}
|
|
1013
|
-
*/
|
|
1014
|
-
this.pos = 0;
|
|
1015
|
-
}
|
|
1016
|
-
}
|
|
1017
|
-
|
|
1018
|
-
/**
|
|
1019
|
-
* @function
|
|
1020
|
-
* @param {Uint8Array} uint8Array
|
|
1021
|
-
* @return {Decoder}
|
|
1022
|
-
*/
|
|
1023
|
-
const createDecoder = uint8Array => new Decoder(uint8Array);
|
|
1024
|
-
|
|
1025
|
-
/**
|
|
1026
|
-
* @function
|
|
1027
|
-
* @param {Decoder} decoder
|
|
1028
|
-
* @return {boolean}
|
|
1029
|
-
*/
|
|
1030
|
-
const hasContent = decoder => decoder.pos !== decoder.arr.length;
|
|
1031
|
-
|
|
1032
|
-
/**
|
|
1033
|
-
* Clone a decoder instance.
|
|
1034
|
-
* Optionally set a new position parameter.
|
|
1035
|
-
*
|
|
1036
|
-
* @function
|
|
1037
|
-
* @param {Decoder} decoder The decoder instance
|
|
1038
|
-
* @param {number} [newPos] Defaults to current position
|
|
1039
|
-
* @return {Decoder} A clone of `decoder`
|
|
1040
|
-
*/
|
|
1041
|
-
const clone = (decoder, newPos = decoder.pos) => {
|
|
1042
|
-
const _decoder = createDecoder(decoder.arr);
|
|
1043
|
-
_decoder.pos = newPos;
|
|
1044
|
-
return _decoder
|
|
1045
|
-
};
|
|
1046
|
-
|
|
1047
|
-
/**
|
|
1048
|
-
* Create an Uint8Array view of the next `len` bytes and advance the position by `len`.
|
|
1049
|
-
*
|
|
1050
|
-
* Important: The Uint8Array still points to the underlying ArrayBuffer. Make sure to discard the result as soon as possible to prevent any memory leaks.
|
|
1051
|
-
* Use `buffer.copyUint8Array` to copy the result into a new Uint8Array.
|
|
1052
|
-
*
|
|
1053
|
-
* @function
|
|
1054
|
-
* @param {Decoder} decoder The decoder instance
|
|
1055
|
-
* @param {number} len The length of bytes to read
|
|
1056
|
-
* @return {Uint8Array}
|
|
1057
|
-
*/
|
|
1058
|
-
const readUint8Array = (decoder, len) => {
|
|
1059
|
-
const view = createUint8ArrayViewFromArrayBuffer(decoder.arr.buffer, decoder.pos + decoder.arr.byteOffset, len);
|
|
1060
|
-
decoder.pos += len;
|
|
1061
|
-
return view
|
|
1062
|
-
};
|
|
1063
|
-
|
|
1064
|
-
/**
|
|
1065
|
-
* Read variable length Uint8Array.
|
|
1066
|
-
*
|
|
1067
|
-
* Important: The Uint8Array still points to the underlying ArrayBuffer. Make sure to discard the result as soon as possible to prevent any memory leaks.
|
|
1068
|
-
* Use `buffer.copyUint8Array` to copy the result into a new Uint8Array.
|
|
1069
|
-
*
|
|
1070
|
-
* @function
|
|
1071
|
-
* @param {Decoder} decoder
|
|
1072
|
-
* @return {Uint8Array}
|
|
1073
|
-
*/
|
|
1074
|
-
const readVarUint8Array = decoder => readUint8Array(decoder, readVarUint(decoder));
|
|
1075
|
-
|
|
1076
|
-
/**
|
|
1077
|
-
* Read the rest of the content as an ArrayBuffer
|
|
1078
|
-
* @function
|
|
1079
|
-
* @param {Decoder} decoder
|
|
1080
|
-
* @return {Uint8Array}
|
|
1081
|
-
*/
|
|
1082
|
-
const readTailAsUint8Array = decoder => readUint8Array(decoder, decoder.arr.length - decoder.pos);
|
|
1083
|
-
|
|
1084
|
-
/**
|
|
1085
|
-
* Skip one byte, jump to the next position.
|
|
1086
|
-
* @function
|
|
1087
|
-
* @param {Decoder} decoder The decoder instance
|
|
1088
|
-
* @return {number} The next position
|
|
1089
|
-
*/
|
|
1090
|
-
const skip8 = decoder => decoder.pos++;
|
|
1091
|
-
|
|
1092
|
-
/**
|
|
1093
|
-
* Read one byte as unsigned integer.
|
|
1094
|
-
* @function
|
|
1095
|
-
* @param {Decoder} decoder The decoder instance
|
|
1096
|
-
* @return {number} Unsigned 8-bit integer
|
|
1097
|
-
*/
|
|
1098
|
-
const readUint8 = decoder => decoder.arr[decoder.pos++];
|
|
1099
|
-
|
|
1100
|
-
/**
|
|
1101
|
-
* Read 2 bytes as unsigned integer.
|
|
1102
|
-
*
|
|
1103
|
-
* @function
|
|
1104
|
-
* @param {Decoder} decoder
|
|
1105
|
-
* @return {number} An unsigned integer.
|
|
1106
|
-
*/
|
|
1107
|
-
const readUint16 = decoder => {
|
|
1108
|
-
const uint =
|
|
1109
|
-
decoder.arr[decoder.pos] +
|
|
1110
|
-
(decoder.arr[decoder.pos + 1] << 8);
|
|
1111
|
-
decoder.pos += 2;
|
|
1112
|
-
return uint
|
|
1113
|
-
};
|
|
1114
|
-
|
|
1115
|
-
/**
|
|
1116
|
-
* Read 4 bytes as unsigned integer.
|
|
1117
|
-
*
|
|
1118
|
-
* @function
|
|
1119
|
-
* @param {Decoder} decoder
|
|
1120
|
-
* @return {number} An unsigned integer.
|
|
1121
|
-
*/
|
|
1122
|
-
const readUint32 = decoder => {
|
|
1123
|
-
const uint =
|
|
1124
|
-
(decoder.arr[decoder.pos] +
|
|
1125
|
-
(decoder.arr[decoder.pos + 1] << 8) +
|
|
1126
|
-
(decoder.arr[decoder.pos + 2] << 16) +
|
|
1127
|
-
(decoder.arr[decoder.pos + 3] << 24)) >>> 0;
|
|
1128
|
-
decoder.pos += 4;
|
|
1129
|
-
return uint
|
|
1130
|
-
};
|
|
1131
|
-
|
|
1132
|
-
/**
|
|
1133
|
-
* Read 4 bytes as unsigned integer in big endian order.
|
|
1134
|
-
* (most significant byte first)
|
|
1135
|
-
*
|
|
1136
|
-
* @function
|
|
1137
|
-
* @param {Decoder} decoder
|
|
1138
|
-
* @return {number} An unsigned integer.
|
|
1139
|
-
*/
|
|
1140
|
-
const readUint32BigEndian = decoder => {
|
|
1141
|
-
const uint =
|
|
1142
|
-
(decoder.arr[decoder.pos + 3] +
|
|
1143
|
-
(decoder.arr[decoder.pos + 2] << 8) +
|
|
1144
|
-
(decoder.arr[decoder.pos + 1] << 16) +
|
|
1145
|
-
(decoder.arr[decoder.pos] << 24)) >>> 0;
|
|
1146
|
-
decoder.pos += 4;
|
|
1147
|
-
return uint
|
|
1148
|
-
};
|
|
1149
|
-
|
|
1150
|
-
/**
|
|
1151
|
-
* Look ahead without incrementing the position
|
|
1152
|
-
* to the next byte and read it as unsigned integer.
|
|
1153
|
-
*
|
|
1154
|
-
* @function
|
|
1155
|
-
* @param {Decoder} decoder
|
|
1156
|
-
* @return {number} An unsigned integer.
|
|
1157
|
-
*/
|
|
1158
|
-
const peekUint8 = decoder => decoder.arr[decoder.pos];
|
|
1159
|
-
|
|
1160
|
-
/**
|
|
1161
|
-
* Look ahead without incrementing the position
|
|
1162
|
-
* to the next byte and read it as unsigned integer.
|
|
1163
|
-
*
|
|
1164
|
-
* @function
|
|
1165
|
-
* @param {Decoder} decoder
|
|
1166
|
-
* @return {number} An unsigned integer.
|
|
1167
|
-
*/
|
|
1168
|
-
const peekUint16 = decoder =>
|
|
1169
|
-
decoder.arr[decoder.pos] +
|
|
1170
|
-
(decoder.arr[decoder.pos + 1] << 8);
|
|
1171
|
-
|
|
1172
|
-
/**
|
|
1173
|
-
* Look ahead without incrementing the position
|
|
1174
|
-
* to the next byte and read it as unsigned integer.
|
|
1175
|
-
*
|
|
1176
|
-
* @function
|
|
1177
|
-
* @param {Decoder} decoder
|
|
1178
|
-
* @return {number} An unsigned integer.
|
|
1179
|
-
*/
|
|
1180
|
-
const peekUint32 = decoder => (
|
|
1181
|
-
decoder.arr[decoder.pos] +
|
|
1182
|
-
(decoder.arr[decoder.pos + 1] << 8) +
|
|
1183
|
-
(decoder.arr[decoder.pos + 2] << 16) +
|
|
1184
|
-
(decoder.arr[decoder.pos + 3] << 24)
|
|
1185
|
-
) >>> 0;
|
|
1186
|
-
|
|
1187
|
-
/**
|
|
1188
|
-
* Read unsigned integer (32bit) with variable length.
|
|
1189
|
-
* 1/8th of the storage is used as encoding overhead.
|
|
1190
|
-
* * numbers < 2^7 is stored in one bytlength
|
|
1191
|
-
* * numbers < 2^14 is stored in two bylength
|
|
1192
|
-
*
|
|
1193
|
-
* @function
|
|
1194
|
-
* @param {Decoder} decoder
|
|
1195
|
-
* @return {number} An unsigned integer.length
|
|
1196
|
-
*/
|
|
1197
|
-
const readVarUint = decoder => {
|
|
1198
|
-
let num = 0;
|
|
1199
|
-
let mult = 1;
|
|
1200
|
-
const len = decoder.arr.length;
|
|
1201
|
-
while (decoder.pos < len) {
|
|
1202
|
-
const r = decoder.arr[decoder.pos++];
|
|
1203
|
-
// num = num | ((r & binary.BITS7) << len)
|
|
1204
|
-
num = num + (r & binary.BITS7) * mult; // shift $r << (7*#iterations) and add it to num
|
|
1205
|
-
mult *= 128; // next iteration, shift 7 "more" to the left
|
|
1206
|
-
if (r < binary.BIT8) {
|
|
1207
|
-
return num
|
|
1208
|
-
}
|
|
1209
|
-
/* c8 ignore start */
|
|
1210
|
-
if (num > number.MAX_SAFE_INTEGER) {
|
|
1211
|
-
throw errorIntegerOutOfRange
|
|
1212
|
-
}
|
|
1213
|
-
/* c8 ignore stop */
|
|
1214
|
-
}
|
|
1215
|
-
throw errorUnexpectedEndOfArray
|
|
1216
|
-
};
|
|
1217
|
-
|
|
1218
|
-
/**
|
|
1219
|
-
* Read signed integer (32bit) with variable length.
|
|
1220
|
-
* 1/8th of the storage is used as encoding overhead.
|
|
1221
|
-
* * numbers < 2^7 is stored in one bytlength
|
|
1222
|
-
* * numbers < 2^14 is stored in two bylength
|
|
1223
|
-
* @todo This should probably create the inverse ~num if number is negative - but this would be a breaking change.
|
|
1224
|
-
*
|
|
1225
|
-
* @function
|
|
1226
|
-
* @param {Decoder} decoder
|
|
1227
|
-
* @return {number} An unsigned integer.length
|
|
1228
|
-
*/
|
|
1229
|
-
const readVarInt = decoder => {
|
|
1230
|
-
let r = decoder.arr[decoder.pos++];
|
|
1231
|
-
let num = r & binary.BITS6;
|
|
1232
|
-
let mult = 64;
|
|
1233
|
-
const sign = (r & binary.BIT7) > 0 ? -1 : 1;
|
|
1234
|
-
if ((r & binary.BIT8) === 0) {
|
|
1235
|
-
// don't continue reading
|
|
1236
|
-
return sign * num
|
|
1237
|
-
}
|
|
1238
|
-
const len = decoder.arr.length;
|
|
1239
|
-
while (decoder.pos < len) {
|
|
1240
|
-
r = decoder.arr[decoder.pos++];
|
|
1241
|
-
// num = num | ((r & binary.BITS7) << len)
|
|
1242
|
-
num = num + (r & binary.BITS7) * mult;
|
|
1243
|
-
mult *= 128;
|
|
1244
|
-
if (r < binary.BIT8) {
|
|
1245
|
-
return sign * num
|
|
1246
|
-
}
|
|
1247
|
-
/* c8 ignore start */
|
|
1248
|
-
if (num > number.MAX_SAFE_INTEGER) {
|
|
1249
|
-
throw errorIntegerOutOfRange
|
|
1250
|
-
}
|
|
1251
|
-
/* c8 ignore stop */
|
|
1252
|
-
}
|
|
1253
|
-
throw errorUnexpectedEndOfArray
|
|
1254
|
-
};
|
|
1255
|
-
|
|
1256
|
-
/**
|
|
1257
|
-
* Look ahead and read varUint without incrementing position
|
|
1258
|
-
*
|
|
1259
|
-
* @function
|
|
1260
|
-
* @param {Decoder} decoder
|
|
1261
|
-
* @return {number}
|
|
1262
|
-
*/
|
|
1263
|
-
const peekVarUint = decoder => {
|
|
1264
|
-
const pos = decoder.pos;
|
|
1265
|
-
const s = readVarUint(decoder);
|
|
1266
|
-
decoder.pos = pos;
|
|
1267
|
-
return s
|
|
1268
|
-
};
|
|
1269
|
-
|
|
1270
|
-
/**
|
|
1271
|
-
* Look ahead and read varUint without incrementing position
|
|
1272
|
-
*
|
|
1273
|
-
* @function
|
|
1274
|
-
* @param {Decoder} decoder
|
|
1275
|
-
* @return {number}
|
|
1276
|
-
*/
|
|
1277
|
-
const peekVarInt = decoder => {
|
|
1278
|
-
const pos = decoder.pos;
|
|
1279
|
-
const s = readVarInt(decoder);
|
|
1280
|
-
decoder.pos = pos;
|
|
1281
|
-
return s
|
|
1282
|
-
};
|
|
1283
|
-
|
|
1284
|
-
/**
|
|
1285
|
-
* We don't test this function anymore as we use native decoding/encoding by default now.
|
|
1286
|
-
* Better not modify this anymore..
|
|
1287
|
-
*
|
|
1288
|
-
* Transforming utf8 to a string is pretty expensive. The code performs 10x better
|
|
1289
|
-
* when String.fromCodePoint is fed with all characters as arguments.
|
|
1290
|
-
* But most environments have a maximum number of arguments per functions.
|
|
1291
|
-
* For effiency reasons we apply a maximum of 10000 characters at once.
|
|
1292
|
-
*
|
|
1293
|
-
* @function
|
|
1294
|
-
* @param {Decoder} decoder
|
|
1295
|
-
* @return {String} The read String.
|
|
1296
|
-
*/
|
|
1297
|
-
/* c8 ignore start */
|
|
1298
|
-
const _readVarStringPolyfill = decoder => {
|
|
1299
|
-
let remainingLen = readVarUint(decoder);
|
|
1300
|
-
if (remainingLen === 0) {
|
|
1301
|
-
return ''
|
|
1302
|
-
} else {
|
|
1303
|
-
let encodedString = String.fromCodePoint(readUint8(decoder)); // remember to decrease remainingLen
|
|
1304
|
-
if (--remainingLen < 100) { // do not create a Uint8Array for small strings
|
|
1305
|
-
while (remainingLen--) {
|
|
1306
|
-
encodedString += String.fromCodePoint(readUint8(decoder));
|
|
1307
|
-
}
|
|
1308
|
-
} else {
|
|
1309
|
-
while (remainingLen > 0) {
|
|
1310
|
-
const nextLen = remainingLen < 10000 ? remainingLen : 10000;
|
|
1311
|
-
// this is dangerous, we create a fresh array view from the existing buffer
|
|
1312
|
-
const bytes = decoder.arr.subarray(decoder.pos, decoder.pos + nextLen);
|
|
1313
|
-
decoder.pos += nextLen;
|
|
1314
|
-
// Starting with ES5.1 we can supply a generic array-like object as arguments
|
|
1315
|
-
encodedString += String.fromCodePoint.apply(null, /** @type {any} */ (bytes));
|
|
1316
|
-
remainingLen -= nextLen;
|
|
1317
|
-
}
|
|
1318
|
-
}
|
|
1319
|
-
return decodeURIComponent(escape(encodedString))
|
|
1320
|
-
}
|
|
1321
|
-
};
|
|
1322
|
-
/* c8 ignore stop */
|
|
1323
|
-
|
|
1324
|
-
/**
|
|
1325
|
-
* @function
|
|
1326
|
-
* @param {Decoder} decoder
|
|
1327
|
-
* @return {String} The read String
|
|
1328
|
-
*/
|
|
1329
|
-
const _readVarStringNative = decoder =>
|
|
1330
|
-
/** @type any */ (string.utf8TextDecoder).decode(readVarUint8Array(decoder));
|
|
1331
|
-
|
|
1332
|
-
/**
|
|
1333
|
-
* Read string of variable length
|
|
1334
|
-
* * varUint is used to store the length of the string
|
|
1335
|
-
*
|
|
1336
|
-
* @function
|
|
1337
|
-
* @param {Decoder} decoder
|
|
1338
|
-
* @return {String} The read String
|
|
1339
|
-
*
|
|
1340
|
-
*/
|
|
1341
|
-
/* c8 ignore next */
|
|
1342
|
-
const readVarString = string.utf8TextDecoder ? _readVarStringNative : _readVarStringPolyfill;
|
|
1343
|
-
|
|
1344
|
-
/**
|
|
1345
|
-
* @param {Decoder} decoder
|
|
1346
|
-
* @return {Uint8Array}
|
|
1347
|
-
*/
|
|
1348
|
-
const readTerminatedUint8Array = decoder => {
|
|
1349
|
-
const encoder = createEncoder();
|
|
1350
|
-
let b;
|
|
1351
|
-
while (true) {
|
|
1352
|
-
b = readUint8(decoder);
|
|
1353
|
-
if (b === 0) {
|
|
1354
|
-
return toUint8Array(encoder)
|
|
1355
|
-
}
|
|
1356
|
-
if (b === 1) {
|
|
1357
|
-
b = readUint8(decoder);
|
|
1358
|
-
}
|
|
1359
|
-
write(encoder, b);
|
|
1360
|
-
}
|
|
1361
|
-
};
|
|
1362
|
-
|
|
1363
|
-
/**
|
|
1364
|
-
* @param {Decoder} decoder
|
|
1365
|
-
* @return {string}
|
|
1366
|
-
*/
|
|
1367
|
-
const readTerminatedString = decoder => string.decodeUtf8(readTerminatedUint8Array(decoder));
|
|
1368
|
-
|
|
1369
|
-
/**
|
|
1370
|
-
* Look ahead and read varString without incrementing position
|
|
1371
|
-
*
|
|
1372
|
-
* @function
|
|
1373
|
-
* @param {Decoder} decoder
|
|
1374
|
-
* @return {string}
|
|
1375
|
-
*/
|
|
1376
|
-
const peekVarString = decoder => {
|
|
1377
|
-
const pos = decoder.pos;
|
|
1378
|
-
const s = readVarString(decoder);
|
|
1379
|
-
decoder.pos = pos;
|
|
1380
|
-
return s
|
|
1381
|
-
};
|
|
1382
|
-
|
|
1383
|
-
/**
|
|
1384
|
-
* @param {Decoder} decoder
|
|
1385
|
-
* @param {number} len
|
|
1386
|
-
* @return {DataView}
|
|
1387
|
-
*/
|
|
1388
|
-
const readFromDataView = (decoder, len) => {
|
|
1389
|
-
const dv = new DataView(decoder.arr.buffer, decoder.arr.byteOffset + decoder.pos, len);
|
|
1390
|
-
decoder.pos += len;
|
|
1391
|
-
return dv
|
|
1392
|
-
};
|
|
1393
|
-
|
|
1394
|
-
/**
|
|
1395
|
-
* @param {Decoder} decoder
|
|
1396
|
-
*/
|
|
1397
|
-
const readFloat32 = decoder => readFromDataView(decoder, 4).getFloat32(0, false);
|
|
1398
|
-
|
|
1399
|
-
/**
|
|
1400
|
-
* @param {Decoder} decoder
|
|
1401
|
-
*/
|
|
1402
|
-
const readFloat64 = decoder => readFromDataView(decoder, 8).getFloat64(0, false);
|
|
1403
|
-
|
|
1404
|
-
/**
|
|
1405
|
-
* @param {Decoder} decoder
|
|
1406
|
-
*/
|
|
1407
|
-
const readBigInt64 = decoder => /** @type {any} */ (readFromDataView(decoder, 8)).getBigInt64(0, false);
|
|
1408
|
-
|
|
1409
|
-
/**
|
|
1410
|
-
* @param {Decoder} decoder
|
|
1411
|
-
*/
|
|
1412
|
-
const readBigUint64 = decoder => /** @type {any} */ (readFromDataView(decoder, 8)).getBigUint64(0, false);
|
|
1413
|
-
|
|
1414
|
-
/**
|
|
1415
|
-
* @type {Array<function(Decoder):any>}
|
|
1416
|
-
*/
|
|
1417
|
-
const readAnyLookupTable = [
|
|
1418
|
-
decoder => undefined, // CASE 127: undefined
|
|
1419
|
-
decoder => null, // CASE 126: null
|
|
1420
|
-
readVarInt, // CASE 125: integer
|
|
1421
|
-
readFloat32, // CASE 124: float32
|
|
1422
|
-
readFloat64, // CASE 123: float64
|
|
1423
|
-
readBigInt64, // CASE 122: bigint
|
|
1424
|
-
decoder => false, // CASE 121: boolean (false)
|
|
1425
|
-
decoder => true, // CASE 120: boolean (true)
|
|
1426
|
-
readVarString, // CASE 119: string
|
|
1427
|
-
decoder => { // CASE 118: object<string,any>
|
|
1428
|
-
const len = readVarUint(decoder);
|
|
1429
|
-
/**
|
|
1430
|
-
* @type {Object<string,any>}
|
|
1431
|
-
*/
|
|
1432
|
-
const obj = {};
|
|
1433
|
-
for (let i = 0; i < len; i++) {
|
|
1434
|
-
const key = readVarString(decoder);
|
|
1435
|
-
obj[key] = readAny(decoder);
|
|
1436
|
-
}
|
|
1437
|
-
return obj
|
|
1438
|
-
},
|
|
1439
|
-
decoder => { // CASE 117: array<any>
|
|
1440
|
-
const len = readVarUint(decoder);
|
|
1441
|
-
const arr = [];
|
|
1442
|
-
for (let i = 0; i < len; i++) {
|
|
1443
|
-
arr.push(readAny(decoder));
|
|
1444
|
-
}
|
|
1445
|
-
return arr
|
|
1446
|
-
},
|
|
1447
|
-
readVarUint8Array // CASE 116: Uint8Array
|
|
1448
|
-
];
|
|
1449
|
-
|
|
1450
|
-
/**
|
|
1451
|
-
* @param {Decoder} decoder
|
|
1452
|
-
*/
|
|
1453
|
-
const readAny = decoder => readAnyLookupTable[127 - readUint8(decoder)](decoder);
|
|
1454
|
-
|
|
1455
|
-
/**
|
|
1456
|
-
* T must not be null.
|
|
1457
|
-
*
|
|
1458
|
-
* @template T
|
|
1459
|
-
*/
|
|
1460
|
-
class RleDecoder extends Decoder {
|
|
1461
|
-
/**
|
|
1462
|
-
* @param {Uint8Array} uint8Array
|
|
1463
|
-
* @param {function(Decoder):T} reader
|
|
1464
|
-
*/
|
|
1465
|
-
constructor (uint8Array, reader) {
|
|
1466
|
-
super(uint8Array);
|
|
1467
|
-
/**
|
|
1468
|
-
* The reader
|
|
1469
|
-
*/
|
|
1470
|
-
this.reader = reader;
|
|
1471
|
-
/**
|
|
1472
|
-
* Current state
|
|
1473
|
-
* @type {T|null}
|
|
1474
|
-
*/
|
|
1475
|
-
this.s = null;
|
|
1476
|
-
this.count = 0;
|
|
1477
|
-
}
|
|
1478
|
-
|
|
1479
|
-
read () {
|
|
1480
|
-
if (this.count === 0) {
|
|
1481
|
-
this.s = this.reader(this);
|
|
1482
|
-
if (hasContent(this)) {
|
|
1483
|
-
this.count = readVarUint(this) + 1; // see encoder implementation for the reason why this is incremented
|
|
1484
|
-
} else {
|
|
1485
|
-
this.count = -1; // read the current value forever
|
|
1486
|
-
}
|
|
1487
|
-
}
|
|
1488
|
-
this.count--;
|
|
1489
|
-
return /** @type {T} */ (this.s)
|
|
1490
|
-
}
|
|
1491
|
-
}
|
|
1492
|
-
|
|
1493
|
-
class IntDiffDecoder extends Decoder {
|
|
1494
|
-
/**
|
|
1495
|
-
* @param {Uint8Array} uint8Array
|
|
1496
|
-
* @param {number} start
|
|
1497
|
-
*/
|
|
1498
|
-
constructor (uint8Array, start) {
|
|
1499
|
-
super(uint8Array);
|
|
1500
|
-
/**
|
|
1501
|
-
* Current state
|
|
1502
|
-
* @type {number}
|
|
1503
|
-
*/
|
|
1504
|
-
this.s = start;
|
|
1505
|
-
}
|
|
1506
|
-
|
|
1507
|
-
/**
|
|
1508
|
-
* @return {number}
|
|
1509
|
-
*/
|
|
1510
|
-
read () {
|
|
1511
|
-
this.s += readVarInt(this);
|
|
1512
|
-
return this.s
|
|
1513
|
-
}
|
|
1514
|
-
}
|
|
1515
|
-
|
|
1516
|
-
class RleIntDiffDecoder extends Decoder {
|
|
1517
|
-
/**
|
|
1518
|
-
* @param {Uint8Array} uint8Array
|
|
1519
|
-
* @param {number} start
|
|
1520
|
-
*/
|
|
1521
|
-
constructor (uint8Array, start) {
|
|
1522
|
-
super(uint8Array);
|
|
1523
|
-
/**
|
|
1524
|
-
* Current state
|
|
1525
|
-
* @type {number}
|
|
1526
|
-
*/
|
|
1527
|
-
this.s = start;
|
|
1528
|
-
this.count = 0;
|
|
1529
|
-
}
|
|
1530
|
-
|
|
1531
|
-
/**
|
|
1532
|
-
* @return {number}
|
|
1533
|
-
*/
|
|
1534
|
-
read () {
|
|
1535
|
-
if (this.count === 0) {
|
|
1536
|
-
this.s += readVarInt(this);
|
|
1537
|
-
if (hasContent(this)) {
|
|
1538
|
-
this.count = readVarUint(this) + 1; // see encoder implementation for the reason why this is incremented
|
|
1539
|
-
} else {
|
|
1540
|
-
this.count = -1; // read the current value forever
|
|
1541
|
-
}
|
|
1542
|
-
}
|
|
1543
|
-
this.count--;
|
|
1544
|
-
return /** @type {number} */ (this.s)
|
|
1545
|
-
}
|
|
1546
|
-
}
|
|
1547
|
-
|
|
1548
|
-
class UintOptRleDecoder extends Decoder {
|
|
1549
|
-
/**
|
|
1550
|
-
* @param {Uint8Array} uint8Array
|
|
1551
|
-
*/
|
|
1552
|
-
constructor (uint8Array) {
|
|
1553
|
-
super(uint8Array);
|
|
1554
|
-
/**
|
|
1555
|
-
* @type {number}
|
|
1556
|
-
*/
|
|
1557
|
-
this.s = 0;
|
|
1558
|
-
this.count = 0;
|
|
1559
|
-
}
|
|
1560
|
-
|
|
1561
|
-
read () {
|
|
1562
|
-
if (this.count === 0) {
|
|
1563
|
-
this.s = readVarInt(this);
|
|
1564
|
-
// if the sign is negative, we read the count too, otherwise count is 1
|
|
1565
|
-
const isNegative = math.isNegativeZero(this.s);
|
|
1566
|
-
this.count = 1;
|
|
1567
|
-
if (isNegative) {
|
|
1568
|
-
this.s = -this.s;
|
|
1569
|
-
this.count = readVarUint(this) + 2;
|
|
1570
|
-
}
|
|
1571
|
-
}
|
|
1572
|
-
this.count--;
|
|
1573
|
-
return /** @type {number} */ (this.s)
|
|
1574
|
-
}
|
|
1575
|
-
}
|
|
1576
|
-
|
|
1577
|
-
class IncUintOptRleDecoder extends Decoder {
|
|
1578
|
-
/**
|
|
1579
|
-
* @param {Uint8Array} uint8Array
|
|
1580
|
-
*/
|
|
1581
|
-
constructor (uint8Array) {
|
|
1582
|
-
super(uint8Array);
|
|
1583
|
-
/**
|
|
1584
|
-
* @type {number}
|
|
1585
|
-
*/
|
|
1586
|
-
this.s = 0;
|
|
1587
|
-
this.count = 0;
|
|
1588
|
-
}
|
|
1589
|
-
|
|
1590
|
-
read () {
|
|
1591
|
-
if (this.count === 0) {
|
|
1592
|
-
this.s = readVarInt(this);
|
|
1593
|
-
// if the sign is negative, we read the count too, otherwise count is 1
|
|
1594
|
-
const isNegative = math.isNegativeZero(this.s);
|
|
1595
|
-
this.count = 1;
|
|
1596
|
-
if (isNegative) {
|
|
1597
|
-
this.s = -this.s;
|
|
1598
|
-
this.count = readVarUint(this) + 2;
|
|
1599
|
-
}
|
|
1600
|
-
}
|
|
1601
|
-
this.count--;
|
|
1602
|
-
return /** @type {number} */ (this.s++)
|
|
1603
|
-
}
|
|
1604
|
-
}
|
|
1605
|
-
|
|
1606
|
-
class IntDiffOptRleDecoder extends Decoder {
|
|
1607
|
-
/**
|
|
1608
|
-
* @param {Uint8Array} uint8Array
|
|
1609
|
-
*/
|
|
1610
|
-
constructor (uint8Array) {
|
|
1611
|
-
super(uint8Array);
|
|
1612
|
-
/**
|
|
1613
|
-
* @type {number}
|
|
1614
|
-
*/
|
|
1615
|
-
this.s = 0;
|
|
1616
|
-
this.count = 0;
|
|
1617
|
-
this.diff = 0;
|
|
1618
|
-
}
|
|
1619
|
-
|
|
1620
|
-
/**
|
|
1621
|
-
* @return {number}
|
|
1622
|
-
*/
|
|
1623
|
-
read () {
|
|
1624
|
-
if (this.count === 0) {
|
|
1625
|
-
const diff = readVarInt(this);
|
|
1626
|
-
// if the first bit is set, we read more data
|
|
1627
|
-
const hasCount = diff & 1;
|
|
1628
|
-
this.diff = math.floor(diff / 2); // shift >> 1
|
|
1629
|
-
this.count = 1;
|
|
1630
|
-
if (hasCount) {
|
|
1631
|
-
this.count = readVarUint(this) + 2;
|
|
1632
|
-
}
|
|
1633
|
-
}
|
|
1634
|
-
this.s += this.diff;
|
|
1635
|
-
this.count--;
|
|
1636
|
-
return this.s
|
|
1637
|
-
}
|
|
1638
|
-
}
|
|
1639
|
-
|
|
1640
|
-
class StringDecoder {
|
|
1641
|
-
/**
|
|
1642
|
-
* @param {Uint8Array} uint8Array
|
|
1643
|
-
*/
|
|
1644
|
-
constructor (uint8Array) {
|
|
1645
|
-
this.decoder = new UintOptRleDecoder(uint8Array);
|
|
1646
|
-
this.str = readVarString(this.decoder);
|
|
1647
|
-
/**
|
|
1648
|
-
* @type {number}
|
|
1649
|
-
*/
|
|
1650
|
-
this.spos = 0;
|
|
1651
|
-
}
|
|
1652
|
-
|
|
1653
|
-
/**
|
|
1654
|
-
* @return {string}
|
|
1655
|
-
*/
|
|
1656
|
-
read () {
|
|
1657
|
-
const end = this.spos + this.decoder.read();
|
|
1658
|
-
const res = this.str.slice(this.spos, end);
|
|
1659
|
-
this.spos = end;
|
|
1660
|
-
return res
|
|
1661
|
-
}
|
|
1662
|
-
}
|
|
1663
|
-
|
|
1664
|
-
var decoding = /*#__PURE__*/Object.freeze({
|
|
1665
|
-
__proto__: null,
|
|
1666
|
-
Decoder: Decoder,
|
|
1667
|
-
createDecoder: createDecoder,
|
|
1668
|
-
hasContent: hasContent,
|
|
1669
|
-
clone: clone,
|
|
1670
|
-
readUint8Array: readUint8Array,
|
|
1671
|
-
readVarUint8Array: readVarUint8Array,
|
|
1672
|
-
readTailAsUint8Array: readTailAsUint8Array,
|
|
1673
|
-
skip8: skip8,
|
|
1674
|
-
readUint8: readUint8,
|
|
1675
|
-
readUint16: readUint16,
|
|
1676
|
-
readUint32: readUint32,
|
|
1677
|
-
readUint32BigEndian: readUint32BigEndian,
|
|
1678
|
-
peekUint8: peekUint8,
|
|
1679
|
-
peekUint16: peekUint16,
|
|
1680
|
-
peekUint32: peekUint32,
|
|
1681
|
-
readVarUint: readVarUint,
|
|
1682
|
-
readVarInt: readVarInt,
|
|
1683
|
-
peekVarUint: peekVarUint,
|
|
1684
|
-
peekVarInt: peekVarInt,
|
|
1685
|
-
_readVarStringPolyfill: _readVarStringPolyfill,
|
|
1686
|
-
_readVarStringNative: _readVarStringNative,
|
|
1687
|
-
readVarString: readVarString,
|
|
1688
|
-
readTerminatedUint8Array: readTerminatedUint8Array,
|
|
1689
|
-
readTerminatedString: readTerminatedString,
|
|
1690
|
-
peekVarString: peekVarString,
|
|
1691
|
-
readFromDataView: readFromDataView,
|
|
1692
|
-
readFloat32: readFloat32,
|
|
1693
|
-
readFloat64: readFloat64,
|
|
1694
|
-
readBigInt64: readBigInt64,
|
|
1695
|
-
readBigUint64: readBigUint64,
|
|
1696
|
-
readAny: readAny,
|
|
1697
|
-
RleDecoder: RleDecoder,
|
|
1698
|
-
IntDiffDecoder: IntDiffDecoder,
|
|
1699
|
-
RleIntDiffDecoder: RleIntDiffDecoder,
|
|
1700
|
-
UintOptRleDecoder: UintOptRleDecoder,
|
|
1701
|
-
IncUintOptRleDecoder: IncUintOptRleDecoder,
|
|
1702
|
-
IntDiffOptRleDecoder: IntDiffOptRleDecoder,
|
|
1703
|
-
StringDecoder: StringDecoder
|
|
1704
|
-
});
|
|
1705
|
-
|
|
1706
|
-
/**
|
|
1707
|
-
* Utility functions to work with buffers (Uint8Array).
|
|
1708
|
-
*
|
|
1709
|
-
* @module buffer
|
|
1710
|
-
*/
|
|
1711
|
-
|
|
1712
|
-
/**
|
|
1713
|
-
* @param {number} len
|
|
1714
|
-
*/
|
|
1715
|
-
const createUint8ArrayFromLen = len => new Uint8Array(len);
|
|
1716
|
-
|
|
1717
|
-
/**
|
|
1718
|
-
* Create Uint8Array with initial content from buffer
|
|
1719
|
-
*
|
|
1720
|
-
* @param {ArrayBuffer} buffer
|
|
1721
|
-
* @param {number} byteOffset
|
|
1722
|
-
* @param {number} length
|
|
1723
|
-
*/
|
|
1724
|
-
const createUint8ArrayViewFromArrayBuffer = (buffer, byteOffset, length) => new Uint8Array(buffer, byteOffset, length);
|
|
1725
|
-
|
|
1726
|
-
/**
|
|
1727
|
-
* Create Uint8Array with initial content from buffer
|
|
1728
|
-
*
|
|
1729
|
-
* @param {ArrayBuffer} buffer
|
|
1730
|
-
*/
|
|
1731
|
-
const createUint8ArrayFromArrayBuffer = buffer => new Uint8Array(buffer);
|
|
1732
|
-
|
|
1733
|
-
/* c8 ignore start */
|
|
1734
|
-
/**
|
|
1735
|
-
* @param {Uint8Array} bytes
|
|
1736
|
-
* @return {string}
|
|
1737
|
-
*/
|
|
1738
|
-
const toBase64Browser = bytes => {
|
|
1739
|
-
let s = '';
|
|
1740
|
-
for (let i = 0; i < bytes.byteLength; i++) {
|
|
1741
|
-
s += string.fromCharCode(bytes[i]);
|
|
1742
|
-
}
|
|
1743
|
-
// eslint-disable-next-line no-undef
|
|
1744
|
-
return btoa(s)
|
|
1745
|
-
};
|
|
1746
|
-
/* c8 ignore stop */
|
|
1747
|
-
|
|
1748
|
-
/**
|
|
1749
|
-
* @param {Uint8Array} bytes
|
|
1750
|
-
* @return {string}
|
|
1751
|
-
*/
|
|
1752
|
-
const toBase64Node = bytes => Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength).toString('base64');
|
|
1753
|
-
|
|
1754
|
-
/* c8 ignore start */
|
|
1755
|
-
/**
|
|
1756
|
-
* @param {string} s
|
|
1757
|
-
* @return {Uint8Array}
|
|
1758
|
-
*/
|
|
1759
|
-
const fromBase64Browser = s => {
|
|
1760
|
-
// eslint-disable-next-line no-undef
|
|
1761
|
-
const a = atob(s);
|
|
1762
|
-
const bytes = createUint8ArrayFromLen(a.length);
|
|
1763
|
-
for (let i = 0; i < a.length; i++) {
|
|
1764
|
-
bytes[i] = a.charCodeAt(i);
|
|
1765
|
-
}
|
|
1766
|
-
return bytes
|
|
1767
|
-
};
|
|
1768
|
-
/* c8 ignore stop */
|
|
1769
|
-
|
|
1770
|
-
/**
|
|
1771
|
-
* @param {string} s
|
|
1772
|
-
*/
|
|
1773
|
-
const fromBase64Node = s => {
|
|
1774
|
-
const buf = Buffer.from(s, 'base64');
|
|
1775
|
-
return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength)
|
|
1776
|
-
};
|
|
1777
|
-
|
|
1778
|
-
/* c8 ignore next */
|
|
1779
|
-
const toBase64 = environment.isBrowser ? toBase64Browser : toBase64Node;
|
|
1780
|
-
|
|
1781
|
-
/* c8 ignore next */
|
|
1782
|
-
const fromBase64 = environment.isBrowser ? fromBase64Browser : fromBase64Node;
|
|
1783
|
-
|
|
1784
|
-
/**
|
|
1785
|
-
* Implements base64url - see https://datatracker.ietf.org/doc/html/rfc4648#section-5
|
|
1786
|
-
* @param {Uint8Array} buf
|
|
1787
|
-
*/
|
|
1788
|
-
const toBase64UrlEncoded = buf => toBase64(buf).replaceAll('+', '-').replaceAll('/', '_').replaceAll('=', '');
|
|
1789
|
-
|
|
1790
|
-
/**
|
|
1791
|
-
* @param {string} base64
|
|
1792
|
-
*/
|
|
1793
|
-
const fromBase64UrlEncoded = base64 => fromBase64(base64.replaceAll('-', '+').replaceAll('_', '/'));
|
|
1794
|
-
|
|
1795
|
-
/**
|
|
1796
|
-
* Base64 is always a more efficient choice. This exists for utility purposes only.
|
|
1797
|
-
*
|
|
1798
|
-
* @param {Uint8Array} buf
|
|
1799
|
-
*/
|
|
1800
|
-
const toHexString = buf => array.map(buf, b => b.toString(16).padStart(2, '0')).join('');
|
|
1801
|
-
|
|
1802
|
-
/**
|
|
1803
|
-
* Note: This function expects that the hex doesn't start with 0x..
|
|
1804
|
-
*
|
|
1805
|
-
* @param {string} hex
|
|
1806
|
-
*/
|
|
1807
|
-
const fromHexString = hex => {
|
|
1808
|
-
const hlen = hex.length;
|
|
1809
|
-
const buf = new Uint8Array(math.ceil(hlen / 2));
|
|
1810
|
-
for (let i = 0; i < hlen; i += 2) {
|
|
1811
|
-
buf[buf.length - i / 2 - 1] = Number.parseInt(hex.slice(hlen - i - 2, hlen - i), 16);
|
|
1812
|
-
}
|
|
1813
|
-
return buf
|
|
1814
|
-
};
|
|
1815
|
-
|
|
1816
|
-
/**
|
|
1817
|
-
* Copy the content of an Uint8Array view to a new ArrayBuffer.
|
|
1818
|
-
*
|
|
1819
|
-
* @param {Uint8Array} uint8Array
|
|
1820
|
-
* @return {Uint8Array}
|
|
1821
|
-
*/
|
|
1822
|
-
const copyUint8Array = uint8Array => {
|
|
1823
|
-
const newBuf = createUint8ArrayFromLen(uint8Array.byteLength);
|
|
1824
|
-
newBuf.set(uint8Array);
|
|
1825
|
-
return newBuf
|
|
1826
|
-
};
|
|
1827
|
-
|
|
1828
|
-
/**
|
|
1829
|
-
* Encode anything as a UInt8Array. It's a pun on typescripts's `any` type.
|
|
1830
|
-
* See encoding.writeAny for more information.
|
|
1831
|
-
*
|
|
1832
|
-
* @param {any} data
|
|
1833
|
-
* @return {Uint8Array}
|
|
1834
|
-
*/
|
|
1835
|
-
const encodeAny = data => {
|
|
1836
|
-
const encoder = createEncoder();
|
|
1837
|
-
writeAny(encoder, data);
|
|
1838
|
-
return toUint8Array(encoder)
|
|
1839
|
-
};
|
|
1840
|
-
|
|
1841
|
-
/**
|
|
1842
|
-
* Decode an any-encoded value.
|
|
1843
|
-
*
|
|
1844
|
-
* @param {Uint8Array} buf
|
|
1845
|
-
* @return {any}
|
|
1846
|
-
*/
|
|
1847
|
-
const decodeAny = buf => readAny(createDecoder(buf));
|
|
1848
|
-
|
|
1849
|
-
/**
|
|
1850
|
-
* Shift Byte Array {N} bits to the left. Does not expand byte array.
|
|
1851
|
-
*
|
|
1852
|
-
* @param {Uint8Array} bs
|
|
1853
|
-
* @param {number} N should be in the range of [0-7]
|
|
1854
|
-
*/
|
|
1855
|
-
const shiftNBitsLeft = (bs, N) => {
|
|
1856
|
-
if (N === 0) return bs
|
|
1857
|
-
bs = new Uint8Array(bs);
|
|
1858
|
-
bs[0] <<= N;
|
|
1859
|
-
for (let i = 1; i < bs.length; i++) {
|
|
1860
|
-
bs[i - 1] |= bs[i] >>> (8 - N);
|
|
1861
|
-
bs[i] <<= N;
|
|
1862
|
-
}
|
|
1863
|
-
return bs
|
|
1864
|
-
};
|
|
1865
|
-
|
|
1866
|
-
var buffer = /*#__PURE__*/Object.freeze({
|
|
1867
|
-
__proto__: null,
|
|
1868
|
-
createUint8ArrayFromLen: createUint8ArrayFromLen,
|
|
1869
|
-
createUint8ArrayViewFromArrayBuffer: createUint8ArrayViewFromArrayBuffer,
|
|
1870
|
-
createUint8ArrayFromArrayBuffer: createUint8ArrayFromArrayBuffer,
|
|
1871
|
-
toBase64: toBase64,
|
|
1872
|
-
fromBase64: fromBase64,
|
|
1873
|
-
toBase64UrlEncoded: toBase64UrlEncoded,
|
|
1874
|
-
fromBase64UrlEncoded: fromBase64UrlEncoded,
|
|
1875
|
-
toHexString: toHexString,
|
|
1876
|
-
fromHexString: fromHexString,
|
|
1877
|
-
copyUint8Array: copyUint8Array,
|
|
1878
|
-
encodeAny: encodeAny,
|
|
1879
|
-
decodeAny: decodeAny,
|
|
1880
|
-
shiftNBitsLeft: shiftNBitsLeft
|
|
1881
|
-
});
|
|
1882
|
-
|
|
1883
|
-
exports.Decoder = Decoder;
|
|
1884
962
|
exports.Encoder = Encoder;
|
|
1885
|
-
exports.IncUintOptRleDecoder = IncUintOptRleDecoder;
|
|
1886
963
|
exports.IncUintOptRleEncoder = IncUintOptRleEncoder;
|
|
1887
|
-
exports.IntDiffDecoder = IntDiffDecoder;
|
|
1888
964
|
exports.IntDiffEncoder = IntDiffEncoder;
|
|
1889
|
-
exports.IntDiffOptRleDecoder = IntDiffOptRleDecoder;
|
|
1890
965
|
exports.IntDiffOptRleEncoder = IntDiffOptRleEncoder;
|
|
1891
|
-
exports.RleDecoder = RleDecoder;
|
|
1892
966
|
exports.RleEncoder = RleEncoder;
|
|
1893
|
-
exports.RleIntDiffDecoder = RleIntDiffDecoder;
|
|
1894
967
|
exports.RleIntDiffEncoder = RleIntDiffEncoder;
|
|
1895
|
-
exports.StringDecoder = StringDecoder;
|
|
1896
968
|
exports.StringEncoder = StringEncoder;
|
|
1897
|
-
exports.UintOptRleDecoder = UintOptRleDecoder;
|
|
1898
969
|
exports.UintOptRleEncoder = UintOptRleEncoder;
|
|
1899
|
-
exports._readVarStringNative = _readVarStringNative;
|
|
1900
|
-
exports._readVarStringPolyfill = _readVarStringPolyfill;
|
|
1901
970
|
exports._writeVarStringNative = _writeVarStringNative;
|
|
1902
971
|
exports._writeVarStringPolyfill = _writeVarStringPolyfill;
|
|
1903
|
-
exports.buffer = buffer;
|
|
1904
|
-
exports.clone = clone;
|
|
1905
|
-
exports.copyUint8Array = copyUint8Array;
|
|
1906
|
-
exports.createDecoder = createDecoder;
|
|
1907
972
|
exports.createEncoder = createEncoder;
|
|
1908
|
-
exports.createUint8ArrayFromArrayBuffer = createUint8ArrayFromArrayBuffer;
|
|
1909
|
-
exports.createUint8ArrayFromLen = createUint8ArrayFromLen;
|
|
1910
|
-
exports.createUint8ArrayViewFromArrayBuffer = createUint8ArrayViewFromArrayBuffer;
|
|
1911
|
-
exports.decodeAny = decodeAny;
|
|
1912
|
-
exports.decoding = decoding;
|
|
1913
973
|
exports.encode = encode;
|
|
1914
|
-
exports.encodeAny = encodeAny;
|
|
1915
974
|
exports.encoding = encoding;
|
|
1916
|
-
exports.
|
|
1917
|
-
exports.fromBase64UrlEncoded = fromBase64UrlEncoded;
|
|
1918
|
-
exports.fromHexString = fromHexString;
|
|
1919
|
-
exports.hasContent = hasContent$1;
|
|
1920
|
-
exports.hasContent$1 = hasContent;
|
|
975
|
+
exports.hasContent = hasContent;
|
|
1921
976
|
exports.length = length;
|
|
1922
|
-
exports.peekUint16 = peekUint16;
|
|
1923
|
-
exports.peekUint32 = peekUint32;
|
|
1924
|
-
exports.peekUint8 = peekUint8;
|
|
1925
|
-
exports.peekVarInt = peekVarInt;
|
|
1926
|
-
exports.peekVarString = peekVarString;
|
|
1927
|
-
exports.peekVarUint = peekVarUint;
|
|
1928
|
-
exports.readAny = readAny;
|
|
1929
|
-
exports.readBigInt64 = readBigInt64;
|
|
1930
|
-
exports.readBigUint64 = readBigUint64;
|
|
1931
|
-
exports.readFloat32 = readFloat32;
|
|
1932
|
-
exports.readFloat64 = readFloat64;
|
|
1933
|
-
exports.readFromDataView = readFromDataView;
|
|
1934
|
-
exports.readTailAsUint8Array = readTailAsUint8Array;
|
|
1935
|
-
exports.readTerminatedString = readTerminatedString;
|
|
1936
|
-
exports.readTerminatedUint8Array = readTerminatedUint8Array;
|
|
1937
|
-
exports.readUint16 = readUint16;
|
|
1938
|
-
exports.readUint32 = readUint32;
|
|
1939
|
-
exports.readUint32BigEndian = readUint32BigEndian;
|
|
1940
|
-
exports.readUint8 = readUint8;
|
|
1941
|
-
exports.readUint8Array = readUint8Array;
|
|
1942
|
-
exports.readVarInt = readVarInt;
|
|
1943
|
-
exports.readVarString = readVarString;
|
|
1944
|
-
exports.readVarUint = readVarUint;
|
|
1945
|
-
exports.readVarUint8Array = readVarUint8Array;
|
|
1946
977
|
exports.set = set;
|
|
1947
978
|
exports.setUint16 = setUint16;
|
|
1948
979
|
exports.setUint32 = setUint32;
|
|
1949
980
|
exports.setUint8 = setUint8;
|
|
1950
|
-
exports.shiftNBitsLeft = shiftNBitsLeft;
|
|
1951
|
-
exports.skip8 = skip8;
|
|
1952
|
-
exports.toBase64 = toBase64;
|
|
1953
|
-
exports.toBase64UrlEncoded = toBase64UrlEncoded;
|
|
1954
|
-
exports.toHexString = toHexString;
|
|
1955
981
|
exports.toUint8Array = toUint8Array;
|
|
1956
982
|
exports.verifyLen = verifyLen;
|
|
1957
983
|
exports.write = write;
|
|
@@ -1973,4 +999,4 @@ exports.writeVarInt = writeVarInt;
|
|
|
1973
999
|
exports.writeVarString = writeVarString;
|
|
1974
1000
|
exports.writeVarUint = writeVarUint;
|
|
1975
1001
|
exports.writeVarUint8Array = writeVarUint8Array;
|
|
1976
|
-
//# sourceMappingURL=
|
|
1002
|
+
//# sourceMappingURL=encoding-5bb79b9b.cjs.map
|