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