@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
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
+
# [@sapphire/string-store@2.0.0](https://github.com/sapphiredev/utilities/compare/@sapphire/string-store@1.2.0...@sapphire/string-store@2.0.0) - (2025-01-31)
|
|
6
|
+
|
|
7
|
+
## 🏠 Refactor
|
|
8
|
+
|
|
9
|
+
- Add `DuplexBuffer` interface ([548200f](https://github.com/sapphiredev/utilities/commit/548200f1af067ae2f017c27a3c5d056ec6dd7ff8)) ([#865](https://github.com/sapphiredev/utilities/pull/865) by @kyranet)
|
|
10
|
+
- **SchemaStore:** Introduce `serializeRaw` ([5141559](https://github.com/sapphiredev/utilities/commit/51415597fa4b8ed0e17ba71743e73f3963a6803b)) ([#862](https://github.com/sapphiredev/utilities/pull/862) by @kyranet)
|
|
11
|
+
- 💥 **BREAKING CHANGE:** `serialize` no longer returns an `UnalignedUint16Array`, if you desire the old behaviour, use `serializeRaw`
|
|
12
|
+
|
|
13
|
+
## 🚀 Features
|
|
14
|
+
|
|
15
|
+
- **Schema:** Add serialization helpers ([8a922c4](https://github.com/sapphiredev/utilities/commit/8a922c421576707dcd1e74379544f20a8c43d785)) ([#864](https://github.com/sapphiredev/utilities/pull/864) by @kyranet)
|
|
16
|
+
- 💥 **BREAKING CHANGE:** `serialize` has been renamed to `serializeInto`
|
|
17
|
+
|
|
5
18
|
# [@sapphire/string-store@1.2.0](https://github.com/sapphiredev/utilities/compare/@sapphire/string-store@1.1.0...@sapphire/string-store@1.2.0) - (2024-12-18)
|
|
6
19
|
|
|
7
20
|
## 🏠 Refactor
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -73,6 +73,247 @@ _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
|
+
|
|
76
317
|
// src/lib/types/Array.ts
|
|
77
318
|
function ArrayType(type) {
|
|
78
319
|
return {
|
|
@@ -494,6 +735,30 @@ var _Schema = class _Schema {
|
|
|
494
735
|
if (!type) throw new Error(`Schema with id ${__privateGet(this, _id)} does not have a property with name "${name}"`);
|
|
495
736
|
return type;
|
|
496
737
|
}
|
|
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
|
+
}
|
|
497
762
|
/**
|
|
498
763
|
* Serialize a value into a buffer.
|
|
499
764
|
*
|
|
@@ -505,7 +770,7 @@ var _Schema = class _Schema {
|
|
|
505
770
|
* The schema's ID is written to the buffer first, followed by each property
|
|
506
771
|
* in the schema.
|
|
507
772
|
*/
|
|
508
|
-
|
|
773
|
+
serializeInto(buffer, value) {
|
|
509
774
|
buffer.writeInt16(__privateGet(this, _id));
|
|
510
775
|
for (const [name, type] of this) {
|
|
511
776
|
type.serialize(buffer, value[name]);
|
|
@@ -520,14 +785,15 @@ var _Schema = class _Schema {
|
|
|
520
785
|
*
|
|
521
786
|
* @remarks
|
|
522
787
|
*
|
|
523
|
-
* Unlike {@link Schema.
|
|
788
|
+
* Unlike {@link Schema.serializeInto}, this method does not read the schema's ID
|
|
524
789
|
* from the buffer, that is reserved for the {@link SchemaStore}.
|
|
525
790
|
*/
|
|
526
791
|
deserialize(buffer, pointer) {
|
|
527
|
-
|
|
792
|
+
buffer = UnalignedUint16Array.from(buffer);
|
|
793
|
+
pointer = Pointer.from(pointer);
|
|
528
794
|
const result = /* @__PURE__ */ Object.create(null);
|
|
529
795
|
for (const [name, type] of this) {
|
|
530
|
-
result[name] = type.deserialize(buffer,
|
|
796
|
+
result[name] = type.deserialize(buffer, pointer);
|
|
531
797
|
}
|
|
532
798
|
return result;
|
|
533
799
|
}
|
|
@@ -907,247 +1173,6 @@ addType_fn = /* @__PURE__ */ __name(function(name, type) {
|
|
|
907
1173
|
__name(_Schema, "Schema");
|
|
908
1174
|
var Schema = _Schema;
|
|
909
1175
|
|
|
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
|
-
|
|
1151
1176
|
// src/lib/schema/SchemaStore.ts
|
|
1152
1177
|
var _schemas;
|
|
1153
1178
|
var _SchemaStore = class _SchemaStore {
|
|
@@ -1215,9 +1240,7 @@ var _SchemaStore = class _SchemaStore {
|
|
|
1215
1240
|
*/
|
|
1216
1241
|
serializeRaw(id, value) {
|
|
1217
1242
|
const schema = this.get(id);
|
|
1218
|
-
|
|
1219
|
-
schema.serialize(buffer, value);
|
|
1220
|
-
return buffer;
|
|
1243
|
+
return schema.serializeRaw(value, this.defaultMaximumArrayLength);
|
|
1221
1244
|
}
|
|
1222
1245
|
/**
|
|
1223
1246
|
* Deserializes a buffer
|