mol_vary 0.0.11 → 0.0.13
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/node.deps.json +1 -1
- package/node.js +24 -29
- package/node.js.map +1 -1
- package/node.mjs +24 -29
- package/node.test.js +25 -30
- package/node.test.js.map +1 -1
- package/package.json +1 -1
- package/web.deps.json +1 -1
- package/web.js +24 -29
- package/web.js.map +1 -1
- package/web.mjs +24 -29
- package/web.test.js +1 -1
- package/web.test.js.map +1 -1
package/node.test.js
CHANGED
|
@@ -187,12 +187,13 @@ var $;
|
|
|
187
187
|
$mol_vary_spec[$mol_vary_spec["fp32"] = 94] = "fp32";
|
|
188
188
|
$mol_vary_spec[$mol_vary_spec["fp64"] = 95] = "fp64";
|
|
189
189
|
})($mol_vary_spec = $.$mol_vary_spec || ($.$mol_vary_spec = {}));
|
|
190
|
-
let
|
|
191
|
-
let
|
|
190
|
+
let buffer = new Uint8Array(256);
|
|
191
|
+
let pack = new DataView(buffer.buffer);
|
|
192
192
|
class $mol_vary extends DataView {
|
|
193
193
|
static pack(data) {
|
|
194
194
|
let pos = 0;
|
|
195
195
|
let capacity = 0;
|
|
196
|
+
const offsets = new Map();
|
|
196
197
|
const acquire = (size) => {
|
|
197
198
|
if (size < 0)
|
|
198
199
|
return;
|
|
@@ -241,29 +242,28 @@ var $;
|
|
|
241
242
|
};
|
|
242
243
|
const dump_unum = (tip, val) => {
|
|
243
244
|
if (val < 28) {
|
|
244
|
-
|
|
245
|
+
buffer[pos++] = tip | Number(val);
|
|
245
246
|
release(8);
|
|
246
247
|
}
|
|
247
248
|
else if (val < 2 ** 8) {
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
pos += 1;
|
|
249
|
+
buffer[pos++] = tip | $.$mol_vary_len[1];
|
|
250
|
+
buffer[pos++] = Number(val);
|
|
251
251
|
release(7);
|
|
252
252
|
}
|
|
253
253
|
else if (val < 2 ** 16) {
|
|
254
|
-
|
|
254
|
+
buffer[pos++] = tip | $.$mol_vary_len[2];
|
|
255
255
|
pack.setUint16(pos, Number(val), true);
|
|
256
256
|
pos += 2;
|
|
257
257
|
release(6);
|
|
258
258
|
}
|
|
259
259
|
else if (val < 2 ** 32) {
|
|
260
|
-
|
|
260
|
+
buffer[pos++] = tip | $.$mol_vary_len[4];
|
|
261
261
|
pack.setUint32(pos, Number(val), true);
|
|
262
262
|
pos += 4;
|
|
263
263
|
release(4);
|
|
264
264
|
}
|
|
265
265
|
else if (val < 2n ** 64n) {
|
|
266
|
-
|
|
266
|
+
buffer[pos++] = tip | $.$mol_vary_len[8];
|
|
267
267
|
pack.setBigUint64(pos, BigInt(val), true);
|
|
268
268
|
pos += 8;
|
|
269
269
|
}
|
|
@@ -294,25 +294,25 @@ var $;
|
|
|
294
294
|
}
|
|
295
295
|
dump_unum($mol_vary_tip.blob, val.byteLength);
|
|
296
296
|
if (val instanceof Uint8Array)
|
|
297
|
-
|
|
297
|
+
buffer[pos++] = $mol_vary_tip.uint | $.$mol_vary_len[1];
|
|
298
298
|
else if (val instanceof Uint16Array)
|
|
299
|
-
|
|
299
|
+
buffer[pos++] = $mol_vary_tip.uint | $.$mol_vary_len[2];
|
|
300
300
|
else if (val instanceof Uint32Array)
|
|
301
|
-
|
|
301
|
+
buffer[pos++] = $mol_vary_tip.uint | $.$mol_vary_len[4];
|
|
302
302
|
else if (val instanceof BigUint64Array)
|
|
303
|
-
|
|
303
|
+
buffer[pos++] = $mol_vary_tip.uint | $.$mol_vary_len[8];
|
|
304
304
|
else if (val instanceof Int8Array)
|
|
305
|
-
|
|
305
|
+
buffer[pos++] = $mol_vary_tip.sint | ~$.$mol_vary_len[1];
|
|
306
306
|
else if (val instanceof Int16Array)
|
|
307
|
-
|
|
307
|
+
buffer[pos++] = $mol_vary_tip.sint | ~$.$mol_vary_len[2];
|
|
308
308
|
else if (val instanceof Int32Array)
|
|
309
|
-
|
|
309
|
+
buffer[pos++] = $mol_vary_tip.sint | ~$.$mol_vary_len[4];
|
|
310
310
|
else if (val instanceof BigInt64Array)
|
|
311
|
-
|
|
311
|
+
buffer[pos++] = $mol_vary_tip.sint | ~$.$mol_vary_len[8];
|
|
312
312
|
else if (val instanceof Float32Array)
|
|
313
|
-
|
|
313
|
+
buffer[pos++] = $mol_vary_spec.fp32;
|
|
314
314
|
else if (val instanceof Float64Array)
|
|
315
|
-
|
|
315
|
+
buffer[pos++] = $mol_vary_spec.fp64;
|
|
316
316
|
else
|
|
317
317
|
$mol_fail(new Error(`Unsupported type`));
|
|
318
318
|
const src = (val instanceof Uint8Array) ? val : new Uint8Array(val.buffer, val.byteOffset, val.byteLength);
|
|
@@ -355,18 +355,18 @@ var $;
|
|
|
355
355
|
const dump = (val) => {
|
|
356
356
|
switch (typeof val) {
|
|
357
357
|
case 'undefined': {
|
|
358
|
-
|
|
358
|
+
buffer[pos++] = $mol_vary_spec.both;
|
|
359
359
|
release(8);
|
|
360
360
|
return;
|
|
361
361
|
}
|
|
362
362
|
case 'boolean': {
|
|
363
|
-
|
|
363
|
+
buffer[pos++] = val ? $mol_vary_spec.true : $mol_vary_spec.fake;
|
|
364
364
|
release(8);
|
|
365
365
|
return;
|
|
366
366
|
}
|
|
367
367
|
case 'number': {
|
|
368
368
|
if (!Number.isInteger(val)) {
|
|
369
|
-
|
|
369
|
+
buffer[pos++] = $mol_vary_spec.fp64;
|
|
370
370
|
pack.setFloat64(pos, val, true);
|
|
371
371
|
pos += 8;
|
|
372
372
|
return;
|
|
@@ -385,7 +385,7 @@ var $;
|
|
|
385
385
|
case 'object': {
|
|
386
386
|
if (!val) {
|
|
387
387
|
release(8);
|
|
388
|
-
return
|
|
388
|
+
return buffer[pos++] = $mol_vary_spec.none;
|
|
389
389
|
}
|
|
390
390
|
if (ArrayBuffer.isView(val))
|
|
391
391
|
return dump_buffer(val);
|
|
@@ -397,8 +397,6 @@ var $;
|
|
|
397
397
|
$mol_fail(new Error(`Unsupported type`));
|
|
398
398
|
};
|
|
399
399
|
dump(data);
|
|
400
|
-
offsets = new Map;
|
|
401
|
-
sizes = new Map;
|
|
402
400
|
return buffer.slice(0, pos);
|
|
403
401
|
}
|
|
404
402
|
static take(buf) {
|
|
@@ -590,7 +588,6 @@ var $;
|
|
|
590
588
|
static type(keys, rich, lean) {
|
|
591
589
|
const obj = rich();
|
|
592
590
|
const proto = Reflect.getPrototypeOf(obj);
|
|
593
|
-
const vals = lean(obj);
|
|
594
591
|
const shape = JSON.stringify(keys);
|
|
595
592
|
this.leanes.set(proto, lean);
|
|
596
593
|
this.keys.set(proto, keys);
|
|
@@ -598,10 +595,8 @@ var $;
|
|
|
598
595
|
}
|
|
599
596
|
}
|
|
600
597
|
$.$mol_vary = $mol_vary;
|
|
601
|
-
let buffer = new Uint8Array(128);
|
|
602
|
-
let pack = new DataView(buffer.buffer);
|
|
603
598
|
$mol_vary.type(['keys', 'vals'], (keys = [], vals = []) => new Map(keys.map((k, i) => [k, vals[i]])), obj => [[...obj.keys()], [...obj.values()]]);
|
|
604
|
-
$mol_vary.type(['
|
|
599
|
+
$mol_vary.type(['set'], (vals = []) => new Set(vals), obj => [[...obj.values()]]);
|
|
605
600
|
$mol_vary.type(['unix_time'], (ts = 0) => new Date(ts * 1000), obj => [obj.valueOf() / 1000]);
|
|
606
601
|
})($ || ($ = {}));
|
|
607
602
|
|
|
@@ -4773,7 +4768,7 @@ var $;
|
|
|
4773
4768
|
check(new Map([['foo', 1], [2, 'bar']]), [tupl | 2, text | 4, ...str('keys'), text | 4, ...str('vals'), list | 2, text | 3, ...str('foo'), 2, list | 2, 1, text | 3, ...str('bar')]);
|
|
4774
4769
|
},
|
|
4775
4770
|
"vary pack Set"($) {
|
|
4776
|
-
check(new Set([7, 'foo']), [tupl | 1, text |
|
|
4771
|
+
check(new Set([7, 'foo']), [tupl | 1, text | 3, ...str('set'), list | 2, 7, text | 3, ...str('foo')]);
|
|
4777
4772
|
},
|
|
4778
4773
|
"vary pack Date"($) {
|
|
4779
4774
|
const date = new Date('2025-01-02T03:04:05.678');
|