json-as 1.3.0 → 1.3.2
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 +400 -0
- package/README.md +137 -32
- package/assembly/deserialize/index/arbitrary.ts +1 -1
- package/assembly/deserialize/index/array.ts +6 -1
- package/assembly/deserialize/index/float.ts +1 -1
- package/assembly/deserialize/index/integer.ts +1 -1
- package/assembly/deserialize/index/typedarray.ts +14 -0
- package/assembly/deserialize/index/unsigned.ts +1 -1
- package/assembly/deserialize/simd/string.ts +20 -16
- package/assembly/deserialize/simple/arbitrary.ts +1 -1
- package/assembly/deserialize/simple/array/generic.ts +42 -0
- package/assembly/deserialize/simple/array.ts +8 -1
- package/assembly/deserialize/{float.ts → simple/float.ts} +22 -2
- package/assembly/deserialize/{integer.ts → simple/integer.ts} +3 -2
- package/assembly/deserialize/simple/map.ts +60 -12
- package/assembly/deserialize/simple/object.ts +1 -1
- package/assembly/deserialize/simple/set.ts +119 -134
- package/assembly/deserialize/simple/staticarray.ts +12 -1
- package/assembly/deserialize/simple/string.ts +93 -2
- package/assembly/deserialize/simple/struct.ts +7 -157
- package/assembly/deserialize/simple/typedarray.ts +1 -1
- package/assembly/deserialize/{unsigned.ts → simple/unsigned.ts} +3 -2
- package/assembly/deserialize/swar/array/array.ts +42 -7
- package/assembly/deserialize/swar/array/bool.ts +5 -2
- package/assembly/deserialize/swar/array/float.ts +7 -3
- package/assembly/deserialize/swar/array/generic.ts +40 -0
- package/assembly/deserialize/swar/array/integer.ts +7 -4
- package/assembly/deserialize/swar/array/object.ts +20 -4
- package/assembly/deserialize/swar/array/shared.ts +18 -4
- package/assembly/deserialize/swar/array/string.ts +5 -2
- package/assembly/deserialize/swar/array/struct.ts +20 -4
- package/assembly/deserialize/swar/array.ts +56 -2
- package/assembly/deserialize/swar/string.ts +245 -370
- package/assembly/index.ts +207 -194
- package/assembly/serialize/index/arbitrary.ts +8 -3
- package/assembly/serialize/index/float.ts +1 -1
- package/assembly/serialize/index/object.ts +1 -5
- package/assembly/serialize/index/typedarray.ts +65 -0
- package/assembly/serialize/simd/string.ts +7 -16
- package/assembly/serialize/simple/arbitrary.ts +9 -3
- package/assembly/serialize/simple/array.ts +17 -6
- package/assembly/serialize/simple/float.ts +18 -4
- package/assembly/serialize/simple/map.ts +10 -27
- package/assembly/serialize/simple/object.ts +1 -5
- package/assembly/serialize/simple/set.ts +3 -4
- package/assembly/serialize/simple/staticarray.ts +4 -3
- package/assembly/serialize/simple/string.ts +3 -11
- package/assembly/serialize/simple/typedarray.ts +9 -7
- package/assembly/serialize/swar/string.ts +3 -12
- package/assembly/tsconfig.json +3 -2
- package/assembly/util/dragonbox-cache.ts +1322 -0
- package/assembly/util/dragonbox.ts +596 -0
- package/assembly/util/swar.ts +49 -0
- package/lib/as-bs.ts +92 -70
- package/package.json +35 -10
- package/transform/lib/index.d.ts +1 -0
- package/transform/lib/index.d.ts.map +1 -1
- package/transform/lib/index.js +559 -221
- package/transform/lib/index.js.map +1 -1
- package/transform/lib/linkers/custom.d.ts.map +1 -1
- package/transform/lib/linkers/custom.js +7 -3
- package/transform/lib/linkers/custom.js.map +1 -1
- package/transform/lib/types.d.ts +2 -0
- package/transform/lib/types.d.ts.map +1 -1
- package/transform/lib/types.js +13 -0
- package/transform/lib/types.js.map +1 -1
- package/.as-test/coverage/naive/coverage.arbitrary.spec.ts.log.json +0 -5628
- package/.as-test/coverage/naive/coverage.array.spec.ts.log.json +0 -5187
- package/.as-test/coverage/naive/coverage.bool.spec.ts.log.json +0 -5187
- package/.as-test/coverage/naive/coverage.box.spec.ts.log.json +0 -5187
- package/.as-test/coverage/naive/coverage.custom.spec.ts.log.json +0 -5187
- package/.as-test/coverage/naive/coverage.date.spec.ts.log.json +0 -5187
- package/.as-test/coverage/naive/coverage.enum.spec.ts.log.json +0 -5187
- package/.as-test/coverage/naive/coverage.float.spec.ts.log.json +0 -5187
- package/.as-test/coverage/naive/coverage.generics.spec.ts.log.json +0 -5187
- package/.as-test/coverage/naive/coverage.hierarchy.spec.ts.log.json +0 -5187
- package/.as-test/coverage/naive/coverage.integer.spec.ts.log.json +0 -5187
- package/.as-test/coverage/naive/coverage.map.spec.ts.log.json +0 -5187
- package/.as-test/coverage/naive/coverage.namespace.spec.ts.log.json +0 -5187
- package/.as-test/coverage/naive/coverage.null.spec.ts.log.json +0 -5187
- package/.as-test/coverage/naive/coverage.raw.spec.ts.log.json +0 -5187
- package/.as-test/coverage/naive/coverage.resolving.spec.ts.log.json +0 -5628
- package/.as-test/coverage/naive/coverage.set.spec.ts.log.json +0 -5187
- package/.as-test/coverage/naive/coverage.staticarray.spec.ts.log.json +0 -5187
- package/.as-test/coverage/naive/coverage.string.spec.ts.log.json +0 -5187
- package/.as-test/coverage/naive/coverage.struct.spec.ts.log.json +0 -5187
- package/.as-test/coverage/naive/coverage.types.spec.ts.log.json +0 -5187
- package/.as-test/coverage/simd/coverage.arbitrary.spec.ts.log.json +0 -5628
- package/.as-test/coverage/simd/coverage.array.spec.ts.log.json +0 -5187
- package/.as-test/coverage/simd/coverage.bool.spec.ts.log.json +0 -5187
- package/.as-test/coverage/simd/coverage.box.spec.ts.log.json +0 -5187
- package/.as-test/coverage/simd/coverage.custom.spec.ts.log.json +0 -5187
- package/.as-test/coverage/simd/coverage.date.spec.ts.log.json +0 -5187
- package/.as-test/coverage/simd/coverage.enum.spec.ts.log.json +0 -5187
- package/.as-test/coverage/simd/coverage.float.spec.ts.log.json +0 -5187
- package/.as-test/coverage/simd/coverage.generics.spec.ts.log.json +0 -5187
- package/.as-test/coverage/simd/coverage.hierarchy.spec.ts.log.json +0 -5187
- package/.as-test/coverage/simd/coverage.integer.spec.ts.log.json +0 -5187
- package/.as-test/coverage/simd/coverage.map.spec.ts.log.json +0 -5187
- package/.as-test/coverage/simd/coverage.namespace.spec.ts.log.json +0 -5187
- package/.as-test/coverage/simd/coverage.null.spec.ts.log.json +0 -5187
- package/.as-test/coverage/simd/coverage.raw.spec.ts.log.json +0 -5187
- package/.as-test/coverage/simd/coverage.resolving.spec.ts.log.json +0 -5628
- package/.as-test/coverage/simd/coverage.set.spec.ts.log.json +0 -5187
- package/.as-test/coverage/simd/coverage.staticarray.spec.ts.log.json +0 -5187
- package/.as-test/coverage/simd/coverage.string.spec.ts.log.json +0 -5187
- package/.as-test/coverage/simd/coverage.struct.spec.ts.log.json +0 -5187
- package/.as-test/coverage/simd/coverage.types.spec.ts.log.json +0 -5187
- package/.as-test/coverage/swar/coverage.arbitrary.spec.ts.log.json +0 -5628
- package/.as-test/coverage/swar/coverage.array.spec.ts.log.json +0 -5187
- package/.as-test/coverage/swar/coverage.bool.spec.ts.log.json +0 -5187
- package/.as-test/coverage/swar/coverage.box.spec.ts.log.json +0 -5187
- package/.as-test/coverage/swar/coverage.custom.spec.ts.log.json +0 -5187
- package/.as-test/coverage/swar/coverage.date.spec.ts.log.json +0 -5187
- package/.as-test/coverage/swar/coverage.enum.spec.ts.log.json +0 -5187
- package/.as-test/coverage/swar/coverage.float.spec.ts.log.json +0 -5187
- package/.as-test/coverage/swar/coverage.generics.spec.ts.log.json +0 -5187
- package/.as-test/coverage/swar/coverage.hierarchy.spec.ts.log.json +0 -5187
- package/.as-test/coverage/swar/coverage.integer.spec.ts.log.json +0 -5187
- package/.as-test/coverage/swar/coverage.map.spec.ts.log.json +0 -5187
- package/.as-test/coverage/swar/coverage.namespace.spec.ts.log.json +0 -5187
- package/.as-test/coverage/swar/coverage.null.spec.ts.log.json +0 -5187
- package/.as-test/coverage/swar/coverage.raw.spec.ts.log.json +0 -5187
- package/.as-test/coverage/swar/coverage.resolving.spec.ts.log.json +0 -5628
- package/.as-test/coverage/swar/coverage.set.spec.ts.log.json +0 -5187
- package/.as-test/coverage/swar/coverage.staticarray.spec.ts.log.json +0 -5187
- package/.as-test/coverage/swar/coverage.string.spec.ts.log.json +0 -5187
- package/.as-test/coverage/swar/coverage.struct.spec.ts.log.json +0 -5187
- package/.as-test/coverage/swar/coverage.types.spec.ts.log.json +0 -5187
- package/.as-test/logs/naive/run.arbitrary.spec.ts.log.json +0 -943
- package/.as-test/logs/naive/run.array.spec.ts.log.json +0 -1053
- package/.as-test/logs/naive/run.bool.spec.ts.log.json +0 -257
- package/.as-test/logs/naive/run.box.spec.ts.log.json +0 -353
- package/.as-test/logs/naive/run.custom.spec.ts.log.json +0 -309
- package/.as-test/logs/naive/run.date.spec.ts.log.json +0 -397
- package/.as-test/logs/naive/run.enum.spec.ts.log.json +0 -343
- package/.as-test/logs/naive/run.float.spec.ts.log.json +0 -453
- package/.as-test/logs/naive/run.generics.spec.ts.log.json +0 -393
- package/.as-test/logs/naive/run.hierarchy.spec.ts.log.json +0 -325
- package/.as-test/logs/naive/run.integer.spec.ts.log.json +0 -373
- package/.as-test/logs/naive/run.map.spec.ts.log.json +0 -247
- package/.as-test/logs/naive/run.namespace.spec.ts.log.json +0 -361
- package/.as-test/logs/naive/run.null.spec.ts.log.json +0 -273
- package/.as-test/logs/naive/run.raw.spec.ts.log.json +0 -309
- package/.as-test/logs/naive/run.resolving.spec.ts.log.json +0 -273
- package/.as-test/logs/naive/run.set.spec.ts.log.json +0 -733
- package/.as-test/logs/naive/run.staticarray.spec.ts.log.json +0 -931
- package/.as-test/logs/naive/run.string.spec.ts.log.json +0 -2289
- package/.as-test/logs/naive/run.struct.spec.ts.log.json +0 -523
- package/.as-test/logs/naive/run.types.spec.ts.log.json +0 -273
- package/.as-test/logs/naive/test.arbitrary.spec.ts.log.json +0 -943
- package/.as-test/logs/naive/test.array.spec.ts.log.json +0 -1053
- package/.as-test/logs/naive/test.bool.spec.ts.log.json +0 -257
- package/.as-test/logs/naive/test.box.spec.ts.log.json +0 -353
- package/.as-test/logs/naive/test.custom.spec.ts.log.json +0 -309
- package/.as-test/logs/naive/test.date.spec.ts.log.json +0 -397
- package/.as-test/logs/naive/test.enum.spec.ts.log.json +0 -343
- package/.as-test/logs/naive/test.float.spec.ts.log.json +0 -453
- package/.as-test/logs/naive/test.generics.spec.ts.log.json +0 -393
- package/.as-test/logs/naive/test.hierarchy.spec.ts.log.json +0 -325
- package/.as-test/logs/naive/test.integer.spec.ts.log.json +0 -373
- package/.as-test/logs/naive/test.log.json +0 -2289
- package/.as-test/logs/naive/test.map.spec.ts.log.json +0 -247
- package/.as-test/logs/naive/test.namespace.spec.ts.log.json +0 -361
- package/.as-test/logs/naive/test.null.spec.ts.log.json +0 -273
- package/.as-test/logs/naive/test.raw.spec.ts.log.json +0 -309
- package/.as-test/logs/naive/test.resolving.spec.ts.log.json +0 -273
- package/.as-test/logs/naive/test.set.spec.ts.log.json +0 -733
- package/.as-test/logs/naive/test.staticarray.spec.ts.log.json +0 -931
- package/.as-test/logs/naive/test.string.spec.ts.log.json +0 -2345
- package/.as-test/logs/naive/test.struct.spec.ts.log.json +0 -523
- package/.as-test/logs/naive/test.types.spec.ts.log.json +0 -273
- package/.as-test/logs/simd/run.arbitrary.spec.ts.log.json +0 -943
- package/.as-test/logs/simd/run.array.spec.ts.log.json +0 -1053
- package/.as-test/logs/simd/run.bool.spec.ts.log.json +0 -257
- package/.as-test/logs/simd/run.box.spec.ts.log.json +0 -353
- package/.as-test/logs/simd/run.custom.spec.ts.log.json +0 -309
- package/.as-test/logs/simd/run.date.spec.ts.log.json +0 -397
- package/.as-test/logs/simd/run.enum.spec.ts.log.json +0 -343
- package/.as-test/logs/simd/run.float.spec.ts.log.json +0 -453
- package/.as-test/logs/simd/run.generics.spec.ts.log.json +0 -393
- package/.as-test/logs/simd/run.hierarchy.spec.ts.log.json +0 -325
- package/.as-test/logs/simd/run.integer.spec.ts.log.json +0 -373
- package/.as-test/logs/simd/run.map.spec.ts.log.json +0 -247
- package/.as-test/logs/simd/run.namespace.spec.ts.log.json +0 -361
- package/.as-test/logs/simd/run.null.spec.ts.log.json +0 -273
- package/.as-test/logs/simd/run.raw.spec.ts.log.json +0 -309
- package/.as-test/logs/simd/run.resolving.spec.ts.log.json +0 -273
- package/.as-test/logs/simd/run.set.spec.ts.log.json +0 -733
- package/.as-test/logs/simd/run.staticarray.spec.ts.log.json +0 -931
- package/.as-test/logs/simd/run.string.spec.ts.log.json +0 -2289
- package/.as-test/logs/simd/run.struct.spec.ts.log.json +0 -523
- package/.as-test/logs/simd/run.types.spec.ts.log.json +0 -273
- package/.as-test/logs/simd/test.arbitrary.spec.ts.log.json +0 -943
- package/.as-test/logs/simd/test.array.spec.ts.log.json +0 -1053
- package/.as-test/logs/simd/test.bool.spec.ts.log.json +0 -257
- package/.as-test/logs/simd/test.box.spec.ts.log.json +0 -353
- package/.as-test/logs/simd/test.custom.spec.ts.log.json +0 -309
- package/.as-test/logs/simd/test.date.spec.ts.log.json +0 -397
- package/.as-test/logs/simd/test.enum.spec.ts.log.json +0 -343
- package/.as-test/logs/simd/test.float.spec.ts.log.json +0 -453
- package/.as-test/logs/simd/test.generics.spec.ts.log.json +0 -393
- package/.as-test/logs/simd/test.hierarchy.spec.ts.log.json +0 -325
- package/.as-test/logs/simd/test.integer.spec.ts.log.json +0 -373
- package/.as-test/logs/simd/test.log.json +0 -11371
- package/.as-test/logs/simd/test.map.spec.ts.log.json +0 -247
- package/.as-test/logs/simd/test.namespace.spec.ts.log.json +0 -361
- package/.as-test/logs/simd/test.null.spec.ts.log.json +0 -273
- package/.as-test/logs/simd/test.raw.spec.ts.log.json +0 -309
- package/.as-test/logs/simd/test.resolving.spec.ts.log.json +0 -273
- package/.as-test/logs/simd/test.set.spec.ts.log.json +0 -733
- package/.as-test/logs/simd/test.staticarray.spec.ts.log.json +0 -931
- package/.as-test/logs/simd/test.string.spec.ts.log.json +0 -2345
- package/.as-test/logs/simd/test.struct.spec.ts.log.json +0 -523
- package/.as-test/logs/simd/test.types.spec.ts.log.json +0 -273
- package/.as-test/logs/swar/run.arbitrary.spec.ts.log.json +0 -943
- package/.as-test/logs/swar/run.array.spec.ts.log.json +0 -1053
- package/.as-test/logs/swar/run.bool.spec.ts.log.json +0 -257
- package/.as-test/logs/swar/run.box.spec.ts.log.json +0 -353
- package/.as-test/logs/swar/run.custom.spec.ts.log.json +0 -309
- package/.as-test/logs/swar/run.date.spec.ts.log.json +0 -397
- package/.as-test/logs/swar/run.enum.spec.ts.log.json +0 -343
- package/.as-test/logs/swar/run.float.spec.ts.log.json +0 -453
- package/.as-test/logs/swar/run.generics.spec.ts.log.json +0 -393
- package/.as-test/logs/swar/run.hierarchy.spec.ts.log.json +0 -325
- package/.as-test/logs/swar/run.integer.spec.ts.log.json +0 -373
- package/.as-test/logs/swar/run.map.spec.ts.log.json +0 -247
- package/.as-test/logs/swar/run.namespace.spec.ts.log.json +0 -361
- package/.as-test/logs/swar/run.null.spec.ts.log.json +0 -273
- package/.as-test/logs/swar/run.raw.spec.ts.log.json +0 -309
- package/.as-test/logs/swar/run.resolving.spec.ts.log.json +0 -273
- package/.as-test/logs/swar/run.set.spec.ts.log.json +0 -733
- package/.as-test/logs/swar/run.staticarray.spec.ts.log.json +0 -931
- package/.as-test/logs/swar/run.string.spec.ts.log.json +0 -2289
- package/.as-test/logs/swar/run.struct.spec.ts.log.json +0 -523
- package/.as-test/logs/swar/run.types.spec.ts.log.json +0 -273
- package/.as-test/logs/swar/test.arbitrary.spec.ts.log.json +0 -943
- package/.as-test/logs/swar/test.array.spec.ts.log.json +0 -1053
- package/.as-test/logs/swar/test.bool.spec.ts.log.json +0 -257
- package/.as-test/logs/swar/test.box.spec.ts.log.json +0 -353
- package/.as-test/logs/swar/test.custom.spec.ts.log.json +0 -309
- package/.as-test/logs/swar/test.date.spec.ts.log.json +0 -397
- package/.as-test/logs/swar/test.enum.spec.ts.log.json +0 -343
- package/.as-test/logs/swar/test.float.spec.ts.log.json +0 -453
- package/.as-test/logs/swar/test.generics.spec.ts.log.json +0 -393
- package/.as-test/logs/swar/test.hierarchy.spec.ts.log.json +0 -325
- package/.as-test/logs/swar/test.integer.spec.ts.log.json +0 -373
- package/.as-test/logs/swar/test.log.json +0 -11371
- package/.as-test/logs/swar/test.map.spec.ts.log.json +0 -247
- package/.as-test/logs/swar/test.namespace.spec.ts.log.json +0 -361
- package/.as-test/logs/swar/test.null.spec.ts.log.json +0 -273
- package/.as-test/logs/swar/test.raw.spec.ts.log.json +0 -309
- package/.as-test/logs/swar/test.resolving.spec.ts.log.json +0 -273
- package/.as-test/logs/swar/test.set.spec.ts.log.json +0 -733
- package/.as-test/logs/swar/test.staticarray.spec.ts.log.json +0 -931
- package/.as-test/logs/swar/test.string.spec.ts.log.json +0 -2345
- package/.as-test/logs/swar/test.struct.spec.ts.log.json +0 -523
- package/.as-test/logs/swar/test.types.spec.ts.log.json +0 -273
- package/.as-test/logs/test.arbitrary.spec.ts.log.json +0 -943
- package/.as-test/logs/test.array.spec.ts.log.json +0 -1053
- package/.as-test/logs/test.bool.spec.ts.log.json +0 -257
- package/.as-test/logs/test.box.spec.ts.log.json +0 -353
- package/.as-test/logs/test.custom.spec.ts.log.json +0 -309
- package/.as-test/logs/test.date.spec.ts.log.json +0 -397
- package/.as-test/logs/test.enum.spec.ts.log.json +0 -343
- package/.as-test/logs/test.float.spec.ts.log.json +0 -453
- package/.as-test/logs/test.generics.spec.ts.log.json +0 -393
- package/.as-test/logs/test.hierarchy.spec.ts.log.json +0 -325
- package/.as-test/logs/test.integer.spec.ts.log.json +0 -373
- package/.as-test/logs/test.log.json +0 -11371
- package/.as-test/logs/test.map.spec.ts.log.json +0 -247
- package/.as-test/logs/test.namespace.spec.ts.log.json +0 -361
- package/.as-test/logs/test.null.spec.ts.log.json +0 -273
- package/.as-test/logs/test.raw.spec.ts.log.json +0 -309
- package/.as-test/logs/test.resolving.spec.ts.log.json +0 -273
- package/.as-test/logs/test.set.spec.ts.log.json +0 -733
- package/.as-test/logs/test.staticarray.spec.ts.log.json +0 -931
- package/.as-test/logs/test.string.spec.ts.log.json +0 -2289
- package/.as-test/logs/test.struct.spec.ts.log.json +0 -523
- package/.as-test/logs/test.types.spec.ts.log.json +0 -273
- package/.as-test/runners/default.bindings.js +0 -68
- package/.as-test/runners/default.wasi.js +0 -38
- package/ARCHITECTURE.md +0 -323
- package/CONTRIBUTING.md +0 -244
- package/TODO +0 -1
- package/as-test.config.json +0 -40
- package/assembly/test.ts +0 -24
- package/eslint.config.js +0 -68
- package/lib/tsconfig.json +0 -8
- package/test.ts +0 -99
- package/tools/assemblyscript-eslint-local.js +0 -6
- package/tools/assemblyscript-eslint.js +0 -53
- package/tools/assemblyscript-prettier-plugin.js +0 -33
- package/tools/replacer.js +0 -63
- package/transform/tsconfig.json +0 -35
package/assembly/index.ts
CHANGED
|
@@ -17,15 +17,26 @@ 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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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";
|
|
32
|
+
import { itoa_buffered } from "util/number";
|
|
23
33
|
import { serializeBool } from "./serialize/index/bool";
|
|
24
34
|
import { serializeInteger } from "./serialize/index/integer";
|
|
25
|
-
import { serializeFloat } from "./serialize/index/float";
|
|
35
|
+
import { serializeFloat, serializeFloat32, serializeFloat64 } from "./serialize/index/float";
|
|
36
|
+
import { dragonbox_f32_buffered, dragonbox_f64_buffered } from "./util/dragonbox";
|
|
26
37
|
import { serializeStruct } from "./serialize/index/struct";
|
|
27
38
|
import { ptrToStr } from "./util/ptrToStr";
|
|
28
|
-
import { atoi, bytes } from "./util";
|
|
39
|
+
import { atoi, bytes, scanStringEnd } from "./util";
|
|
29
40
|
import { deserializeArbitrary } from "./deserialize/index/arbitrary";
|
|
30
41
|
import { serializeObject } from "./serialize/index/object";
|
|
31
42
|
import { deserializeObject } from "./deserialize/index/object";
|
|
@@ -34,7 +45,7 @@ import { deserializeRaw } from "./deserialize/index/raw";
|
|
|
34
45
|
import { deserializeString } from "./deserialize/index/string";
|
|
35
46
|
import { serializeString } from "./serialize/index/string";
|
|
36
47
|
import { deserializeArrayBuffer, deserializeTypedArray } from "./deserialize/index/typedarray";
|
|
37
|
-
import { serializeArrayBufferUnsafe, serializeTypedArray } from "./serialize/index/typedarray";
|
|
48
|
+
import { serializeArrayBufferUnsafe, serializeDynamic, serializeTypedArray } from "./serialize/index/typedarray";
|
|
38
49
|
|
|
39
50
|
/**
|
|
40
51
|
* Offset of the 'storage' property in the JSON.Value class.
|
|
@@ -59,7 +70,7 @@ export namespace JSON {
|
|
|
59
70
|
* ```
|
|
60
71
|
*/
|
|
61
72
|
export function shrink(): void {
|
|
62
|
-
bs.
|
|
73
|
+
bs.shrink();
|
|
63
74
|
}
|
|
64
75
|
}
|
|
65
76
|
/**
|
|
@@ -101,13 +112,9 @@ export namespace JSON {
|
|
|
101
112
|
}
|
|
102
113
|
return data.toString();
|
|
103
114
|
} else if (isFloat<T>(data)) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
const bytes = dtoa_buffered(changetype<usize>(out), data) << 1;
|
|
108
|
-
return (out = changetype<string>(__renew(changetype<usize>(out), bytes)));
|
|
109
|
-
}
|
|
110
|
-
return data.toString();
|
|
115
|
+
out = out ? changetype<string>(__renew(changetype<usize>(out), 64)) : changetype<string>(__new(64, idof<string>()));
|
|
116
|
+
const bytes = (sizeof<T>() == 4 ? dragonbox_f32_buffered(changetype<usize>(out), <f32>data) : dragonbox_f64_buffered(changetype<usize>(out), <f64>data)) << 1;
|
|
117
|
+
return changetype<string>(__renew(changetype<usize>(out), bytes));
|
|
111
118
|
} else if (isNullable<T>() && changetype<usize>(data) == <usize>0) {
|
|
112
119
|
if (out) {
|
|
113
120
|
out = changetype<string>(__renew(changetype<usize>(out), 8));
|
|
@@ -118,9 +125,14 @@ export namespace JSON {
|
|
|
118
125
|
} else if (isString<nonnull<T>>()) {
|
|
119
126
|
serializeString(data as string);
|
|
120
127
|
return bs.out<string>();
|
|
121
|
-
// @ts-expect-error:
|
|
128
|
+
// @ts-expect-error: Defined by transform
|
|
129
|
+
} else if (isDefined(data.__SERIALIZE_CUSTOM)) {
|
|
130
|
+
// @ts-expect-error: Defined by transform
|
|
131
|
+
data.__SERIALIZE_CUSTOM();
|
|
132
|
+
return bs.out<string>();
|
|
133
|
+
// @ts-expect-error: Defined by transform
|
|
122
134
|
} else if (isDefined(data.__SERIALIZE)) {
|
|
123
|
-
// @ts-expect-error
|
|
135
|
+
// @ts-expect-error: Defined by transform
|
|
124
136
|
inline.always(data.__SERIALIZE(changetype<usize>(data)));
|
|
125
137
|
return bs.out<string>();
|
|
126
138
|
} else if (data instanceof Date) {
|
|
@@ -171,6 +183,10 @@ export namespace JSON {
|
|
|
171
183
|
} else if (data instanceof Float64Array) {
|
|
172
184
|
inline.always(serializeTypedArray<Float64Array>(data));
|
|
173
185
|
return bs.out<string>();
|
|
186
|
+
} else if (data instanceof ArrayBuffer) {
|
|
187
|
+
const dataStart = changetype<usize>(data);
|
|
188
|
+
serializeArrayBufferUnsafe(dataStart, changetype<OBJECT>(dataStart - TOTAL_OVERHEAD).rtSize);
|
|
189
|
+
return bs.out<string>();
|
|
174
190
|
} else if (data instanceof Set) {
|
|
175
191
|
// @ts-expect-error
|
|
176
192
|
inline.always(serializeSet(changetype<nonnull<T>>(data)));
|
|
@@ -191,16 +207,10 @@ export namespace JSON {
|
|
|
191
207
|
} else if (data instanceof JSON.Box) {
|
|
192
208
|
return JSON.stringify(data.value);
|
|
193
209
|
} else {
|
|
194
|
-
throw new Error(`Could not serialize data of type '${nameof<T>()}'. ` + `If this is a custom class, add the @json decorator: @json class ${nameof<T>()} { ... }. ` + `Supported types: primitives, string, Array, StaticArray, TypedArray, Map, Date, and @json decorated classes
|
|
210
|
+
throw new Error(`Could not serialize data of type '${nameof<T>()}'. ` + `If this is a custom class, add the @json decorator: @json class ${nameof<T>()} { ... }. ` + `Supported types: primitives, string, Array, StaticArray, TypedArray, ArrayBuffer, Map, Date, and @json decorated classes.`);
|
|
195
211
|
}
|
|
196
212
|
}
|
|
197
213
|
|
|
198
|
-
|
|
199
|
-
@inline export function stringifyArrayBuffer(dataStart: usize): string {
|
|
200
|
-
serializeArrayBufferUnsafe(dataStart, changetype<OBJECT>(dataStart - TOTAL_OVERHEAD).rtSize);
|
|
201
|
-
return bs.out<string>();
|
|
202
|
-
}
|
|
203
|
-
|
|
204
214
|
/**
|
|
205
215
|
* Parses valid JSON strings into their original format
|
|
206
216
|
* ```js
|
|
@@ -225,6 +235,24 @@ export namespace JSON {
|
|
|
225
235
|
return deserializeString(dataPtr, dataPtr + dataSize) as T;
|
|
226
236
|
} else {
|
|
227
237
|
let type: nonnull<T> = changetype<nonnull<T>>(0);
|
|
238
|
+
// @ts-expect-error: Defined by transform
|
|
239
|
+
if (isDefined(type.__DESERIALIZE_CUSTOM)) {
|
|
240
|
+
const out = changetype<nonnull<T>>(0);
|
|
241
|
+
// @ts-expect-error
|
|
242
|
+
return out.__DESERIALIZE_CUSTOM(data);
|
|
243
|
+
// @ts-expect-error: Defined by transform
|
|
244
|
+
} else if (isDefined(type.__DESERIALIZE_SLOW) || isDefined(type.__DESERIALIZE_FAST)) {
|
|
245
|
+
const out = changetype<nonnull<T>>(__new(offsetof<nonnull<T>>(), idof<nonnull<T>>()));
|
|
246
|
+
// @ts-expect-error: Defined by transform
|
|
247
|
+
if (isDefined(type.__INITIALIZE)) out.__INITIALIZE();
|
|
248
|
+
// @ts-expect-error: Defined by transform
|
|
249
|
+
if (isDefined(type.__DESERIALIZE_FAST)) {
|
|
250
|
+
// @ts-expect-error: Defined by transform
|
|
251
|
+
out.__DESERIALIZE_FAST(dataPtr, dataPtr + dataSize, out);
|
|
252
|
+
// @ts-expect-error: Defined by transform
|
|
253
|
+
} else out.__DESERIALIZE_SLOW(dataPtr, dataPtr + dataSize, out);
|
|
254
|
+
return out;
|
|
255
|
+
}
|
|
228
256
|
if (type instanceof StaticArray) {
|
|
229
257
|
// @ts-expect-error
|
|
230
258
|
return inline.always(deserializeStaticArray<nonnull<T>>(dataPtr, dataPtr + dataSize, 0));
|
|
@@ -232,40 +260,32 @@ export namespace JSON {
|
|
|
232
260
|
// @ts-expect-error
|
|
233
261
|
return inline.always(deserializeArray<nonnull<T>>(dataPtr, dataPtr + dataSize, changetype<usize>(instantiate<T>())));
|
|
234
262
|
} else if (type instanceof Int8Array) {
|
|
235
|
-
return deserializeTypedArray<
|
|
263
|
+
return deserializeTypedArray<nonnull<T>>(dataPtr, dataPtr + dataSize, 0) as T;
|
|
236
264
|
} else if (type instanceof Uint8Array) {
|
|
237
|
-
return deserializeTypedArray<
|
|
265
|
+
return deserializeTypedArray<nonnull<T>>(dataPtr, dataPtr + dataSize, 0) as T;
|
|
238
266
|
} else if (type instanceof Uint8ClampedArray) {
|
|
239
|
-
return deserializeTypedArray<
|
|
267
|
+
return deserializeTypedArray<nonnull<T>>(dataPtr, dataPtr + dataSize, 0) as T;
|
|
240
268
|
} else if (type instanceof Int16Array) {
|
|
241
|
-
return deserializeTypedArray<
|
|
269
|
+
return deserializeTypedArray<nonnull<T>>(dataPtr, dataPtr + dataSize, 0) as T;
|
|
242
270
|
} else if (type instanceof Uint16Array) {
|
|
243
|
-
return deserializeTypedArray<
|
|
271
|
+
return deserializeTypedArray<nonnull<T>>(dataPtr, dataPtr + dataSize, 0) as T;
|
|
244
272
|
} else if (type instanceof Int32Array) {
|
|
245
|
-
return deserializeTypedArray<
|
|
273
|
+
return deserializeTypedArray<nonnull<T>>(dataPtr, dataPtr + dataSize, 0) as T;
|
|
246
274
|
} else if (type instanceof Uint32Array) {
|
|
247
|
-
return deserializeTypedArray<
|
|
275
|
+
return deserializeTypedArray<nonnull<T>>(dataPtr, dataPtr + dataSize, 0) as T;
|
|
248
276
|
} else if (type instanceof Int64Array) {
|
|
249
|
-
return deserializeTypedArray<
|
|
277
|
+
return deserializeTypedArray<nonnull<T>>(dataPtr, dataPtr + dataSize, 0) as T;
|
|
250
278
|
} else if (type instanceof Uint64Array) {
|
|
251
|
-
return deserializeTypedArray<
|
|
279
|
+
return deserializeTypedArray<nonnull<T>>(dataPtr, dataPtr + dataSize, 0) as T;
|
|
252
280
|
} else if (type instanceof Float32Array) {
|
|
253
|
-
return deserializeTypedArray<
|
|
281
|
+
return deserializeTypedArray<nonnull<T>>(dataPtr, dataPtr + dataSize, 0) as T;
|
|
254
282
|
} else if (type instanceof Float64Array) {
|
|
255
|
-
return deserializeTypedArray<
|
|
283
|
+
return deserializeTypedArray<nonnull<T>>(dataPtr, dataPtr + dataSize, 0) as T;
|
|
256
284
|
} else if (type instanceof ArrayBuffer) {
|
|
257
285
|
return deserializeArrayBuffer(dataPtr, dataPtr + dataSize, 0) as T;
|
|
258
286
|
} else if (type instanceof Set) {
|
|
259
287
|
// @ts-expect-error
|
|
260
288
|
return inline.always(deserializeSet<nonnull<T>>(dataPtr, dataPtr + dataSize, 0));
|
|
261
|
-
// @ts-expect-error: Defined by transform
|
|
262
|
-
} else if (isDefined(type.__DESERIALIZE)) {
|
|
263
|
-
const out = changetype<nonnull<T>>(__new(offsetof<nonnull<T>>(), idof<nonnull<T>>()));
|
|
264
|
-
// @ts-expect-error: Defined by transform
|
|
265
|
-
if (isDefined(type.__INITIALIZE)) out.__INITIALIZE();
|
|
266
|
-
// @ts-expect-error
|
|
267
|
-
out.__DESERIALIZE(dataPtr, dataPtr + dataSize, out);
|
|
268
|
-
return out;
|
|
269
289
|
} else if (type instanceof Map) {
|
|
270
290
|
// @ts-expect-error
|
|
271
291
|
return inline.always(deserializeMap<nonnull<T>>(dataPtr, dataPtr + dataSize, 0));
|
|
@@ -299,7 +319,7 @@ export namespace JSON {
|
|
|
299
319
|
* Enum-like namespace representing the different types supported by JSON.Value.
|
|
300
320
|
*
|
|
301
321
|
* Used internally to track the runtime type of values stored in JSON.Value instances.
|
|
302
|
-
* Types 0-
|
|
322
|
+
* Types 0-19 are reserved for built-in types; custom @json classes use idof<T>() + Struct.
|
|
303
323
|
*/
|
|
304
324
|
export namespace Types {
|
|
305
325
|
/** Represents a null value */
|
|
@@ -340,6 +360,10 @@ export namespace JSON {
|
|
|
340
360
|
@inline export const Map: u16 = 16;
|
|
341
361
|
// @ts-expect-error
|
|
342
362
|
@inline export const Struct: u16 = 17;
|
|
363
|
+
// @ts-expect-error
|
|
364
|
+
@inline export const TypedArray: u16 = 18;
|
|
365
|
+
// @ts-expect-error
|
|
366
|
+
@inline export const ArrayBuffer: u16 = 19;
|
|
343
367
|
}
|
|
344
368
|
|
|
345
369
|
/**
|
|
@@ -470,12 +494,23 @@ export namespace JSON {
|
|
|
470
494
|
if (value instanceof u64) return JSON.Types.U64;
|
|
471
495
|
if (value instanceof f32) return JSON.Types.F32;
|
|
472
496
|
if (value instanceof f64) return JSON.Types.F64;
|
|
497
|
+
// @ts-expect-error: supplied by transform
|
|
498
|
+
if (isDefined(value.__SERIALIZE) && isManaged<T>(value)) return u16(idof<T>()) + JSON.Types.Struct;
|
|
499
|
+
if (value instanceof Int8Array) return JSON.Types.TypedArray;
|
|
500
|
+
if (value instanceof Uint8Array) return JSON.Types.TypedArray;
|
|
501
|
+
if (value instanceof Uint8ClampedArray) return JSON.Types.TypedArray;
|
|
502
|
+
if (value instanceof Int16Array) return JSON.Types.TypedArray;
|
|
503
|
+
if (value instanceof Uint16Array) return JSON.Types.TypedArray;
|
|
504
|
+
if (value instanceof Int32Array) return JSON.Types.TypedArray;
|
|
505
|
+
if (value instanceof Uint32Array) return JSON.Types.TypedArray;
|
|
506
|
+
if (value instanceof Int64Array) return JSON.Types.TypedArray;
|
|
507
|
+
if (value instanceof Uint64Array) return JSON.Types.TypedArray;
|
|
508
|
+
if (value instanceof Float32Array) return JSON.Types.TypedArray;
|
|
509
|
+
if (value instanceof Float64Array) return JSON.Types.TypedArray;
|
|
510
|
+
if (value instanceof ArrayBuffer) return JSON.Types.ArrayBuffer;
|
|
473
511
|
if (value instanceof Map) return JSON.Types.Map;
|
|
474
512
|
if (value instanceof JSON.Raw) return JSON.Types.Raw;
|
|
475
513
|
if (value instanceof JSON.Obj) return JSON.Types.Object;
|
|
476
|
-
|
|
477
|
-
// @ts-expect-error: supplied by transform
|
|
478
|
-
if (isDefined(value.__SERIALIZE) && isManaged<T>(value)) return u16(idof<T>()) + JSON.Types.Struct;
|
|
479
514
|
return JSON.Types.Null;
|
|
480
515
|
}
|
|
481
516
|
/**
|
|
@@ -492,16 +527,28 @@ export namespace JSON {
|
|
|
492
527
|
else if (isNullable<T>() && changetype<usize>(value) === 0) store<usize>(changetype<usize>(this), 0, STORAGE);
|
|
493
528
|
else if (isString<T>()) store<T>(changetype<usize>(this), value, STORAGE);
|
|
494
529
|
else if (value instanceof JSON.Raw) store<T>(changetype<usize>(this), value, STORAGE);
|
|
530
|
+
// @ts-expect-error: supplied by transform
|
|
531
|
+
else if (isDefined(value.__SERIALIZE) && isManaged<T>(value)) {
|
|
532
|
+
// @ts-expect-error
|
|
533
|
+
if (!JSON.Value.METHODS.has(idof<T>())) JSON.Value.METHODS.set(idof<T>(), value.__SERIALIZE.index);
|
|
534
|
+
store<usize>(changetype<usize>(this), changetype<usize>(value), STORAGE);
|
|
535
|
+
} else if (value instanceof Int8Array) store<T>(changetype<usize>(this), value, STORAGE);
|
|
536
|
+
else if (value instanceof Uint8Array) store<T>(changetype<usize>(this), value, STORAGE);
|
|
537
|
+
else if (value instanceof Uint8ClampedArray) store<T>(changetype<usize>(this), value, STORAGE);
|
|
538
|
+
else if (value instanceof Int16Array) store<T>(changetype<usize>(this), value, STORAGE);
|
|
539
|
+
else if (value instanceof Uint16Array) store<T>(changetype<usize>(this), value, STORAGE);
|
|
540
|
+
else if (value instanceof Int32Array) store<T>(changetype<usize>(this), value, STORAGE);
|
|
541
|
+
else if (value instanceof Uint32Array) store<T>(changetype<usize>(this), value, STORAGE);
|
|
542
|
+
else if (value instanceof Int64Array) store<T>(changetype<usize>(this), value, STORAGE);
|
|
543
|
+
else if (value instanceof Uint64Array) store<T>(changetype<usize>(this), value, STORAGE);
|
|
544
|
+
else if (value instanceof Float32Array) store<T>(changetype<usize>(this), value, STORAGE);
|
|
545
|
+
else if (value instanceof Float64Array) store<T>(changetype<usize>(this), value, STORAGE);
|
|
546
|
+
else if (value instanceof ArrayBuffer) store<T>(changetype<usize>(this), value, STORAGE);
|
|
495
547
|
else if (value instanceof Map) {
|
|
496
548
|
if (idof<T>() !== idof<Map<string, JSON.Value>>()) {
|
|
497
549
|
abort("Maps must be of type Map<string, JSON.Value>!");
|
|
498
550
|
}
|
|
499
551
|
store<T>(changetype<usize>(this), value, STORAGE);
|
|
500
|
-
// @ts-expect-error: supplied by transform
|
|
501
|
-
} else if (isDefined(value.__SERIALIZE) && isManaged<T>(value)) {
|
|
502
|
-
// @ts-expect-error
|
|
503
|
-
if (!JSON.Value.METHODS.has(idof<T>())) JSON.Value.METHODS.set(idof<T>(), value.__SERIALIZE.index);
|
|
504
|
-
store<usize>(changetype<usize>(this), changetype<usize>(value), STORAGE);
|
|
505
552
|
} else if (value instanceof JSON.Obj) {
|
|
506
553
|
store<T>(changetype<usize>(this), value, STORAGE);
|
|
507
554
|
// @ts-expect-error
|
|
@@ -587,6 +634,11 @@ export namespace JSON {
|
|
|
587
634
|
|
|
588
635
|
return out.toString();
|
|
589
636
|
}
|
|
637
|
+
case JSON.Types.TypedArray:
|
|
638
|
+
case JSON.Types.ArrayBuffer: {
|
|
639
|
+
serializeDynamic(this.type, this.get<usize>());
|
|
640
|
+
return bs.out<string>();
|
|
641
|
+
}
|
|
590
642
|
case JSON.Types.Object: {
|
|
591
643
|
return JSON.stringify(this.get<JSON.Obj>());
|
|
592
644
|
}
|
|
@@ -801,20 +853,22 @@ export namespace JSON {
|
|
|
801
853
|
serializeInteger<T>(data);
|
|
802
854
|
} else if (isFloat<T>(data)) {
|
|
803
855
|
// @ts-expect-error
|
|
804
|
-
|
|
856
|
+
if (sizeof<T>() == 4) serializeFloat32(<f32>data);
|
|
857
|
+
// @ts-expect-error
|
|
858
|
+
else serializeFloat64(<f64>data);
|
|
805
859
|
} else if (isNullable<T>() && changetype<usize>(data) == <usize>0) {
|
|
806
860
|
bs.proposeSize(8);
|
|
807
861
|
store<u64>(bs.offset, NULL_WORD_U64);
|
|
808
862
|
bs.offset += 8;
|
|
809
863
|
} else if (isString<nonnull<T>>()) {
|
|
810
864
|
serializeString(data as string);
|
|
811
|
-
// @ts-expect-error:
|
|
865
|
+
// @ts-expect-error: Defined by transform
|
|
812
866
|
} else if (isDefined(data.__SERIALIZE_CUSTOM)) {
|
|
813
867
|
// @ts-expect-error
|
|
814
868
|
return data.__SERIALIZE_CUSTOM();
|
|
815
|
-
// @ts-expect-error:
|
|
869
|
+
// @ts-expect-error: Defined by transform
|
|
816
870
|
} else if (isDefined(data.__SERIALIZE)) {
|
|
817
|
-
// @ts-expect-error
|
|
871
|
+
// @ts-expect-error: type
|
|
818
872
|
serializeStruct(changetype<nonnull<T>>(data));
|
|
819
873
|
} else if (data instanceof Date) {
|
|
820
874
|
// @ts-expect-error
|
|
@@ -847,6 +901,9 @@ export namespace JSON {
|
|
|
847
901
|
serializeTypedArray<Float32Array>(data);
|
|
848
902
|
} else if (data instanceof Float64Array) {
|
|
849
903
|
serializeTypedArray<Float64Array>(data);
|
|
904
|
+
} else if (data instanceof ArrayBuffer) {
|
|
905
|
+
const dataStart = changetype<usize>(data);
|
|
906
|
+
serializeArrayBufferUnsafe(dataStart, changetype<OBJECT>(dataStart - TOTAL_OVERHEAD).rtSize);
|
|
850
907
|
} else if (data instanceof Set) {
|
|
851
908
|
// @ts-expect-error
|
|
852
909
|
serializeSet(changetype<nonnull<T>>(data));
|
|
@@ -862,33 +919,10 @@ export namespace JSON {
|
|
|
862
919
|
} else if (data instanceof JSON.Box) {
|
|
863
920
|
__serialize(data.value);
|
|
864
921
|
} else {
|
|
865
|
-
throw new Error(`Could not serialize data of type '${nameof<T>()}'. ` + `If this is a custom class, add the @json decorator: @json class ${nameof<T>()} { ... }. ` + `Supported types: primitives, string, Array, StaticArray, TypedArray, Map, Date, and @json decorated classes
|
|
922
|
+
throw new Error(`Could not serialize data of type '${nameof<T>()}'. ` + `If this is a custom class, add the @json decorator: @json class ${nameof<T>()} { ... }. ` + `Supported types: primitives, string, Array, StaticArray, TypedArray, ArrayBuffer, Map, Date, and @json decorated classes.`);
|
|
866
923
|
}
|
|
867
924
|
}
|
|
868
925
|
|
|
869
|
-
|
|
870
|
-
@inline export function __serializeArrayBufferUnsafe(dataStart: usize): void {
|
|
871
|
-
serializeArrayBufferUnsafe(dataStart, changetype<OBJECT>(dataStart - TOTAL_OVERHEAD).rtSize);
|
|
872
|
-
}
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
@inline export function __serializeArrayBuffer(data: ArrayBuffer): void {
|
|
876
|
-
const dataStart = changetype<usize>(data);
|
|
877
|
-
serializeArrayBufferUnsafe(dataStart, changetype<OBJECT>(dataStart - TOTAL_OVERHEAD).rtSize);
|
|
878
|
-
}
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
@inline export function parseArrayBuffer(data: string): ArrayBuffer {
|
|
882
|
-
const dataSize = bytes(data);
|
|
883
|
-
const dataPtr = changetype<usize>(data);
|
|
884
|
-
return deserializeArrayBuffer(dataPtr, dataPtr + dataSize, 0);
|
|
885
|
-
}
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
@inline export function __deserializeArrayBuffer(srcStart: usize, srcEnd: usize, dst: usize = 0): ArrayBuffer {
|
|
889
|
-
return deserializeArrayBuffer(srcStart, srcEnd, dst);
|
|
890
|
-
}
|
|
891
|
-
|
|
892
926
|
/**
|
|
893
927
|
* Deserializes JSON data directly from the buffer.
|
|
894
928
|
* Should only be used if you know what you are doing.
|
|
@@ -913,6 +947,22 @@ export namespace JSON {
|
|
|
913
947
|
return null;
|
|
914
948
|
} else {
|
|
915
949
|
let type: nonnull<T> = changetype<nonnull<T>>(0);
|
|
950
|
+
// @ts-expect-error: Defined by transform
|
|
951
|
+
if (isDefined(type.__DESERIALIZE_CUSTOM)) {
|
|
952
|
+
const out = changetype<nonnull<T>>(0);
|
|
953
|
+
// @ts-expect-error: Defined by transform
|
|
954
|
+
return out.__DESERIALIZE_CUSTOM(ptrToStr(srcStart, srcEnd));
|
|
955
|
+
// @ts-expect-error: Defined by transform
|
|
956
|
+
} else if (isDefined(type.__DESERIALIZE_SLOW) || isDefined(type.__DESERIALIZE_FAST)) {
|
|
957
|
+
const out = changetype<nonnull<T>>(dst || __new(offsetof<nonnull<T>>(), idof<nonnull<T>>()));
|
|
958
|
+
// @ts-expect-error: Defined by transform
|
|
959
|
+
if (isDefined(type.__INITIALIZE)) out.__INITIALIZE();
|
|
960
|
+
// @ts-expect-error: Defined by transform
|
|
961
|
+
if (isDefined(type.__DESERIALIZE_FAST)) out.__DESERIALIZE_FAST(srcStart, srcEnd, out);
|
|
962
|
+
// @ts-expect-error: Defined by transform
|
|
963
|
+
else out.__DESERIALIZE_SLOW(srcStart, srcEnd, out);
|
|
964
|
+
return out;
|
|
965
|
+
}
|
|
916
966
|
if (type instanceof StaticArray) {
|
|
917
967
|
// @ts-expect-error: type
|
|
918
968
|
return deserializeStaticArray<T>(srcStart, srcEnd, dst);
|
|
@@ -920,40 +970,32 @@ export namespace JSON {
|
|
|
920
970
|
// @ts-expect-error: type
|
|
921
971
|
return deserializeArray<T>(srcStart, srcEnd, dst);
|
|
922
972
|
} else if (type instanceof Int8Array) {
|
|
923
|
-
return deserializeTypedArray<
|
|
973
|
+
return deserializeTypedArray<nonnull<T>>(srcStart, srcEnd, dst) as T;
|
|
924
974
|
} else if (type instanceof Uint8Array) {
|
|
925
|
-
return deserializeTypedArray<
|
|
975
|
+
return deserializeTypedArray<nonnull<T>>(srcStart, srcEnd, dst) as T;
|
|
926
976
|
} else if (type instanceof Uint8ClampedArray) {
|
|
927
|
-
return deserializeTypedArray<
|
|
977
|
+
return deserializeTypedArray<nonnull<T>>(srcStart, srcEnd, dst) as T;
|
|
928
978
|
} else if (type instanceof Int16Array) {
|
|
929
|
-
return deserializeTypedArray<
|
|
979
|
+
return deserializeTypedArray<nonnull<T>>(srcStart, srcEnd, dst) as T;
|
|
930
980
|
} else if (type instanceof Uint16Array) {
|
|
931
|
-
return deserializeTypedArray<
|
|
981
|
+
return deserializeTypedArray<nonnull<T>>(srcStart, srcEnd, dst) as T;
|
|
932
982
|
} else if (type instanceof Int32Array) {
|
|
933
|
-
return deserializeTypedArray<
|
|
983
|
+
return deserializeTypedArray<nonnull<T>>(srcStart, srcEnd, dst) as T;
|
|
934
984
|
} else if (type instanceof Uint32Array) {
|
|
935
|
-
return deserializeTypedArray<
|
|
985
|
+
return deserializeTypedArray<nonnull<T>>(srcStart, srcEnd, dst) as T;
|
|
936
986
|
} else if (type instanceof Int64Array) {
|
|
937
|
-
return deserializeTypedArray<
|
|
987
|
+
return deserializeTypedArray<nonnull<T>>(srcStart, srcEnd, dst) as T;
|
|
938
988
|
} else if (type instanceof Uint64Array) {
|
|
939
|
-
return deserializeTypedArray<
|
|
989
|
+
return deserializeTypedArray<nonnull<T>>(srcStart, srcEnd, dst) as T;
|
|
940
990
|
} else if (type instanceof Float32Array) {
|
|
941
|
-
return deserializeTypedArray<
|
|
991
|
+
return deserializeTypedArray<nonnull<T>>(srcStart, srcEnd, dst) as T;
|
|
942
992
|
} else if (type instanceof Float64Array) {
|
|
943
|
-
return deserializeTypedArray<
|
|
993
|
+
return deserializeTypedArray<nonnull<T>>(srcStart, srcEnd, dst) as T;
|
|
944
994
|
} else if (type instanceof ArrayBuffer) {
|
|
945
995
|
return deserializeArrayBuffer(srcStart, srcEnd, dst) as T;
|
|
946
996
|
} else if (type instanceof Set) {
|
|
947
997
|
// @ts-expect-error: type
|
|
948
998
|
return deserializeSet<T>(srcStart, srcEnd, dst);
|
|
949
|
-
// @ts-expect-error: Defined by transform
|
|
950
|
-
} else if (isDefined(type.__DESERIALIZE)) {
|
|
951
|
-
const out = changetype<nonnull<T>>(dst || __new(offsetof<nonnull<T>>(), idof<nonnull<T>>()));
|
|
952
|
-
// @ts-expect-error: Defined by transform
|
|
953
|
-
if (isDefined(type.__INITIALIZE)) out.__INITIALIZE();
|
|
954
|
-
// @ts-expect-error: Defined by transform
|
|
955
|
-
out.__DESERIALIZE(srcStart, srcEnd, out);
|
|
956
|
-
return out;
|
|
957
999
|
} else if (type instanceof Map) {
|
|
958
1000
|
// @ts-expect-error: type
|
|
959
1001
|
return deserializeMap<T>(srcStart, srcEnd, dst);
|
|
@@ -983,6 +1025,48 @@ export namespace JSON {
|
|
|
983
1025
|
return code == 0x20 || code - 9 <= 4;
|
|
984
1026
|
}
|
|
985
1027
|
// @ts-expect-error: decorator
|
|
1028
|
+
@inline export function scanValueEnd(srcStart: usize, srcEnd: usize): usize {
|
|
1029
|
+
if (srcStart >= srcEnd) return 0;
|
|
1030
|
+
let ptr = srcStart;
|
|
1031
|
+
while (ptr < srcEnd && isSpace(load<u16>(ptr))) ptr += 2;
|
|
1032
|
+
if (ptr >= srcEnd) return 0;
|
|
1033
|
+
const first = load<u16>(ptr);
|
|
1034
|
+
|
|
1035
|
+
if (first == QUOTE) {
|
|
1036
|
+
const endQuote = scanStringEnd(ptr, srcEnd);
|
|
1037
|
+
return endQuote >= srcEnd ? 0 : endQuote + 2;
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
if (first == BRACE_LEFT || first == BRACKET_LEFT) {
|
|
1041
|
+
let depth: i32 = 1;
|
|
1042
|
+
ptr += 2;
|
|
1043
|
+
while (ptr < srcEnd) {
|
|
1044
|
+
const code = load<u16>(ptr);
|
|
1045
|
+
if (code == QUOTE) {
|
|
1046
|
+
const endQuote = scanStringEnd(ptr, srcEnd);
|
|
1047
|
+
if (endQuote >= srcEnd) return 0;
|
|
1048
|
+
ptr = endQuote + 2;
|
|
1049
|
+
continue;
|
|
1050
|
+
}
|
|
1051
|
+
if (code == BRACE_LEFT || code == BRACKET_LEFT) {
|
|
1052
|
+
depth++;
|
|
1053
|
+
} else if (code == BRACE_RIGHT || code == BRACKET_RIGHT) {
|
|
1054
|
+
if (--depth == 0) return ptr + 2;
|
|
1055
|
+
}
|
|
1056
|
+
ptr += 2;
|
|
1057
|
+
}
|
|
1058
|
+
return 0;
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
while (ptr < srcEnd) {
|
|
1062
|
+
const code = load<u16>(ptr);
|
|
1063
|
+
if (code == COMMA || code == BRACKET_RIGHT || code == BRACE_RIGHT || isSpace(code)) return ptr;
|
|
1064
|
+
ptr += 2;
|
|
1065
|
+
}
|
|
1066
|
+
|
|
1067
|
+
return ptr;
|
|
1068
|
+
}
|
|
1069
|
+
// @ts-expect-error: decorator
|
|
986
1070
|
@inline export function ptrToStr(start: usize, end: usize): string {
|
|
987
1071
|
const size = end - start;
|
|
988
1072
|
const out = __new(size, idof<string>());
|
|
@@ -991,7 +1075,8 @@ export namespace JSON {
|
|
|
991
1075
|
}
|
|
992
1076
|
}
|
|
993
1077
|
/**
|
|
994
|
-
* Methods for use when using JSON methods inside another JSON method or custom serializer/deserializer
|
|
1078
|
+
* Methods for use when using JSON methods inside another JSON method or custom serializer/deserializer
|
|
1079
|
+
* Transform will automatically convert JSON.x calls to JSON.internal.x when in a custom (de)serializer
|
|
995
1080
|
*/
|
|
996
1081
|
export namespace internal {
|
|
997
1082
|
/**
|
|
@@ -1002,102 +1087,30 @@ export namespace JSON {
|
|
|
1002
1087
|
*/
|
|
1003
1088
|
// @ts-expect-error: inline
|
|
1004
1089
|
@inline export function stringify<T>(data: T, out: string | null = null): string {
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
store<u16>(changetype<usize>(out), 101, 8);
|
|
1014
|
-
}
|
|
1015
|
-
return out;
|
|
1016
|
-
}
|
|
1017
|
-
return data ? "true" : "false";
|
|
1018
|
-
} else if (isInteger<T>() && !isSigned<T>() && nameof<T>() == "usize" && data == 0) {
|
|
1019
|
-
if (out) {
|
|
1020
|
-
out = changetype<string>(__renew(changetype<usize>(out), 8));
|
|
1021
|
-
store<u64>(changetype<usize>(out), NULL_WORD_U64);
|
|
1022
|
-
return out;
|
|
1023
|
-
}
|
|
1024
|
-
return NULL_WORD;
|
|
1025
|
-
} else if (isInteger<T>(data)) {
|
|
1026
|
-
if (out) {
|
|
1027
|
-
out = changetype<string>(__renew(changetype<usize>(out), sizeof<T>() << 3));
|
|
1028
|
-
|
|
1029
|
-
const bytes = itoa_buffered(changetype<usize>(out), data) << 1;
|
|
1030
|
-
return (out = changetype<string>(__renew(changetype<usize>(out), bytes)));
|
|
1031
|
-
}
|
|
1032
|
-
return data.toString();
|
|
1033
|
-
} else if (isFloat<T>(data)) {
|
|
1034
|
-
if (out) {
|
|
1035
|
-
out = changetype<string>(__renew(changetype<usize>(out), 64));
|
|
1036
|
-
|
|
1037
|
-
const bytes = dtoa_buffered(changetype<usize>(out), data) << 1;
|
|
1038
|
-
return (out = changetype<string>(__renew(changetype<usize>(out), bytes)));
|
|
1039
|
-
}
|
|
1040
|
-
return data.toString();
|
|
1041
|
-
} else if (isNullable<T>() && changetype<usize>(data) == <usize>0) {
|
|
1042
|
-
if (out) {
|
|
1043
|
-
out = changetype<string>(__renew(changetype<usize>(out), 8));
|
|
1044
|
-
store<u64>(changetype<usize>(out), NULL_WORD_U64);
|
|
1045
|
-
return out;
|
|
1046
|
-
}
|
|
1047
|
-
return NULL_WORD;
|
|
1048
|
-
} else if (isString<nonnull<T>>()) {
|
|
1049
|
-
serializeString(data as string);
|
|
1050
|
-
return bs.cpyOut<string>();
|
|
1051
|
-
// @ts-expect-error: Supplied by transform
|
|
1052
|
-
} else if (isDefined(data.__SERIALIZE)) {
|
|
1053
|
-
bs.saveState();
|
|
1054
|
-
// @ts-expect-error
|
|
1055
|
-
inline.always(data.__SERIALIZE(changetype<usize>(data)));
|
|
1056
|
-
return bs.cpyOut<string>();
|
|
1057
|
-
} else if (data instanceof Date) {
|
|
1058
|
-
out = out ? changetype<string>(__renew(changetype<usize>(out), 52)) : changetype<string>(__new(52, idof<string>()));
|
|
1059
|
-
|
|
1060
|
-
store<u16>(changetype<usize>(out), QUOTE);
|
|
1061
|
-
memory.copy(changetype<usize>(out) + 2, changetype<usize>(data.toISOString()), 48);
|
|
1062
|
-
store<u16>(changetype<usize>(out), QUOTE, 50);
|
|
1063
|
-
return changetype<string>(out);
|
|
1064
|
-
} else if (data instanceof Array) {
|
|
1065
|
-
bs.saveState();
|
|
1066
|
-
// @ts-expect-error
|
|
1067
|
-
inline.always(serializeArray(changetype<nonnull<T>>(data)));
|
|
1068
|
-
return bs.cpyOut<string>();
|
|
1069
|
-
} else if (data instanceof StaticArray) {
|
|
1070
|
-
bs.saveState();
|
|
1071
|
-
// @ts-expect-error
|
|
1072
|
-
inline.always(serializeStaticArray(changetype<nonnull<T>>(data)));
|
|
1073
|
-
return bs.cpyOut<string>();
|
|
1074
|
-
} else if (data instanceof Set) {
|
|
1075
|
-
bs.saveState();
|
|
1076
|
-
// @ts-expect-error
|
|
1077
|
-
inline.always(serializeSet(changetype<nonnull<T>>(data)));
|
|
1078
|
-
return bs.cpyOut<string>();
|
|
1079
|
-
} else if (data instanceof Map) {
|
|
1080
|
-
bs.saveState();
|
|
1081
|
-
// @ts-expect-error
|
|
1082
|
-
inline.always(serializeMap(changetype<nonnull<T>>(data)));
|
|
1083
|
-
return bs.cpyOut<string>();
|
|
1084
|
-
} else if (data instanceof JSON.Raw) {
|
|
1085
|
-
bs.saveState();
|
|
1086
|
-
serializeRaw(data);
|
|
1087
|
-
return bs.cpyOut<string>();
|
|
1088
|
-
} else if (data instanceof JSON.Value) {
|
|
1089
|
-
bs.saveState();
|
|
1090
|
-
inline.always(serializeArbitrary(data));
|
|
1091
|
-
return bs.cpyOut<string>();
|
|
1092
|
-
} else if (data instanceof JSON.Obj) {
|
|
1093
|
-
bs.saveState();
|
|
1094
|
-
inline.always(serializeObject(data));
|
|
1095
|
-
return bs.cpyOut<string>();
|
|
1096
|
-
} else if (data instanceof JSON.Box) {
|
|
1097
|
-
return JSON.internal.stringify(data.value);
|
|
1098
|
-
} else {
|
|
1099
|
-
throw new Error(`Could not serialize data of type '${nameof<T>()}'. ` + `If this is a custom class, add the @json decorator: @json class ${nameof<T>()} { ... }. ` + `Supported types: primitives, string, Array, Map, Date, and @json decorated classes.`);
|
|
1090
|
+
bs.saveState();
|
|
1091
|
+
JSON.__serialize<T>(data);
|
|
1092
|
+
const result = bs.cpyOut<string>();
|
|
1093
|
+
if (out) {
|
|
1094
|
+
const len = bytes(result);
|
|
1095
|
+
out = changetype<string>(__renew(changetype<usize>(out), len));
|
|
1096
|
+
memory.copy(changetype<usize>(out), changetype<usize>(result), len);
|
|
1097
|
+
return out;
|
|
1100
1098
|
}
|
|
1099
|
+
return result;
|
|
1100
|
+
}
|
|
1101
|
+
|
|
1102
|
+
/**
|
|
1103
|
+
* Parses JSON data without mutating the caller's active serialization buffer state.
|
|
1104
|
+
* Don't use this directly, use `JSON.parse` instead.
|
|
1105
|
+
* @param data - string
|
|
1106
|
+
* @returns - T
|
|
1107
|
+
*/
|
|
1108
|
+
// @ts-expect-error: inline
|
|
1109
|
+
@inline export function parse<T>(data: string): T {
|
|
1110
|
+
bs.saveState();
|
|
1111
|
+
const result = JSON.parse<T>(data);
|
|
1112
|
+
bs.loadState();
|
|
1113
|
+
return result;
|
|
1101
1114
|
}
|
|
1102
1115
|
}
|
|
1103
1116
|
}
|
|
@@ -2,11 +2,12 @@ import { JSON } from "../..";
|
|
|
2
2
|
import { bs } from "../../../lib/as-bs";
|
|
3
3
|
import { serializeArray } from "./array";
|
|
4
4
|
import { serializeBool } from "./bool";
|
|
5
|
-
import {
|
|
5
|
+
import { serializeFloat32, serializeFloat64 } from "./float";
|
|
6
6
|
import { serializeInteger } from "./integer";
|
|
7
7
|
import { serializeMap } from "./map";
|
|
8
8
|
import { serializeObject } from "./object";
|
|
9
9
|
import { serializeString } from "./string";
|
|
10
|
+
import { serializeDynamic } from "./typedarray";
|
|
10
11
|
|
|
11
12
|
export function serializeArbitrary(src: JSON.Value): void {
|
|
12
13
|
switch (src.type) {
|
|
@@ -40,10 +41,10 @@ export function serializeArbitrary(src: JSON.Value): void {
|
|
|
40
41
|
serializeInteger<i64>(src.get<i64>());
|
|
41
42
|
break;
|
|
42
43
|
case JSON.Types.F32:
|
|
43
|
-
|
|
44
|
+
serializeFloat32(src.get<f32>());
|
|
44
45
|
break;
|
|
45
46
|
case JSON.Types.F64:
|
|
46
|
-
|
|
47
|
+
serializeFloat64(src.get<f64>());
|
|
47
48
|
break;
|
|
48
49
|
case JSON.Types.String:
|
|
49
50
|
serializeString(src.get<string>());
|
|
@@ -60,6 +61,10 @@ export function serializeArbitrary(src: JSON.Value): void {
|
|
|
60
61
|
case JSON.Types.Map:
|
|
61
62
|
serializeMap(src.get<Map<string, JSON.Value>>());
|
|
62
63
|
break;
|
|
64
|
+
case JSON.Types.TypedArray:
|
|
65
|
+
case JSON.Types.ArrayBuffer:
|
|
66
|
+
serializeDynamic(src.type, src.get<usize>());
|
|
67
|
+
break;
|
|
63
68
|
default: {
|
|
64
69
|
const fn = JSON.Value.METHODS.get(src.type - JSON.Types.Struct);
|
|
65
70
|
const ptr = src.get<usize>();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { serializeFloat } from "../simple/float";
|
|
1
|
+
export { serializeFloat, serializeFloat32, serializeFloat64 } from "../simple/float";
|