@bare-ts/lib 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -2
- package/dist/codec/data.d.ts +4 -4
- package/dist/codec/data.js +26 -0
- package/dist/codec/float-array.d.ts +12 -12
- package/dist/codec/float-array.js +85 -0
- package/dist/codec/i16-array.d.ts +6 -6
- package/dist/codec/i16-array.js +43 -0
- package/dist/codec/i32-array.d.ts +6 -6
- package/dist/codec/i32-array.js +43 -0
- package/dist/codec/i64-array.d.ts +6 -6
- package/dist/codec/i64-array.js +43 -0
- package/dist/codec/i8-array.d.ts +4 -4
- package/dist/codec/i8-array.js +24 -0
- package/dist/codec/index.js +15 -0
- package/dist/codec/primitive.d.ts +34 -36
- package/dist/codec/primitive.js +345 -0
- package/dist/codec/string.d.ts +4 -2
- package/dist/codec/string.js +126 -0
- package/dist/codec/u16-array.d.ts +6 -6
- package/dist/codec/u16-array.js +43 -0
- package/dist/codec/u32-array.d.ts +6 -6
- package/dist/codec/u32-array.js +43 -0
- package/dist/codec/u64-array.d.ts +6 -6
- package/dist/codec/u64-array.js +43 -0
- package/dist/codec/u8-array.d.ts +4 -4
- package/dist/codec/u8-array.js +27 -0
- package/dist/codec/u8-clamped-array.d.ts +4 -4
- package/dist/codec/u8-clamped-array.js +24 -0
- package/dist/core/bare-error.js +14 -0
- package/dist/core/byte-cursor.d.ts +26 -8
- package/dist/core/byte-cursor.js +42 -0
- package/dist/core/config.d.ts +6 -1
- package/dist/core/config.js +27 -0
- package/dist/core/index.js +5 -0
- package/dist/index.cjs +591 -636
- package/dist/index.js +3 -987
- package/dist/util/assert.d.ts +6 -1
- package/dist/util/assert.js +1 -4
- package/dist/util/constants.d.ts +13 -0
- package/dist/util/constants.js +30 -0
- package/dist/util/util.js +6 -0
- package/dist/util/validator.js +40 -0
- package/package.json +16 -14
- package/CHANGELOG.md +0 -12
package/dist/index.cjs
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
1
|
var __defProp = Object.defineProperty;
|
|
3
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
5
|
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
8
6
|
var __export = (target, all) => {
|
|
@@ -17,9 +15,6 @@ var __reExport = (target, module2, copyDefault, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return target;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (module2, isNodeMode) => {
|
|
21
|
-
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
|
22
|
-
};
|
|
23
18
|
var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
|
24
19
|
return (module2, temp) => {
|
|
25
20
|
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
|
|
@@ -32,99 +27,110 @@ __export(src_exports, {
|
|
|
32
27
|
BareError: () => BareError,
|
|
33
28
|
ByteCursor: () => ByteCursor,
|
|
34
29
|
Config: () => Config,
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
30
|
+
readBool: () => readBool,
|
|
31
|
+
readData: () => readData,
|
|
32
|
+
readF32: () => readF32,
|
|
33
|
+
readF32Array: () => readF32Array,
|
|
34
|
+
readF32FixedArray: () => readF32FixedArray,
|
|
35
|
+
readF64: () => readF64,
|
|
36
|
+
readF64Array: () => readF64Array,
|
|
37
|
+
readF64FixedArray: () => readF64FixedArray,
|
|
38
|
+
readFixedData: () => readFixedData,
|
|
39
|
+
readFixedString: () => readFixedString,
|
|
40
|
+
readI16: () => readI16,
|
|
41
|
+
readI16Array: () => readI16Array,
|
|
42
|
+
readI16FixedArray: () => readI16FixedArray,
|
|
43
|
+
readI32: () => readI32,
|
|
44
|
+
readI32Array: () => readI32Array,
|
|
45
|
+
readI32FixedArray: () => readI32FixedArray,
|
|
46
|
+
readI64: () => readI64,
|
|
47
|
+
readI64Array: () => readI64Array,
|
|
48
|
+
readI64FixedArray: () => readI64FixedArray,
|
|
49
|
+
readI64Safe: () => readI64Safe,
|
|
50
|
+
readI8: () => readI8,
|
|
51
|
+
readI8Array: () => readI8Array,
|
|
52
|
+
readI8FixedArray: () => readI8FixedArray,
|
|
53
|
+
readInt: () => readInt,
|
|
54
|
+
readIntSafe: () => readIntSafe,
|
|
55
|
+
readString: () => readString,
|
|
56
|
+
readU16: () => readU16,
|
|
57
|
+
readU16Array: () => readU16Array,
|
|
58
|
+
readU16FixedArray: () => readU16FixedArray,
|
|
59
|
+
readU32: () => readU32,
|
|
60
|
+
readU32Array: () => readU32Array,
|
|
61
|
+
readU32FixedArray: () => readU32FixedArray,
|
|
62
|
+
readU64: () => readU64,
|
|
63
|
+
readU64Array: () => readU64Array,
|
|
64
|
+
readU64FixedArray: () => readU64FixedArray,
|
|
65
|
+
readU64Safe: () => readU64Safe,
|
|
66
|
+
readU8: () => readU8,
|
|
67
|
+
readU8Array: () => readU8Array,
|
|
68
|
+
readU8ClampedArray: () => readU8ClampedArray,
|
|
69
|
+
readU8ClampedFixedArray: () => readU8ClampedFixedArray,
|
|
70
|
+
readU8FixedArray: () => readU8FixedArray,
|
|
71
|
+
readUint: () => readUint,
|
|
72
|
+
readUintSafe: () => readUintSafe,
|
|
73
|
+
writeBool: () => writeBool,
|
|
74
|
+
writeData: () => writeData,
|
|
75
|
+
writeF32: () => writeF32,
|
|
76
|
+
writeF32Array: () => writeF32Array,
|
|
77
|
+
writeF32FixedArray: () => writeF32FixedArray,
|
|
78
|
+
writeF64: () => writeF64,
|
|
79
|
+
writeF64Array: () => writeF64Array,
|
|
80
|
+
writeF64FixedArray: () => writeF64FixedArray,
|
|
81
|
+
writeFixedData: () => writeFixedData,
|
|
82
|
+
writeFixedString: () => writeFixedString,
|
|
83
|
+
writeI16: () => writeI16,
|
|
84
|
+
writeI16Array: () => writeI16Array,
|
|
85
|
+
writeI16FixedArray: () => writeI16FixedArray,
|
|
86
|
+
writeI32: () => writeI32,
|
|
87
|
+
writeI32Array: () => writeI32Array,
|
|
88
|
+
writeI32FixedArray: () => writeI32FixedArray,
|
|
89
|
+
writeI64: () => writeI64,
|
|
90
|
+
writeI64Array: () => writeI64Array,
|
|
91
|
+
writeI64FixedArray: () => writeI64FixedArray,
|
|
92
|
+
writeI64Safe: () => writeI64Safe,
|
|
93
|
+
writeI8: () => writeI8,
|
|
94
|
+
writeI8Array: () => writeI8Array,
|
|
95
|
+
writeI8FixedArray: () => writeI8FixedArray,
|
|
96
|
+
writeInt: () => writeInt,
|
|
97
|
+
writeIntSafe: () => writeIntSafe,
|
|
98
|
+
writeString: () => writeString,
|
|
99
|
+
writeU16: () => writeU16,
|
|
100
|
+
writeU16Array: () => writeU16Array,
|
|
101
|
+
writeU16FixedArray: () => writeU16FixedArray,
|
|
102
|
+
writeU32: () => writeU32,
|
|
103
|
+
writeU32Array: () => writeU32Array,
|
|
104
|
+
writeU32FixedArray: () => writeU32FixedArray,
|
|
105
|
+
writeU64: () => writeU64,
|
|
106
|
+
writeU64Array: () => writeU64Array,
|
|
107
|
+
writeU64FixedArray: () => writeU64FixedArray,
|
|
108
|
+
writeU64Safe: () => writeU64Safe,
|
|
109
|
+
writeU8: () => writeU8,
|
|
110
|
+
writeU8Array: () => writeU8Array,
|
|
111
|
+
writeU8ClampedArray: () => writeU8ClampedArray,
|
|
112
|
+
writeU8ClampedFixedArray: () => writeU8ClampedFixedArray,
|
|
113
|
+
writeU8FixedArray: () => writeU8FixedArray,
|
|
114
|
+
writeUint: () => writeUint,
|
|
115
|
+
writeUintSafe: () => writeUintSafe
|
|
121
116
|
});
|
|
122
117
|
|
|
123
|
-
// src/
|
|
124
|
-
var
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
118
|
+
// src/util/assert.ts
|
|
119
|
+
var AssertionError = class extends Error {
|
|
120
|
+
constructor(message) {
|
|
121
|
+
super(message);
|
|
122
|
+
this.name = "AssertionError";
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
function assert(test, message) {
|
|
126
|
+
if (!test) {
|
|
127
|
+
const e = new AssertionError(message);
|
|
128
|
+
if (Error.captureStackTrace) {
|
|
129
|
+
Error.captureStackTrace(e, assert);
|
|
130
|
+
}
|
|
131
|
+
throw e;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
128
134
|
|
|
129
135
|
// src/core/bare-error.ts
|
|
130
136
|
var BareError = class extends Error {
|
|
@@ -137,8 +143,20 @@ var BareError = class extends Error {
|
|
|
137
143
|
}
|
|
138
144
|
};
|
|
139
145
|
|
|
140
|
-
// src/
|
|
141
|
-
var
|
|
146
|
+
// src/util/constants.ts
|
|
147
|
+
var I16_BYTE_COUNT = 2;
|
|
148
|
+
var I32_BYTE_COUNT = 4;
|
|
149
|
+
var I64_BYTE_COUNT = 8;
|
|
150
|
+
var U16_BYTE_COUNT = 2;
|
|
151
|
+
var U32_BYTE_COUNT = 4;
|
|
152
|
+
var U64_BYTE_COUNT = 8;
|
|
153
|
+
var INT_SAFE_MAX_BYTE_COUNT = 8;
|
|
154
|
+
var UINT_MAX_BYTE_COUNT = 10;
|
|
155
|
+
var UINT_SAFE_MAX_BYTE_COUNT = 8;
|
|
156
|
+
var INVALID_UTF8_STRING = "invalid UTF-8 string";
|
|
157
|
+
var NON_CANONICAL_REPRESENTATION = "must be canonical";
|
|
158
|
+
var TOO_LARGE_BUFFER = "too large buffer";
|
|
159
|
+
var TOO_LARGE_NUMBER = "too large number";
|
|
142
160
|
|
|
143
161
|
// src/util/validator.ts
|
|
144
162
|
function isI8(val) {
|
|
@@ -170,176 +188,155 @@ function isU64(val) {
|
|
|
170
188
|
}
|
|
171
189
|
|
|
172
190
|
// src/core/config.ts
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
const config =
|
|
191
|
+
function Config({
|
|
192
|
+
initialBufferLength = 1024,
|
|
193
|
+
maxBufferLength = 1024 * 1024 * 32,
|
|
194
|
+
textDecoderThreshold = 256,
|
|
195
|
+
textEncoderThreshold = 256
|
|
196
|
+
}) {
|
|
197
|
+
const config = {
|
|
180
198
|
initialBufferLength,
|
|
181
199
|
maxBufferLength,
|
|
182
200
|
textDecoderThreshold,
|
|
183
201
|
textEncoderThreshold
|
|
184
|
-
}
|
|
185
|
-
(
|
|
186
|
-
(
|
|
187
|
-
(
|
|
188
|
-
(
|
|
189
|
-
(
|
|
202
|
+
};
|
|
203
|
+
assert(isU32(config.initialBufferLength), TOO_LARGE_NUMBER);
|
|
204
|
+
assert(isU32(config.maxBufferLength), TOO_LARGE_NUMBER);
|
|
205
|
+
assert(isU32(config.textDecoderThreshold), TOO_LARGE_NUMBER);
|
|
206
|
+
assert(isU32(config.textEncoderThreshold), TOO_LARGE_NUMBER);
|
|
207
|
+
assert(config.initialBufferLength <= config.maxBufferLength, "initialBufferLength must be lower than or equal to maxBufferLength");
|
|
190
208
|
return config;
|
|
191
209
|
}
|
|
192
210
|
|
|
193
211
|
// src/core/byte-cursor.ts
|
|
194
|
-
var import_assert2 = __toESM(require("assert"), 1);
|
|
195
|
-
var TOO_LARGE_BUFFER = "too large buffer";
|
|
196
212
|
var ByteCursor = class {
|
|
197
213
|
constructor(bytes, config) {
|
|
198
|
-
|
|
199
|
-
this.offset = 0;
|
|
200
|
-
this.view = bytes instanceof Uint8Array ? new DataView(bytes.buffer, bytes.byteOffset, bytes.length) : new DataView(bytes);
|
|
201
|
-
if (this.view.byteLength > config.maxBufferLength) {
|
|
214
|
+
if (bytes.length > config.maxBufferLength) {
|
|
202
215
|
throw new BareError(0, TOO_LARGE_BUFFER);
|
|
203
216
|
}
|
|
217
|
+
this.bytes = bytes;
|
|
218
|
+
this.config = config;
|
|
219
|
+
this.offset = 0;
|
|
220
|
+
this.view = new DataView(bytes.buffer, bytes.byteOffset, bytes.length);
|
|
204
221
|
}
|
|
205
222
|
check(min) {
|
|
206
|
-
if (this.offset + min > this.
|
|
223
|
+
if (this.offset + min > this.bytes.length) {
|
|
207
224
|
throw new BareError(this.offset, "missing bytes");
|
|
208
225
|
}
|
|
209
226
|
}
|
|
210
227
|
reserve(min) {
|
|
211
|
-
const
|
|
212
|
-
if (
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
const newLen = Math.min(bytes.length + Math.max(minExtraLength, bytes.length), config.maxBufferLength);
|
|
228
|
+
const minLen = this.offset + min | 0;
|
|
229
|
+
if (minLen > this.bytes.length) {
|
|
230
|
+
if (minLen > this.config.maxBufferLength) {
|
|
231
|
+
throw new BareError(0, TOO_LARGE_BUFFER);
|
|
232
|
+
}
|
|
233
|
+
const newLen = Math.min(minLen << 1, this.config.maxBufferLength);
|
|
218
234
|
const newBytes = new Uint8Array(newLen);
|
|
219
|
-
newBytes.set(bytes);
|
|
220
|
-
this.
|
|
235
|
+
newBytes.set(this.bytes);
|
|
236
|
+
this.bytes = newBytes;
|
|
237
|
+
this.view = new DataView(newBytes.buffer);
|
|
221
238
|
}
|
|
222
239
|
}
|
|
223
240
|
read(len) {
|
|
224
241
|
this.check(len);
|
|
225
|
-
const
|
|
242
|
+
const offset = this.offset;
|
|
226
243
|
this.offset += len;
|
|
227
|
-
return
|
|
228
|
-
}
|
|
229
|
-
write(bytes) {
|
|
230
|
-
const len = bytes.length;
|
|
231
|
-
if (len !== 0) {
|
|
232
|
-
this.reserve(len);
|
|
233
|
-
const writableArea = new Uint8Array(this.view.buffer, this.offset, len);
|
|
234
|
-
writableArea.set(bytes);
|
|
235
|
-
this.offset += len;
|
|
236
|
-
}
|
|
244
|
+
return this.bytes.subarray(offset, offset + len);
|
|
237
245
|
}
|
|
238
246
|
};
|
|
239
247
|
|
|
240
248
|
// src/codec/primitive.ts
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
var TOO_LARGE_NUMBER2 = "too large number";
|
|
244
|
-
function decodeBool(bc) {
|
|
245
|
-
const val = decodeU8(bc);
|
|
249
|
+
function readBool(bc) {
|
|
250
|
+
const val = readU8(bc);
|
|
246
251
|
if (val > 1) {
|
|
247
252
|
bc.offset--;
|
|
248
253
|
throw new BareError(bc.offset, "a bool must be equal to 0 or 1");
|
|
249
254
|
}
|
|
250
255
|
return val !== 0;
|
|
251
256
|
}
|
|
252
|
-
function
|
|
253
|
-
|
|
257
|
+
function writeBool(bc, x) {
|
|
258
|
+
writeU8(bc, x ? 1 : 0);
|
|
254
259
|
}
|
|
255
|
-
function
|
|
260
|
+
function readF32(bc) {
|
|
256
261
|
bc.check(4);
|
|
257
262
|
const result = bc.view.getFloat32(bc.offset, true);
|
|
258
|
-
if (Number.isNaN(result)) {
|
|
259
|
-
throw new BareError(bc.offset, NAN_NOT_ALLOWED);
|
|
260
|
-
}
|
|
261
263
|
bc.offset += 4;
|
|
262
264
|
return result;
|
|
263
265
|
}
|
|
264
|
-
function
|
|
265
|
-
(0, import_assert3.default)(!Number.isNaN(x), NAN_NOT_ALLOWED);
|
|
266
|
+
function writeF32(bc, x) {
|
|
266
267
|
bc.reserve(4);
|
|
267
268
|
bc.view.setFloat32(bc.offset, x, true);
|
|
268
|
-
(
|
|
269
|
+
assert(Number.isNaN(x) || Math.abs(bc.view.getFloat32(bc.offset, true) - x) <= Number.EPSILON, TOO_LARGE_NUMBER);
|
|
269
270
|
bc.offset += 4;
|
|
270
271
|
}
|
|
271
|
-
function
|
|
272
|
+
function readF64(bc) {
|
|
272
273
|
bc.check(8);
|
|
273
274
|
const result = bc.view.getFloat64(bc.offset, true);
|
|
274
|
-
if (Number.isNaN(result)) {
|
|
275
|
-
throw new BareError(bc.offset, NAN_NOT_ALLOWED);
|
|
276
|
-
}
|
|
277
275
|
bc.offset += 8;
|
|
278
276
|
return result;
|
|
279
277
|
}
|
|
280
|
-
function
|
|
281
|
-
(0, import_assert3.default)(!Number.isNaN(x), NAN_NOT_ALLOWED);
|
|
278
|
+
function writeF64(bc, x) {
|
|
282
279
|
bc.reserve(8);
|
|
283
280
|
bc.view.setFloat64(bc.offset, x, true);
|
|
284
281
|
bc.offset += 8;
|
|
285
282
|
}
|
|
286
|
-
function
|
|
283
|
+
function readI8(bc) {
|
|
287
284
|
bc.check(1);
|
|
288
285
|
return bc.view.getInt8(bc.offset++);
|
|
289
286
|
}
|
|
290
|
-
function
|
|
291
|
-
(
|
|
287
|
+
function writeI8(bc, x) {
|
|
288
|
+
assert(isI8(x), TOO_LARGE_NUMBER);
|
|
292
289
|
bc.reserve(1);
|
|
293
290
|
bc.view.setInt8(bc.offset++, x);
|
|
294
291
|
}
|
|
295
|
-
function
|
|
292
|
+
function readI16(bc) {
|
|
296
293
|
bc.check(2);
|
|
297
294
|
const result = bc.view.getInt16(bc.offset, true);
|
|
298
295
|
bc.offset += 2;
|
|
299
296
|
return result;
|
|
300
297
|
}
|
|
301
|
-
function
|
|
302
|
-
(
|
|
298
|
+
function writeI16(bc, x) {
|
|
299
|
+
assert(isI16(x), TOO_LARGE_NUMBER);
|
|
303
300
|
bc.reserve(2);
|
|
304
301
|
bc.view.setInt16(bc.offset, x, true);
|
|
305
302
|
bc.offset += 2;
|
|
306
303
|
}
|
|
307
|
-
function
|
|
304
|
+
function readI32(bc) {
|
|
308
305
|
bc.check(4);
|
|
309
306
|
const result = bc.view.getInt32(bc.offset, true);
|
|
310
307
|
bc.offset += 4;
|
|
311
308
|
return result;
|
|
312
309
|
}
|
|
313
|
-
function
|
|
314
|
-
(
|
|
310
|
+
function writeI32(bc, x) {
|
|
311
|
+
assert(isI32(x), TOO_LARGE_NUMBER);
|
|
315
312
|
bc.reserve(4);
|
|
316
313
|
bc.view.setInt32(bc.offset, x, true);
|
|
317
314
|
bc.offset += 4;
|
|
318
315
|
}
|
|
319
|
-
function
|
|
316
|
+
function readI64(bc) {
|
|
320
317
|
bc.check(8);
|
|
321
318
|
const result = bc.view.getBigInt64(bc.offset, true);
|
|
322
319
|
bc.offset += 8;
|
|
323
320
|
return result;
|
|
324
321
|
}
|
|
325
|
-
function
|
|
326
|
-
(
|
|
322
|
+
function writeI64(bc, x) {
|
|
323
|
+
assert(isI64(x), TOO_LARGE_NUMBER);
|
|
327
324
|
bc.reserve(8);
|
|
328
325
|
bc.view.setBigInt64(bc.offset, x, true);
|
|
329
326
|
bc.offset += 8;
|
|
330
327
|
}
|
|
331
|
-
function
|
|
332
|
-
const result =
|
|
328
|
+
function readI64Safe(bc) {
|
|
329
|
+
const result = readU32(bc) + readI32(bc) * 4294967296;
|
|
333
330
|
if (!Number.isSafeInteger(result)) {
|
|
334
331
|
bc.offset -= 8;
|
|
335
|
-
throw new BareError(bc.offset,
|
|
332
|
+
throw new BareError(bc.offset, TOO_LARGE_NUMBER);
|
|
336
333
|
}
|
|
337
334
|
return result;
|
|
338
335
|
}
|
|
339
|
-
function
|
|
340
|
-
(
|
|
336
|
+
function writeI64Safe(bc, x) {
|
|
337
|
+
assert(Number.isSafeInteger(x), TOO_LARGE_NUMBER);
|
|
341
338
|
const lowest32 = x >>> 0;
|
|
342
|
-
|
|
339
|
+
writeU32(bc, lowest32);
|
|
343
340
|
let highest32 = x / 4294967296 | 0;
|
|
344
341
|
if (x < 0) {
|
|
345
342
|
highest32 = ~Math.abs(highest32) >>> 0;
|
|
@@ -347,27 +344,26 @@ function encodeI64Safe(bc, x) {
|
|
|
347
344
|
highest32++;
|
|
348
345
|
}
|
|
349
346
|
}
|
|
350
|
-
|
|
347
|
+
writeU32(bc, highest32);
|
|
351
348
|
}
|
|
352
|
-
function
|
|
353
|
-
const zigZag =
|
|
349
|
+
function readInt(bc) {
|
|
350
|
+
const zigZag = readUint(bc);
|
|
354
351
|
return zigZag >> BigInt(1) ^ -(zigZag & BigInt(1));
|
|
355
352
|
}
|
|
356
|
-
function
|
|
357
|
-
(
|
|
353
|
+
function writeInt(bc, x) {
|
|
354
|
+
assert(isI64(x), TOO_LARGE_NUMBER);
|
|
358
355
|
const zigZag = x >> BigInt(63) ^ x << BigInt(1);
|
|
359
|
-
|
|
356
|
+
writeUint(bc, zigZag);
|
|
360
357
|
}
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
const firstByte = decodeU8(bc);
|
|
358
|
+
function readIntSafe(bc) {
|
|
359
|
+
const firstByte = readU8(bc);
|
|
364
360
|
let result = (firstByte & 127) >> 1;
|
|
365
361
|
if (firstByte >= 128) {
|
|
366
362
|
let shiftMul = 64;
|
|
367
363
|
let byteCount = 1;
|
|
368
364
|
let byte;
|
|
369
365
|
do {
|
|
370
|
-
byte =
|
|
366
|
+
byte = readU8(bc);
|
|
371
367
|
result += (byte & 127) * shiftMul;
|
|
372
368
|
shiftMul *= 128;
|
|
373
369
|
byteCount++;
|
|
@@ -378,7 +374,7 @@ function decodeIntSafe(bc) {
|
|
|
378
374
|
}
|
|
379
375
|
if (byteCount === INT_SAFE_MAX_BYTE_COUNT && (byte > 31 || firstByte === 255)) {
|
|
380
376
|
bc.offset -= byteCount - 1;
|
|
381
|
-
throw new BareError(bc.offset,
|
|
377
|
+
throw new BareError(bc.offset, TOO_LARGE_NUMBER);
|
|
382
378
|
}
|
|
383
379
|
}
|
|
384
380
|
const isNeg = (firstByte & 1) === 1;
|
|
@@ -387,8 +383,8 @@ function decodeIntSafe(bc) {
|
|
|
387
383
|
}
|
|
388
384
|
return result;
|
|
389
385
|
}
|
|
390
|
-
function
|
|
391
|
-
(
|
|
386
|
+
function writeIntSafe(bc, x) {
|
|
387
|
+
assert(Number.isSafeInteger(x), TOO_LARGE_NUMBER);
|
|
392
388
|
const sign = x < 0 ? 1 : 0;
|
|
393
389
|
if (x < 0) {
|
|
394
390
|
x = -(x + 1);
|
|
@@ -396,103 +392,106 @@ function encodeIntSafe(bc, x) {
|
|
|
396
392
|
const firstByte = (x & 63) << 1 | sign;
|
|
397
393
|
x = Math.floor(x / 64);
|
|
398
394
|
if (x > 0) {
|
|
399
|
-
|
|
400
|
-
|
|
395
|
+
writeU8(bc, 128 | firstByte);
|
|
396
|
+
writeUintSafe(bc, x);
|
|
401
397
|
} else {
|
|
402
|
-
|
|
398
|
+
writeU8(bc, firstByte);
|
|
403
399
|
}
|
|
404
400
|
}
|
|
405
|
-
function
|
|
401
|
+
function readU8(bc) {
|
|
406
402
|
bc.check(1);
|
|
407
|
-
return bc.
|
|
403
|
+
return bc.bytes[bc.offset++];
|
|
408
404
|
}
|
|
409
|
-
function
|
|
410
|
-
(
|
|
405
|
+
function writeU8(bc, x) {
|
|
406
|
+
assert(isU8(x), TOO_LARGE_NUMBER);
|
|
411
407
|
bc.reserve(1);
|
|
412
|
-
bc.
|
|
408
|
+
bc.bytes[bc.offset++] = x;
|
|
413
409
|
}
|
|
414
|
-
function
|
|
410
|
+
function readU16(bc) {
|
|
415
411
|
bc.check(2);
|
|
416
412
|
const result = bc.view.getUint16(bc.offset, true);
|
|
417
413
|
bc.offset += 2;
|
|
418
414
|
return result;
|
|
419
415
|
}
|
|
420
|
-
function
|
|
421
|
-
(
|
|
416
|
+
function writeU16(bc, x) {
|
|
417
|
+
assert(isU16(x), TOO_LARGE_NUMBER);
|
|
422
418
|
bc.reserve(2);
|
|
423
419
|
bc.view.setUint16(bc.offset, x, true);
|
|
424
420
|
bc.offset += 2;
|
|
425
421
|
}
|
|
426
|
-
function
|
|
422
|
+
function readU32(bc) {
|
|
427
423
|
bc.check(4);
|
|
428
424
|
const result = bc.view.getUint32(bc.offset, true);
|
|
429
425
|
bc.offset += 4;
|
|
430
426
|
return result;
|
|
431
427
|
}
|
|
432
|
-
function
|
|
433
|
-
(
|
|
428
|
+
function writeU32(bc, x) {
|
|
429
|
+
assert(isU32(x), TOO_LARGE_NUMBER);
|
|
434
430
|
bc.reserve(4);
|
|
435
431
|
bc.view.setUint32(bc.offset, x, true);
|
|
436
432
|
bc.offset += 4;
|
|
437
433
|
}
|
|
438
|
-
function
|
|
434
|
+
function readU64(bc) {
|
|
439
435
|
bc.check(8);
|
|
440
436
|
const result = bc.view.getBigUint64(bc.offset, true);
|
|
441
437
|
bc.offset += 8;
|
|
442
438
|
return result;
|
|
443
439
|
}
|
|
444
|
-
function
|
|
445
|
-
(
|
|
440
|
+
function writeU64(bc, x) {
|
|
441
|
+
assert(isU64(x), TOO_LARGE_NUMBER);
|
|
446
442
|
bc.reserve(8);
|
|
447
443
|
bc.view.setBigUint64(bc.offset, x, true);
|
|
448
444
|
bc.offset += 8;
|
|
449
445
|
}
|
|
450
|
-
function
|
|
451
|
-
const result =
|
|
446
|
+
function readU64Safe(bc) {
|
|
447
|
+
const result = readU32(bc) + readU32(bc) * 4294967296;
|
|
452
448
|
if (!isSafeU64(result)) {
|
|
453
449
|
bc.offset -= 8;
|
|
454
|
-
throw new BareError(bc.offset,
|
|
450
|
+
throw new BareError(bc.offset, TOO_LARGE_NUMBER);
|
|
455
451
|
}
|
|
456
452
|
return result;
|
|
457
453
|
}
|
|
458
|
-
function
|
|
459
|
-
(
|
|
460
|
-
|
|
461
|
-
|
|
454
|
+
function writeU64Safe(bc, x) {
|
|
455
|
+
assert(isSafeU64(x), TOO_LARGE_NUMBER);
|
|
456
|
+
writeU32(bc, x >>> 0);
|
|
457
|
+
writeU32(bc, x / 4294967296 >>> 0);
|
|
462
458
|
}
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
byte
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
459
|
+
function readUint(bc) {
|
|
460
|
+
let low = readU8(bc);
|
|
461
|
+
if (low >= 128) {
|
|
462
|
+
low &= 127;
|
|
463
|
+
let shiftMul = 128;
|
|
464
|
+
let byteCount = 1;
|
|
465
|
+
let byte;
|
|
466
|
+
do {
|
|
467
|
+
byte = readU8(bc);
|
|
468
|
+
low += (byte & 127) * shiftMul;
|
|
469
|
+
shiftMul *= 128;
|
|
470
|
+
byteCount++;
|
|
471
|
+
} while (byte >= 128 && byteCount < 7);
|
|
472
|
+
let height = 0;
|
|
473
|
+
shiftMul = 1;
|
|
474
|
+
while (byte >= 128 && byteCount < UINT_MAX_BYTE_COUNT) {
|
|
475
|
+
byte = readU8(bc);
|
|
476
|
+
height += (byte & 127) * shiftMul;
|
|
477
|
+
shiftMul *= 128;
|
|
478
|
+
byteCount++;
|
|
479
|
+
}
|
|
480
|
+
if (byte === 0 || byteCount === UINT_MAX_BYTE_COUNT && byte > 1) {
|
|
481
|
+
bc.offset -= byteCount;
|
|
482
|
+
throw new BareError(bc.offset, NON_CANONICAL_REPRESENTATION);
|
|
483
|
+
}
|
|
484
|
+
return BigInt(low) + (BigInt(height) << BigInt(7 * 7));
|
|
486
485
|
}
|
|
487
|
-
return BigInt(low)
|
|
486
|
+
return BigInt(low);
|
|
488
487
|
}
|
|
489
|
-
function
|
|
490
|
-
(
|
|
488
|
+
function writeUint(bc, x) {
|
|
489
|
+
assert(isU64(x), TOO_LARGE_NUMBER);
|
|
491
490
|
let tmp = Number(BigInt.asUintN(7 * 7, x));
|
|
492
491
|
let rest = Number(x >> BigInt(7 * 7));
|
|
493
492
|
let byteCount = 0;
|
|
494
493
|
while (tmp >= 128 || rest !== 0) {
|
|
495
|
-
|
|
494
|
+
writeU8(bc, 128 | tmp & 127);
|
|
496
495
|
tmp = Math.floor(tmp / 128);
|
|
497
496
|
byteCount++;
|
|
498
497
|
if (byteCount === 7) {
|
|
@@ -500,521 +499,478 @@ function encodeUint(bc, x) {
|
|
|
500
499
|
rest = 0;
|
|
501
500
|
}
|
|
502
501
|
}
|
|
503
|
-
|
|
502
|
+
writeU8(bc, tmp);
|
|
504
503
|
}
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
504
|
+
function readUintSafe(bc) {
|
|
505
|
+
let result = readU8(bc);
|
|
506
|
+
if (result >= 128) {
|
|
507
|
+
result &= 127;
|
|
508
|
+
let shiftMul = 128;
|
|
509
|
+
let byteCount = 1;
|
|
510
|
+
let byte;
|
|
511
|
+
do {
|
|
512
|
+
byte = readU8(bc);
|
|
513
|
+
result += (byte & 127) * shiftMul;
|
|
514
|
+
shiftMul *= 128;
|
|
515
|
+
byteCount++;
|
|
516
|
+
} while (byte >= 128 && byteCount < UINT_SAFE_MAX_BYTE_COUNT);
|
|
517
|
+
if (byte === 0) {
|
|
518
|
+
bc.offset -= byteCount - 1;
|
|
519
|
+
throw new BareError(bc.offset - byteCount + 1, NON_CANONICAL_REPRESENTATION);
|
|
520
|
+
}
|
|
521
|
+
if (byteCount === UINT_SAFE_MAX_BYTE_COUNT && byte > 15) {
|
|
522
|
+
bc.offset -= byteCount - 1;
|
|
523
|
+
throw new BareError(bc.offset, TOO_LARGE_NUMBER);
|
|
524
|
+
}
|
|
524
525
|
}
|
|
525
526
|
return result;
|
|
526
527
|
}
|
|
527
|
-
function
|
|
528
|
-
(
|
|
528
|
+
function writeUintSafe(bc, x) {
|
|
529
|
+
assert(isSafeU64(x), TOO_LARGE_NUMBER);
|
|
529
530
|
while (x >= 128) {
|
|
530
|
-
|
|
531
|
+
writeU8(bc, 128 | x & 127);
|
|
531
532
|
x = Math.floor(x / 128);
|
|
532
533
|
}
|
|
533
|
-
|
|
534
|
-
}
|
|
535
|
-
function decodeVoid(_dc) {
|
|
536
|
-
return void 0;
|
|
537
|
-
}
|
|
538
|
-
function encodeVoid(_dc, _x) {
|
|
534
|
+
writeU8(bc, x);
|
|
539
535
|
}
|
|
540
536
|
|
|
541
537
|
// src/codec/u8-array.ts
|
|
542
|
-
function
|
|
543
|
-
|
|
544
|
-
return bc.read(len).slice();
|
|
538
|
+
function readU8Array(bc) {
|
|
539
|
+
return readU8FixedArray(bc, readUintSafe(bc));
|
|
545
540
|
}
|
|
546
|
-
function
|
|
547
|
-
|
|
548
|
-
bc
|
|
541
|
+
function writeU8Array(bc, x) {
|
|
542
|
+
writeUintSafe(bc, x.length);
|
|
543
|
+
writeU8FixedArray(bc, x);
|
|
549
544
|
}
|
|
550
|
-
function
|
|
545
|
+
function readU8FixedArray(bc, len) {
|
|
551
546
|
return bc.read(len).slice();
|
|
552
547
|
}
|
|
553
|
-
function
|
|
554
|
-
|
|
555
|
-
|
|
548
|
+
function writeU8FixedArray(bc, x) {
|
|
549
|
+
const len = x.length;
|
|
550
|
+
if (len !== 0) {
|
|
551
|
+
bc.reserve(len);
|
|
552
|
+
bc.bytes.set(x, bc.offset);
|
|
553
|
+
bc.offset += len;
|
|
554
|
+
}
|
|
556
555
|
}
|
|
557
556
|
|
|
558
557
|
// src/codec/data.ts
|
|
559
|
-
function
|
|
560
|
-
return
|
|
558
|
+
function readData(bc) {
|
|
559
|
+
return readU8Array(bc).buffer;
|
|
561
560
|
}
|
|
562
|
-
function
|
|
563
|
-
|
|
561
|
+
function writeData(bc, x) {
|
|
562
|
+
writeU8Array(bc, new Uint8Array(x));
|
|
564
563
|
}
|
|
565
|
-
function
|
|
566
|
-
return
|
|
564
|
+
function readFixedData(bc, len) {
|
|
565
|
+
return readU8FixedArray(bc, len).buffer;
|
|
567
566
|
}
|
|
568
|
-
function
|
|
569
|
-
|
|
567
|
+
function writeFixedData(bc, x) {
|
|
568
|
+
writeU8FixedArray(bc, new Uint8Array(x));
|
|
570
569
|
}
|
|
571
570
|
|
|
572
|
-
// src/codec/float-array.ts
|
|
573
|
-
var import_assert5 = __toESM(require("assert"), 1);
|
|
574
|
-
|
|
575
571
|
// src/util/util.ts
|
|
576
|
-
var IS_LITTLE_ENDIAN_PLATFORM = new DataView(Uint16Array.of(1).buffer).getUint8(0) === 1;
|
|
572
|
+
var IS_LITTLE_ENDIAN_PLATFORM = /* @__PURE__ */ new DataView(Uint16Array.of(1).buffer).getUint8(0) === 1;
|
|
577
573
|
|
|
578
574
|
// src/codec/float-array.ts
|
|
579
|
-
var
|
|
580
|
-
|
|
581
|
-
function decodeF32FixedArrayLE(bc, len) {
|
|
575
|
+
var readF32FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? readF32FixedArrayLE : readF32FixedArrayBE;
|
|
576
|
+
function readF32FixedArrayLE(bc, len) {
|
|
582
577
|
const byteLen = len * 4;
|
|
583
|
-
const result = new Float32Array(
|
|
584
|
-
if (result.some(Number.isNaN)) {
|
|
585
|
-
throw new BareError(bc.offset, NAN_NOT_ALLOWED2);
|
|
586
|
-
}
|
|
578
|
+
const result = new Float32Array(readFixedData(bc, byteLen));
|
|
587
579
|
return result;
|
|
588
580
|
}
|
|
589
|
-
function
|
|
581
|
+
function readF32FixedArrayBE(bc, len) {
|
|
590
582
|
bc.check(len * 4);
|
|
591
583
|
const result = new Float32Array(len);
|
|
592
584
|
for (let i = 0; i < len; i++)
|
|
593
|
-
result[i] =
|
|
585
|
+
result[i] = readF32(bc);
|
|
594
586
|
return result;
|
|
595
587
|
}
|
|
596
|
-
var
|
|
597
|
-
function
|
|
598
|
-
(
|
|
599
|
-
(0, import_assert5.default)(!x.every(Number.isNaN), NAN_NOT_ALLOWED2);
|
|
600
|
-
bc.write(new Uint8Array(x.buffer, x.byteOffset, x.byteLength));
|
|
588
|
+
var writeF32FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? writeF32FixedArrayLE : writeF32FixedArrayBE;
|
|
589
|
+
function writeF32FixedArrayLE(bc, x) {
|
|
590
|
+
writeU8FixedArray(bc, new Uint8Array(x.buffer, x.byteOffset, x.byteLength));
|
|
601
591
|
}
|
|
602
|
-
function
|
|
603
|
-
(0, import_assert5.default)(val.length === len);
|
|
592
|
+
function writeF32FixedArrayBE(bc, val) {
|
|
604
593
|
bc.reserve(val.length * 4);
|
|
605
594
|
for (let i = 0; i < val.length; i++)
|
|
606
|
-
|
|
595
|
+
writeF32(bc, val[i]);
|
|
607
596
|
}
|
|
608
|
-
function
|
|
609
|
-
return
|
|
597
|
+
function readF32Array(bc) {
|
|
598
|
+
return readF32FixedArray(bc, readUintSafe(bc));
|
|
610
599
|
}
|
|
611
|
-
function
|
|
612
|
-
|
|
600
|
+
function writeF32Array(bc, x) {
|
|
601
|
+
writeUintSafe(bc, x.length);
|
|
613
602
|
if (x.length !== 0) {
|
|
614
|
-
|
|
603
|
+
writeF32FixedArray(bc, x);
|
|
615
604
|
}
|
|
616
605
|
}
|
|
617
|
-
var
|
|
618
|
-
function
|
|
606
|
+
var readF64FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? readF64FixedArrayLE : readF64FixedArrayBE;
|
|
607
|
+
function readF64FixedArrayLE(bc, len) {
|
|
619
608
|
const byteLen = len * 8;
|
|
620
|
-
const result = new Float64Array(
|
|
621
|
-
if (result.some(Number.isNaN)) {
|
|
622
|
-
throw new BareError(bc.offset, NAN_NOT_ALLOWED2);
|
|
623
|
-
}
|
|
609
|
+
const result = new Float64Array(readFixedData(bc, byteLen));
|
|
624
610
|
return result;
|
|
625
611
|
}
|
|
626
|
-
function
|
|
612
|
+
function readF64FixedArrayBE(bc, len) {
|
|
627
613
|
bc.check(len * 8);
|
|
628
614
|
const result = new Float64Array(len);
|
|
629
615
|
for (let i = 0; i < len; i++)
|
|
630
|
-
result[i] =
|
|
616
|
+
result[i] = readF64(bc);
|
|
631
617
|
return result;
|
|
632
618
|
}
|
|
633
|
-
var
|
|
634
|
-
function
|
|
635
|
-
(
|
|
636
|
-
(0, import_assert5.default)(!x.every(Number.isNaN), NAN_NOT_ALLOWED2);
|
|
637
|
-
bc.write(new Uint8Array(x.buffer, x.byteOffset, x.byteLength));
|
|
619
|
+
var writeF64FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? writeF64FixedArrayLE : writeF64FixedArrayBE;
|
|
620
|
+
function writeF64FixedArrayLE(bc, x) {
|
|
621
|
+
writeU8FixedArray(bc, new Uint8Array(x.buffer, x.byteOffset, x.byteLength));
|
|
638
622
|
}
|
|
639
|
-
function
|
|
640
|
-
(0, import_assert5.default)(x.length === len);
|
|
623
|
+
function writeF64FixedArrayBE(bc, x) {
|
|
641
624
|
bc.reserve(x.length * 8);
|
|
642
625
|
for (let i = 0; i < x.length; i++)
|
|
643
|
-
|
|
626
|
+
writeF64(bc, x[i]);
|
|
644
627
|
}
|
|
645
|
-
function
|
|
646
|
-
return
|
|
628
|
+
function readF64Array(bc) {
|
|
629
|
+
return readF64FixedArray(bc, readUintSafe(bc));
|
|
647
630
|
}
|
|
648
|
-
function
|
|
649
|
-
|
|
631
|
+
function writeF64Array(bc, x) {
|
|
632
|
+
writeUintSafe(bc, x.length);
|
|
650
633
|
if (x.length !== 0) {
|
|
651
|
-
|
|
634
|
+
writeF64FixedArray(bc, x);
|
|
652
635
|
}
|
|
653
636
|
}
|
|
654
637
|
|
|
655
638
|
// src/codec/i16-array.ts
|
|
656
|
-
var
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
function decodeI16Array(bc) {
|
|
660
|
-
return decodeI16FixedArray(bc, decodeUintSafe(bc));
|
|
639
|
+
var readI16FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? readI16FixedArrayLE : readI16FixedArrayBE;
|
|
640
|
+
function readI16Array(bc) {
|
|
641
|
+
return readI16FixedArray(bc, readUintSafe(bc));
|
|
661
642
|
}
|
|
662
|
-
function
|
|
643
|
+
function readI16FixedArrayLE(bc, len) {
|
|
663
644
|
const byteCount = len * I16_BYTE_COUNT;
|
|
664
|
-
return new Int16Array(
|
|
645
|
+
return new Int16Array(readFixedData(bc, byteCount));
|
|
665
646
|
}
|
|
666
|
-
function
|
|
647
|
+
function readI16FixedArrayBE(bc, len) {
|
|
667
648
|
bc.check(len * I16_BYTE_COUNT);
|
|
668
649
|
const result = new Int16Array(len);
|
|
669
650
|
for (let i = 0; i < len; i++)
|
|
670
|
-
result[i] =
|
|
651
|
+
result[i] = readI16(bc);
|
|
671
652
|
return result;
|
|
672
653
|
}
|
|
673
|
-
var
|
|
674
|
-
function
|
|
675
|
-
|
|
654
|
+
var writeI16FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? writeI16FixedArrayLE : writeI16FixedArrayBE;
|
|
655
|
+
function writeI16Array(bc, x) {
|
|
656
|
+
writeUintSafe(bc, x.length);
|
|
676
657
|
if (x.length !== 0) {
|
|
677
|
-
|
|
658
|
+
writeI16FixedArray(bc, x);
|
|
678
659
|
}
|
|
679
660
|
}
|
|
680
|
-
function
|
|
681
|
-
(
|
|
682
|
-
bc.write(new Uint8Array(x.buffer, x.byteOffset, x.byteLength));
|
|
661
|
+
function writeI16FixedArrayLE(bc, x) {
|
|
662
|
+
writeU8FixedArray(bc, new Uint8Array(x.buffer, x.byteOffset, x.byteLength));
|
|
683
663
|
}
|
|
684
|
-
function
|
|
685
|
-
(0, import_assert6.default)(x.length === len);
|
|
664
|
+
function writeI16FixedArrayBE(bc, x) {
|
|
686
665
|
bc.reserve(x.length * I16_BYTE_COUNT);
|
|
687
666
|
for (let i = 0; i < x.length; i++)
|
|
688
|
-
|
|
667
|
+
writeI16(bc, x[i]);
|
|
689
668
|
}
|
|
690
669
|
|
|
691
670
|
// src/codec/i32-array.ts
|
|
692
|
-
var
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
function decodeI32Array(bc) {
|
|
696
|
-
return decodeI32FixedArray(bc, decodeUintSafe(bc));
|
|
671
|
+
var readI32FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? readI32FixedArrayLE : readI32FixedArrayBE;
|
|
672
|
+
function readI32Array(bc) {
|
|
673
|
+
return readI32FixedArray(bc, readUintSafe(bc));
|
|
697
674
|
}
|
|
698
|
-
function
|
|
675
|
+
function readI32FixedArrayLE(bc, len) {
|
|
699
676
|
const byteCount = len * I32_BYTE_COUNT;
|
|
700
|
-
return new Int32Array(
|
|
677
|
+
return new Int32Array(readFixedData(bc, byteCount));
|
|
701
678
|
}
|
|
702
|
-
function
|
|
679
|
+
function readI32FixedArrayBE(bc, len) {
|
|
703
680
|
bc.check(len * I32_BYTE_COUNT);
|
|
704
681
|
const result = new Int32Array(len);
|
|
705
682
|
for (let i = 0; i < len; i++)
|
|
706
|
-
result[i] =
|
|
683
|
+
result[i] = readI32(bc);
|
|
707
684
|
return result;
|
|
708
685
|
}
|
|
709
|
-
var
|
|
710
|
-
function
|
|
711
|
-
|
|
686
|
+
var writeI32FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? writeI32FixedArrayLE : writeI32FixedArrayBE;
|
|
687
|
+
function writeI32Array(bc, x) {
|
|
688
|
+
writeUintSafe(bc, x.length);
|
|
712
689
|
if (x.length !== 0) {
|
|
713
|
-
|
|
690
|
+
writeI32FixedArray(bc, x);
|
|
714
691
|
}
|
|
715
692
|
}
|
|
716
|
-
function
|
|
717
|
-
(
|
|
718
|
-
bc.write(new Uint8Array(x.buffer, x.byteOffset, x.byteLength));
|
|
693
|
+
function writeI32FixedArrayLE(bc, x) {
|
|
694
|
+
writeU8FixedArray(bc, new Uint8Array(x.buffer, x.byteOffset, x.byteLength));
|
|
719
695
|
}
|
|
720
|
-
function
|
|
721
|
-
(0, import_assert7.default)(x.length === len);
|
|
696
|
+
function writeI32FixedArrayBE(bc, x) {
|
|
722
697
|
bc.reserve(x.length * I32_BYTE_COUNT);
|
|
723
698
|
for (let i = 0; i < x.length; i++)
|
|
724
|
-
|
|
699
|
+
writeI32(bc, x[i]);
|
|
725
700
|
}
|
|
726
701
|
|
|
727
702
|
// src/codec/i64-array.ts
|
|
728
|
-
var
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
function decodeI64Array(bc) {
|
|
732
|
-
return decodeI64FixedArray(bc, decodeUintSafe(bc));
|
|
703
|
+
var readI64FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? readI64FixedArrayLE : readI64FixedArrayBE;
|
|
704
|
+
function readI64Array(bc) {
|
|
705
|
+
return readI64FixedArray(bc, readUintSafe(bc));
|
|
733
706
|
}
|
|
734
|
-
function
|
|
707
|
+
function readI64FixedArrayLE(bc, len) {
|
|
735
708
|
const byteCount = len * I64_BYTE_COUNT;
|
|
736
|
-
return new BigInt64Array(
|
|
709
|
+
return new BigInt64Array(readFixedData(bc, byteCount));
|
|
737
710
|
}
|
|
738
|
-
function
|
|
711
|
+
function readI64FixedArrayBE(bc, len) {
|
|
739
712
|
bc.check(len * I64_BYTE_COUNT);
|
|
740
713
|
const result = new BigInt64Array(len);
|
|
741
714
|
for (let i = 0; i < len; i++)
|
|
742
|
-
result[i] =
|
|
715
|
+
result[i] = readI64(bc);
|
|
743
716
|
return result;
|
|
744
717
|
}
|
|
745
|
-
var
|
|
746
|
-
function
|
|
747
|
-
|
|
718
|
+
var writeI64FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? writeI64FixedArrayLE : writeI64FixedArrayBE;
|
|
719
|
+
function writeI64Array(bc, x) {
|
|
720
|
+
writeUintSafe(bc, x.length);
|
|
748
721
|
if (x.length !== 0) {
|
|
749
|
-
|
|
722
|
+
writeI64FixedArray(bc, x);
|
|
750
723
|
}
|
|
751
724
|
}
|
|
752
|
-
function
|
|
753
|
-
(
|
|
754
|
-
bc.write(new Uint8Array(x.buffer, x.byteOffset, x.byteLength));
|
|
725
|
+
function writeI64FixedArrayLE(bc, x) {
|
|
726
|
+
writeU8FixedArray(bc, new Uint8Array(x.buffer, x.byteOffset, x.byteLength));
|
|
755
727
|
}
|
|
756
|
-
function
|
|
757
|
-
(0, import_assert8.default)(x.length === len);
|
|
728
|
+
function writeI64FixedArrayBE(bc, x) {
|
|
758
729
|
bc.reserve(x.length * I64_BYTE_COUNT);
|
|
759
730
|
for (let i = 0; i < x.length; i++)
|
|
760
|
-
|
|
731
|
+
writeI64(bc, x[i]);
|
|
761
732
|
}
|
|
762
733
|
|
|
763
734
|
// src/codec/i8-array.ts
|
|
764
|
-
function
|
|
765
|
-
return
|
|
735
|
+
function readI8Array(bc) {
|
|
736
|
+
return readI8FixedArray(bc, readUintSafe(bc));
|
|
766
737
|
}
|
|
767
|
-
function
|
|
768
|
-
|
|
769
|
-
|
|
738
|
+
function writeI8Array(bc, x) {
|
|
739
|
+
writeUintSafe(bc, x.length);
|
|
740
|
+
writeI8FixedArray(bc, x);
|
|
770
741
|
}
|
|
771
|
-
function
|
|
772
|
-
return new Int8Array(
|
|
742
|
+
function readI8FixedArray(bc, len) {
|
|
743
|
+
return new Int8Array(readFixedData(bc, len));
|
|
773
744
|
}
|
|
774
|
-
function
|
|
775
|
-
|
|
745
|
+
function writeI8FixedArray(bc, x) {
|
|
746
|
+
writeU8FixedArray(bc, new Uint8Array(x.buffer, x.byteOffset, x.byteLength));
|
|
776
747
|
}
|
|
777
748
|
|
|
778
749
|
// src/codec/string.ts
|
|
779
|
-
function
|
|
780
|
-
|
|
781
|
-
|
|
750
|
+
function readString(bc) {
|
|
751
|
+
return readFixedString(bc, readUintSafe(bc));
|
|
752
|
+
}
|
|
753
|
+
function writeString(bc, x) {
|
|
754
|
+
if (x.length < bc.config.textEncoderThreshold) {
|
|
755
|
+
const byteLen = utf8ByteLength(x);
|
|
756
|
+
writeUintSafe(bc, byteLen);
|
|
757
|
+
bc.reserve(byteLen);
|
|
758
|
+
writeUtf8Js(bc, x);
|
|
759
|
+
} else {
|
|
760
|
+
const strBytes = UTF8_ENCODER.encode(x);
|
|
761
|
+
writeUintSafe(bc, strBytes.length);
|
|
762
|
+
writeU8FixedArray(bc, strBytes);
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
function readFixedString(bc, byteLen) {
|
|
766
|
+
if (byteLen < bc.config.textDecoderThreshold) {
|
|
767
|
+
return readUtf8Js(bc, byteLen);
|
|
768
|
+
}
|
|
782
769
|
try {
|
|
783
|
-
return
|
|
770
|
+
return UTF8_DECODER.decode(bc.read(byteLen));
|
|
784
771
|
} catch (cause) {
|
|
785
|
-
throw new BareError(bc.offset
|
|
786
|
-
cause
|
|
787
|
-
});
|
|
772
|
+
throw new BareError(bc.offset, INVALID_UTF8_STRING);
|
|
788
773
|
}
|
|
789
774
|
}
|
|
790
|
-
function
|
|
775
|
+
function writeFixedString(bc, x) {
|
|
791
776
|
if (x.length < bc.config.textEncoderThreshold) {
|
|
792
777
|
const byteLen = utf8ByteLength(x);
|
|
793
|
-
encodeUintSafe(bc, byteLen);
|
|
794
778
|
bc.reserve(byteLen);
|
|
795
|
-
|
|
779
|
+
writeUtf8Js(bc, x);
|
|
796
780
|
} else {
|
|
797
|
-
|
|
798
|
-
encodeUintSafe(bc, strBytes.length);
|
|
799
|
-
bc.write(strBytes);
|
|
781
|
+
writeU8FixedArray(bc, UTF8_ENCODER.encode(x));
|
|
800
782
|
}
|
|
801
783
|
}
|
|
802
|
-
function
|
|
803
|
-
|
|
784
|
+
function readUtf8Js(bc, byteLen) {
|
|
785
|
+
bc.check(byteLen);
|
|
804
786
|
let result = "";
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
i += 2;
|
|
829
|
-
break;
|
|
787
|
+
const bytes = bc.bytes;
|
|
788
|
+
let offset = bc.offset;
|
|
789
|
+
const upperOffset = offset + byteLen;
|
|
790
|
+
while (offset < upperOffset) {
|
|
791
|
+
let codePoint = bytes[offset++];
|
|
792
|
+
if (codePoint > 127) {
|
|
793
|
+
let malformed = true;
|
|
794
|
+
const byte1 = codePoint;
|
|
795
|
+
if (offset < upperOffset && codePoint < 224) {
|
|
796
|
+
const byte2 = bytes[offset++];
|
|
797
|
+
codePoint = (byte1 & 31) << 6 | byte2 & 63;
|
|
798
|
+
malformed = codePoint >> 7 === 0 || byte1 >> 5 !== 6 || byte2 >> 6 !== 2;
|
|
799
|
+
} else if (offset + 1 < upperOffset && codePoint < 240) {
|
|
800
|
+
const byte2 = bytes[offset++];
|
|
801
|
+
const byte3 = bytes[offset++];
|
|
802
|
+
codePoint = (byte1 & 15) << 12 | (byte2 & 63) << 6 | byte3 & 63;
|
|
803
|
+
malformed = codePoint >> 11 === 0 || codePoint >> 11 === 27 || byte1 >> 4 !== 14 || byte2 >> 6 !== 2 || byte3 >> 6 !== 2;
|
|
804
|
+
} else if (offset + 2 < upperOffset) {
|
|
805
|
+
const byte2 = bytes[offset++];
|
|
806
|
+
const byte3 = bytes[offset++];
|
|
807
|
+
const byte4 = bytes[offset++];
|
|
808
|
+
codePoint = (byte1 & 7) << 18 | (byte2 & 63) << 12 | (byte3 & 63) << 6 | byte4 & 63;
|
|
809
|
+
malformed = codePoint >> 16 === 0 || codePoint > 1114111 || byte1 >> 3 !== 30 || byte2 >> 6 !== 2 || byte3 >> 6 !== 2 || byte4 >> 6 !== 2;
|
|
830
810
|
}
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
codePoint = (codePoint & 7) << 18 | (bytes[i] & 63) << 12 | (bytes[i + 1] & 63) << 6 | bytes[i + 2] & 63;
|
|
834
|
-
}
|
|
835
|
-
if (codePoint >> 16 === 0 || codePoint > 1114111 || bytes[i] >> 6 !== 2 || bytes[i + 1] >> 6 !== 2 || bytes[i + 2] >> 6 !== 2) {
|
|
836
|
-
throw TypeError("Decoding failed");
|
|
837
|
-
}
|
|
838
|
-
i += 3;
|
|
839
|
-
break;
|
|
811
|
+
if (malformed) {
|
|
812
|
+
throw new BareError(bc.offset, INVALID_UTF8_STRING);
|
|
840
813
|
}
|
|
841
|
-
default:
|
|
842
|
-
throw TypeError("Decoding failed");
|
|
843
814
|
}
|
|
844
815
|
result += String.fromCodePoint(codePoint);
|
|
845
816
|
}
|
|
817
|
+
bc.offset = offset;
|
|
846
818
|
return result;
|
|
847
819
|
}
|
|
848
|
-
function
|
|
849
|
-
const
|
|
820
|
+
function writeUtf8Js(bc, s) {
|
|
821
|
+
const bytes = bc.bytes;
|
|
850
822
|
let offset = bc.offset;
|
|
851
|
-
const view = bc.view;
|
|
852
823
|
let i = 0;
|
|
853
|
-
while (i <
|
|
824
|
+
while (i < s.length) {
|
|
854
825
|
const codePoint = s.codePointAt(i++);
|
|
855
826
|
if (codePoint < 128) {
|
|
856
|
-
|
|
857
|
-
} else if (codePoint < 2048) {
|
|
858
|
-
view.setUint8(offset++, 192 | codePoint >> 6);
|
|
859
|
-
view.setUint8(offset++, 128 | codePoint & 63);
|
|
860
|
-
} else if (codePoint < 65536) {
|
|
861
|
-
view.setUint8(offset++, 224 | codePoint >> 12);
|
|
862
|
-
view.setUint8(offset++, 128 | codePoint >> 6 & 63);
|
|
863
|
-
view.setUint8(offset++, 128 | codePoint & 63);
|
|
827
|
+
bytes[offset++] = codePoint;
|
|
864
828
|
} else {
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
829
|
+
if (codePoint < 2048) {
|
|
830
|
+
bytes[offset++] = 192 | codePoint >> 6;
|
|
831
|
+
} else {
|
|
832
|
+
if (codePoint < 65536) {
|
|
833
|
+
bytes[offset++] = 224 | codePoint >> 12;
|
|
834
|
+
} else {
|
|
835
|
+
bytes[offset++] = 240 | codePoint >> 18;
|
|
836
|
+
bytes[offset++] = 128 | codePoint >> 12 & 63;
|
|
837
|
+
i++;
|
|
838
|
+
}
|
|
839
|
+
bytes[offset++] = 128 | codePoint >> 6 & 63;
|
|
840
|
+
}
|
|
841
|
+
bytes[offset++] = 128 | codePoint & 63;
|
|
870
842
|
}
|
|
871
843
|
}
|
|
872
844
|
bc.offset = offset;
|
|
873
845
|
}
|
|
874
846
|
function utf8ByteLength(s) {
|
|
875
|
-
|
|
876
|
-
let
|
|
877
|
-
let i = 0;
|
|
878
|
-
while (i < sLen) {
|
|
847
|
+
let result = s.length;
|
|
848
|
+
for (let i = 0; i < s.length; i++) {
|
|
879
849
|
const codePoint = s.codePointAt(i);
|
|
880
|
-
|
|
881
|
-
if (codePoint < 128) {
|
|
850
|
+
if (codePoint > 127) {
|
|
882
851
|
result++;
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
i++;
|
|
852
|
+
if (codePoint > 2047) {
|
|
853
|
+
result++;
|
|
854
|
+
if (codePoint > 65535) {
|
|
855
|
+
i++;
|
|
856
|
+
}
|
|
857
|
+
}
|
|
890
858
|
}
|
|
891
859
|
}
|
|
892
860
|
return result;
|
|
893
861
|
}
|
|
894
|
-
var UTF8_DECODER = new TextDecoder("utf-8", { fatal: true });
|
|
895
|
-
var UTF8_ENCODER = new TextEncoder();
|
|
862
|
+
var UTF8_DECODER = /* @__PURE__ */ new TextDecoder("utf-8", { fatal: true });
|
|
863
|
+
var UTF8_ENCODER = /* @__PURE__ */ new TextEncoder();
|
|
896
864
|
|
|
897
865
|
// src/codec/u16-array.ts
|
|
898
|
-
var
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
function decodeU16Array(bc) {
|
|
902
|
-
return decodeU16FixedArray(bc, decodeUintSafe(bc));
|
|
866
|
+
var readU16FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? readU16FixedArrayLE : readU16FixedArrayBE;
|
|
867
|
+
function readU16Array(bc) {
|
|
868
|
+
return readU16FixedArray(bc, readUintSafe(bc));
|
|
903
869
|
}
|
|
904
|
-
function
|
|
870
|
+
function readU16FixedArrayLE(bc, len) {
|
|
905
871
|
const byteCount = len * U16_BYTE_COUNT;
|
|
906
|
-
return new Uint16Array(
|
|
872
|
+
return new Uint16Array(readFixedData(bc, byteCount));
|
|
907
873
|
}
|
|
908
|
-
function
|
|
874
|
+
function readU16FixedArrayBE(bc, len) {
|
|
909
875
|
bc.check(len * U16_BYTE_COUNT);
|
|
910
876
|
const result = new Uint16Array(len);
|
|
911
877
|
for (let i = 0; i < len; i++)
|
|
912
|
-
result[i] =
|
|
878
|
+
result[i] = readU16(bc);
|
|
913
879
|
return result;
|
|
914
880
|
}
|
|
915
|
-
var
|
|
916
|
-
function
|
|
917
|
-
|
|
881
|
+
var writeU16FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? writeU16FixedArrayLE : writeU16FixedArrayBE;
|
|
882
|
+
function writeU16Array(bc, x) {
|
|
883
|
+
writeUintSafe(bc, x.length);
|
|
918
884
|
if (x.length !== 0) {
|
|
919
|
-
|
|
885
|
+
writeU16FixedArray(bc, x);
|
|
920
886
|
}
|
|
921
887
|
}
|
|
922
|
-
function
|
|
923
|
-
(
|
|
924
|
-
bc.write(new Uint8Array(x.buffer, x.byteOffset, x.byteLength));
|
|
888
|
+
function writeU16FixedArrayLE(bc, x) {
|
|
889
|
+
writeU8FixedArray(bc, new Uint8Array(x.buffer, x.byteOffset, x.byteLength));
|
|
925
890
|
}
|
|
926
|
-
function
|
|
927
|
-
(0, import_assert9.default)(x.length === len);
|
|
891
|
+
function writeU16FixedArrayBE(bc, x) {
|
|
928
892
|
bc.reserve(x.length * U16_BYTE_COUNT);
|
|
929
893
|
for (let i = 0; i < x.length; i++)
|
|
930
|
-
|
|
894
|
+
writeU16(bc, x[i]);
|
|
931
895
|
}
|
|
932
896
|
|
|
933
897
|
// src/codec/u32-array.ts
|
|
934
|
-
var
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
function decodeU32Array(bc) {
|
|
938
|
-
return decodeU32FixedArray(bc, decodeUintSafe(bc));
|
|
898
|
+
var readU32FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? readU32FixedArrayLE : readU32FixedArrayBE;
|
|
899
|
+
function readU32Array(bc) {
|
|
900
|
+
return readU32FixedArray(bc, readUintSafe(bc));
|
|
939
901
|
}
|
|
940
|
-
function
|
|
902
|
+
function readU32FixedArrayLE(bc, len) {
|
|
941
903
|
const byteCount = len * U32_BYTE_COUNT;
|
|
942
|
-
return new Uint32Array(
|
|
904
|
+
return new Uint32Array(readFixedData(bc, byteCount));
|
|
943
905
|
}
|
|
944
|
-
function
|
|
906
|
+
function readU32FixedArrayBE(bc, len) {
|
|
945
907
|
bc.check(len * U32_BYTE_COUNT);
|
|
946
908
|
const result = new Uint32Array(len);
|
|
947
909
|
for (let i = 0; i < len; i++)
|
|
948
|
-
result[i] =
|
|
910
|
+
result[i] = readU32(bc);
|
|
949
911
|
return result;
|
|
950
912
|
}
|
|
951
|
-
var
|
|
952
|
-
function
|
|
953
|
-
|
|
913
|
+
var writeU32FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? writeU32FixedArrayLE : writeU32FixedArrayBE;
|
|
914
|
+
function writeU32Array(bc, x) {
|
|
915
|
+
writeUintSafe(bc, x.length);
|
|
954
916
|
if (x.length !== 0) {
|
|
955
|
-
|
|
917
|
+
writeU32FixedArray(bc, x);
|
|
956
918
|
}
|
|
957
919
|
}
|
|
958
|
-
function
|
|
959
|
-
(
|
|
960
|
-
bc.write(new Uint8Array(x.buffer, x.byteOffset, x.byteLength));
|
|
920
|
+
function writeU32FixedArrayLE(bc, x) {
|
|
921
|
+
writeU8FixedArray(bc, new Uint8Array(x.buffer, x.byteOffset, x.byteLength));
|
|
961
922
|
}
|
|
962
|
-
function
|
|
963
|
-
(0, import_assert10.default)(x.length === len);
|
|
923
|
+
function writeU32FixedArrayBE(bc, x) {
|
|
964
924
|
bc.reserve(x.length * U32_BYTE_COUNT);
|
|
965
925
|
for (let i = 0; i < x.length; i++)
|
|
966
|
-
|
|
926
|
+
writeU32(bc, x[i]);
|
|
967
927
|
}
|
|
968
928
|
|
|
969
929
|
// src/codec/u64-array.ts
|
|
970
|
-
var
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
function decodeU64Array(bc) {
|
|
974
|
-
return decodeU64FixedArray(bc, decodeUintSafe(bc));
|
|
930
|
+
var readU64FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? readU64FixedArrayLE : readU64FixedArrayBE;
|
|
931
|
+
function readU64Array(bc) {
|
|
932
|
+
return readU64FixedArray(bc, readUintSafe(bc));
|
|
975
933
|
}
|
|
976
|
-
function
|
|
934
|
+
function readU64FixedArrayLE(bc, len) {
|
|
977
935
|
const byteCount = len * U64_BYTE_COUNT;
|
|
978
|
-
return new BigUint64Array(
|
|
936
|
+
return new BigUint64Array(readFixedData(bc, byteCount));
|
|
979
937
|
}
|
|
980
|
-
function
|
|
938
|
+
function readU64FixedArrayBE(bc, len) {
|
|
981
939
|
bc.check(len * U64_BYTE_COUNT);
|
|
982
940
|
const result = new BigUint64Array(len);
|
|
983
941
|
for (let i = 0; i < len; i++)
|
|
984
|
-
result[i] =
|
|
942
|
+
result[i] = readU64(bc);
|
|
985
943
|
return result;
|
|
986
944
|
}
|
|
987
|
-
var
|
|
988
|
-
function
|
|
989
|
-
|
|
945
|
+
var writeU64FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? writeU64FixedArrayLE : writeU64FixedArrayBE;
|
|
946
|
+
function writeU64Array(bc, x) {
|
|
947
|
+
writeUintSafe(bc, x.length);
|
|
990
948
|
if (x.length !== 0) {
|
|
991
|
-
|
|
949
|
+
writeU64FixedArray(bc, x);
|
|
992
950
|
}
|
|
993
951
|
}
|
|
994
|
-
function
|
|
995
|
-
(
|
|
996
|
-
bc.write(new Uint8Array(x.buffer, x.byteOffset, x.byteLength));
|
|
952
|
+
function writeU64FixedArrayLE(bc, x) {
|
|
953
|
+
writeU8FixedArray(bc, new Uint8Array(x.buffer, x.byteOffset, x.byteLength));
|
|
997
954
|
}
|
|
998
|
-
function
|
|
999
|
-
(0, import_assert11.default)(x.length === len);
|
|
955
|
+
function writeU64FixedArrayBE(bc, x) {
|
|
1000
956
|
bc.reserve(x.length * U64_BYTE_COUNT);
|
|
1001
957
|
for (let i = 0; i < x.length; i++)
|
|
1002
|
-
|
|
958
|
+
writeU64(bc, x[i]);
|
|
1003
959
|
}
|
|
1004
960
|
|
|
1005
961
|
// src/codec/u8-clamped-array.ts
|
|
1006
|
-
function
|
|
1007
|
-
return
|
|
962
|
+
function readU8ClampedArray(bc) {
|
|
963
|
+
return readU8ClampedFixedArray(bc, readUintSafe(bc));
|
|
1008
964
|
}
|
|
1009
|
-
function
|
|
1010
|
-
|
|
1011
|
-
|
|
965
|
+
function writeU8ClampedArray(bc, x) {
|
|
966
|
+
writeUintSafe(bc, x.length);
|
|
967
|
+
writeU8ClampedFixedArray(bc, x);
|
|
1012
968
|
}
|
|
1013
|
-
function
|
|
1014
|
-
return new Uint8ClampedArray(
|
|
969
|
+
function readU8ClampedFixedArray(bc, len) {
|
|
970
|
+
return new Uint8ClampedArray(readFixedData(bc, len));
|
|
1015
971
|
}
|
|
1016
|
-
function
|
|
1017
|
-
|
|
972
|
+
function writeU8ClampedFixedArray(bc, x) {
|
|
973
|
+
writeU8FixedArray(bc, new Uint8Array(x.buffer, x.byteOffset, x.byteLength));
|
|
1018
974
|
}
|
|
1019
975
|
module.exports = __toCommonJS(src_exports);
|
|
1020
976
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -1022,91 +978,90 @@ module.exports = __toCommonJS(src_exports);
|
|
|
1022
978
|
BareError,
|
|
1023
979
|
ByteCursor,
|
|
1024
980
|
Config,
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
981
|
+
readBool,
|
|
982
|
+
readData,
|
|
983
|
+
readF32,
|
|
984
|
+
readF32Array,
|
|
985
|
+
readF32FixedArray,
|
|
986
|
+
readF64,
|
|
987
|
+
readF64Array,
|
|
988
|
+
readF64FixedArray,
|
|
989
|
+
readFixedData,
|
|
990
|
+
readFixedString,
|
|
991
|
+
readI16,
|
|
992
|
+
readI16Array,
|
|
993
|
+
readI16FixedArray,
|
|
994
|
+
readI32,
|
|
995
|
+
readI32Array,
|
|
996
|
+
readI32FixedArray,
|
|
997
|
+
readI64,
|
|
998
|
+
readI64Array,
|
|
999
|
+
readI64FixedArray,
|
|
1000
|
+
readI64Safe,
|
|
1001
|
+
readI8,
|
|
1002
|
+
readI8Array,
|
|
1003
|
+
readI8FixedArray,
|
|
1004
|
+
readInt,
|
|
1005
|
+
readIntSafe,
|
|
1006
|
+
readString,
|
|
1007
|
+
readU16,
|
|
1008
|
+
readU16Array,
|
|
1009
|
+
readU16FixedArray,
|
|
1010
|
+
readU32,
|
|
1011
|
+
readU32Array,
|
|
1012
|
+
readU32FixedArray,
|
|
1013
|
+
readU64,
|
|
1014
|
+
readU64Array,
|
|
1015
|
+
readU64FixedArray,
|
|
1016
|
+
readU64Safe,
|
|
1017
|
+
readU8,
|
|
1018
|
+
readU8Array,
|
|
1019
|
+
readU8ClampedArray,
|
|
1020
|
+
readU8ClampedFixedArray,
|
|
1021
|
+
readU8FixedArray,
|
|
1022
|
+
readUint,
|
|
1023
|
+
readUintSafe,
|
|
1024
|
+
writeBool,
|
|
1025
|
+
writeData,
|
|
1026
|
+
writeF32,
|
|
1027
|
+
writeF32Array,
|
|
1028
|
+
writeF32FixedArray,
|
|
1029
|
+
writeF64,
|
|
1030
|
+
writeF64Array,
|
|
1031
|
+
writeF64FixedArray,
|
|
1032
|
+
writeFixedData,
|
|
1033
|
+
writeFixedString,
|
|
1034
|
+
writeI16,
|
|
1035
|
+
writeI16Array,
|
|
1036
|
+
writeI16FixedArray,
|
|
1037
|
+
writeI32,
|
|
1038
|
+
writeI32Array,
|
|
1039
|
+
writeI32FixedArray,
|
|
1040
|
+
writeI64,
|
|
1041
|
+
writeI64Array,
|
|
1042
|
+
writeI64FixedArray,
|
|
1043
|
+
writeI64Safe,
|
|
1044
|
+
writeI8,
|
|
1045
|
+
writeI8Array,
|
|
1046
|
+
writeI8FixedArray,
|
|
1047
|
+
writeInt,
|
|
1048
|
+
writeIntSafe,
|
|
1049
|
+
writeString,
|
|
1050
|
+
writeU16,
|
|
1051
|
+
writeU16Array,
|
|
1052
|
+
writeU16FixedArray,
|
|
1053
|
+
writeU32,
|
|
1054
|
+
writeU32Array,
|
|
1055
|
+
writeU32FixedArray,
|
|
1056
|
+
writeU64,
|
|
1057
|
+
writeU64Array,
|
|
1058
|
+
writeU64FixedArray,
|
|
1059
|
+
writeU64Safe,
|
|
1060
|
+
writeU8,
|
|
1061
|
+
writeU8Array,
|
|
1062
|
+
writeU8ClampedArray,
|
|
1063
|
+
writeU8ClampedFixedArray,
|
|
1064
|
+
writeU8FixedArray,
|
|
1065
|
+
writeUint,
|
|
1066
|
+
writeUintSafe
|
|
1111
1067
|
});
|
|
1112
|
-
//# sourceMappingURL=index.cjs.map
|