@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.
Files changed (44) hide show
  1. package/README.md +12 -2
  2. package/dist/codec/data.d.ts +4 -4
  3. package/dist/codec/data.js +26 -0
  4. package/dist/codec/float-array.d.ts +12 -12
  5. package/dist/codec/float-array.js +85 -0
  6. package/dist/codec/i16-array.d.ts +6 -6
  7. package/dist/codec/i16-array.js +43 -0
  8. package/dist/codec/i32-array.d.ts +6 -6
  9. package/dist/codec/i32-array.js +43 -0
  10. package/dist/codec/i64-array.d.ts +6 -6
  11. package/dist/codec/i64-array.js +43 -0
  12. package/dist/codec/i8-array.d.ts +4 -4
  13. package/dist/codec/i8-array.js +24 -0
  14. package/dist/codec/index.js +15 -0
  15. package/dist/codec/primitive.d.ts +34 -36
  16. package/dist/codec/primitive.js +345 -0
  17. package/dist/codec/string.d.ts +4 -2
  18. package/dist/codec/string.js +126 -0
  19. package/dist/codec/u16-array.d.ts +6 -6
  20. package/dist/codec/u16-array.js +43 -0
  21. package/dist/codec/u32-array.d.ts +6 -6
  22. package/dist/codec/u32-array.js +43 -0
  23. package/dist/codec/u64-array.d.ts +6 -6
  24. package/dist/codec/u64-array.js +43 -0
  25. package/dist/codec/u8-array.d.ts +4 -4
  26. package/dist/codec/u8-array.js +27 -0
  27. package/dist/codec/u8-clamped-array.d.ts +4 -4
  28. package/dist/codec/u8-clamped-array.js +24 -0
  29. package/dist/core/bare-error.js +14 -0
  30. package/dist/core/byte-cursor.d.ts +26 -8
  31. package/dist/core/byte-cursor.js +42 -0
  32. package/dist/core/config.d.ts +6 -1
  33. package/dist/core/config.js +27 -0
  34. package/dist/core/index.js +5 -0
  35. package/dist/index.cjs +591 -636
  36. package/dist/index.js +3 -987
  37. package/dist/util/assert.d.ts +6 -1
  38. package/dist/util/assert.js +1 -4
  39. package/dist/util/constants.d.ts +13 -0
  40. package/dist/util/constants.js +30 -0
  41. package/dist/util/util.js +6 -0
  42. package/dist/util/validator.js +40 -0
  43. package/package.json +16 -14
  44. 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
- decodeBool: () => decodeBool,
36
- decodeData: () => decodeData,
37
- decodeF32: () => decodeF32,
38
- decodeF32Array: () => decodeF32Array,
39
- decodeF32FixedArray: () => decodeF32FixedArray,
40
- decodeF64: () => decodeF64,
41
- decodeF64Array: () => decodeF64Array,
42
- decodeF64FixedArray: () => decodeF64FixedArray,
43
- decodeFixedData: () => decodeFixedData,
44
- decodeI16: () => decodeI16,
45
- decodeI16Array: () => decodeI16Array,
46
- decodeI16FixedArray: () => decodeI16FixedArray,
47
- decodeI32: () => decodeI32,
48
- decodeI32Array: () => decodeI32Array,
49
- decodeI32FixedArray: () => decodeI32FixedArray,
50
- decodeI64: () => decodeI64,
51
- decodeI64Array: () => decodeI64Array,
52
- decodeI64FixedArray: () => decodeI64FixedArray,
53
- decodeI64Safe: () => decodeI64Safe,
54
- decodeI8: () => decodeI8,
55
- decodeI8Array: () => decodeI8Array,
56
- decodeI8FixedArray: () => decodeI8FixedArray,
57
- decodeInt: () => decodeInt,
58
- decodeIntSafe: () => decodeIntSafe,
59
- decodeString: () => decodeString,
60
- decodeU16: () => decodeU16,
61
- decodeU16Array: () => decodeU16Array,
62
- decodeU16FixedArray: () => decodeU16FixedArray,
63
- decodeU32: () => decodeU32,
64
- decodeU32Array: () => decodeU32Array,
65
- decodeU32FixedArray: () => decodeU32FixedArray,
66
- decodeU64: () => decodeU64,
67
- decodeU64Array: () => decodeU64Array,
68
- decodeU64FixedArray: () => decodeU64FixedArray,
69
- decodeU64Safe: () => decodeU64Safe,
70
- decodeU8: () => decodeU8,
71
- decodeU8Array: () => decodeU8Array,
72
- decodeU8ClampedArray: () => decodeU8ClampedArray,
73
- decodeU8ClampedFixedArray: () => decodeU8ClampedFixedArray,
74
- decodeU8FixedArray: () => decodeU8FixedArray,
75
- decodeUint: () => decodeUint,
76
- decodeUintSafe: () => decodeUintSafe,
77
- decodeVoid: () => decodeVoid,
78
- encodeBool: () => encodeBool,
79
- encodeData: () => encodeData,
80
- encodeF32: () => encodeF32,
81
- encodeF32Array: () => encodeF32Array,
82
- encodeF32FixedArray: () => encodeF32FixedArray,
83
- encodeF64: () => encodeF64,
84
- encodeF64Array: () => encodeF64Array,
85
- encodeF64FixedArray: () => encodeF64FixedArray,
86
- encodeFixedData: () => encodeFixedData,
87
- encodeI16: () => encodeI16,
88
- encodeI16Array: () => encodeI16Array,
89
- encodeI16FixedArray: () => encodeI16FixedArray,
90
- encodeI32: () => encodeI32,
91
- encodeI32Array: () => encodeI32Array,
92
- encodeI32FixedArray: () => encodeI32FixedArray,
93
- encodeI64: () => encodeI64,
94
- encodeI64Array: () => encodeI64Array,
95
- encodeI64FixedArray: () => encodeI64FixedArray,
96
- encodeI64Safe: () => encodeI64Safe,
97
- encodeI8: () => encodeI8,
98
- encodeI8Array: () => encodeI8Array,
99
- encodeI8FixedArray: () => encodeI8FixedArray,
100
- encodeInt: () => encodeInt,
101
- encodeIntSafe: () => encodeIntSafe,
102
- encodeString: () => encodeString,
103
- encodeU16: () => encodeU16,
104
- encodeU16Array: () => encodeU16Array,
105
- encodeU16FixedArray: () => encodeU16FixedArray,
106
- encodeU32: () => encodeU32,
107
- encodeU32Array: () => encodeU32Array,
108
- encodeU32FixedArray: () => encodeU32FixedArray,
109
- encodeU64: () => encodeU64,
110
- encodeU64Array: () => encodeU64Array,
111
- encodeU64FixedArray: () => encodeU64FixedArray,
112
- encodeU64Safe: () => encodeU64Safe,
113
- encodeU8: () => encodeU8,
114
- encodeU8Array: () => encodeU8Array,
115
- encodeU8ClampedArray: () => encodeU8ClampedArray,
116
- encodeU8ClampedFixedArray: () => encodeU8ClampedFixedArray,
117
- encodeU8FixedArray: () => encodeU8FixedArray,
118
- encodeUint: () => encodeUint,
119
- encodeUintSafe: () => encodeUintSafe,
120
- encodeVoid: () => encodeVoid
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/codec/u8-array.ts
124
- var import_assert4 = __toESM(require("assert"), 1);
125
-
126
- // src/codec/primitive.ts
127
- var import_assert3 = __toESM(require("assert"), 1);
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/core/config.ts
141
- var import_assert = __toESM(require("assert"), 1);
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
- var TOO_LARGE_NUMBER = "too large number";
174
- var initialBufferLength = 1024;
175
- var maxBufferLength = 1024 * 1024 * 32;
176
- var textDecoderThreshold = 256;
177
- var textEncoderThreshold = 256;
178
- function Config(part) {
179
- const config = Object.assign({
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
- }, part);
185
- (0, import_assert.default)(isU32(config.initialBufferLength), TOO_LARGE_NUMBER);
186
- (0, import_assert.default)(isU32(config.maxBufferLength), TOO_LARGE_NUMBER);
187
- (0, import_assert.default)(isU32(config.textDecoderThreshold), TOO_LARGE_NUMBER);
188
- (0, import_assert.default)(isU32(config.textEncoderThreshold), TOO_LARGE_NUMBER);
189
- (0, import_assert.default)(config.initialBufferLength <= config.maxBufferLength, "initialBufferLength must be lower than or equal to maxBufferLength");
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
- this.config = config;
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.view.byteLength) {
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 { config, offset, view } = this;
212
- if (offset + min > view.byteLength) {
213
- const bytes = new Uint8Array(view.buffer);
214
- const minExtraLength = min + offset - view.byteLength;
215
- (0, import_assert2.default)(bytes.length === view.byteOffset + view.byteLength, "un-growable buffer");
216
- (0, import_assert2.default)(bytes.length + minExtraLength <= config.maxBufferLength, TOO_LARGE_BUFFER);
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.view = new DataView(newBytes.buffer, view.byteOffset);
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 bufferOffset = this.view.byteOffset + this.offset;
242
+ const offset = this.offset;
226
243
  this.offset += len;
227
- return new Uint8Array(this.view.buffer, bufferOffset, len);
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
- var NAN_NOT_ALLOWED = "NaN is not allowed";
242
- var NON_CANONICAL_REPRESENTATION = "must be canonical";
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 encodeBool(bc, x) {
253
- encodeU8(bc, x ? 1 : 0);
257
+ function writeBool(bc, x) {
258
+ writeU8(bc, x ? 1 : 0);
254
259
  }
255
- function decodeF32(bc) {
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 encodeF32(bc, x) {
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
- (0, import_assert3.default)(Math.abs(bc.view.getFloat32(bc.offset, true) - x) <= Number.EPSILON, TOO_LARGE_NUMBER2);
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 decodeF64(bc) {
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 encodeF64(bc, x) {
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 decodeI8(bc) {
283
+ function readI8(bc) {
287
284
  bc.check(1);
288
285
  return bc.view.getInt8(bc.offset++);
289
286
  }
290
- function encodeI8(bc, x) {
291
- (0, import_assert3.default)(isI8(x), TOO_LARGE_NUMBER2);
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 decodeI16(bc) {
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 encodeI16(bc, x) {
302
- (0, import_assert3.default)(isI16(x), TOO_LARGE_NUMBER2);
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 decodeI32(bc) {
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 encodeI32(bc, x) {
314
- (0, import_assert3.default)(isI32(x), TOO_LARGE_NUMBER2);
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 decodeI64(bc) {
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 encodeI64(bc, x) {
326
- (0, import_assert3.default)(isI64(x), TOO_LARGE_NUMBER2);
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 decodeI64Safe(bc) {
332
- const result = decodeU32(bc) + decodeI32(bc) * 4294967296;
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, TOO_LARGE_NUMBER2);
332
+ throw new BareError(bc.offset, TOO_LARGE_NUMBER);
336
333
  }
337
334
  return result;
338
335
  }
339
- function encodeI64Safe(bc, x) {
340
- (0, import_assert3.default)(Number.isSafeInteger(x), TOO_LARGE_NUMBER2);
336
+ function writeI64Safe(bc, x) {
337
+ assert(Number.isSafeInteger(x), TOO_LARGE_NUMBER);
341
338
  const lowest32 = x >>> 0;
342
- encodeU32(bc, lowest32);
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
- encodeU32(bc, highest32);
347
+ writeU32(bc, highest32);
351
348
  }
352
- function decodeInt(bc) {
353
- const zigZag = decodeUint(bc);
349
+ function readInt(bc) {
350
+ const zigZag = readUint(bc);
354
351
  return zigZag >> BigInt(1) ^ -(zigZag & BigInt(1));
355
352
  }
356
- function encodeInt(bc, x) {
357
- (0, import_assert3.default)(isI64(x), TOO_LARGE_NUMBER2);
353
+ function writeInt(bc, x) {
354
+ assert(isI64(x), TOO_LARGE_NUMBER);
358
355
  const zigZag = x >> BigInt(63) ^ x << BigInt(1);
359
- encodeUint(bc, zigZag);
356
+ writeUint(bc, zigZag);
360
357
  }
361
- var INT_SAFE_MAX_BYTE_COUNT = 8;
362
- function decodeIntSafe(bc) {
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 = decodeU8(bc);
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, TOO_LARGE_NUMBER2);
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 encodeIntSafe(bc, x) {
391
- (0, import_assert3.default)(Number.isSafeInteger(x), TOO_LARGE_NUMBER2);
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
- encodeU8(bc, 128 | firstByte);
400
- encodeUintSafe(bc, x);
395
+ writeU8(bc, 128 | firstByte);
396
+ writeUintSafe(bc, x);
401
397
  } else {
402
- encodeU8(bc, firstByte);
398
+ writeU8(bc, firstByte);
403
399
  }
404
400
  }
405
- function decodeU8(bc) {
401
+ function readU8(bc) {
406
402
  bc.check(1);
407
- return bc.view.getUint8(bc.offset++);
403
+ return bc.bytes[bc.offset++];
408
404
  }
409
- function encodeU8(bc, x) {
410
- (0, import_assert3.default)(isU8(x), TOO_LARGE_NUMBER2);
405
+ function writeU8(bc, x) {
406
+ assert(isU8(x), TOO_LARGE_NUMBER);
411
407
  bc.reserve(1);
412
- bc.view.setUint8(bc.offset++, x);
408
+ bc.bytes[bc.offset++] = x;
413
409
  }
414
- function decodeU16(bc) {
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 encodeU16(bc, x) {
421
- (0, import_assert3.default)(isU16(x), TOO_LARGE_NUMBER2);
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 decodeU32(bc) {
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 encodeU32(bc, x) {
433
- (0, import_assert3.default)(isU32(x), TOO_LARGE_NUMBER2);
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 decodeU64(bc) {
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 encodeU64(bc, x) {
445
- (0, import_assert3.default)(isU64(x), TOO_LARGE_NUMBER2);
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 decodeU64Safe(bc) {
451
- const result = decodeU32(bc) + decodeU32(bc) * 4294967296;
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, TOO_LARGE_NUMBER2);
450
+ throw new BareError(bc.offset, TOO_LARGE_NUMBER);
455
451
  }
456
452
  return result;
457
453
  }
458
- function encodeU64Safe(bc, x) {
459
- (0, import_assert3.default)(isSafeU64(x), TOO_LARGE_NUMBER2);
460
- encodeU32(bc, x >>> 0);
461
- encodeU32(bc, x / 4294967296 >>> 0);
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
- var UINT_MAX_BYTE_COUNT = 10;
464
- function decodeUint(bc) {
465
- let byteCount = 0;
466
- let byte;
467
- let low = 0;
468
- let shiftMul = 1;
469
- do {
470
- byte = decodeU8(bc);
471
- low += (byte & 127) * shiftMul;
472
- shiftMul *= 128;
473
- byteCount++;
474
- } while (byte >= 128 && byteCount < 7);
475
- let height = 0;
476
- shiftMul = 1;
477
- while (byte >= 128 && byteCount < UINT_MAX_BYTE_COUNT) {
478
- byte = decodeU8(bc);
479
- height += (byte & 127) * shiftMul;
480
- shiftMul *= 128;
481
- byteCount++;
482
- }
483
- if (byteCount !== 1 && byte === 0 || byteCount === UINT_MAX_BYTE_COUNT && byte > 1) {
484
- bc.offset -= byteCount;
485
- throw new BareError(bc.offset, NON_CANONICAL_REPRESENTATION);
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) + (BigInt(height) << BigInt(7 * 7));
486
+ return BigInt(low);
488
487
  }
489
- function encodeUint(bc, x) {
490
- (0, import_assert3.default)(isU64(x), TOO_LARGE_NUMBER2);
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
- encodeU8(bc, 128 | tmp & 127);
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
- encodeU8(bc, tmp);
502
+ writeU8(bc, tmp);
504
503
  }
505
- var UINT_SAFE_MAX_BYTE_COUNT = 8;
506
- function decodeUintSafe(bc) {
507
- let result = 0;
508
- let shiftMul = 1;
509
- let byteCount = 0;
510
- let byte;
511
- do {
512
- byte = decodeU8(bc);
513
- result += (byte & 127) * shiftMul;
514
- shiftMul *= 128;
515
- byteCount++;
516
- } while (byte >= 128 && byteCount < UINT_SAFE_MAX_BYTE_COUNT);
517
- if (byteCount !== 1 && 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_NUMBER2);
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 encodeUintSafe(bc, x) {
528
- (0, import_assert3.default)(isSafeU64(x), TOO_LARGE_NUMBER2);
528
+ function writeUintSafe(bc, x) {
529
+ assert(isSafeU64(x), TOO_LARGE_NUMBER);
529
530
  while (x >= 128) {
530
- encodeU8(bc, 128 | x & 127);
531
+ writeU8(bc, 128 | x & 127);
531
532
  x = Math.floor(x / 128);
532
533
  }
533
- encodeU8(bc, x);
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 decodeU8Array(bc) {
543
- const len = decodeUintSafe(bc);
544
- return bc.read(len).slice();
538
+ function readU8Array(bc) {
539
+ return readU8FixedArray(bc, readUintSafe(bc));
545
540
  }
546
- function encodeU8Array(bc, x) {
547
- encodeUintSafe(bc, x.length);
548
- bc.write(x);
541
+ function writeU8Array(bc, x) {
542
+ writeUintSafe(bc, x.length);
543
+ writeU8FixedArray(bc, x);
549
544
  }
550
- function decodeU8FixedArray(bc, len) {
545
+ function readU8FixedArray(bc, len) {
551
546
  return bc.read(len).slice();
552
547
  }
553
- function encodeU8FixedArray(bc, x, len) {
554
- (0, import_assert4.default)(x.length === len);
555
- bc.write(x);
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 decodeData(bc) {
560
- return decodeU8Array(bc).buffer;
558
+ function readData(bc) {
559
+ return readU8Array(bc).buffer;
561
560
  }
562
- function encodeData(bc, x) {
563
- encodeU8Array(bc, new Uint8Array(x));
561
+ function writeData(bc, x) {
562
+ writeU8Array(bc, new Uint8Array(x));
564
563
  }
565
- function decodeFixedData(bc, len) {
566
- return decodeU8FixedArray(bc, len).buffer;
564
+ function readFixedData(bc, len) {
565
+ return readU8FixedArray(bc, len).buffer;
567
566
  }
568
- function encodeFixedData(bc, x, len) {
569
- encodeU8FixedArray(bc, new Uint8Array(x), len);
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 NAN_NOT_ALLOWED2 = "NaN is not allowed";
580
- var decodeF32FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? decodeF32FixedArrayLE : decodeF32FixedArrayBE;
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(decodeFixedData(bc, byteLen));
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 decodeF32FixedArrayBE(bc, len) {
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] = decodeF32(bc);
585
+ result[i] = readF32(bc);
594
586
  return result;
595
587
  }
596
- var encodeF32FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? encodeF32FixedArrayLE : encodeF32FixedArrayBE;
597
- function encodeF32FixedArrayLE(bc, x, len) {
598
- (0, import_assert5.default)(x.length === len);
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 encodeF32FixedArrayBE(bc, val, len) {
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
- encodeF32(bc, val[i]);
595
+ writeF32(bc, val[i]);
607
596
  }
608
- function decodeF32Array(bc) {
609
- return decodeF32FixedArray(bc, decodeUintSafe(bc));
597
+ function readF32Array(bc) {
598
+ return readF32FixedArray(bc, readUintSafe(bc));
610
599
  }
611
- function encodeF32Array(bc, x) {
612
- encodeUintSafe(bc, x.length);
600
+ function writeF32Array(bc, x) {
601
+ writeUintSafe(bc, x.length);
613
602
  if (x.length !== 0) {
614
- encodeF32FixedArray(bc, x, x.length);
603
+ writeF32FixedArray(bc, x);
615
604
  }
616
605
  }
617
- var decodeF64FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? decodeF64FixedArrayLE : decodeF64FixedArrayBE;
618
- function decodeF64FixedArrayLE(bc, len) {
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(decodeFixedData(bc, byteLen));
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 decodeF64FixedArrayBE(bc, len) {
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] = decodeF64(bc);
616
+ result[i] = readF64(bc);
631
617
  return result;
632
618
  }
633
- var encodeF64FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? encodeF64FixedArrayLE : encodeF64FixedArrayBE;
634
- function encodeF64FixedArrayLE(bc, x, len) {
635
- (0, import_assert5.default)(x.length === len);
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 encodeF64FixedArrayBE(bc, x, len) {
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
- encodeF64(bc, x[i]);
626
+ writeF64(bc, x[i]);
644
627
  }
645
- function decodeF64Array(bc) {
646
- return decodeF64FixedArray(bc, decodeUintSafe(bc));
628
+ function readF64Array(bc) {
629
+ return readF64FixedArray(bc, readUintSafe(bc));
647
630
  }
648
- function encodeF64Array(bc, x) {
649
- encodeUintSafe(bc, x.length);
631
+ function writeF64Array(bc, x) {
632
+ writeUintSafe(bc, x.length);
650
633
  if (x.length !== 0) {
651
- encodeF64FixedArray(bc, x, x.length);
634
+ writeF64FixedArray(bc, x);
652
635
  }
653
636
  }
654
637
 
655
638
  // src/codec/i16-array.ts
656
- var import_assert6 = __toESM(require("assert"), 1);
657
- var I16_BYTE_COUNT = 2;
658
- var decodeI16FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? decodeI16FixedArrayLE : decodeI16FixedArrayBE;
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 decodeI16FixedArrayLE(bc, len) {
643
+ function readI16FixedArrayLE(bc, len) {
663
644
  const byteCount = len * I16_BYTE_COUNT;
664
- return new Int16Array(decodeFixedData(bc, byteCount));
645
+ return new Int16Array(readFixedData(bc, byteCount));
665
646
  }
666
- function decodeI16FixedArrayBE(bc, len) {
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] = decodeI16(bc);
651
+ result[i] = readI16(bc);
671
652
  return result;
672
653
  }
673
- var encodeI16FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? encodeI16FixedArrayLE : encodeI16FixedArrayBE;
674
- function encodeI16Array(bc, x) {
675
- encodeUintSafe(bc, x.length);
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
- encodeI16FixedArray(bc, x, x.length);
658
+ writeI16FixedArray(bc, x);
678
659
  }
679
660
  }
680
- function encodeI16FixedArrayLE(bc, x, len) {
681
- (0, import_assert6.default)(x.length === len);
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 encodeI16FixedArrayBE(bc, x, len) {
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
- encodeI16(bc, x[i]);
667
+ writeI16(bc, x[i]);
689
668
  }
690
669
 
691
670
  // src/codec/i32-array.ts
692
- var import_assert7 = __toESM(require("assert"), 1);
693
- var I32_BYTE_COUNT = 4;
694
- var decodeI32FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? decodeI32FixedArrayLE : decodeI32FixedArrayBE;
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 decodeI32FixedArrayLE(bc, len) {
675
+ function readI32FixedArrayLE(bc, len) {
699
676
  const byteCount = len * I32_BYTE_COUNT;
700
- return new Int32Array(decodeFixedData(bc, byteCount));
677
+ return new Int32Array(readFixedData(bc, byteCount));
701
678
  }
702
- function decodeI32FixedArrayBE(bc, len) {
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] = decodeI32(bc);
683
+ result[i] = readI32(bc);
707
684
  return result;
708
685
  }
709
- var encodeI32FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? encodeI32FixedArrayLE : encodeI32FixedArrayBE;
710
- function encodeI32Array(bc, x) {
711
- encodeUintSafe(bc, x.length);
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
- encodeI32FixedArray(bc, x, x.length);
690
+ writeI32FixedArray(bc, x);
714
691
  }
715
692
  }
716
- function encodeI32FixedArrayLE(bc, x, len) {
717
- (0, import_assert7.default)(x.length === len);
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 encodeI32FixedArrayBE(bc, x, len) {
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
- encodeI32(bc, x[i]);
699
+ writeI32(bc, x[i]);
725
700
  }
726
701
 
727
702
  // src/codec/i64-array.ts
728
- var import_assert8 = __toESM(require("assert"), 1);
729
- var I64_BYTE_COUNT = 8;
730
- var decodeI64FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? decodeI64FixedArrayLE : decodeI64FixedArrayBE;
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 decodeI64FixedArrayLE(bc, len) {
707
+ function readI64FixedArrayLE(bc, len) {
735
708
  const byteCount = len * I64_BYTE_COUNT;
736
- return new BigInt64Array(decodeFixedData(bc, byteCount));
709
+ return new BigInt64Array(readFixedData(bc, byteCount));
737
710
  }
738
- function decodeI64FixedArrayBE(bc, len) {
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] = decodeI64(bc);
715
+ result[i] = readI64(bc);
743
716
  return result;
744
717
  }
745
- var encodeI64FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? encodeI64FixedArrayLE : encodeI64FixedArrayBE;
746
- function encodeI64Array(bc, x) {
747
- encodeUintSafe(bc, x.length);
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
- encodeI64FixedArray(bc, x, x.length);
722
+ writeI64FixedArray(bc, x);
750
723
  }
751
724
  }
752
- function encodeI64FixedArrayLE(bc, x, len) {
753
- (0, import_assert8.default)(x.length === len);
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 encodeI64FixedArrayBE(bc, x, len) {
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
- encodeI64(bc, x[i]);
731
+ writeI64(bc, x[i]);
761
732
  }
762
733
 
763
734
  // src/codec/i8-array.ts
764
- function decodeI8Array(bc) {
765
- return decodeI8FixedArray(bc, decodeUintSafe(bc));
735
+ function readI8Array(bc) {
736
+ return readI8FixedArray(bc, readUintSafe(bc));
766
737
  }
767
- function encodeI8Array(bc, x) {
768
- encodeUintSafe(bc, x.length);
769
- encodeI8FixedArray(bc, x, x.length);
738
+ function writeI8Array(bc, x) {
739
+ writeUintSafe(bc, x.length);
740
+ writeI8FixedArray(bc, x);
770
741
  }
771
- function decodeI8FixedArray(bc, len) {
772
- return new Int8Array(decodeFixedData(bc, len));
742
+ function readI8FixedArray(bc, len) {
743
+ return new Int8Array(readFixedData(bc, len));
773
744
  }
774
- function encodeI8FixedArray(bc, x, len) {
775
- encodeU8FixedArray(bc, new Uint8Array(x.buffer, x.byteOffset, x.byteLength), len);
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 decodeString(bc) {
780
- const strBytesLen = decodeUintSafe(bc);
781
- const strBytes = bc.read(strBytesLen);
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 strBytesLen < bc.config.textDecoderThreshold ? decodeUtf8Js(strBytes) : UTF8_DECODER.decode(strBytes);
770
+ return UTF8_DECODER.decode(bc.read(byteLen));
784
771
  } catch (cause) {
785
- throw new BareError(bc.offset - strBytesLen, "invalid UTF-8 string", {
786
- cause
787
- });
772
+ throw new BareError(bc.offset, INVALID_UTF8_STRING);
788
773
  }
789
774
  }
790
- function encodeString(bc, x) {
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
- encodeUtf8Js(bc, x);
779
+ writeUtf8Js(bc, x);
796
780
  } else {
797
- const strBytes = UTF8_ENCODER.encode(x);
798
- encodeUintSafe(bc, strBytes.length);
799
- bc.write(strBytes);
781
+ writeU8FixedArray(bc, UTF8_ENCODER.encode(x));
800
782
  }
801
783
  }
802
- function decodeUtf8Js(bytes) {
803
- const bytesLen = bytes.length;
784
+ function readUtf8Js(bc, byteLen) {
785
+ bc.check(byteLen);
804
786
  let result = "";
805
- let i = 0;
806
- while (i < bytesLen) {
807
- let codePoint = bytes[i++] | 0;
808
- switch (Math.clz32(~codePoint << 24)) {
809
- case 0:
810
- break;
811
- case 2: {
812
- if (i < bytesLen) {
813
- codePoint = (codePoint & 31) << 6 | bytes[i] & 63;
814
- }
815
- if (codePoint >> 7 === 0 || bytes[i] >> 6 !== 2) {
816
- throw TypeError("Decoding failed");
817
- }
818
- i += 1;
819
- break;
820
- }
821
- case 3: {
822
- if (i + 1 < bytesLen) {
823
- codePoint = (codePoint & 15) << 12 | (bytes[i] & 63) << 6 | bytes[i + 1] & 63;
824
- }
825
- if (codePoint >> 11 === 0 || bytes[i] >> 6 !== 2 || bytes[i + 1] >> 6 !== 2 || codePoint >> 11 === 27) {
826
- throw TypeError("Decoding failed");
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
- case 4: {
832
- if (i + 2 < bytesLen) {
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 encodeUtf8Js(bc, s) {
849
- const sLen = s.length;
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 < sLen) {
824
+ while (i < s.length) {
854
825
  const codePoint = s.codePointAt(i++);
855
826
  if (codePoint < 128) {
856
- view.setUint8(offset++, codePoint);
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
- view.setUint8(offset++, 240 | codePoint >> 18);
866
- view.setUint8(offset++, 128 | codePoint >> 12 & 63);
867
- view.setUint8(offset++, 128 | codePoint >> 6 & 63);
868
- view.setUint8(offset++, 128 | codePoint & 63);
869
- i++;
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
- const sLen = s.length;
876
- let result = 0;
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
- i++;
881
- if (codePoint < 128) {
850
+ if (codePoint > 127) {
882
851
  result++;
883
- } else if (codePoint < 2048) {
884
- result += 2;
885
- } else if (codePoint < 65536) {
886
- result += 3;
887
- } else {
888
- result += 4;
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 import_assert9 = __toESM(require("assert"), 1);
899
- var U16_BYTE_COUNT = 2;
900
- var decodeU16FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? decodeU16FixedArrayLE : decodeU16FixedArrayBE;
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 decodeU16FixedArrayLE(bc, len) {
870
+ function readU16FixedArrayLE(bc, len) {
905
871
  const byteCount = len * U16_BYTE_COUNT;
906
- return new Uint16Array(decodeFixedData(bc, byteCount));
872
+ return new Uint16Array(readFixedData(bc, byteCount));
907
873
  }
908
- function decodeU16FixedArrayBE(bc, len) {
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] = decodeU16(bc);
878
+ result[i] = readU16(bc);
913
879
  return result;
914
880
  }
915
- var encodeU16FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? encodeU16FixedArrayLE : encodeU16FixedArrayBE;
916
- function encodeU16Array(bc, x) {
917
- encodeUintSafe(bc, x.length);
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
- encodeU16FixedArray(bc, x, x.length);
885
+ writeU16FixedArray(bc, x);
920
886
  }
921
887
  }
922
- function encodeU16FixedArrayLE(bc, x, len) {
923
- (0, import_assert9.default)(x.length === len);
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 encodeU16FixedArrayBE(bc, x, len) {
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
- encodeU16(bc, x[i]);
894
+ writeU16(bc, x[i]);
931
895
  }
932
896
 
933
897
  // src/codec/u32-array.ts
934
- var import_assert10 = __toESM(require("assert"), 1);
935
- var U32_BYTE_COUNT = 4;
936
- var decodeU32FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? decodeU32FixedArrayLE : decodeU32FixedArrayBE;
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 decodeU32FixedArrayLE(bc, len) {
902
+ function readU32FixedArrayLE(bc, len) {
941
903
  const byteCount = len * U32_BYTE_COUNT;
942
- return new Uint32Array(decodeFixedData(bc, byteCount));
904
+ return new Uint32Array(readFixedData(bc, byteCount));
943
905
  }
944
- function decodeU32FixedArrayBE(bc, len) {
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] = decodeU32(bc);
910
+ result[i] = readU32(bc);
949
911
  return result;
950
912
  }
951
- var encodeU32FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? encodeU32FixedArrayLE : encodeU32FixedArrayBE;
952
- function encodeU32Array(bc, x) {
953
- encodeUintSafe(bc, x.length);
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
- encodeU32FixedArray(bc, x, x.length);
917
+ writeU32FixedArray(bc, x);
956
918
  }
957
919
  }
958
- function encodeU32FixedArrayLE(bc, x, len) {
959
- (0, import_assert10.default)(x.length === len);
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 encodeU32FixedArrayBE(bc, x, len) {
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
- encodeU32(bc, x[i]);
926
+ writeU32(bc, x[i]);
967
927
  }
968
928
 
969
929
  // src/codec/u64-array.ts
970
- var import_assert11 = __toESM(require("assert"), 1);
971
- var U64_BYTE_COUNT = 8;
972
- var decodeU64FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? decodeU64FixedArrayLE : decodeU64FixedArrayBE;
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 decodeU64FixedArrayLE(bc, len) {
934
+ function readU64FixedArrayLE(bc, len) {
977
935
  const byteCount = len * U64_BYTE_COUNT;
978
- return new BigUint64Array(decodeFixedData(bc, byteCount));
936
+ return new BigUint64Array(readFixedData(bc, byteCount));
979
937
  }
980
- function decodeU64FixedArrayBE(bc, len) {
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] = decodeU64(bc);
942
+ result[i] = readU64(bc);
985
943
  return result;
986
944
  }
987
- var encodeU64FixedArray = IS_LITTLE_ENDIAN_PLATFORM ? encodeU64FixedArrayLE : encodeU64FixedArrayBE;
988
- function encodeU64Array(bc, x) {
989
- encodeUintSafe(bc, x.length);
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
- encodeU64FixedArray(bc, x, x.length);
949
+ writeU64FixedArray(bc, x);
992
950
  }
993
951
  }
994
- function encodeU64FixedArrayLE(bc, x, len) {
995
- (0, import_assert11.default)(x.length === len);
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 encodeU64FixedArrayBE(bc, x, len) {
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
- encodeU64(bc, x[i]);
958
+ writeU64(bc, x[i]);
1003
959
  }
1004
960
 
1005
961
  // src/codec/u8-clamped-array.ts
1006
- function decodeU8ClampedArray(bc) {
1007
- return decodeU8ClampedFixedArray(bc, decodeUintSafe(bc));
962
+ function readU8ClampedArray(bc) {
963
+ return readU8ClampedFixedArray(bc, readUintSafe(bc));
1008
964
  }
1009
- function encodeU8ClampedArray(bc, x) {
1010
- encodeUintSafe(bc, x.length);
1011
- encodeU8ClampedFixedArray(bc, x, x.length);
965
+ function writeU8ClampedArray(bc, x) {
966
+ writeUintSafe(bc, x.length);
967
+ writeU8ClampedFixedArray(bc, x);
1012
968
  }
1013
- function decodeU8ClampedFixedArray(bc, len) {
1014
- return new Uint8ClampedArray(decodeFixedData(bc, len));
969
+ function readU8ClampedFixedArray(bc, len) {
970
+ return new Uint8ClampedArray(readFixedData(bc, len));
1015
971
  }
1016
- function encodeU8ClampedFixedArray(bc, x, len) {
1017
- encodeU8FixedArray(bc, new Uint8Array(x.buffer, x.byteOffset, x.byteLength), len);
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
- decodeBool,
1026
- decodeData,
1027
- decodeF32,
1028
- decodeF32Array,
1029
- decodeF32FixedArray,
1030
- decodeF64,
1031
- decodeF64Array,
1032
- decodeF64FixedArray,
1033
- decodeFixedData,
1034
- decodeI16,
1035
- decodeI16Array,
1036
- decodeI16FixedArray,
1037
- decodeI32,
1038
- decodeI32Array,
1039
- decodeI32FixedArray,
1040
- decodeI64,
1041
- decodeI64Array,
1042
- decodeI64FixedArray,
1043
- decodeI64Safe,
1044
- decodeI8,
1045
- decodeI8Array,
1046
- decodeI8FixedArray,
1047
- decodeInt,
1048
- decodeIntSafe,
1049
- decodeString,
1050
- decodeU16,
1051
- decodeU16Array,
1052
- decodeU16FixedArray,
1053
- decodeU32,
1054
- decodeU32Array,
1055
- decodeU32FixedArray,
1056
- decodeU64,
1057
- decodeU64Array,
1058
- decodeU64FixedArray,
1059
- decodeU64Safe,
1060
- decodeU8,
1061
- decodeU8Array,
1062
- decodeU8ClampedArray,
1063
- decodeU8ClampedFixedArray,
1064
- decodeU8FixedArray,
1065
- decodeUint,
1066
- decodeUintSafe,
1067
- decodeVoid,
1068
- encodeBool,
1069
- encodeData,
1070
- encodeF32,
1071
- encodeF32Array,
1072
- encodeF32FixedArray,
1073
- encodeF64,
1074
- encodeF64Array,
1075
- encodeF64FixedArray,
1076
- encodeFixedData,
1077
- encodeI16,
1078
- encodeI16Array,
1079
- encodeI16FixedArray,
1080
- encodeI32,
1081
- encodeI32Array,
1082
- encodeI32FixedArray,
1083
- encodeI64,
1084
- encodeI64Array,
1085
- encodeI64FixedArray,
1086
- encodeI64Safe,
1087
- encodeI8,
1088
- encodeI8Array,
1089
- encodeI8FixedArray,
1090
- encodeInt,
1091
- encodeIntSafe,
1092
- encodeString,
1093
- encodeU16,
1094
- encodeU16Array,
1095
- encodeU16FixedArray,
1096
- encodeU32,
1097
- encodeU32Array,
1098
- encodeU32FixedArray,
1099
- encodeU64,
1100
- encodeU64Array,
1101
- encodeU64FixedArray,
1102
- encodeU64Safe,
1103
- encodeU8,
1104
- encodeU8Array,
1105
- encodeU8ClampedArray,
1106
- encodeU8ClampedFixedArray,
1107
- encodeU8FixedArray,
1108
- encodeUint,
1109
- encodeUintSafe,
1110
- encodeVoid
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