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