@bare-ts/lib 0.3.0 → 0.5.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/LICENSE +21 -201
- package/README.md +7 -8
- package/dist/codec/data.d.ts +1 -1
- package/dist/codec/data.js +10 -12
- package/dist/codec/float-array.d.ts +7 -12
- package/dist/codec/float-array.js +53 -45
- package/dist/codec/i16-array.d.ts +4 -7
- package/dist/codec/i16-array.js +35 -27
- package/dist/codec/i32-array.d.ts +4 -7
- package/dist/codec/i32-array.js +35 -27
- package/dist/codec/i64-array.d.ts +4 -7
- package/dist/codec/i64-array.js +35 -27
- package/dist/codec/i8-array.d.ts +3 -3
- package/dist/codec/i8-array.js +12 -14
- package/dist/codec/primitive.d.ts +3 -1
- package/dist/codec/primitive.js +227 -149
- package/dist/codec/string.d.ts +1 -1
- package/dist/codec/string.js +45 -31
- package/dist/codec/u16-array.d.ts +4 -7
- package/dist/codec/u16-array.js +35 -27
- package/dist/codec/u32-array.d.ts +4 -7
- package/dist/codec/u32-array.js +35 -27
- package/dist/codec/u64-array.d.ts +4 -7
- package/dist/codec/u64-array.js +35 -27
- package/dist/codec/u8-array.d.ts +9 -3
- package/dist/codec/u8-array.js +23 -18
- package/dist/codec/u8-clamped-array.d.ts +3 -3
- package/dist/codec/u8-clamped-array.js +13 -15
- package/dist/core/bare-error.d.ts +4 -1
- package/dist/core/bare-error.js +4 -8
- package/dist/core/byte-cursor.d.ts +22 -28
- package/dist/core/byte-cursor.js +33 -29
- package/dist/core/config.d.ts +4 -10
- package/dist/core/config.js +15 -20
- package/dist/env/dev.d.ts +1 -0
- package/dist/env/dev.development.d.ts +1 -0
- package/dist/env/dev.development.js +2 -0
- package/dist/env/dev.js +2 -0
- package/dist/env/dev.node.d.ts +1 -0
- package/dist/env/dev.node.js +2 -0
- package/dist/index.cjs +545 -324
- package/dist/index.d.cts +16 -0
- package/dist/index.d.ts +16 -2
- package/dist/index.js +17 -4
- package/dist/util/assert.d.ts +6 -8
- package/dist/util/assert.js +10 -13
- package/dist/util/constants.d.ts +4 -7
- package/dist/util/constants.js +11 -30
- package/dist/util/validator.d.ts +1 -1
- package/dist/util/validator.js +12 -24
- package/package.json +31 -25
- package/dist/codec/index.d.ts +0 -13
- package/dist/codec/index.js +0 -15
- package/dist/core/index.d.ts +0 -3
- package/dist/core/index.js +0 -5
- package/dist/util/util.d.ts +0 -1
- package/dist/util/util.js +0 -6
package/dist/index.cjs
CHANGED
|
@@ -1,32 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
6
6
|
var __export = (target, all) => {
|
|
7
7
|
for (var name in all)
|
|
8
8
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
9
|
};
|
|
10
|
-
var
|
|
11
|
-
if (
|
|
12
|
-
for (let key of __getOwnPropNames(
|
|
13
|
-
if (!__hasOwnProp.call(
|
|
14
|
-
__defProp(
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
15
|
}
|
|
16
|
-
return
|
|
16
|
+
return to;
|
|
17
17
|
};
|
|
18
|
-
var __toCommonJS =
|
|
19
|
-
return (module2, temp) => {
|
|
20
|
-
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
|
|
21
|
-
};
|
|
22
|
-
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
23
19
|
|
|
24
20
|
// src/index.ts
|
|
25
|
-
var
|
|
26
|
-
__export(
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
27
23
|
BareError: () => BareError,
|
|
28
24
|
ByteCursor: () => ByteCursor,
|
|
29
25
|
Config: () => Config,
|
|
26
|
+
DEFAULT_CONFIG: () => DEFAULT_CONFIG,
|
|
27
|
+
check: () => check,
|
|
30
28
|
readBool: () => readBool,
|
|
31
29
|
readData: () => readData,
|
|
32
30
|
readF32: () => readF32,
|
|
@@ -70,6 +68,9 @@ __export(src_exports, {
|
|
|
70
68
|
readU8FixedArray: () => readU8FixedArray,
|
|
71
69
|
readUint: () => readUint,
|
|
72
70
|
readUintSafe: () => readUintSafe,
|
|
71
|
+
readUintSafe32: () => readUintSafe32,
|
|
72
|
+
readUnsafeU8FixedArray: () => readUnsafeU8FixedArray,
|
|
73
|
+
reserve: () => reserve,
|
|
73
74
|
writeBool: () => writeBool,
|
|
74
75
|
writeData: () => writeData,
|
|
75
76
|
writeF32: () => writeF32,
|
|
@@ -112,52 +113,32 @@ __export(src_exports, {
|
|
|
112
113
|
writeU8ClampedFixedArray: () => writeU8ClampedFixedArray,
|
|
113
114
|
writeU8FixedArray: () => writeU8FixedArray,
|
|
114
115
|
writeUint: () => writeUint,
|
|
115
|
-
writeUintSafe: () => writeUintSafe
|
|
116
|
+
writeUintSafe: () => writeUintSafe,
|
|
117
|
+
writeUintSafe32: () => writeUintSafe32
|
|
116
118
|
});
|
|
119
|
+
module.exports = __toCommonJS(index_exports);
|
|
120
|
+
|
|
121
|
+
// dist/env/dev.node.js
|
|
122
|
+
var DEV = process.env.NODE_ENV === "development";
|
|
117
123
|
|
|
118
124
|
// src/util/assert.ts
|
|
119
125
|
var AssertionError = class extends Error {
|
|
120
|
-
constructor(
|
|
121
|
-
super(
|
|
126
|
+
constructor() {
|
|
127
|
+
super(...arguments);
|
|
122
128
|
this.name = "AssertionError";
|
|
123
129
|
}
|
|
124
130
|
};
|
|
125
|
-
|
|
131
|
+
var V8Error = Error;
|
|
132
|
+
function assert(test, message = "") {
|
|
126
133
|
if (!test) {
|
|
127
134
|
const e = new AssertionError(message);
|
|
128
|
-
if (
|
|
129
|
-
|
|
135
|
+
if (V8Error.captureStackTrace) {
|
|
136
|
+
V8Error.captureStackTrace(e, assert);
|
|
130
137
|
}
|
|
131
138
|
throw e;
|
|
132
139
|
}
|
|
133
140
|
}
|
|
134
141
|
|
|
135
|
-
// src/core/bare-error.ts
|
|
136
|
-
var BareError = class extends Error {
|
|
137
|
-
constructor(offset, issue, opts) {
|
|
138
|
-
super(`(byte:${offset}) ${issue}`);
|
|
139
|
-
this.name = "BareError";
|
|
140
|
-
this.issue = issue;
|
|
141
|
-
this.offset = offset;
|
|
142
|
-
this.cause = opts == null ? void 0 : opts.cause;
|
|
143
|
-
}
|
|
144
|
-
};
|
|
145
|
-
|
|
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";
|
|
160
|
-
|
|
161
142
|
// src/util/validator.ts
|
|
162
143
|
function isI8(val) {
|
|
163
144
|
return val === val << 24 >> 24;
|
|
@@ -171,9 +152,6 @@ function isI32(val) {
|
|
|
171
152
|
function isI64(val) {
|
|
172
153
|
return val === BigInt.asIntN(64, val);
|
|
173
154
|
}
|
|
174
|
-
function isSafeU64(val) {
|
|
175
|
-
return Number.isSafeInteger(val) && val >= 0;
|
|
176
|
-
}
|
|
177
155
|
function isU8(val) {
|
|
178
156
|
return val === (val & 255);
|
|
179
157
|
}
|
|
@@ -186,64 +164,75 @@ function isU32(val) {
|
|
|
186
164
|
function isU64(val) {
|
|
187
165
|
return val === BigInt.asUintN(64, val);
|
|
188
166
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
function Config({
|
|
192
|
-
initialBufferLength = 1024,
|
|
193
|
-
maxBufferLength = 1024 * 1024 * 32,
|
|
194
|
-
textDecoderThreshold = 256,
|
|
195
|
-
textEncoderThreshold = 256
|
|
196
|
-
}) {
|
|
197
|
-
const config = {
|
|
198
|
-
initialBufferLength,
|
|
199
|
-
maxBufferLength,
|
|
200
|
-
textDecoderThreshold,
|
|
201
|
-
textEncoderThreshold
|
|
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");
|
|
208
|
-
return config;
|
|
167
|
+
function isU64Safe(val) {
|
|
168
|
+
return Number.isSafeInteger(val) && val >= 0;
|
|
209
169
|
}
|
|
210
170
|
|
|
171
|
+
// src/util/constants.ts
|
|
172
|
+
var TEXT_DECODER_THRESHOLD = 256;
|
|
173
|
+
var TEXT_ENCODER_THRESHOLD = 256;
|
|
174
|
+
var INT_SAFE_MAX_BYTE_COUNT = 8;
|
|
175
|
+
var UINT_MAX_BYTE_COUNT = 10;
|
|
176
|
+
var UINT_SAFE32_MAX_BYTE_COUNT = 5;
|
|
177
|
+
var INVALID_UTF8_STRING = "invalid UTF-8 string";
|
|
178
|
+
var NON_CANONICAL_REPRESENTATION = "must be canonical";
|
|
179
|
+
var TOO_LARGE_BUFFER = "too large buffer";
|
|
180
|
+
var TOO_LARGE_NUMBER = "too large number";
|
|
181
|
+
var IS_LITTLE_ENDIAN_PLATFORM = /* @__PURE__ */ new DataView(Uint16Array.of(1).buffer).getUint8(0) === 1;
|
|
182
|
+
|
|
183
|
+
// src/core/bare-error.ts
|
|
184
|
+
var BareError = class extends Error {
|
|
185
|
+
constructor(offset, issue, opts) {
|
|
186
|
+
super(`(byte:${offset}) ${issue}`);
|
|
187
|
+
this.name = "BareError";
|
|
188
|
+
this.issue = issue;
|
|
189
|
+
this.offset = offset;
|
|
190
|
+
this.cause = opts?.cause;
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
|
|
211
194
|
// src/core/byte-cursor.ts
|
|
212
195
|
var ByteCursor = class {
|
|
196
|
+
/**
|
|
197
|
+
* @throws {BareError} Buffer exceeds `config.maxBufferLength`
|
|
198
|
+
*/
|
|
213
199
|
constructor(bytes, config) {
|
|
200
|
+
/**
|
|
201
|
+
* Read and write Offset in {@link view} and {@link bytes}
|
|
202
|
+
*/
|
|
203
|
+
this.offset = 0;
|
|
214
204
|
if (bytes.length > config.maxBufferLength) {
|
|
215
205
|
throw new BareError(0, TOO_LARGE_BUFFER);
|
|
216
206
|
}
|
|
217
207
|
this.bytes = bytes;
|
|
218
208
|
this.config = config;
|
|
219
|
-
this.offset = 0;
|
|
220
209
|
this.view = new DataView(bytes.buffer, bytes.byteOffset, bytes.length);
|
|
221
210
|
}
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
211
|
+
};
|
|
212
|
+
function check(bc, min) {
|
|
213
|
+
if (DEV) {
|
|
214
|
+
assert(isU32(min));
|
|
226
215
|
}
|
|
227
|
-
|
|
228
|
-
|
|
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);
|
|
234
|
-
const newBytes = new Uint8Array(newLen);
|
|
235
|
-
newBytes.set(this.bytes);
|
|
236
|
-
this.bytes = newBytes;
|
|
237
|
-
this.view = new DataView(newBytes.buffer);
|
|
238
|
-
}
|
|
216
|
+
if (bc.offset + min > bc.bytes.length) {
|
|
217
|
+
throw new BareError(bc.offset, "missing bytes");
|
|
239
218
|
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
return this.bytes.subarray(offset, offset + len);
|
|
219
|
+
}
|
|
220
|
+
function reserve(bc, min) {
|
|
221
|
+
if (DEV) {
|
|
222
|
+
assert(isU32(min));
|
|
245
223
|
}
|
|
246
|
-
|
|
224
|
+
const minLen = bc.offset + min | 0;
|
|
225
|
+
if (minLen > bc.bytes.length) {
|
|
226
|
+
if (minLen > bc.config.maxBufferLength) {
|
|
227
|
+
throw new BareError(0, TOO_LARGE_BUFFER);
|
|
228
|
+
}
|
|
229
|
+
const newLen = Math.min(minLen << 1, bc.config.maxBufferLength);
|
|
230
|
+
const newBytes = new Uint8Array(newLen);
|
|
231
|
+
newBytes.set(bc.bytes);
|
|
232
|
+
bc.bytes = newBytes;
|
|
233
|
+
bc.view = new DataView(newBytes.buffer);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
247
236
|
|
|
248
237
|
// src/codec/primitive.ts
|
|
249
238
|
function readBool(bc) {
|
|
@@ -252,81 +241,95 @@ function readBool(bc) {
|
|
|
252
241
|
bc.offset--;
|
|
253
242
|
throw new BareError(bc.offset, "a bool must be equal to 0 or 1");
|
|
254
243
|
}
|
|
255
|
-
return val
|
|
244
|
+
return val > 0;
|
|
256
245
|
}
|
|
257
246
|
function writeBool(bc, x) {
|
|
258
247
|
writeU8(bc, x ? 1 : 0);
|
|
259
248
|
}
|
|
260
249
|
function readF32(bc) {
|
|
261
|
-
|
|
250
|
+
check(bc, 4);
|
|
262
251
|
const result = bc.view.getFloat32(bc.offset, true);
|
|
263
252
|
bc.offset += 4;
|
|
264
253
|
return result;
|
|
265
254
|
}
|
|
266
255
|
function writeF32(bc, x) {
|
|
267
|
-
|
|
256
|
+
reserve(bc, 4);
|
|
268
257
|
bc.view.setFloat32(bc.offset, x, true);
|
|
269
|
-
|
|
258
|
+
if (DEV) {
|
|
259
|
+
assert(
|
|
260
|
+
Number.isNaN(x) || Math.abs(bc.view.getFloat32(bc.offset, true) - x) <= Number.EPSILON,
|
|
261
|
+
TOO_LARGE_NUMBER
|
|
262
|
+
);
|
|
263
|
+
}
|
|
270
264
|
bc.offset += 4;
|
|
271
265
|
}
|
|
272
266
|
function readF64(bc) {
|
|
273
|
-
|
|
267
|
+
check(bc, 8);
|
|
274
268
|
const result = bc.view.getFloat64(bc.offset, true);
|
|
275
269
|
bc.offset += 8;
|
|
276
270
|
return result;
|
|
277
271
|
}
|
|
278
272
|
function writeF64(bc, x) {
|
|
279
|
-
|
|
273
|
+
reserve(bc, 8);
|
|
280
274
|
bc.view.setFloat64(bc.offset, x, true);
|
|
281
275
|
bc.offset += 8;
|
|
282
276
|
}
|
|
283
277
|
function readI8(bc) {
|
|
284
|
-
|
|
278
|
+
check(bc, 1);
|
|
285
279
|
return bc.view.getInt8(bc.offset++);
|
|
286
280
|
}
|
|
287
281
|
function writeI8(bc, x) {
|
|
288
|
-
|
|
289
|
-
|
|
282
|
+
if (DEV) {
|
|
283
|
+
assert(isI8(x), TOO_LARGE_NUMBER);
|
|
284
|
+
}
|
|
285
|
+
reserve(bc, 1);
|
|
290
286
|
bc.view.setInt8(bc.offset++, x);
|
|
291
287
|
}
|
|
292
288
|
function readI16(bc) {
|
|
293
|
-
|
|
289
|
+
check(bc, 2);
|
|
294
290
|
const result = bc.view.getInt16(bc.offset, true);
|
|
295
291
|
bc.offset += 2;
|
|
296
292
|
return result;
|
|
297
293
|
}
|
|
298
294
|
function writeI16(bc, x) {
|
|
299
|
-
|
|
300
|
-
|
|
295
|
+
if (DEV) {
|
|
296
|
+
assert(isI16(x), TOO_LARGE_NUMBER);
|
|
297
|
+
}
|
|
298
|
+
reserve(bc, 2);
|
|
301
299
|
bc.view.setInt16(bc.offset, x, true);
|
|
302
300
|
bc.offset += 2;
|
|
303
301
|
}
|
|
304
302
|
function readI32(bc) {
|
|
305
|
-
|
|
303
|
+
check(bc, 4);
|
|
306
304
|
const result = bc.view.getInt32(bc.offset, true);
|
|
307
305
|
bc.offset += 4;
|
|
308
306
|
return result;
|
|
309
307
|
}
|
|
310
308
|
function writeI32(bc, x) {
|
|
311
|
-
|
|
312
|
-
|
|
309
|
+
if (DEV) {
|
|
310
|
+
assert(isI32(x), TOO_LARGE_NUMBER);
|
|
311
|
+
}
|
|
312
|
+
reserve(bc, 4);
|
|
313
313
|
bc.view.setInt32(bc.offset, x, true);
|
|
314
314
|
bc.offset += 4;
|
|
315
315
|
}
|
|
316
316
|
function readI64(bc) {
|
|
317
|
-
|
|
317
|
+
check(bc, 8);
|
|
318
318
|
const result = bc.view.getBigInt64(bc.offset, true);
|
|
319
319
|
bc.offset += 8;
|
|
320
320
|
return result;
|
|
321
321
|
}
|
|
322
322
|
function writeI64(bc, x) {
|
|
323
|
-
|
|
324
|
-
|
|
323
|
+
if (DEV) {
|
|
324
|
+
assert(isI64(x), TOO_LARGE_NUMBER);
|
|
325
|
+
}
|
|
326
|
+
reserve(bc, 8);
|
|
325
327
|
bc.view.setBigInt64(bc.offset, x, true);
|
|
326
328
|
bc.offset += 8;
|
|
327
329
|
}
|
|
328
330
|
function readI64Safe(bc) {
|
|
329
|
-
const result = readU32(bc) + readI32(bc) *
|
|
331
|
+
const result = readU32(bc) + readI32(bc) * /* 2**32 */
|
|
332
|
+
4294967296;
|
|
330
333
|
if (!Number.isSafeInteger(result)) {
|
|
331
334
|
bc.offset -= 8;
|
|
332
335
|
throw new BareError(bc.offset, TOO_LARGE_NUMBER);
|
|
@@ -334,14 +337,22 @@ function readI64Safe(bc) {
|
|
|
334
337
|
return result;
|
|
335
338
|
}
|
|
336
339
|
function writeI64Safe(bc, x) {
|
|
337
|
-
|
|
338
|
-
|
|
340
|
+
if (DEV) {
|
|
341
|
+
assert(Number.isSafeInteger(x), TOO_LARGE_NUMBER);
|
|
342
|
+
}
|
|
343
|
+
let lowest32 = x >>> 0;
|
|
339
344
|
writeU32(bc, lowest32);
|
|
340
|
-
let highest32 = x /
|
|
345
|
+
let highest32 = x / /* 2**32 */
|
|
346
|
+
4294967296 | 0;
|
|
341
347
|
if (x < 0) {
|
|
342
|
-
highest32 = ~Math.abs(highest32)
|
|
348
|
+
highest32 = ~(Math.abs(highest32) & /* 2**21-1 */
|
|
349
|
+
2097151) >>> 0;
|
|
343
350
|
if (lowest32 === 0) {
|
|
344
|
-
highest32
|
|
351
|
+
if (highest32 === 2097151) {
|
|
352
|
+
lowest32 = 1;
|
|
353
|
+
} else {
|
|
354
|
+
highest32++;
|
|
355
|
+
}
|
|
345
356
|
}
|
|
346
357
|
}
|
|
347
358
|
writeU32(bc, highest32);
|
|
@@ -351,21 +362,28 @@ function readInt(bc) {
|
|
|
351
362
|
return zigZag >> BigInt(1) ^ -(zigZag & BigInt(1));
|
|
352
363
|
}
|
|
353
364
|
function writeInt(bc, x) {
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
365
|
+
const truncated = BigInt.asIntN(64, x);
|
|
366
|
+
if (DEV) {
|
|
367
|
+
assert(truncated === x, TOO_LARGE_NUMBER);
|
|
368
|
+
}
|
|
369
|
+
const zigZag = truncated >> BigInt(63) ^ truncated << BigInt(1);
|
|
370
|
+
writeTruncatedUint(bc, zigZag);
|
|
357
371
|
}
|
|
358
372
|
function readIntSafe(bc) {
|
|
359
373
|
const firstByte = readU8(bc);
|
|
360
374
|
let result = (firstByte & 127) >> 1;
|
|
361
375
|
if (firstByte >= 128) {
|
|
362
|
-
let shiftMul =
|
|
376
|
+
let shiftMul = (
|
|
377
|
+
/* 2**6 */
|
|
378
|
+
64
|
|
379
|
+
);
|
|
363
380
|
let byteCount = 1;
|
|
364
381
|
let byte;
|
|
365
382
|
do {
|
|
366
383
|
byte = readU8(bc);
|
|
367
384
|
result += (byte & 127) * shiftMul;
|
|
368
|
-
shiftMul *=
|
|
385
|
+
shiftMul *= /* 2**7 */
|
|
386
|
+
128;
|
|
369
387
|
byteCount++;
|
|
370
388
|
} while (byte >= 128 && byteCount < INT_SAFE_MAX_BYTE_COUNT);
|
|
371
389
|
if (byte === 0) {
|
|
@@ -384,77 +402,99 @@ function readIntSafe(bc) {
|
|
|
384
402
|
return result;
|
|
385
403
|
}
|
|
386
404
|
function writeIntSafe(bc, x) {
|
|
387
|
-
assert(Number.isSafeInteger(x), TOO_LARGE_NUMBER);
|
|
388
405
|
const sign = x < 0 ? 1 : 0;
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
406
|
+
let zigZag = x < 0 ? -(x + 1) : x;
|
|
407
|
+
let first7Bits = (zigZag & 63) << 1 | sign;
|
|
408
|
+
zigZag = Math.floor(zigZag / /* 2**6 */
|
|
409
|
+
64);
|
|
410
|
+
if (zigZag > 0) {
|
|
411
|
+
if (!Number.isSafeInteger(x)) {
|
|
412
|
+
if (DEV) {
|
|
413
|
+
assert(false, TOO_LARGE_NUMBER);
|
|
414
|
+
}
|
|
415
|
+
const low = zigZag & 32767;
|
|
416
|
+
const high = (zigZag / 32768 >>> 0) * 32768;
|
|
417
|
+
if (first7Bits === 127 && low === 32767 && high === 4294967295) {
|
|
418
|
+
first7Bits &= ~2;
|
|
419
|
+
}
|
|
420
|
+
zigZag = high + low;
|
|
421
|
+
}
|
|
422
|
+
writeU8(bc, 128 | first7Bits);
|
|
423
|
+
writeUintSafe(bc, zigZag);
|
|
397
424
|
} else {
|
|
398
|
-
writeU8(bc,
|
|
425
|
+
writeU8(bc, first7Bits);
|
|
399
426
|
}
|
|
400
427
|
}
|
|
401
428
|
function readU8(bc) {
|
|
402
|
-
|
|
429
|
+
check(bc, 1);
|
|
403
430
|
return bc.bytes[bc.offset++];
|
|
404
431
|
}
|
|
405
432
|
function writeU8(bc, x) {
|
|
406
|
-
|
|
407
|
-
|
|
433
|
+
if (DEV) {
|
|
434
|
+
assert(isU8(x), TOO_LARGE_NUMBER);
|
|
435
|
+
}
|
|
436
|
+
reserve(bc, 1);
|
|
408
437
|
bc.bytes[bc.offset++] = x;
|
|
409
438
|
}
|
|
410
439
|
function readU16(bc) {
|
|
411
|
-
|
|
440
|
+
check(bc, 2);
|
|
412
441
|
const result = bc.view.getUint16(bc.offset, true);
|
|
413
442
|
bc.offset += 2;
|
|
414
443
|
return result;
|
|
415
444
|
}
|
|
416
445
|
function writeU16(bc, x) {
|
|
417
|
-
|
|
418
|
-
|
|
446
|
+
if (DEV) {
|
|
447
|
+
assert(isU16(x), TOO_LARGE_NUMBER);
|
|
448
|
+
}
|
|
449
|
+
reserve(bc, 2);
|
|
419
450
|
bc.view.setUint16(bc.offset, x, true);
|
|
420
451
|
bc.offset += 2;
|
|
421
452
|
}
|
|
422
453
|
function readU32(bc) {
|
|
423
|
-
|
|
454
|
+
check(bc, 4);
|
|
424
455
|
const result = bc.view.getUint32(bc.offset, true);
|
|
425
456
|
bc.offset += 4;
|
|
426
457
|
return result;
|
|
427
458
|
}
|
|
428
459
|
function writeU32(bc, x) {
|
|
429
|
-
|
|
430
|
-
|
|
460
|
+
if (DEV) {
|
|
461
|
+
assert(isU32(x), TOO_LARGE_NUMBER);
|
|
462
|
+
}
|
|
463
|
+
reserve(bc, 4);
|
|
431
464
|
bc.view.setUint32(bc.offset, x, true);
|
|
432
465
|
bc.offset += 4;
|
|
433
466
|
}
|
|
434
467
|
function readU64(bc) {
|
|
435
|
-
|
|
468
|
+
check(bc, 8);
|
|
436
469
|
const result = bc.view.getBigUint64(bc.offset, true);
|
|
437
470
|
bc.offset += 8;
|
|
438
471
|
return result;
|
|
439
472
|
}
|
|
440
473
|
function writeU64(bc, x) {
|
|
441
|
-
|
|
442
|
-
|
|
474
|
+
if (DEV) {
|
|
475
|
+
assert(isU64(x), TOO_LARGE_NUMBER);
|
|
476
|
+
}
|
|
477
|
+
reserve(bc, 8);
|
|
443
478
|
bc.view.setBigUint64(bc.offset, x, true);
|
|
444
479
|
bc.offset += 8;
|
|
445
480
|
}
|
|
446
481
|
function readU64Safe(bc) {
|
|
447
|
-
const result = readU32(bc) + readU32(bc) *
|
|
448
|
-
|
|
482
|
+
const result = readU32(bc) + readU32(bc) * /* 2**32 */
|
|
483
|
+
4294967296;
|
|
484
|
+
if (!isU64Safe(result)) {
|
|
449
485
|
bc.offset -= 8;
|
|
450
486
|
throw new BareError(bc.offset, TOO_LARGE_NUMBER);
|
|
451
487
|
}
|
|
452
488
|
return result;
|
|
453
489
|
}
|
|
454
490
|
function writeU64Safe(bc, x) {
|
|
455
|
-
|
|
491
|
+
if (DEV) {
|
|
492
|
+
assert(isU64Safe(x), TOO_LARGE_NUMBER);
|
|
493
|
+
}
|
|
456
494
|
writeU32(bc, x >>> 0);
|
|
457
|
-
writeU32(bc, x /
|
|
495
|
+
writeU32(bc, x / /* 2**32 */
|
|
496
|
+
4294967296 & /* 2**21-1 */
|
|
497
|
+
2097151);
|
|
458
498
|
}
|
|
459
499
|
function readUint(bc) {
|
|
460
500
|
let low = readU8(bc);
|
|
@@ -466,7 +506,8 @@ function readUint(bc) {
|
|
|
466
506
|
do {
|
|
467
507
|
byte = readU8(bc);
|
|
468
508
|
low += (byte & 127) * shiftMul;
|
|
469
|
-
shiftMul *=
|
|
509
|
+
shiftMul *= /* 2**7 */
|
|
510
|
+
128;
|
|
470
511
|
byteCount++;
|
|
471
512
|
} while (byte >= 128 && byteCount < 7);
|
|
472
513
|
let height = 0;
|
|
@@ -474,7 +515,8 @@ function readUint(bc) {
|
|
|
474
515
|
while (byte >= 128 && byteCount < UINT_MAX_BYTE_COUNT) {
|
|
475
516
|
byte = readU8(bc);
|
|
476
517
|
height += (byte & 127) * shiftMul;
|
|
477
|
-
shiftMul *=
|
|
518
|
+
shiftMul *= /* 2**7 */
|
|
519
|
+
128;
|
|
478
520
|
byteCount++;
|
|
479
521
|
}
|
|
480
522
|
if (byte === 0 || byteCount === UINT_MAX_BYTE_COUNT && byte > 1) {
|
|
@@ -486,13 +528,20 @@ function readUint(bc) {
|
|
|
486
528
|
return BigInt(low);
|
|
487
529
|
}
|
|
488
530
|
function writeUint(bc, x) {
|
|
489
|
-
|
|
531
|
+
const truncated = BigInt.asUintN(64, x);
|
|
532
|
+
if (DEV) {
|
|
533
|
+
assert(truncated === x, TOO_LARGE_NUMBER);
|
|
534
|
+
}
|
|
535
|
+
writeTruncatedUint(bc, truncated);
|
|
536
|
+
}
|
|
537
|
+
function writeTruncatedUint(bc, x) {
|
|
490
538
|
let tmp = Number(BigInt.asUintN(7 * 7, x));
|
|
491
539
|
let rest = Number(x >> BigInt(7 * 7));
|
|
492
540
|
let byteCount = 0;
|
|
493
|
-
while (tmp >= 128 || rest
|
|
541
|
+
while (tmp >= 128 || rest > 0) {
|
|
494
542
|
writeU8(bc, 128 | tmp & 127);
|
|
495
|
-
tmp = Math.floor(tmp /
|
|
543
|
+
tmp = Math.floor(tmp / /* 2**7 */
|
|
544
|
+
128);
|
|
496
545
|
byteCount++;
|
|
497
546
|
if (byteCount === 7) {
|
|
498
547
|
tmp = rest;
|
|
@@ -501,24 +550,69 @@ function writeUint(bc, x) {
|
|
|
501
550
|
}
|
|
502
551
|
writeU8(bc, tmp);
|
|
503
552
|
}
|
|
553
|
+
function readUintSafe32(bc) {
|
|
554
|
+
let result = readU8(bc);
|
|
555
|
+
if (result >= 128) {
|
|
556
|
+
result &= 127;
|
|
557
|
+
let shift = 7;
|
|
558
|
+
let byteCount = 1;
|
|
559
|
+
let byte;
|
|
560
|
+
do {
|
|
561
|
+
byte = readU8(bc);
|
|
562
|
+
result += (byte & 127) << shift >>> 0;
|
|
563
|
+
shift += 7;
|
|
564
|
+
byteCount++;
|
|
565
|
+
} while (byte >= 128 && byteCount < UINT_SAFE32_MAX_BYTE_COUNT);
|
|
566
|
+
if (byte === 0) {
|
|
567
|
+
bc.offset -= byteCount - 1;
|
|
568
|
+
throw new BareError(
|
|
569
|
+
bc.offset - byteCount + 1,
|
|
570
|
+
NON_CANONICAL_REPRESENTATION
|
|
571
|
+
);
|
|
572
|
+
}
|
|
573
|
+
if (byteCount === UINT_SAFE32_MAX_BYTE_COUNT && byte > 15) {
|
|
574
|
+
bc.offset -= byteCount - 1;
|
|
575
|
+
throw new BareError(bc.offset, TOO_LARGE_NUMBER);
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
return result;
|
|
579
|
+
}
|
|
580
|
+
function writeUintSafe32(bc, x) {
|
|
581
|
+
if (DEV) {
|
|
582
|
+
assert(isU32(x), TOO_LARGE_NUMBER);
|
|
583
|
+
}
|
|
584
|
+
let zigZag = x >>> 0;
|
|
585
|
+
while (zigZag >= 128) {
|
|
586
|
+
writeU8(bc, 128 | x & 127);
|
|
587
|
+
zigZag >>>= 7;
|
|
588
|
+
}
|
|
589
|
+
writeU8(bc, zigZag);
|
|
590
|
+
}
|
|
504
591
|
function readUintSafe(bc) {
|
|
505
592
|
let result = readU8(bc);
|
|
506
593
|
if (result >= 128) {
|
|
507
594
|
result &= 127;
|
|
508
|
-
let shiftMul =
|
|
595
|
+
let shiftMul = (
|
|
596
|
+
/* 2**7 */
|
|
597
|
+
128
|
|
598
|
+
);
|
|
509
599
|
let byteCount = 1;
|
|
510
600
|
let byte;
|
|
511
601
|
do {
|
|
512
602
|
byte = readU8(bc);
|
|
513
603
|
result += (byte & 127) * shiftMul;
|
|
514
|
-
shiftMul *=
|
|
604
|
+
shiftMul *= /* 2**7 */
|
|
605
|
+
128;
|
|
515
606
|
byteCount++;
|
|
516
|
-
} while (byte >= 128 && byteCount <
|
|
607
|
+
} while (byte >= 128 && byteCount < INT_SAFE_MAX_BYTE_COUNT);
|
|
517
608
|
if (byte === 0) {
|
|
518
609
|
bc.offset -= byteCount - 1;
|
|
519
|
-
throw new BareError(
|
|
610
|
+
throw new BareError(
|
|
611
|
+
bc.offset - byteCount + 1,
|
|
612
|
+
NON_CANONICAL_REPRESENTATION
|
|
613
|
+
);
|
|
520
614
|
}
|
|
521
|
-
if (byteCount ===
|
|
615
|
+
if (byteCount === INT_SAFE_MAX_BYTE_COUNT && byte > 15) {
|
|
522
616
|
bc.offset -= byteCount - 1;
|
|
523
617
|
throw new BareError(bc.offset, TOO_LARGE_NUMBER);
|
|
524
618
|
}
|
|
@@ -526,33 +620,51 @@ function readUintSafe(bc) {
|
|
|
526
620
|
return result;
|
|
527
621
|
}
|
|
528
622
|
function writeUintSafe(bc, x) {
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
623
|
+
if (DEV) {
|
|
624
|
+
assert(isU64Safe(x), TOO_LARGE_NUMBER);
|
|
625
|
+
}
|
|
626
|
+
let byteCount = 1;
|
|
627
|
+
let zigZag = x;
|
|
628
|
+
while (zigZag >= 128 && byteCount < INT_SAFE_MAX_BYTE_COUNT) {
|
|
629
|
+
writeU8(bc, 128 | zigZag & 127);
|
|
630
|
+
zigZag = Math.floor(zigZag / /* 2**7 */
|
|
631
|
+
128);
|
|
632
|
+
byteCount++;
|
|
533
633
|
}
|
|
534
|
-
|
|
634
|
+
if (byteCount === INT_SAFE_MAX_BYTE_COUNT) {
|
|
635
|
+
zigZag &= 15;
|
|
636
|
+
}
|
|
637
|
+
writeU8(bc, zigZag);
|
|
535
638
|
}
|
|
536
639
|
|
|
537
640
|
// src/codec/u8-array.ts
|
|
538
641
|
function readU8Array(bc) {
|
|
539
|
-
return readU8FixedArray(bc,
|
|
642
|
+
return readU8FixedArray(bc, readUintSafe32(bc));
|
|
540
643
|
}
|
|
541
644
|
function writeU8Array(bc, x) {
|
|
542
|
-
|
|
645
|
+
writeUintSafe32(bc, x.length);
|
|
543
646
|
writeU8FixedArray(bc, x);
|
|
544
647
|
}
|
|
545
648
|
function readU8FixedArray(bc, len) {
|
|
546
|
-
return bc
|
|
649
|
+
return readUnsafeU8FixedArray(bc, len).slice();
|
|
547
650
|
}
|
|
548
651
|
function writeU8FixedArray(bc, x) {
|
|
549
652
|
const len = x.length;
|
|
550
|
-
if (len
|
|
551
|
-
|
|
653
|
+
if (len > 0) {
|
|
654
|
+
reserve(bc, len);
|
|
552
655
|
bc.bytes.set(x, bc.offset);
|
|
553
656
|
bc.offset += len;
|
|
554
657
|
}
|
|
555
658
|
}
|
|
659
|
+
function readUnsafeU8FixedArray(bc, len) {
|
|
660
|
+
if (DEV) {
|
|
661
|
+
assert(isU32(len));
|
|
662
|
+
}
|
|
663
|
+
check(bc, len);
|
|
664
|
+
const offset = bc.offset;
|
|
665
|
+
bc.offset += len;
|
|
666
|
+
return bc.bytes.subarray(offset, offset + len);
|
|
667
|
+
}
|
|
556
668
|
|
|
557
669
|
// src/codec/data.ts
|
|
558
670
|
function readData(bc) {
|
|
@@ -562,227 +674,273 @@ function writeData(bc, x) {
|
|
|
562
674
|
writeU8Array(bc, new Uint8Array(x));
|
|
563
675
|
}
|
|
564
676
|
function readFixedData(bc, len) {
|
|
677
|
+
if (DEV) {
|
|
678
|
+
assert(isU32(len));
|
|
679
|
+
}
|
|
565
680
|
return readU8FixedArray(bc, len).buffer;
|
|
566
681
|
}
|
|
567
682
|
function writeFixedData(bc, x) {
|
|
568
683
|
writeU8FixedArray(bc, new Uint8Array(x));
|
|
569
684
|
}
|
|
570
685
|
|
|
571
|
-
// src/util/util.ts
|
|
572
|
-
var IS_LITTLE_ENDIAN_PLATFORM = /* @__PURE__ */ new DataView(Uint16Array.of(1).buffer).getUint8(0) === 1;
|
|
573
|
-
|
|
574
686
|
// src/codec/float-array.ts
|
|
575
|
-
var readF32FixedArray = IS_LITTLE_ENDIAN_PLATFORM ?
|
|
576
|
-
function
|
|
687
|
+
var readF32FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? readF32FixedArrayLe : readF32FixedArrayBe;
|
|
688
|
+
function readF32FixedArrayLe(bc, len) {
|
|
689
|
+
if (DEV) {
|
|
690
|
+
assert(isU32(len));
|
|
691
|
+
}
|
|
577
692
|
const byteLen = len * 4;
|
|
578
693
|
const result = new Float32Array(readFixedData(bc, byteLen));
|
|
579
694
|
return result;
|
|
580
695
|
}
|
|
581
|
-
function
|
|
582
|
-
|
|
696
|
+
function readF32FixedArrayBe(bc, len) {
|
|
697
|
+
if (DEV) {
|
|
698
|
+
assert(isU32(len));
|
|
699
|
+
}
|
|
700
|
+
check(bc, len * 4);
|
|
583
701
|
const result = new Float32Array(len);
|
|
584
|
-
for (let i = 0; i < len; i++)
|
|
702
|
+
for (let i = 0; i < len; i++) {
|
|
585
703
|
result[i] = readF32(bc);
|
|
704
|
+
}
|
|
586
705
|
return result;
|
|
587
706
|
}
|
|
588
|
-
var writeF32FixedArray = IS_LITTLE_ENDIAN_PLATFORM ?
|
|
589
|
-
function
|
|
707
|
+
var writeF32FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? writeF32FixedArrayLe : writeF32FixedArrayBe;
|
|
708
|
+
function writeF32FixedArrayLe(bc, x) {
|
|
590
709
|
writeU8FixedArray(bc, new Uint8Array(x.buffer, x.byteOffset, x.byteLength));
|
|
591
710
|
}
|
|
592
|
-
function
|
|
593
|
-
|
|
594
|
-
for (let i = 0; i < val.length; i++)
|
|
711
|
+
function writeF32FixedArrayBe(bc, val) {
|
|
712
|
+
reserve(bc, val.length * 4);
|
|
713
|
+
for (let i = 0; i < val.length; i++) {
|
|
595
714
|
writeF32(bc, val[i]);
|
|
715
|
+
}
|
|
596
716
|
}
|
|
597
717
|
function readF32Array(bc) {
|
|
598
|
-
return readF32FixedArray(bc,
|
|
718
|
+
return readF32FixedArray(bc, readUintSafe32(bc));
|
|
599
719
|
}
|
|
600
720
|
function writeF32Array(bc, x) {
|
|
601
|
-
|
|
602
|
-
if (x.length
|
|
721
|
+
writeUintSafe32(bc, x.length);
|
|
722
|
+
if (x.length > 0) {
|
|
603
723
|
writeF32FixedArray(bc, x);
|
|
604
724
|
}
|
|
605
725
|
}
|
|
606
|
-
var readF64FixedArray = IS_LITTLE_ENDIAN_PLATFORM ?
|
|
607
|
-
function
|
|
726
|
+
var readF64FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? readF64FixedArrayLe : readF64FixedArrayBe;
|
|
727
|
+
function readF64FixedArrayLe(bc, len) {
|
|
728
|
+
if (DEV) {
|
|
729
|
+
assert(isU32(len));
|
|
730
|
+
}
|
|
608
731
|
const byteLen = len * 8;
|
|
609
732
|
const result = new Float64Array(readFixedData(bc, byteLen));
|
|
610
733
|
return result;
|
|
611
734
|
}
|
|
612
|
-
function
|
|
613
|
-
|
|
735
|
+
function readF64FixedArrayBe(bc, len) {
|
|
736
|
+
if (DEV) {
|
|
737
|
+
assert(isU32(len));
|
|
738
|
+
}
|
|
739
|
+
check(bc, len * 8);
|
|
614
740
|
const result = new Float64Array(len);
|
|
615
|
-
for (let i = 0; i < len; i++)
|
|
741
|
+
for (let i = 0; i < len; i++) {
|
|
616
742
|
result[i] = readF64(bc);
|
|
743
|
+
}
|
|
617
744
|
return result;
|
|
618
745
|
}
|
|
619
|
-
var writeF64FixedArray = IS_LITTLE_ENDIAN_PLATFORM ?
|
|
620
|
-
function
|
|
746
|
+
var writeF64FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? writeF64FixedArrayLe : writeF64FixedArrayBe;
|
|
747
|
+
function writeF64FixedArrayLe(bc, x) {
|
|
621
748
|
writeU8FixedArray(bc, new Uint8Array(x.buffer, x.byteOffset, x.byteLength));
|
|
622
749
|
}
|
|
623
|
-
function
|
|
624
|
-
|
|
625
|
-
for (let i = 0; i < x.length; i++)
|
|
750
|
+
function writeF64FixedArrayBe(bc, x) {
|
|
751
|
+
reserve(bc, x.length * 8);
|
|
752
|
+
for (let i = 0; i < x.length; i++) {
|
|
626
753
|
writeF64(bc, x[i]);
|
|
754
|
+
}
|
|
627
755
|
}
|
|
628
756
|
function readF64Array(bc) {
|
|
629
|
-
return readF64FixedArray(bc,
|
|
757
|
+
return readF64FixedArray(bc, readUintSafe32(bc));
|
|
630
758
|
}
|
|
631
759
|
function writeF64Array(bc, x) {
|
|
632
|
-
|
|
633
|
-
if (x.length
|
|
760
|
+
writeUintSafe32(bc, x.length);
|
|
761
|
+
if (x.length > 0) {
|
|
634
762
|
writeF64FixedArray(bc, x);
|
|
635
763
|
}
|
|
636
764
|
}
|
|
637
765
|
|
|
766
|
+
// src/codec/i8-array.ts
|
|
767
|
+
function readI8Array(bc) {
|
|
768
|
+
return readI8FixedArray(bc, readUintSafe(bc));
|
|
769
|
+
}
|
|
770
|
+
function writeI8Array(bc, x) {
|
|
771
|
+
writeUintSafe32(bc, x.length);
|
|
772
|
+
writeI8FixedArray(bc, x);
|
|
773
|
+
}
|
|
774
|
+
function readI8FixedArray(bc, len) {
|
|
775
|
+
if (DEV) {
|
|
776
|
+
assert(isU32(len));
|
|
777
|
+
}
|
|
778
|
+
return new Int8Array(readFixedData(bc, len));
|
|
779
|
+
}
|
|
780
|
+
function writeI8FixedArray(bc, x) {
|
|
781
|
+
writeU8FixedArray(bc, new Uint8Array(x.buffer, x.byteOffset, x.byteLength));
|
|
782
|
+
}
|
|
783
|
+
|
|
638
784
|
// src/codec/i16-array.ts
|
|
639
|
-
var readI16FixedArray = IS_LITTLE_ENDIAN_PLATFORM ?
|
|
785
|
+
var readI16FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? readI16FixedArrayLe : readI16FixedArrayBe;
|
|
640
786
|
function readI16Array(bc) {
|
|
641
|
-
return readI16FixedArray(bc,
|
|
787
|
+
return readI16FixedArray(bc, readUintSafe32(bc));
|
|
642
788
|
}
|
|
643
|
-
function
|
|
644
|
-
|
|
789
|
+
function readI16FixedArrayLe(bc, len) {
|
|
790
|
+
if (DEV) {
|
|
791
|
+
assert(isU32(len));
|
|
792
|
+
}
|
|
793
|
+
const byteCount = len * 2;
|
|
645
794
|
return new Int16Array(readFixedData(bc, byteCount));
|
|
646
795
|
}
|
|
647
|
-
function
|
|
648
|
-
|
|
796
|
+
function readI16FixedArrayBe(bc, len) {
|
|
797
|
+
if (DEV) {
|
|
798
|
+
assert(isU32(len));
|
|
799
|
+
}
|
|
800
|
+
check(bc, len * 2);
|
|
649
801
|
const result = new Int16Array(len);
|
|
650
|
-
for (let i = 0; i < len; i++)
|
|
802
|
+
for (let i = 0; i < len; i++) {
|
|
651
803
|
result[i] = readI16(bc);
|
|
804
|
+
}
|
|
652
805
|
return result;
|
|
653
806
|
}
|
|
654
|
-
var writeI16FixedArray = IS_LITTLE_ENDIAN_PLATFORM ?
|
|
807
|
+
var writeI16FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? writeI16FixedArrayLe : writeI16FixedArrayBe;
|
|
655
808
|
function writeI16Array(bc, x) {
|
|
656
|
-
|
|
657
|
-
if (x.length
|
|
809
|
+
writeUintSafe32(bc, x.length);
|
|
810
|
+
if (x.length > 0) {
|
|
658
811
|
writeI16FixedArray(bc, x);
|
|
659
812
|
}
|
|
660
813
|
}
|
|
661
|
-
function
|
|
814
|
+
function writeI16FixedArrayLe(bc, x) {
|
|
662
815
|
writeU8FixedArray(bc, new Uint8Array(x.buffer, x.byteOffset, x.byteLength));
|
|
663
816
|
}
|
|
664
|
-
function
|
|
665
|
-
|
|
666
|
-
for (let i = 0; i < x.length; i++)
|
|
817
|
+
function writeI16FixedArrayBe(bc, x) {
|
|
818
|
+
reserve(bc, x.length * 2);
|
|
819
|
+
for (let i = 0; i < x.length; i++) {
|
|
667
820
|
writeI16(bc, x[i]);
|
|
821
|
+
}
|
|
668
822
|
}
|
|
669
823
|
|
|
670
824
|
// src/codec/i32-array.ts
|
|
671
|
-
var readI32FixedArray = IS_LITTLE_ENDIAN_PLATFORM ?
|
|
825
|
+
var readI32FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? readI32FixedArrayLe : readI32FixedArrayBe;
|
|
672
826
|
function readI32Array(bc) {
|
|
673
|
-
return readI32FixedArray(bc,
|
|
827
|
+
return readI32FixedArray(bc, readUintSafe32(bc));
|
|
674
828
|
}
|
|
675
|
-
function
|
|
676
|
-
|
|
829
|
+
function readI32FixedArrayLe(bc, len) {
|
|
830
|
+
if (DEV) {
|
|
831
|
+
assert(isU32(len));
|
|
832
|
+
}
|
|
833
|
+
const byteCount = len * 4;
|
|
677
834
|
return new Int32Array(readFixedData(bc, byteCount));
|
|
678
835
|
}
|
|
679
|
-
function
|
|
680
|
-
|
|
836
|
+
function readI32FixedArrayBe(bc, len) {
|
|
837
|
+
if (DEV) {
|
|
838
|
+
assert(isU32(len));
|
|
839
|
+
}
|
|
840
|
+
check(bc, len * 4);
|
|
681
841
|
const result = new Int32Array(len);
|
|
682
|
-
for (let i = 0; i < len; i++)
|
|
842
|
+
for (let i = 0; i < len; i++) {
|
|
683
843
|
result[i] = readI32(bc);
|
|
844
|
+
}
|
|
684
845
|
return result;
|
|
685
846
|
}
|
|
686
|
-
var writeI32FixedArray = IS_LITTLE_ENDIAN_PLATFORM ?
|
|
847
|
+
var writeI32FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? writeI32FixedArrayLe : writeI32FixedArrayBe;
|
|
687
848
|
function writeI32Array(bc, x) {
|
|
688
|
-
|
|
689
|
-
if (x.length
|
|
849
|
+
writeUintSafe32(bc, x.length);
|
|
850
|
+
if (x.length > 0) {
|
|
690
851
|
writeI32FixedArray(bc, x);
|
|
691
852
|
}
|
|
692
853
|
}
|
|
693
|
-
function
|
|
854
|
+
function writeI32FixedArrayLe(bc, x) {
|
|
694
855
|
writeU8FixedArray(bc, new Uint8Array(x.buffer, x.byteOffset, x.byteLength));
|
|
695
856
|
}
|
|
696
|
-
function
|
|
697
|
-
|
|
698
|
-
for (let i = 0; i < x.length; i++)
|
|
857
|
+
function writeI32FixedArrayBe(bc, x) {
|
|
858
|
+
reserve(bc, x.length * 4);
|
|
859
|
+
for (let i = 0; i < x.length; i++) {
|
|
699
860
|
writeI32(bc, x[i]);
|
|
861
|
+
}
|
|
700
862
|
}
|
|
701
863
|
|
|
702
864
|
// src/codec/i64-array.ts
|
|
703
|
-
var readI64FixedArray = IS_LITTLE_ENDIAN_PLATFORM ?
|
|
865
|
+
var readI64FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? readI64FixedArrayLe : readI64FixedArrayBe;
|
|
704
866
|
function readI64Array(bc) {
|
|
705
|
-
return readI64FixedArray(bc,
|
|
867
|
+
return readI64FixedArray(bc, readUintSafe32(bc));
|
|
706
868
|
}
|
|
707
|
-
function
|
|
708
|
-
|
|
869
|
+
function readI64FixedArrayLe(bc, len) {
|
|
870
|
+
if (DEV) {
|
|
871
|
+
assert(isU32(len));
|
|
872
|
+
}
|
|
873
|
+
const byteCount = len * 8;
|
|
709
874
|
return new BigInt64Array(readFixedData(bc, byteCount));
|
|
710
875
|
}
|
|
711
|
-
function
|
|
712
|
-
|
|
876
|
+
function readI64FixedArrayBe(bc, len) {
|
|
877
|
+
if (DEV) {
|
|
878
|
+
assert(isU32(len));
|
|
879
|
+
}
|
|
880
|
+
check(bc, len * 8);
|
|
713
881
|
const result = new BigInt64Array(len);
|
|
714
|
-
for (let i = 0; i < len; i++)
|
|
882
|
+
for (let i = 0; i < len; i++) {
|
|
715
883
|
result[i] = readI64(bc);
|
|
884
|
+
}
|
|
716
885
|
return result;
|
|
717
886
|
}
|
|
718
|
-
var writeI64FixedArray = IS_LITTLE_ENDIAN_PLATFORM ?
|
|
887
|
+
var writeI64FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? writeI64FixedArrayLe : writeI64FixedArrayBe;
|
|
719
888
|
function writeI64Array(bc, x) {
|
|
720
|
-
|
|
721
|
-
if (x.length
|
|
889
|
+
writeUintSafe32(bc, x.length);
|
|
890
|
+
if (x.length > 0) {
|
|
722
891
|
writeI64FixedArray(bc, x);
|
|
723
892
|
}
|
|
724
893
|
}
|
|
725
|
-
function
|
|
894
|
+
function writeI64FixedArrayLe(bc, x) {
|
|
726
895
|
writeU8FixedArray(bc, new Uint8Array(x.buffer, x.byteOffset, x.byteLength));
|
|
727
896
|
}
|
|
728
|
-
function
|
|
729
|
-
|
|
730
|
-
for (let i = 0; i < x.length; i++)
|
|
897
|
+
function writeI64FixedArrayBe(bc, x) {
|
|
898
|
+
reserve(bc, x.length * 8);
|
|
899
|
+
for (let i = 0; i < x.length; i++) {
|
|
731
900
|
writeI64(bc, x[i]);
|
|
732
|
-
}
|
|
733
|
-
|
|
734
|
-
// src/codec/i8-array.ts
|
|
735
|
-
function readI8Array(bc) {
|
|
736
|
-
return readI8FixedArray(bc, readUintSafe(bc));
|
|
737
|
-
}
|
|
738
|
-
function writeI8Array(bc, x) {
|
|
739
|
-
writeUintSafe(bc, x.length);
|
|
740
|
-
writeI8FixedArray(bc, x);
|
|
741
|
-
}
|
|
742
|
-
function readI8FixedArray(bc, len) {
|
|
743
|
-
return new Int8Array(readFixedData(bc, len));
|
|
744
|
-
}
|
|
745
|
-
function writeI8FixedArray(bc, x) {
|
|
746
|
-
writeU8FixedArray(bc, new Uint8Array(x.buffer, x.byteOffset, x.byteLength));
|
|
901
|
+
}
|
|
747
902
|
}
|
|
748
903
|
|
|
749
904
|
// src/codec/string.ts
|
|
750
905
|
function readString(bc) {
|
|
751
|
-
return readFixedString(bc,
|
|
906
|
+
return readFixedString(bc, readUintSafe32(bc));
|
|
752
907
|
}
|
|
753
908
|
function writeString(bc, x) {
|
|
754
|
-
if (x.length <
|
|
909
|
+
if (x.length < TEXT_ENCODER_THRESHOLD) {
|
|
755
910
|
const byteLen = utf8ByteLength(x);
|
|
756
|
-
|
|
757
|
-
|
|
911
|
+
writeUintSafe32(bc, byteLen);
|
|
912
|
+
reserve(bc, byteLen);
|
|
758
913
|
writeUtf8Js(bc, x);
|
|
759
914
|
} else {
|
|
760
915
|
const strBytes = UTF8_ENCODER.encode(x);
|
|
761
|
-
|
|
916
|
+
writeUintSafe32(bc, strBytes.length);
|
|
762
917
|
writeU8FixedArray(bc, strBytes);
|
|
763
918
|
}
|
|
764
919
|
}
|
|
765
920
|
function readFixedString(bc, byteLen) {
|
|
766
|
-
if (
|
|
921
|
+
if (DEV) {
|
|
922
|
+
assert(isU32(byteLen));
|
|
923
|
+
}
|
|
924
|
+
if (byteLen < TEXT_DECODER_THRESHOLD) {
|
|
767
925
|
return readUtf8Js(bc, byteLen);
|
|
768
926
|
}
|
|
769
927
|
try {
|
|
770
|
-
return UTF8_DECODER.decode(bc
|
|
771
|
-
} catch (
|
|
928
|
+
return UTF8_DECODER.decode(readUnsafeU8FixedArray(bc, byteLen));
|
|
929
|
+
} catch (_cause) {
|
|
772
930
|
throw new BareError(bc.offset, INVALID_UTF8_STRING);
|
|
773
931
|
}
|
|
774
932
|
}
|
|
775
933
|
function writeFixedString(bc, x) {
|
|
776
|
-
if (x.length <
|
|
934
|
+
if (x.length < TEXT_ENCODER_THRESHOLD) {
|
|
777
935
|
const byteLen = utf8ByteLength(x);
|
|
778
|
-
|
|
936
|
+
reserve(bc, byteLen);
|
|
779
937
|
writeUtf8Js(bc, x);
|
|
780
938
|
} else {
|
|
781
939
|
writeU8FixedArray(bc, UTF8_ENCODER.encode(x));
|
|
782
940
|
}
|
|
783
941
|
}
|
|
784
942
|
function readUtf8Js(bc, byteLen) {
|
|
785
|
-
|
|
943
|
+
check(bc, byteLen);
|
|
786
944
|
let result = "";
|
|
787
945
|
const bytes = bc.bytes;
|
|
788
946
|
let offset = bc.offset;
|
|
@@ -795,18 +953,29 @@ function readUtf8Js(bc, byteLen) {
|
|
|
795
953
|
if (offset < upperOffset && codePoint < 224) {
|
|
796
954
|
const byte2 = bytes[offset++];
|
|
797
955
|
codePoint = (byte1 & 31) << 6 | byte2 & 63;
|
|
798
|
-
malformed = codePoint >> 7 === 0 ||
|
|
956
|
+
malformed = codePoint >> 7 === 0 || // non-canonical char
|
|
957
|
+
byte1 >> 5 !== 6 || // invalid tag
|
|
958
|
+
byte2 >> 6 !== 2;
|
|
799
959
|
} else if (offset + 1 < upperOffset && codePoint < 240) {
|
|
800
960
|
const byte2 = bytes[offset++];
|
|
801
961
|
const byte3 = bytes[offset++];
|
|
802
962
|
codePoint = (byte1 & 15) << 12 | (byte2 & 63) << 6 | byte3 & 63;
|
|
803
|
-
malformed = codePoint >> 11 === 0 ||
|
|
963
|
+
malformed = codePoint >> 11 === 0 || // non-canonical char or missing data
|
|
964
|
+
codePoint >> 11 === 27 || // surrogate char (0xD800 <= codePoint <= 0xDFFF)
|
|
965
|
+
byte1 >> 4 !== 14 || // invalid tag
|
|
966
|
+
byte2 >> 6 !== 2 || // invalid tag
|
|
967
|
+
byte3 >> 6 !== 2;
|
|
804
968
|
} else if (offset + 2 < upperOffset) {
|
|
805
969
|
const byte2 = bytes[offset++];
|
|
806
970
|
const byte3 = bytes[offset++];
|
|
807
971
|
const byte4 = bytes[offset++];
|
|
808
972
|
codePoint = (byte1 & 7) << 18 | (byte2 & 63) << 12 | (byte3 & 63) << 6 | byte4 & 63;
|
|
809
|
-
malformed = codePoint >> 16 === 0 ||
|
|
973
|
+
malformed = codePoint >> 16 === 0 || // non-canonical char or missing data
|
|
974
|
+
codePoint > 1114111 || // too large code point
|
|
975
|
+
byte1 >> 3 !== 30 || // invalid tag
|
|
976
|
+
byte2 >> 6 !== 2 || // invalid tag
|
|
977
|
+
byte3 >> 6 !== 2 || // invalid tag
|
|
978
|
+
byte4 >> 6 !== 2;
|
|
810
979
|
}
|
|
811
980
|
if (malformed) {
|
|
812
981
|
throw new BareError(bc.offset, INVALID_UTF8_STRING);
|
|
@@ -862,122 +1031,170 @@ function utf8ByteLength(s) {
|
|
|
862
1031
|
var UTF8_DECODER = /* @__PURE__ */ new TextDecoder("utf-8", { fatal: true });
|
|
863
1032
|
var UTF8_ENCODER = /* @__PURE__ */ new TextEncoder();
|
|
864
1033
|
|
|
1034
|
+
// src/codec/u8-clamped-array.ts
|
|
1035
|
+
function readU8ClampedArray(bc) {
|
|
1036
|
+
return readU8ClampedFixedArray(bc, readUintSafe32(bc));
|
|
1037
|
+
}
|
|
1038
|
+
function writeU8ClampedArray(bc, x) {
|
|
1039
|
+
writeUintSafe32(bc, x.length);
|
|
1040
|
+
writeU8ClampedFixedArray(bc, x);
|
|
1041
|
+
}
|
|
1042
|
+
function readU8ClampedFixedArray(bc, len) {
|
|
1043
|
+
if (DEV) {
|
|
1044
|
+
assert(isU32(len));
|
|
1045
|
+
}
|
|
1046
|
+
return new Uint8ClampedArray(readFixedData(bc, len));
|
|
1047
|
+
}
|
|
1048
|
+
function writeU8ClampedFixedArray(bc, x) {
|
|
1049
|
+
writeU8FixedArray(bc, new Uint8Array(x.buffer, x.byteOffset, x.byteLength));
|
|
1050
|
+
}
|
|
1051
|
+
|
|
865
1052
|
// src/codec/u16-array.ts
|
|
866
|
-
var readU16FixedArray = IS_LITTLE_ENDIAN_PLATFORM ?
|
|
1053
|
+
var readU16FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? readU16FixedArrayLe : readU16FixedArrayBe;
|
|
867
1054
|
function readU16Array(bc) {
|
|
868
|
-
return readU16FixedArray(bc,
|
|
1055
|
+
return readU16FixedArray(bc, readUintSafe32(bc));
|
|
869
1056
|
}
|
|
870
|
-
function
|
|
871
|
-
|
|
1057
|
+
function readU16FixedArrayLe(bc, len) {
|
|
1058
|
+
if (DEV) {
|
|
1059
|
+
assert(isU32(len));
|
|
1060
|
+
}
|
|
1061
|
+
const byteCount = len * 2;
|
|
872
1062
|
return new Uint16Array(readFixedData(bc, byteCount));
|
|
873
1063
|
}
|
|
874
|
-
function
|
|
875
|
-
|
|
1064
|
+
function readU16FixedArrayBe(bc, len) {
|
|
1065
|
+
if (DEV) {
|
|
1066
|
+
assert(isU32(len));
|
|
1067
|
+
}
|
|
1068
|
+
check(bc, len * 2);
|
|
876
1069
|
const result = new Uint16Array(len);
|
|
877
|
-
for (let i = 0; i < len; i++)
|
|
1070
|
+
for (let i = 0; i < len; i++) {
|
|
878
1071
|
result[i] = readU16(bc);
|
|
1072
|
+
}
|
|
879
1073
|
return result;
|
|
880
1074
|
}
|
|
881
|
-
var writeU16FixedArray = IS_LITTLE_ENDIAN_PLATFORM ?
|
|
1075
|
+
var writeU16FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? writeU16FixedArrayLe : writeU16FixedArrayBe;
|
|
882
1076
|
function writeU16Array(bc, x) {
|
|
883
|
-
|
|
884
|
-
if (x.length
|
|
1077
|
+
writeUintSafe32(bc, x.length);
|
|
1078
|
+
if (x.length > 0) {
|
|
885
1079
|
writeU16FixedArray(bc, x);
|
|
886
1080
|
}
|
|
887
1081
|
}
|
|
888
|
-
function
|
|
1082
|
+
function writeU16FixedArrayLe(bc, x) {
|
|
889
1083
|
writeU8FixedArray(bc, new Uint8Array(x.buffer, x.byteOffset, x.byteLength));
|
|
890
1084
|
}
|
|
891
|
-
function
|
|
892
|
-
|
|
893
|
-
for (let i = 0; i < x.length; i++)
|
|
1085
|
+
function writeU16FixedArrayBe(bc, x) {
|
|
1086
|
+
reserve(bc, x.length * 2);
|
|
1087
|
+
for (let i = 0; i < x.length; i++) {
|
|
894
1088
|
writeU16(bc, x[i]);
|
|
1089
|
+
}
|
|
895
1090
|
}
|
|
896
1091
|
|
|
897
1092
|
// src/codec/u32-array.ts
|
|
898
|
-
var readU32FixedArray = IS_LITTLE_ENDIAN_PLATFORM ?
|
|
1093
|
+
var readU32FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? readU32FixedArrayLe : readU32FixedArrayBe;
|
|
899
1094
|
function readU32Array(bc) {
|
|
900
|
-
return readU32FixedArray(bc,
|
|
1095
|
+
return readU32FixedArray(bc, readUintSafe32(bc));
|
|
901
1096
|
}
|
|
902
|
-
function
|
|
903
|
-
|
|
1097
|
+
function readU32FixedArrayLe(bc, len) {
|
|
1098
|
+
if (DEV) {
|
|
1099
|
+
assert(isU32(len));
|
|
1100
|
+
}
|
|
1101
|
+
const byteCount = len * 4;
|
|
904
1102
|
return new Uint32Array(readFixedData(bc, byteCount));
|
|
905
1103
|
}
|
|
906
|
-
function
|
|
907
|
-
|
|
1104
|
+
function readU32FixedArrayBe(bc, len) {
|
|
1105
|
+
if (DEV) {
|
|
1106
|
+
assert(isU32(len));
|
|
1107
|
+
}
|
|
1108
|
+
check(bc, len * 4);
|
|
908
1109
|
const result = new Uint32Array(len);
|
|
909
|
-
for (let i = 0; i < len; i++)
|
|
1110
|
+
for (let i = 0; i < len; i++) {
|
|
910
1111
|
result[i] = readU32(bc);
|
|
1112
|
+
}
|
|
911
1113
|
return result;
|
|
912
1114
|
}
|
|
913
|
-
var writeU32FixedArray = IS_LITTLE_ENDIAN_PLATFORM ?
|
|
1115
|
+
var writeU32FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? writeU32FixedArrayLe : writeU32FixedArrayBe;
|
|
914
1116
|
function writeU32Array(bc, x) {
|
|
915
|
-
|
|
916
|
-
if (x.length
|
|
1117
|
+
writeUintSafe32(bc, x.length);
|
|
1118
|
+
if (x.length > 0) {
|
|
917
1119
|
writeU32FixedArray(bc, x);
|
|
918
1120
|
}
|
|
919
1121
|
}
|
|
920
|
-
function
|
|
1122
|
+
function writeU32FixedArrayLe(bc, x) {
|
|
921
1123
|
writeU8FixedArray(bc, new Uint8Array(x.buffer, x.byteOffset, x.byteLength));
|
|
922
1124
|
}
|
|
923
|
-
function
|
|
924
|
-
|
|
925
|
-
for (let i = 0; i < x.length; i++)
|
|
1125
|
+
function writeU32FixedArrayBe(bc, x) {
|
|
1126
|
+
reserve(bc, x.length * 4);
|
|
1127
|
+
for (let i = 0; i < x.length; i++) {
|
|
926
1128
|
writeU32(bc, x[i]);
|
|
1129
|
+
}
|
|
927
1130
|
}
|
|
928
1131
|
|
|
929
1132
|
// src/codec/u64-array.ts
|
|
930
|
-
var readU64FixedArray = IS_LITTLE_ENDIAN_PLATFORM ?
|
|
1133
|
+
var readU64FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? readU64FixedArrayLe : readU64FixedArrayBe;
|
|
931
1134
|
function readU64Array(bc) {
|
|
932
|
-
return readU64FixedArray(bc,
|
|
1135
|
+
return readU64FixedArray(bc, readUintSafe32(bc));
|
|
933
1136
|
}
|
|
934
|
-
function
|
|
935
|
-
|
|
1137
|
+
function readU64FixedArrayLe(bc, len) {
|
|
1138
|
+
if (DEV) {
|
|
1139
|
+
assert(isU32(len));
|
|
1140
|
+
}
|
|
1141
|
+
const byteCount = len * 8;
|
|
936
1142
|
return new BigUint64Array(readFixedData(bc, byteCount));
|
|
937
1143
|
}
|
|
938
|
-
function
|
|
939
|
-
|
|
1144
|
+
function readU64FixedArrayBe(bc, len) {
|
|
1145
|
+
if (DEV) {
|
|
1146
|
+
assert(isU32(len));
|
|
1147
|
+
}
|
|
1148
|
+
check(bc, len * 8);
|
|
940
1149
|
const result = new BigUint64Array(len);
|
|
941
|
-
for (let i = 0; i < len; i++)
|
|
1150
|
+
for (let i = 0; i < len; i++) {
|
|
942
1151
|
result[i] = readU64(bc);
|
|
1152
|
+
}
|
|
943
1153
|
return result;
|
|
944
1154
|
}
|
|
945
|
-
var writeU64FixedArray = IS_LITTLE_ENDIAN_PLATFORM ?
|
|
1155
|
+
var writeU64FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? writeU64FixedArrayLe : writeU64FixedArrayBe;
|
|
946
1156
|
function writeU64Array(bc, x) {
|
|
947
|
-
|
|
948
|
-
if (x.length
|
|
1157
|
+
writeUintSafe32(bc, x.length);
|
|
1158
|
+
if (x.length > 0) {
|
|
949
1159
|
writeU64FixedArray(bc, x);
|
|
950
1160
|
}
|
|
951
1161
|
}
|
|
952
|
-
function
|
|
1162
|
+
function writeU64FixedArrayLe(bc, x) {
|
|
953
1163
|
writeU8FixedArray(bc, new Uint8Array(x.buffer, x.byteOffset, x.byteLength));
|
|
954
1164
|
}
|
|
955
|
-
function
|
|
956
|
-
|
|
957
|
-
for (let i = 0; i < x.length; i++)
|
|
1165
|
+
function writeU64FixedArrayBe(bc, x) {
|
|
1166
|
+
reserve(bc, x.length * 8);
|
|
1167
|
+
for (let i = 0; i < x.length; i++) {
|
|
958
1168
|
writeU64(bc, x[i]);
|
|
1169
|
+
}
|
|
959
1170
|
}
|
|
960
1171
|
|
|
961
|
-
// src/
|
|
962
|
-
function
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
1172
|
+
// src/core/config.ts
|
|
1173
|
+
function Config({
|
|
1174
|
+
initialBufferLength = 1024,
|
|
1175
|
+
maxBufferLength = 1024 * 1024 * 32
|
|
1176
|
+
}) {
|
|
1177
|
+
if (DEV) {
|
|
1178
|
+
assert(isU32(initialBufferLength), TOO_LARGE_NUMBER);
|
|
1179
|
+
assert(isU32(maxBufferLength), TOO_LARGE_NUMBER);
|
|
1180
|
+
assert(
|
|
1181
|
+
initialBufferLength <= maxBufferLength,
|
|
1182
|
+
"initialBufferLength must be lower than or equal to maxBufferLength"
|
|
1183
|
+
);
|
|
1184
|
+
}
|
|
1185
|
+
return {
|
|
1186
|
+
initialBufferLength,
|
|
1187
|
+
maxBufferLength
|
|
1188
|
+
};
|
|
974
1189
|
}
|
|
975
|
-
|
|
1190
|
+
var DEFAULT_CONFIG = /* @__PURE__ */ Config({});
|
|
976
1191
|
// Annotate the CommonJS export names for ESM import in node:
|
|
977
1192
|
0 && (module.exports = {
|
|
978
1193
|
BareError,
|
|
979
1194
|
ByteCursor,
|
|
980
1195
|
Config,
|
|
1196
|
+
DEFAULT_CONFIG,
|
|
1197
|
+
check,
|
|
981
1198
|
readBool,
|
|
982
1199
|
readData,
|
|
983
1200
|
readF32,
|
|
@@ -1021,6 +1238,9 @@ module.exports = __toCommonJS(src_exports);
|
|
|
1021
1238
|
readU8FixedArray,
|
|
1022
1239
|
readUint,
|
|
1023
1240
|
readUintSafe,
|
|
1241
|
+
readUintSafe32,
|
|
1242
|
+
readUnsafeU8FixedArray,
|
|
1243
|
+
reserve,
|
|
1024
1244
|
writeBool,
|
|
1025
1245
|
writeData,
|
|
1026
1246
|
writeF32,
|
|
@@ -1063,5 +1283,6 @@ module.exports = __toCommonJS(src_exports);
|
|
|
1063
1283
|
writeU8ClampedFixedArray,
|
|
1064
1284
|
writeU8FixedArray,
|
|
1065
1285
|
writeUint,
|
|
1066
|
-
writeUintSafe
|
|
1286
|
+
writeUintSafe,
|
|
1287
|
+
writeUintSafe32
|
|
1067
1288
|
});
|