json-as 1.3.2 → 1.3.3
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/README.md +3 -2
- package/assembly/deserialize/simple/map.ts +2 -0
- package/assembly/deserialize/simple/staticarray.ts +1 -0
- package/assembly/deserialize/simple/struct.ts +3 -1
- package/assembly/deserialize/swar/array/bool.ts +1 -0
- package/assembly/deserialize/swar/array/generic.ts +2 -1
- package/assembly/deserialize/swar/array/integer.ts +1 -0
- package/assembly/deserialize/swar/array/object.ts +1 -0
- package/assembly/deserialize/swar/array/shared.ts +1 -0
- package/assembly/deserialize/swar/array/string.ts +1 -0
- package/assembly/deserialize/swar/array/struct.ts +1 -0
- package/assembly/deserialize/swar/array.ts +1 -0
- package/assembly/deserialize/swar/string.ts +0 -2
- package/assembly/index.d.ts +1 -0
- package/assembly/index.ts +22 -21
- package/assembly/serialize/simple/array.ts +1 -0
- package/assembly/serialize/simple/float.ts +2 -0
- package/assembly/serialize/simple/typedarray.ts +1 -1
- package/assembly/tsconfig.json +2 -2
- package/assembly/util/dragonbox-cache.ts +2 -1320
- package/assembly/util/dragonbox.ts +63 -35
- package/lib/as-bs.ts +26 -18
- package/package.json +11 -10
- package/transform/lib/index.d.ts.map +1 -1
- package/transform/lib/index.js +200 -57
- package/transform/lib/index.js.map +1 -1
package/README.md
CHANGED
|
@@ -542,13 +542,13 @@ The following charts compare JSON-AS (both SWAR and SIMD variants) against JavaS
|
|
|
542
542
|
Instead of using flags for setting options, `json-as` is configured by environmental variables.
|
|
543
543
|
Here's a short list:
|
|
544
544
|
|
|
545
|
-
**JSON_CACHE** (default: 0) - Enables
|
|
545
|
+
**JSON_CACHE** (default: 0) - Enables and sizes string cache. Supports `true|false`, raw bytes (`JSON_CACHE=1048576`), bits (`JSON_CACHE=512kb`, `2mb`, `1gb`), and bytes (`JSON_CACHE=64KB`, `2MB`, `1GB`). May boost string serialization in excess of 22 GB/s.
|
|
546
546
|
|
|
547
547
|
**JSON_DEBUG** (default: 0) - Sets the debug level. May be within range `0-3`
|
|
548
548
|
|
|
549
549
|
**JSON_MODE** (default: SWAR) - Selects which mode should be used. Can be `NAIVE,SWAR,SIMD`. Note that `--enable simd` may be required.
|
|
550
550
|
|
|
551
|
-
**JSON_USE_FAST_PATH** (default:
|
|
551
|
+
**JSON_USE_FAST_PATH** (default: 1) - The transform emits the fast `__DESERIALIZE` implementation for generated structs by default. Set to `0`, `false`, `off`, or `no` to force slow-path-only output. See [FAST_PATH_DESERIALIZE.md](./FAST_PATH_DESERIALIZE.md) for the current support matrix, known gaps, and dedicated test command.
|
|
552
552
|
|
|
553
553
|
**JSON_WRITE** (default: "") - Select a series of files to output after transform and optimization passes have completed for easy inspection. Usage: `JSON_WRITE=.path-to-file-a.ts,./path-to-file-b.ts`
|
|
554
554
|
|
|
@@ -629,6 +629,7 @@ A few companies and open-source projects use json-as!
|
|
|
629
629
|
| [Klave](https://klave.com) | Privacy-first platform |
|
|
630
630
|
| [Bifrost](https://github.com/maximhq/bifrost) | Open source project by Maxim HQ |
|
|
631
631
|
| [Massa Labs](https://github.com/massalabs) | Massa blockchain tooling |
|
|
632
|
+
| [Seda Protocol](https://github.com/sedaprotocl) | Wasm-based blockchain VM |
|
|
632
633
|
|
|
633
634
|
## License
|
|
634
635
|
|
|
@@ -170,6 +170,7 @@ export function deserializeMap<T extends Map<any, any>>(srcStart: usize, srcEnd:
|
|
|
170
170
|
return out;
|
|
171
171
|
}
|
|
172
172
|
|
|
173
|
+
|
|
173
174
|
@inline export function deserializeMapInto<T extends Map<any, any>>(srcStart: usize, srcEnd: usize, out: T): usize {
|
|
174
175
|
changetype<nonnull<T>>(out).clear();
|
|
175
176
|
|
|
@@ -209,6 +210,7 @@ export function deserializeMap<T extends Map<any, any>>(srcStart: usize, srcEnd:
|
|
|
209
210
|
throw new Error("Failed to parse JSON!");
|
|
210
211
|
}
|
|
211
212
|
|
|
213
|
+
|
|
212
214
|
@inline export function deserializeMapField<T extends Map<any, any>>(srcStart: usize, srcEnd: usize, dstObj: usize, dstOffset: usize = 0): usize {
|
|
213
215
|
let out = load<T>(dstObj, dstOffset);
|
|
214
216
|
if (!changetype<usize>(out)) {
|
|
@@ -72,6 +72,7 @@ export function deserializeStaticArray<T extends StaticArray<any>>(srcStart: usi
|
|
|
72
72
|
throw new Error("Could not parse static array of type " + nameof<T>() + "!");
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
+
|
|
75
76
|
@inline export function deserializeStaticArrayField<T extends StaticArray<any>>(srcStart: usize, srcEnd: usize, dstObj: usize, dstOffset: usize = 0): usize {
|
|
76
77
|
const valueEnd = scanValueEnd(srcStart, srcEnd);
|
|
77
78
|
if (!valueEnd) throw new Error("Failed to parse JSON!");
|
|
@@ -7,9 +7,11 @@ export function deserializeStruct<T>(srcStart: usize, srcEnd: usize, dst: usize)
|
|
|
7
7
|
if (isDefined(out.__DESERIALIZE_FAST)) {
|
|
8
8
|
// @ts-ignore: supplied by transform
|
|
9
9
|
out.__DESERIALIZE_FAST(srcStart, srcEnd, out);
|
|
10
|
-
} else {
|
|
10
|
+
} else if (isDefined(out.__DESERIALIZE_SLOW)) {
|
|
11
11
|
// @ts-ignore: supplied by transform
|
|
12
12
|
out.__DESERIALIZE_SLOW(srcStart, srcEnd, out);
|
|
13
|
+
} else {
|
|
14
|
+
throw new Error("Missing __DESERIALIZE_FAST/__DESERIALIZE_SLOW");
|
|
13
15
|
}
|
|
14
16
|
return out;
|
|
15
17
|
}
|
|
@@ -45,6 +45,7 @@ import { ensureArrayElementSlot, ensureArrayField } from "./shared";
|
|
|
45
45
|
throw new Error("Failed to parse JSON!");
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
|
|
48
49
|
@inline export function deserializeBooleanArrayField<T extends boolean[]>(srcStart: usize, srcEnd: usize, fieldPtr: usize): usize {
|
|
49
50
|
return deserializeBooleanArrayInto<T>(srcStart, srcEnd, ensureArrayField<T>(fieldPtr));
|
|
50
51
|
}
|
|
@@ -2,8 +2,8 @@ import { JSON } from "../../..";
|
|
|
2
2
|
import { BRACKET_LEFT, BRACKET_RIGHT, COMMA } from "../../../custom/chars";
|
|
3
3
|
import { ensureArrayElementSlot, ensureArrayField, scanValueEnd } from "./shared";
|
|
4
4
|
|
|
5
|
-
@inline export function deserializeGenericArrayInto<T extends unknown[]>(srcStart: usize, srcEnd: usize, out: T): usize {
|
|
6
5
|
|
|
6
|
+
@inline export function deserializeGenericArrayInto<T extends unknown[]>(srcStart: usize, srcEnd: usize, out: T): usize {
|
|
7
7
|
if (srcStart >= srcEnd || load<u16>(srcStart) != BRACKET_LEFT) throw new Error("Failed to parse JSON!");
|
|
8
8
|
srcStart += 2;
|
|
9
9
|
if (srcStart >= srcEnd) throw new Error("Failed to parse JSON!");
|
|
@@ -35,6 +35,7 @@ import { ensureArrayElementSlot, ensureArrayField, scanValueEnd } from "./shared
|
|
|
35
35
|
throw new Error("Failed to parse JSON!");
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
|
|
38
39
|
@inline export function deserializeGenericArrayField<T extends unknown[]>(srcStart: usize, srcEnd: usize, fieldPtr: usize): usize {
|
|
39
40
|
return deserializeGenericArrayInto<T>(srcStart, srcEnd, ensureArrayField<T>(fieldPtr));
|
|
40
41
|
}
|
|
@@ -459,6 +459,7 @@ export function deserializeIntegerArray_SWAR<T extends number[]>(srcStart: usize
|
|
|
459
459
|
throw new Error("Failed to parse JSON!");
|
|
460
460
|
}
|
|
461
461
|
|
|
462
|
+
|
|
462
463
|
@inline export function deserializeIntegerArrayField<T extends number[]>(srcStart: usize, srcEnd: usize, fieldPtr: usize): usize {
|
|
463
464
|
return deserializeIntegerArrayInto<T>(srcStart, srcEnd, ensureArrayField<T>(fieldPtr));
|
|
464
465
|
}
|
|
@@ -55,6 +55,7 @@ import { ensureArrayElementSlot, ensureArrayField } from "./shared";
|
|
|
55
55
|
throw new Error("Failed to parse JSON!");
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
|
|
58
59
|
@inline export function deserializeObjectArrayField<T extends unknown[]>(srcStart: usize, srcEnd: usize, fieldPtr: usize): usize {
|
|
59
60
|
return deserializeObjectArrayInto<T>(srcStart, srcEnd, ensureArrayField<T>(fieldPtr));
|
|
60
61
|
}
|
|
@@ -10,6 +10,7 @@ import { BACK_SLASH, BRACE_LEFT, BRACE_RIGHT, BRACKET_LEFT, BRACKET_RIGHT, COMMA
|
|
|
10
10
|
return out;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
|
|
13
14
|
@inline export function ensureArrayFieldAt<T extends Array<any>>(dstObj: usize, dstOffset: usize): T {
|
|
14
15
|
let out = load<T>(dstObj, dstOffset);
|
|
15
16
|
if (!changetype<usize>(out)) {
|
|
@@ -37,6 +37,7 @@ import { deserializeStringField_SWAR } from "../string";
|
|
|
37
37
|
throw new Error("Failed to parse JSON!");
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
|
|
40
41
|
@inline export function deserializeStringArrayField<T extends string[]>(srcStart: usize, srcEnd: usize, fieldPtr: usize): usize {
|
|
41
42
|
return deserializeStringArrayInto<T>(srcStart, srcEnd, ensureArrayField<T>(fieldPtr));
|
|
42
43
|
}
|
|
@@ -55,6 +55,7 @@ import { ensureArrayElementSlot, ensureArrayField } from "./shared";
|
|
|
55
55
|
throw new Error("Failed to parse JSON!");
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
|
|
58
59
|
@inline export function deserializeStructArrayField<T extends unknown[]>(srcStart: usize, srcEnd: usize, fieldPtr: usize): usize {
|
|
59
60
|
return deserializeStructArrayInto<T>(srcStart, srcEnd, ensureArrayField<T>(fieldPtr));
|
|
60
61
|
}
|
|
@@ -62,6 +62,7 @@ import { deserializeStructArrayInto } from "./array/struct";
|
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
+
|
|
65
66
|
@inline export function deserializeArrayInto_SWAR<T extends unknown[]>(srcStart: usize, srcEnd: usize, out: T): usize {
|
|
66
67
|
if (isString<valueof<T>>()) {
|
|
67
68
|
return deserializeStringArrayInto<T>(srcStart, srcEnd, out);
|
|
@@ -209,7 +209,6 @@ export function deserializeString_SWAR(srcStart: usize, srcEnd: usize): string {
|
|
|
209
209
|
memory.copy(stringPtr, srcStart, byteLength);
|
|
210
210
|
}
|
|
211
211
|
|
|
212
|
-
|
|
213
212
|
// @ts-expect-error: @inline is a valid decorator
|
|
214
213
|
@inline function deserializeEscapedStringContinuation_SWAR(lastPtr: usize, srcStart: usize, srcEnd: usize, dstFieldPtr: usize, outStart: usize): usize {
|
|
215
214
|
const srcEnd8 = srcEnd - 8;
|
|
@@ -630,7 +629,6 @@ export function deserializeStringField_SWAR<T extends string | null>(srcStart: u
|
|
|
630
629
|
return srcStart;
|
|
631
630
|
}
|
|
632
631
|
|
|
633
|
-
|
|
634
632
|
/**
|
|
635
633
|
* Computes a per-byte mask identifying ASCII backslash or quote bytes.
|
|
636
634
|
*
|
package/assembly/index.d.ts
CHANGED
package/assembly/index.ts
CHANGED
|
@@ -17,18 +17,7 @@ import { serializeSet } from "./serialize/index/set";
|
|
|
17
17
|
import { deserializeSet } from "./deserialize/index/set";
|
|
18
18
|
import { serializeStaticArray } from "./serialize/index/staticarray";
|
|
19
19
|
import { deserializeStaticArray } from "./deserialize/index/staticarray";
|
|
20
|
-
import {
|
|
21
|
-
BRACE_LEFT,
|
|
22
|
-
BRACE_RIGHT,
|
|
23
|
-
BRACKET_LEFT,
|
|
24
|
-
BRACKET_RIGHT,
|
|
25
|
-
COMMA,
|
|
26
|
-
NULL_WORD,
|
|
27
|
-
QUOTE,
|
|
28
|
-
NULL_WORD_U64,
|
|
29
|
-
TRUE_WORD_U64,
|
|
30
|
-
FALSE_WORD_U64,
|
|
31
|
-
} from "./custom/chars";
|
|
20
|
+
import { BRACE_LEFT, BRACE_RIGHT, BRACKET_LEFT, BRACKET_RIGHT, COMMA, NULL_WORD, QUOTE, NULL_WORD_U64, TRUE_WORD_U64, FALSE_WORD_U64 } from "./custom/chars";
|
|
32
21
|
import { itoa_buffered } from "util/number";
|
|
33
22
|
import { serializeBool } from "./serialize/index/bool";
|
|
34
23
|
import { serializeInteger } from "./serialize/index/integer";
|
|
@@ -244,14 +233,19 @@ export namespace JSON {
|
|
|
244
233
|
} else if (isDefined(type.__DESERIALIZE_SLOW) || isDefined(type.__DESERIALIZE_FAST)) {
|
|
245
234
|
const out = changetype<nonnull<T>>(__new(offsetof<nonnull<T>>(), idof<nonnull<T>>()));
|
|
246
235
|
// @ts-expect-error: Defined by transform
|
|
247
|
-
if (isDefined(type.__INITIALIZE)) out.__INITIALIZE();
|
|
248
|
-
// @ts-expect-error: Defined by transform
|
|
249
236
|
if (isDefined(type.__DESERIALIZE_FAST)) {
|
|
250
237
|
// @ts-expect-error: Defined by transform
|
|
251
|
-
out.__DESERIALIZE_FAST(dataPtr, dataPtr + dataSize, out);
|
|
238
|
+
if (out.__DESERIALIZE_FAST(dataPtr, dataPtr + dataSize, out) == dataPtr + dataSize) return out;
|
|
252
239
|
// @ts-expect-error: Defined by transform
|
|
253
|
-
}
|
|
254
|
-
|
|
240
|
+
}
|
|
241
|
+
if (isDefined(type.__INITIALIZE)) out.__INITIALIZE();
|
|
242
|
+
// @ts-expect-error: Defined by transform
|
|
243
|
+
if (isDefined(type.__DESERIALIZE_SLOW)) {
|
|
244
|
+
// @ts-expect-error: Defined by transform
|
|
245
|
+
out.__DESERIALIZE_SLOW(dataPtr, dataPtr + dataSize, out);
|
|
246
|
+
return out;
|
|
247
|
+
}
|
|
248
|
+
throw new Error(`No deserialize method defined for type ${type}`);
|
|
255
249
|
}
|
|
256
250
|
if (type instanceof StaticArray) {
|
|
257
251
|
// @ts-expect-error
|
|
@@ -956,12 +950,19 @@ export namespace JSON {
|
|
|
956
950
|
} else if (isDefined(type.__DESERIALIZE_SLOW) || isDefined(type.__DESERIALIZE_FAST)) {
|
|
957
951
|
const out = changetype<nonnull<T>>(dst || __new(offsetof<nonnull<T>>(), idof<nonnull<T>>()));
|
|
958
952
|
// @ts-expect-error: Defined by transform
|
|
959
|
-
if (isDefined(type.
|
|
953
|
+
if (isDefined(type.__DESERIALIZE_FAST)) {
|
|
954
|
+
// @ts-expect-error: Defined by transform
|
|
955
|
+
if (out.__DESERIALIZE_FAST(srcStart, srcEnd, out) == srcEnd) return out;
|
|
956
|
+
}
|
|
960
957
|
// @ts-expect-error: Defined by transform
|
|
961
|
-
if (isDefined(type.
|
|
958
|
+
if (isDefined(type.__INITIALIZE)) out.__INITIALIZE();
|
|
962
959
|
// @ts-expect-error: Defined by transform
|
|
963
|
-
|
|
964
|
-
|
|
960
|
+
if (isDefined(type.__DESERIALIZE_SLOW)) {
|
|
961
|
+
// @ts-expect-error: Defined by transform
|
|
962
|
+
out.__DESERIALIZE_SLOW(srcStart, srcEnd, out);
|
|
963
|
+
return out;
|
|
964
|
+
}
|
|
965
|
+
throw new Error(`No deserialize method defined for type ${type}`);
|
|
965
966
|
}
|
|
966
967
|
if (type instanceof StaticArray) {
|
|
967
968
|
// @ts-expect-error: type
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { bs } from "../../../lib/as-bs";
|
|
2
2
|
import { dragonbox_f32_buffered, dragonbox_f64_buffered } from "../../util/dragonbox";
|
|
3
3
|
|
|
4
|
+
|
|
4
5
|
@inline
|
|
5
6
|
export function serializeFloat32(data: f32): void {
|
|
6
7
|
bs.ensureSize(64);
|
|
@@ -9,6 +10,7 @@ export function serializeFloat32(data: f32): void {
|
|
|
9
10
|
bs.offset += size;
|
|
10
11
|
}
|
|
11
12
|
|
|
13
|
+
|
|
12
14
|
@inline
|
|
13
15
|
export function serializeFloat64(data: f64): void {
|
|
14
16
|
bs.ensureSize(64);
|
package/assembly/tsconfig.json
CHANGED