@sapphire/string-store 2.0.0-next.548200f1 → 2.0.0-next.598c24a3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +248 -271
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +11 -69
- package/dist/esm/index.d.mts +11 -69
- package/dist/esm/index.mjs +248 -271
- package/dist/esm/index.mjs.map +1 -1
- package/dist/iife/index.global.js +248 -271
- package/dist/iife/index.global.js.map +1 -1
- package/package.json +1 -1
package/dist/cjs/index.cjs
CHANGED
|
@@ -73,247 +73,6 @@ _value = new WeakMap();
|
|
|
73
73
|
__name(_Pointer, "Pointer");
|
|
74
74
|
var Pointer = _Pointer;
|
|
75
75
|
|
|
76
|
-
// src/lib/buffer/UnalignedUint16Array.ts
|
|
77
|
-
var ConverterUint8 = new Uint8Array(8);
|
|
78
|
-
var ConverterUint16 = new Uint16Array(ConverterUint8.buffer);
|
|
79
|
-
var ConverterUint32 = new Uint32Array(ConverterUint8.buffer);
|
|
80
|
-
var ConverterUint64 = new BigUint64Array(ConverterUint8.buffer);
|
|
81
|
-
var ConverterInt32 = new Int32Array(ConverterUint8.buffer);
|
|
82
|
-
var ConverterInt64 = new BigInt64Array(ConverterUint8.buffer);
|
|
83
|
-
var ConverterFloat = new Float32Array(ConverterUint8.buffer);
|
|
84
|
-
var ConverterDouble = new Float64Array(ConverterUint8.buffer);
|
|
85
|
-
var _buffer, _bitLength, _wordIndex, _wordLength, _UnalignedUint16Array_instances, readBit_fn, readByte_fn, bufferRead16_fn, bufferRead32_fn, bufferRead64_fn, writeBit_fn, bufferWrite16_fn;
|
|
86
|
-
var _UnalignedUint16Array = class _UnalignedUint16Array {
|
|
87
|
-
constructor(maxLength) {
|
|
88
|
-
__privateAdd(this, _UnalignedUint16Array_instances);
|
|
89
|
-
__privateAdd(this, _buffer);
|
|
90
|
-
__privateAdd(this, _bitLength, 0);
|
|
91
|
-
__privateAdd(this, _wordIndex, 0);
|
|
92
|
-
__privateAdd(this, _wordLength, 0);
|
|
93
|
-
__privateSet(this, _buffer, new Uint16Array(maxLength));
|
|
94
|
-
}
|
|
95
|
-
at(index) {
|
|
96
|
-
return __privateGet(this, _buffer).at(index);
|
|
97
|
-
}
|
|
98
|
-
get maxLength() {
|
|
99
|
-
return __privateGet(this, _buffer).length;
|
|
100
|
-
}
|
|
101
|
-
get maxBitLength() {
|
|
102
|
-
return __privateGet(this, _buffer).length * 16;
|
|
103
|
-
}
|
|
104
|
-
get length() {
|
|
105
|
-
return __privateGet(this, _wordLength);
|
|
106
|
-
}
|
|
107
|
-
get bitLength() {
|
|
108
|
-
return __privateGet(this, _bitLength);
|
|
109
|
-
}
|
|
110
|
-
writeBit(value) {
|
|
111
|
-
__privateMethod(this, _UnalignedUint16Array_instances, writeBit_fn).call(this, value);
|
|
112
|
-
}
|
|
113
|
-
writeInt2(value) {
|
|
114
|
-
this.writeBit(value & 1);
|
|
115
|
-
this.writeBit(value >> 1);
|
|
116
|
-
}
|
|
117
|
-
writeInt4(value) {
|
|
118
|
-
this.writeInt2(value & 3);
|
|
119
|
-
this.writeInt2(value >> 2);
|
|
120
|
-
}
|
|
121
|
-
writeInt8(value) {
|
|
122
|
-
this.writeInt4(value & 15);
|
|
123
|
-
this.writeInt4(value >> 4);
|
|
124
|
-
}
|
|
125
|
-
writeInt16(value) {
|
|
126
|
-
__privateMethod(this, _UnalignedUint16Array_instances, bufferWrite16_fn).call(this, value);
|
|
127
|
-
}
|
|
128
|
-
writeInt32(value) {
|
|
129
|
-
__privateMethod(this, _UnalignedUint16Array_instances, bufferWrite16_fn).call(this, value);
|
|
130
|
-
__privateMethod(this, _UnalignedUint16Array_instances, bufferWrite16_fn).call(this, value >> 16);
|
|
131
|
-
}
|
|
132
|
-
writeInt64(value) {
|
|
133
|
-
this.writeBigInt64(BigInt(value));
|
|
134
|
-
}
|
|
135
|
-
writeBigInt32(value) {
|
|
136
|
-
ConverterInt64[0] = value;
|
|
137
|
-
__privateMethod(this, _UnalignedUint16Array_instances, bufferWrite16_fn).call(this, ConverterUint16[0]);
|
|
138
|
-
__privateMethod(this, _UnalignedUint16Array_instances, bufferWrite16_fn).call(this, ConverterUint16[1]);
|
|
139
|
-
}
|
|
140
|
-
writeBigInt64(value) {
|
|
141
|
-
ConverterInt64[0] = value;
|
|
142
|
-
__privateMethod(this, _UnalignedUint16Array_instances, bufferWrite16_fn).call(this, ConverterUint16[0]);
|
|
143
|
-
__privateMethod(this, _UnalignedUint16Array_instances, bufferWrite16_fn).call(this, ConverterUint16[1]);
|
|
144
|
-
__privateMethod(this, _UnalignedUint16Array_instances, bufferWrite16_fn).call(this, ConverterUint16[2]);
|
|
145
|
-
__privateMethod(this, _UnalignedUint16Array_instances, bufferWrite16_fn).call(this, ConverterUint16[3]);
|
|
146
|
-
}
|
|
147
|
-
writeFloat32(value) {
|
|
148
|
-
ConverterFloat[0] = value;
|
|
149
|
-
__privateMethod(this, _UnalignedUint16Array_instances, bufferWrite16_fn).call(this, ConverterUint16[0]);
|
|
150
|
-
__privateMethod(this, _UnalignedUint16Array_instances, bufferWrite16_fn).call(this, ConverterUint16[1]);
|
|
151
|
-
}
|
|
152
|
-
writeFloat64(value) {
|
|
153
|
-
ConverterDouble[0] = value;
|
|
154
|
-
__privateMethod(this, _UnalignedUint16Array_instances, bufferWrite16_fn).call(this, ConverterUint16[0]);
|
|
155
|
-
__privateMethod(this, _UnalignedUint16Array_instances, bufferWrite16_fn).call(this, ConverterUint16[1]);
|
|
156
|
-
__privateMethod(this, _UnalignedUint16Array_instances, bufferWrite16_fn).call(this, ConverterUint16[2]);
|
|
157
|
-
__privateMethod(this, _UnalignedUint16Array_instances, bufferWrite16_fn).call(this, ConverterUint16[3]);
|
|
158
|
-
}
|
|
159
|
-
readBit(offset) {
|
|
160
|
-
const ptr = Pointer.from(offset);
|
|
161
|
-
return __privateMethod(this, _UnalignedUint16Array_instances, readBit_fn).call(this, ptr);
|
|
162
|
-
}
|
|
163
|
-
readInt2(offset) {
|
|
164
|
-
return this.readUint2(offset) << 30 >> 30;
|
|
165
|
-
}
|
|
166
|
-
readUint2(offset) {
|
|
167
|
-
const ptr = Pointer.from(offset);
|
|
168
|
-
return __privateMethod(this, _UnalignedUint16Array_instances, readBit_fn).call(this, ptr) | __privateMethod(this, _UnalignedUint16Array_instances, readBit_fn).call(this, ptr) << 1;
|
|
169
|
-
}
|
|
170
|
-
readInt4(offset) {
|
|
171
|
-
return this.readUint4(offset) << 28 >> 28;
|
|
172
|
-
}
|
|
173
|
-
readUint4(offset) {
|
|
174
|
-
const ptr = Pointer.from(offset);
|
|
175
|
-
return __privateMethod(this, _UnalignedUint16Array_instances, readBit_fn).call(this, ptr) | __privateMethod(this, _UnalignedUint16Array_instances, readBit_fn).call(this, ptr) << 1 | __privateMethod(this, _UnalignedUint16Array_instances, readBit_fn).call(this, ptr) << 2 | __privateMethod(this, _UnalignedUint16Array_instances, readBit_fn).call(this, ptr) << 3;
|
|
176
|
-
}
|
|
177
|
-
readInt8(offset) {
|
|
178
|
-
return this.readUint8(offset) << 24 >> 24;
|
|
179
|
-
}
|
|
180
|
-
readUint8(offset) {
|
|
181
|
-
const ptr = Pointer.from(offset);
|
|
182
|
-
return __privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr);
|
|
183
|
-
}
|
|
184
|
-
readInt16(offset) {
|
|
185
|
-
return this.readUint16(offset) << 16 >> 16;
|
|
186
|
-
}
|
|
187
|
-
readUint16(offset) {
|
|
188
|
-
__privateMethod(this, _UnalignedUint16Array_instances, bufferRead16_fn).call(this, Pointer.from(offset));
|
|
189
|
-
return ConverterUint16[0];
|
|
190
|
-
}
|
|
191
|
-
readInt32(offset) {
|
|
192
|
-
__privateMethod(this, _UnalignedUint16Array_instances, bufferRead32_fn).call(this, Pointer.from(offset));
|
|
193
|
-
return ConverterInt32[0];
|
|
194
|
-
}
|
|
195
|
-
readUint32(offset) {
|
|
196
|
-
__privateMethod(this, _UnalignedUint16Array_instances, bufferRead32_fn).call(this, Pointer.from(offset));
|
|
197
|
-
return ConverterUint32[0];
|
|
198
|
-
}
|
|
199
|
-
readInt64(offset) {
|
|
200
|
-
return Number(this.readBigInt64(offset));
|
|
201
|
-
}
|
|
202
|
-
readUint64(offset) {
|
|
203
|
-
return Number(this.readBigUint64(offset));
|
|
204
|
-
}
|
|
205
|
-
readBigInt32(offset) {
|
|
206
|
-
__privateMethod(this, _UnalignedUint16Array_instances, bufferRead32_fn).call(this, Pointer.from(offset));
|
|
207
|
-
return BigInt(ConverterInt32[0]);
|
|
208
|
-
}
|
|
209
|
-
readBigUint32(offset) {
|
|
210
|
-
__privateMethod(this, _UnalignedUint16Array_instances, bufferRead32_fn).call(this, Pointer.from(offset));
|
|
211
|
-
return BigInt(ConverterUint32[0]);
|
|
212
|
-
}
|
|
213
|
-
readBigInt64(offset) {
|
|
214
|
-
__privateMethod(this, _UnalignedUint16Array_instances, bufferRead64_fn).call(this, Pointer.from(offset));
|
|
215
|
-
return ConverterInt64[0];
|
|
216
|
-
}
|
|
217
|
-
readBigUint64(offset) {
|
|
218
|
-
__privateMethod(this, _UnalignedUint16Array_instances, bufferRead64_fn).call(this, Pointer.from(offset));
|
|
219
|
-
return ConverterUint64[0];
|
|
220
|
-
}
|
|
221
|
-
readFloat32(offset) {
|
|
222
|
-
__privateMethod(this, _UnalignedUint16Array_instances, bufferRead32_fn).call(this, Pointer.from(offset));
|
|
223
|
-
return ConverterFloat[0];
|
|
224
|
-
}
|
|
225
|
-
readFloat64(offset) {
|
|
226
|
-
__privateMethod(this, _UnalignedUint16Array_instances, bufferRead64_fn).call(this, Pointer.from(offset));
|
|
227
|
-
return ConverterDouble[0];
|
|
228
|
-
}
|
|
229
|
-
toString() {
|
|
230
|
-
let result = "";
|
|
231
|
-
for (let i = 0; i < this.length; i++) {
|
|
232
|
-
result += String.fromCharCode(__privateGet(this, _buffer)[i]);
|
|
233
|
-
}
|
|
234
|
-
return result;
|
|
235
|
-
}
|
|
236
|
-
toArray() {
|
|
237
|
-
return __privateGet(this, _buffer).slice(0, this.length);
|
|
238
|
-
}
|
|
239
|
-
static from(value) {
|
|
240
|
-
if (typeof value !== "string") return value;
|
|
241
|
-
const buffer = new _UnalignedUint16Array(value.length);
|
|
242
|
-
for (let i = 0; i < value.length; i++) {
|
|
243
|
-
__privateGet(buffer, _buffer)[i] = value.charCodeAt(i);
|
|
244
|
-
}
|
|
245
|
-
__privateSet(buffer, _bitLength, value.length << 4);
|
|
246
|
-
return buffer;
|
|
247
|
-
}
|
|
248
|
-
};
|
|
249
|
-
_buffer = new WeakMap();
|
|
250
|
-
_bitLength = new WeakMap();
|
|
251
|
-
_wordIndex = new WeakMap();
|
|
252
|
-
_wordLength = new WeakMap();
|
|
253
|
-
_UnalignedUint16Array_instances = new WeakSet();
|
|
254
|
-
readBit_fn = /* @__PURE__ */ __name(function(pointer) {
|
|
255
|
-
const bitOffset = pointer.value;
|
|
256
|
-
const index = bitOffset >> 4;
|
|
257
|
-
const bitIndex = bitOffset & 15;
|
|
258
|
-
pointer.add(1);
|
|
259
|
-
return __privateGet(this, _buffer)[index] >> bitIndex & 1;
|
|
260
|
-
}, "#readBit");
|
|
261
|
-
readByte_fn = /* @__PURE__ */ __name(function(ptr) {
|
|
262
|
-
return __privateMethod(this, _UnalignedUint16Array_instances, readBit_fn).call(this, ptr) | __privateMethod(this, _UnalignedUint16Array_instances, readBit_fn).call(this, ptr) << 1 | __privateMethod(this, _UnalignedUint16Array_instances, readBit_fn).call(this, ptr) << 2 | __privateMethod(this, _UnalignedUint16Array_instances, readBit_fn).call(this, ptr) << 3 | __privateMethod(this, _UnalignedUint16Array_instances, readBit_fn).call(this, ptr) << 4 | __privateMethod(this, _UnalignedUint16Array_instances, readBit_fn).call(this, ptr) << 5 | __privateMethod(this, _UnalignedUint16Array_instances, readBit_fn).call(this, ptr) << 6 | __privateMethod(this, _UnalignedUint16Array_instances, readBit_fn).call(this, ptr) << 7;
|
|
263
|
-
}, "#readByte");
|
|
264
|
-
bufferRead16_fn = /* @__PURE__ */ __name(function(ptr) {
|
|
265
|
-
ConverterUint8[0] = __privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr);
|
|
266
|
-
ConverterUint8[1] = __privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr);
|
|
267
|
-
}, "#bufferRead16");
|
|
268
|
-
bufferRead32_fn = /* @__PURE__ */ __name(function(ptr) {
|
|
269
|
-
ConverterUint8[0] = __privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr);
|
|
270
|
-
ConverterUint8[1] = __privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr);
|
|
271
|
-
ConverterUint8[2] = __privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr);
|
|
272
|
-
ConverterUint8[3] = __privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr);
|
|
273
|
-
}, "#bufferRead32");
|
|
274
|
-
bufferRead64_fn = /* @__PURE__ */ __name(function(ptr) {
|
|
275
|
-
ConverterUint8[0] = __privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr);
|
|
276
|
-
ConverterUint8[1] = __privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr);
|
|
277
|
-
ConverterUint8[2] = __privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr);
|
|
278
|
-
ConverterUint8[3] = __privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr);
|
|
279
|
-
ConverterUint8[4] = __privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr);
|
|
280
|
-
ConverterUint8[5] = __privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr);
|
|
281
|
-
ConverterUint8[6] = __privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr);
|
|
282
|
-
ConverterUint8[7] = __privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr);
|
|
283
|
-
}, "#bufferRead64");
|
|
284
|
-
writeBit_fn = /* @__PURE__ */ __name(function(value) {
|
|
285
|
-
if (__privateGet(this, _wordIndex) === this.maxLength) {
|
|
286
|
-
throw new RangeError(`The buffer is full`);
|
|
287
|
-
}
|
|
288
|
-
if (value) {
|
|
289
|
-
const index = __privateGet(this, _wordIndex);
|
|
290
|
-
const bitIndex = this.bitLength & 15;
|
|
291
|
-
__privateGet(this, _buffer)[index] |= 1 << bitIndex;
|
|
292
|
-
}
|
|
293
|
-
if ((__privateGet(this, _bitLength) & 15) === 0) __privateWrapper(this, _wordLength)._++;
|
|
294
|
-
__privateWrapper(this, _bitLength)._++;
|
|
295
|
-
if ((__privateGet(this, _bitLength) & 15) === 0) __privateWrapper(this, _wordIndex)._++;
|
|
296
|
-
}, "#writeBit");
|
|
297
|
-
bufferWrite16_fn = /* @__PURE__ */ __name(function(value) {
|
|
298
|
-
const wordIndex = __privateGet(this, _wordIndex);
|
|
299
|
-
const bitIndex = this.bitLength & 15;
|
|
300
|
-
if (wordIndex + (bitIndex === 0 ? 0 : 1) === this.maxLength) {
|
|
301
|
-
throw new RangeError(`The buffer is full`);
|
|
302
|
-
}
|
|
303
|
-
if (bitIndex === 0) {
|
|
304
|
-
__privateGet(this, _buffer)[wordIndex] = value;
|
|
305
|
-
} else {
|
|
306
|
-
value &= 65535;
|
|
307
|
-
__privateGet(this, _buffer)[wordIndex] |= value << bitIndex;
|
|
308
|
-
__privateGet(this, _buffer)[wordIndex + 1] = value >> 16 - bitIndex;
|
|
309
|
-
}
|
|
310
|
-
__privateSet(this, _bitLength, __privateGet(this, _bitLength) + 16);
|
|
311
|
-
__privateWrapper(this, _wordIndex)._++;
|
|
312
|
-
__privateWrapper(this, _wordLength)._++;
|
|
313
|
-
}, "#bufferWrite16");
|
|
314
|
-
__name(_UnalignedUint16Array, "UnalignedUint16Array");
|
|
315
|
-
var UnalignedUint16Array = _UnalignedUint16Array;
|
|
316
|
-
|
|
317
76
|
// src/lib/types/Array.ts
|
|
318
77
|
function ArrayType(type) {
|
|
319
78
|
return {
|
|
@@ -735,30 +494,6 @@ var _Schema = class _Schema {
|
|
|
735
494
|
if (!type) throw new Error(`Schema with id ${__privateGet(this, _id)} does not have a property with name "${name}"`);
|
|
736
495
|
return type;
|
|
737
496
|
}
|
|
738
|
-
/**
|
|
739
|
-
* Create a buffer and serialize a value into it, then convert it to a string
|
|
740
|
-
*
|
|
741
|
-
* @param value The value to serialize into the buffer
|
|
742
|
-
* @param defaultMaximumArrayLength The default maximum array length, if any
|
|
743
|
-
* @returns The newly created string.
|
|
744
|
-
*
|
|
745
|
-
* @seealso This method calls {@link Schema.serializeRaw} before calling `toString()` to its result.
|
|
746
|
-
*/
|
|
747
|
-
serialize(value, defaultMaximumArrayLength = 100) {
|
|
748
|
-
return this.serializeRaw(value, defaultMaximumArrayLength).toString();
|
|
749
|
-
}
|
|
750
|
-
/**
|
|
751
|
-
* Create a buffer and serialize a value into it.
|
|
752
|
-
*
|
|
753
|
-
* @param value The value to serialize into the buffer
|
|
754
|
-
* @param defaultMaximumArrayLength The default maximum array length, if any
|
|
755
|
-
* @returns The newly created buffer.
|
|
756
|
-
*/
|
|
757
|
-
serializeRaw(value, defaultMaximumArrayLength = 100) {
|
|
758
|
-
const buffer = new UnalignedUint16Array(this.totalBitSize ?? defaultMaximumArrayLength);
|
|
759
|
-
this.serializeInto(buffer, value);
|
|
760
|
-
return buffer;
|
|
761
|
-
}
|
|
762
497
|
/**
|
|
763
498
|
* Serialize a value into a buffer.
|
|
764
499
|
*
|
|
@@ -770,7 +505,7 @@ var _Schema = class _Schema {
|
|
|
770
505
|
* The schema's ID is written to the buffer first, followed by each property
|
|
771
506
|
* in the schema.
|
|
772
507
|
*/
|
|
773
|
-
|
|
508
|
+
serialize(buffer, value) {
|
|
774
509
|
buffer.writeInt16(__privateGet(this, _id));
|
|
775
510
|
for (const [name, type] of this) {
|
|
776
511
|
type.serialize(buffer, value[name]);
|
|
@@ -785,15 +520,14 @@ var _Schema = class _Schema {
|
|
|
785
520
|
*
|
|
786
521
|
* @remarks
|
|
787
522
|
*
|
|
788
|
-
* Unlike {@link Schema.
|
|
523
|
+
* Unlike {@link Schema.serialize}, this method does not read the schema's ID
|
|
789
524
|
* from the buffer, that is reserved for the {@link SchemaStore}.
|
|
790
525
|
*/
|
|
791
526
|
deserialize(buffer, pointer) {
|
|
792
|
-
|
|
793
|
-
pointer = Pointer.from(pointer);
|
|
527
|
+
const ptr = Pointer.from(pointer);
|
|
794
528
|
const result = /* @__PURE__ */ Object.create(null);
|
|
795
529
|
for (const [name, type] of this) {
|
|
796
|
-
result[name] = type.deserialize(buffer,
|
|
530
|
+
result[name] = type.deserialize(buffer, ptr);
|
|
797
531
|
}
|
|
798
532
|
return result;
|
|
799
533
|
}
|
|
@@ -1173,6 +907,247 @@ addType_fn = /* @__PURE__ */ __name(function(name, type) {
|
|
|
1173
907
|
__name(_Schema, "Schema");
|
|
1174
908
|
var Schema = _Schema;
|
|
1175
909
|
|
|
910
|
+
// src/lib/UnalignedUint16Array.ts
|
|
911
|
+
var ConverterUint8 = new Uint8Array(8);
|
|
912
|
+
var ConverterUint16 = new Uint16Array(ConverterUint8.buffer);
|
|
913
|
+
var ConverterUint32 = new Uint32Array(ConverterUint8.buffer);
|
|
914
|
+
var ConverterUint64 = new BigUint64Array(ConverterUint8.buffer);
|
|
915
|
+
var ConverterInt32 = new Int32Array(ConverterUint8.buffer);
|
|
916
|
+
var ConverterInt64 = new BigInt64Array(ConverterUint8.buffer);
|
|
917
|
+
var ConverterFloat = new Float32Array(ConverterUint8.buffer);
|
|
918
|
+
var ConverterDouble = new Float64Array(ConverterUint8.buffer);
|
|
919
|
+
var _buffer, _bitLength, _wordIndex, _wordLength, _UnalignedUint16Array_instances, readBit_fn, readByte_fn, bufferRead16_fn, bufferRead32_fn, bufferRead64_fn, writeBit_fn, bufferWrite16_fn;
|
|
920
|
+
var _UnalignedUint16Array = class _UnalignedUint16Array {
|
|
921
|
+
constructor(maxLength) {
|
|
922
|
+
__privateAdd(this, _UnalignedUint16Array_instances);
|
|
923
|
+
__privateAdd(this, _buffer);
|
|
924
|
+
__privateAdd(this, _bitLength, 0);
|
|
925
|
+
__privateAdd(this, _wordIndex, 0);
|
|
926
|
+
__privateAdd(this, _wordLength, 0);
|
|
927
|
+
__privateSet(this, _buffer, new Uint16Array(maxLength));
|
|
928
|
+
}
|
|
929
|
+
at(index) {
|
|
930
|
+
return __privateGet(this, _buffer).at(index);
|
|
931
|
+
}
|
|
932
|
+
get maxLength() {
|
|
933
|
+
return __privateGet(this, _buffer).length;
|
|
934
|
+
}
|
|
935
|
+
get maxBitLength() {
|
|
936
|
+
return __privateGet(this, _buffer).length * 16;
|
|
937
|
+
}
|
|
938
|
+
get length() {
|
|
939
|
+
return __privateGet(this, _wordLength);
|
|
940
|
+
}
|
|
941
|
+
get bitLength() {
|
|
942
|
+
return __privateGet(this, _bitLength);
|
|
943
|
+
}
|
|
944
|
+
writeBit(value) {
|
|
945
|
+
__privateMethod(this, _UnalignedUint16Array_instances, writeBit_fn).call(this, value);
|
|
946
|
+
}
|
|
947
|
+
writeInt2(value) {
|
|
948
|
+
this.writeBit(value & 1);
|
|
949
|
+
this.writeBit(value >> 1);
|
|
950
|
+
}
|
|
951
|
+
writeInt4(value) {
|
|
952
|
+
this.writeInt2(value & 3);
|
|
953
|
+
this.writeInt2(value >> 2);
|
|
954
|
+
}
|
|
955
|
+
writeInt8(value) {
|
|
956
|
+
this.writeInt4(value & 15);
|
|
957
|
+
this.writeInt4(value >> 4);
|
|
958
|
+
}
|
|
959
|
+
writeInt16(value) {
|
|
960
|
+
__privateMethod(this, _UnalignedUint16Array_instances, bufferWrite16_fn).call(this, value);
|
|
961
|
+
}
|
|
962
|
+
writeInt32(value) {
|
|
963
|
+
__privateMethod(this, _UnalignedUint16Array_instances, bufferWrite16_fn).call(this, value);
|
|
964
|
+
__privateMethod(this, _UnalignedUint16Array_instances, bufferWrite16_fn).call(this, value >> 16);
|
|
965
|
+
}
|
|
966
|
+
writeInt64(value) {
|
|
967
|
+
this.writeBigInt64(BigInt(value));
|
|
968
|
+
}
|
|
969
|
+
writeBigInt32(value) {
|
|
970
|
+
ConverterInt64[0] = value;
|
|
971
|
+
__privateMethod(this, _UnalignedUint16Array_instances, bufferWrite16_fn).call(this, ConverterUint16[0]);
|
|
972
|
+
__privateMethod(this, _UnalignedUint16Array_instances, bufferWrite16_fn).call(this, ConverterUint16[1]);
|
|
973
|
+
}
|
|
974
|
+
writeBigInt64(value) {
|
|
975
|
+
ConverterInt64[0] = value;
|
|
976
|
+
__privateMethod(this, _UnalignedUint16Array_instances, bufferWrite16_fn).call(this, ConverterUint16[0]);
|
|
977
|
+
__privateMethod(this, _UnalignedUint16Array_instances, bufferWrite16_fn).call(this, ConverterUint16[1]);
|
|
978
|
+
__privateMethod(this, _UnalignedUint16Array_instances, bufferWrite16_fn).call(this, ConverterUint16[2]);
|
|
979
|
+
__privateMethod(this, _UnalignedUint16Array_instances, bufferWrite16_fn).call(this, ConverterUint16[3]);
|
|
980
|
+
}
|
|
981
|
+
writeFloat32(value) {
|
|
982
|
+
ConverterFloat[0] = value;
|
|
983
|
+
__privateMethod(this, _UnalignedUint16Array_instances, bufferWrite16_fn).call(this, ConverterUint16[0]);
|
|
984
|
+
__privateMethod(this, _UnalignedUint16Array_instances, bufferWrite16_fn).call(this, ConverterUint16[1]);
|
|
985
|
+
}
|
|
986
|
+
writeFloat64(value) {
|
|
987
|
+
ConverterDouble[0] = value;
|
|
988
|
+
__privateMethod(this, _UnalignedUint16Array_instances, bufferWrite16_fn).call(this, ConverterUint16[0]);
|
|
989
|
+
__privateMethod(this, _UnalignedUint16Array_instances, bufferWrite16_fn).call(this, ConverterUint16[1]);
|
|
990
|
+
__privateMethod(this, _UnalignedUint16Array_instances, bufferWrite16_fn).call(this, ConverterUint16[2]);
|
|
991
|
+
__privateMethod(this, _UnalignedUint16Array_instances, bufferWrite16_fn).call(this, ConverterUint16[3]);
|
|
992
|
+
}
|
|
993
|
+
readBit(offset) {
|
|
994
|
+
const ptr = Pointer.from(offset);
|
|
995
|
+
return __privateMethod(this, _UnalignedUint16Array_instances, readBit_fn).call(this, ptr);
|
|
996
|
+
}
|
|
997
|
+
readInt2(offset) {
|
|
998
|
+
return this.readUint2(offset) << 30 >> 30;
|
|
999
|
+
}
|
|
1000
|
+
readUint2(offset) {
|
|
1001
|
+
const ptr = Pointer.from(offset);
|
|
1002
|
+
return __privateMethod(this, _UnalignedUint16Array_instances, readBit_fn).call(this, ptr) | __privateMethod(this, _UnalignedUint16Array_instances, readBit_fn).call(this, ptr) << 1;
|
|
1003
|
+
}
|
|
1004
|
+
readInt4(offset) {
|
|
1005
|
+
return this.readUint4(offset) << 28 >> 28;
|
|
1006
|
+
}
|
|
1007
|
+
readUint4(offset) {
|
|
1008
|
+
const ptr = Pointer.from(offset);
|
|
1009
|
+
return __privateMethod(this, _UnalignedUint16Array_instances, readBit_fn).call(this, ptr) | __privateMethod(this, _UnalignedUint16Array_instances, readBit_fn).call(this, ptr) << 1 | __privateMethod(this, _UnalignedUint16Array_instances, readBit_fn).call(this, ptr) << 2 | __privateMethod(this, _UnalignedUint16Array_instances, readBit_fn).call(this, ptr) << 3;
|
|
1010
|
+
}
|
|
1011
|
+
readInt8(offset) {
|
|
1012
|
+
return this.readUint8(offset) << 24 >> 24;
|
|
1013
|
+
}
|
|
1014
|
+
readUint8(offset) {
|
|
1015
|
+
const ptr = Pointer.from(offset);
|
|
1016
|
+
return __privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr);
|
|
1017
|
+
}
|
|
1018
|
+
readInt16(offset) {
|
|
1019
|
+
return this.readUint16(offset) << 16 >> 16;
|
|
1020
|
+
}
|
|
1021
|
+
readUint16(offset) {
|
|
1022
|
+
__privateMethod(this, _UnalignedUint16Array_instances, bufferRead16_fn).call(this, Pointer.from(offset));
|
|
1023
|
+
return ConverterUint16[0];
|
|
1024
|
+
}
|
|
1025
|
+
readInt32(offset) {
|
|
1026
|
+
__privateMethod(this, _UnalignedUint16Array_instances, bufferRead32_fn).call(this, Pointer.from(offset));
|
|
1027
|
+
return ConverterInt32[0];
|
|
1028
|
+
}
|
|
1029
|
+
readUint32(offset) {
|
|
1030
|
+
__privateMethod(this, _UnalignedUint16Array_instances, bufferRead32_fn).call(this, Pointer.from(offset));
|
|
1031
|
+
return ConverterUint32[0];
|
|
1032
|
+
}
|
|
1033
|
+
readInt64(offset) {
|
|
1034
|
+
return Number(this.readBigInt64(offset));
|
|
1035
|
+
}
|
|
1036
|
+
readUint64(offset) {
|
|
1037
|
+
return Number(this.readBigUint64(offset));
|
|
1038
|
+
}
|
|
1039
|
+
readBigInt32(offset) {
|
|
1040
|
+
__privateMethod(this, _UnalignedUint16Array_instances, bufferRead32_fn).call(this, Pointer.from(offset));
|
|
1041
|
+
return BigInt(ConverterInt32[0]);
|
|
1042
|
+
}
|
|
1043
|
+
readBigUint32(offset) {
|
|
1044
|
+
__privateMethod(this, _UnalignedUint16Array_instances, bufferRead32_fn).call(this, Pointer.from(offset));
|
|
1045
|
+
return BigInt(ConverterUint32[0]);
|
|
1046
|
+
}
|
|
1047
|
+
readBigInt64(offset) {
|
|
1048
|
+
__privateMethod(this, _UnalignedUint16Array_instances, bufferRead64_fn).call(this, Pointer.from(offset));
|
|
1049
|
+
return ConverterInt64[0];
|
|
1050
|
+
}
|
|
1051
|
+
readBigUint64(offset) {
|
|
1052
|
+
__privateMethod(this, _UnalignedUint16Array_instances, bufferRead64_fn).call(this, Pointer.from(offset));
|
|
1053
|
+
return ConverterUint64[0];
|
|
1054
|
+
}
|
|
1055
|
+
readFloat32(offset) {
|
|
1056
|
+
__privateMethod(this, _UnalignedUint16Array_instances, bufferRead32_fn).call(this, Pointer.from(offset));
|
|
1057
|
+
return ConverterFloat[0];
|
|
1058
|
+
}
|
|
1059
|
+
readFloat64(offset) {
|
|
1060
|
+
__privateMethod(this, _UnalignedUint16Array_instances, bufferRead64_fn).call(this, Pointer.from(offset));
|
|
1061
|
+
return ConverterDouble[0];
|
|
1062
|
+
}
|
|
1063
|
+
toString() {
|
|
1064
|
+
let result = "";
|
|
1065
|
+
for (let i = 0; i < this.length; i++) {
|
|
1066
|
+
result += String.fromCharCode(__privateGet(this, _buffer)[i]);
|
|
1067
|
+
}
|
|
1068
|
+
return result;
|
|
1069
|
+
}
|
|
1070
|
+
toArray() {
|
|
1071
|
+
return __privateGet(this, _buffer).slice(0, this.length);
|
|
1072
|
+
}
|
|
1073
|
+
static from(value) {
|
|
1074
|
+
if (value instanceof _UnalignedUint16Array) return value;
|
|
1075
|
+
const buffer = new _UnalignedUint16Array(value.length);
|
|
1076
|
+
for (let i = 0; i < value.length; i++) {
|
|
1077
|
+
__privateGet(buffer, _buffer)[i] = value.charCodeAt(i);
|
|
1078
|
+
}
|
|
1079
|
+
__privateSet(buffer, _bitLength, value.length << 4);
|
|
1080
|
+
return buffer;
|
|
1081
|
+
}
|
|
1082
|
+
};
|
|
1083
|
+
_buffer = new WeakMap();
|
|
1084
|
+
_bitLength = new WeakMap();
|
|
1085
|
+
_wordIndex = new WeakMap();
|
|
1086
|
+
_wordLength = new WeakMap();
|
|
1087
|
+
_UnalignedUint16Array_instances = new WeakSet();
|
|
1088
|
+
readBit_fn = /* @__PURE__ */ __name(function(pointer) {
|
|
1089
|
+
const bitOffset = pointer.value;
|
|
1090
|
+
const index = bitOffset >> 4;
|
|
1091
|
+
const bitIndex = bitOffset & 15;
|
|
1092
|
+
pointer.add(1);
|
|
1093
|
+
return __privateGet(this, _buffer)[index] >> bitIndex & 1;
|
|
1094
|
+
}, "#readBit");
|
|
1095
|
+
readByte_fn = /* @__PURE__ */ __name(function(ptr) {
|
|
1096
|
+
return __privateMethod(this, _UnalignedUint16Array_instances, readBit_fn).call(this, ptr) | __privateMethod(this, _UnalignedUint16Array_instances, readBit_fn).call(this, ptr) << 1 | __privateMethod(this, _UnalignedUint16Array_instances, readBit_fn).call(this, ptr) << 2 | __privateMethod(this, _UnalignedUint16Array_instances, readBit_fn).call(this, ptr) << 3 | __privateMethod(this, _UnalignedUint16Array_instances, readBit_fn).call(this, ptr) << 4 | __privateMethod(this, _UnalignedUint16Array_instances, readBit_fn).call(this, ptr) << 5 | __privateMethod(this, _UnalignedUint16Array_instances, readBit_fn).call(this, ptr) << 6 | __privateMethod(this, _UnalignedUint16Array_instances, readBit_fn).call(this, ptr) << 7;
|
|
1097
|
+
}, "#readByte");
|
|
1098
|
+
bufferRead16_fn = /* @__PURE__ */ __name(function(ptr) {
|
|
1099
|
+
ConverterUint8[0] = __privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr);
|
|
1100
|
+
ConverterUint8[1] = __privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr);
|
|
1101
|
+
}, "#bufferRead16");
|
|
1102
|
+
bufferRead32_fn = /* @__PURE__ */ __name(function(ptr) {
|
|
1103
|
+
ConverterUint8[0] = __privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr);
|
|
1104
|
+
ConverterUint8[1] = __privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr);
|
|
1105
|
+
ConverterUint8[2] = __privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr);
|
|
1106
|
+
ConverterUint8[3] = __privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr);
|
|
1107
|
+
}, "#bufferRead32");
|
|
1108
|
+
bufferRead64_fn = /* @__PURE__ */ __name(function(ptr) {
|
|
1109
|
+
ConverterUint8[0] = __privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr);
|
|
1110
|
+
ConverterUint8[1] = __privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr);
|
|
1111
|
+
ConverterUint8[2] = __privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr);
|
|
1112
|
+
ConverterUint8[3] = __privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr);
|
|
1113
|
+
ConverterUint8[4] = __privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr);
|
|
1114
|
+
ConverterUint8[5] = __privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr);
|
|
1115
|
+
ConverterUint8[6] = __privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr);
|
|
1116
|
+
ConverterUint8[7] = __privateMethod(this, _UnalignedUint16Array_instances, readByte_fn).call(this, ptr);
|
|
1117
|
+
}, "#bufferRead64");
|
|
1118
|
+
writeBit_fn = /* @__PURE__ */ __name(function(value) {
|
|
1119
|
+
if (__privateGet(this, _wordIndex) === this.maxLength) {
|
|
1120
|
+
throw new RangeError(`The buffer is full`);
|
|
1121
|
+
}
|
|
1122
|
+
if (value) {
|
|
1123
|
+
const index = __privateGet(this, _wordIndex);
|
|
1124
|
+
const bitIndex = this.bitLength & 15;
|
|
1125
|
+
__privateGet(this, _buffer)[index] |= 1 << bitIndex;
|
|
1126
|
+
}
|
|
1127
|
+
if ((__privateGet(this, _bitLength) & 15) === 0) __privateWrapper(this, _wordLength)._++;
|
|
1128
|
+
__privateWrapper(this, _bitLength)._++;
|
|
1129
|
+
if ((__privateGet(this, _bitLength) & 15) === 0) __privateWrapper(this, _wordIndex)._++;
|
|
1130
|
+
}, "#writeBit");
|
|
1131
|
+
bufferWrite16_fn = /* @__PURE__ */ __name(function(value) {
|
|
1132
|
+
const wordIndex = __privateGet(this, _wordIndex);
|
|
1133
|
+
const bitIndex = this.bitLength & 15;
|
|
1134
|
+
if (wordIndex + (bitIndex === 0 ? 0 : 1) === this.maxLength) {
|
|
1135
|
+
throw new RangeError(`The buffer is full`);
|
|
1136
|
+
}
|
|
1137
|
+
if (bitIndex === 0) {
|
|
1138
|
+
__privateGet(this, _buffer)[wordIndex] = value;
|
|
1139
|
+
} else {
|
|
1140
|
+
value &= 65535;
|
|
1141
|
+
__privateGet(this, _buffer)[wordIndex] |= value << bitIndex;
|
|
1142
|
+
__privateGet(this, _buffer)[wordIndex + 1] = value >> 16 - bitIndex;
|
|
1143
|
+
}
|
|
1144
|
+
__privateSet(this, _bitLength, __privateGet(this, _bitLength) + 16);
|
|
1145
|
+
__privateWrapper(this, _wordIndex)._++;
|
|
1146
|
+
__privateWrapper(this, _wordLength)._++;
|
|
1147
|
+
}, "#bufferWrite16");
|
|
1148
|
+
__name(_UnalignedUint16Array, "UnalignedUint16Array");
|
|
1149
|
+
var UnalignedUint16Array = _UnalignedUint16Array;
|
|
1150
|
+
|
|
1176
1151
|
// src/lib/schema/SchemaStore.ts
|
|
1177
1152
|
var _schemas;
|
|
1178
1153
|
var _SchemaStore = class _SchemaStore {
|
|
@@ -1240,7 +1215,9 @@ var _SchemaStore = class _SchemaStore {
|
|
|
1240
1215
|
*/
|
|
1241
1216
|
serializeRaw(id, value) {
|
|
1242
1217
|
const schema = this.get(id);
|
|
1243
|
-
|
|
1218
|
+
const buffer = new UnalignedUint16Array(schema.totalBitSize ?? this.defaultMaximumArrayLength);
|
|
1219
|
+
schema.serialize(buffer, value);
|
|
1220
|
+
return buffer;
|
|
1244
1221
|
}
|
|
1245
1222
|
/**
|
|
1246
1223
|
* Deserializes a buffer
|