json-as 1.2.5 → 1.2.6
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/.prettierrc +3 -0
- package/README.md +2 -0
- package/assembly/custom/util.ts +70 -24
- package/assembly/deserialize/simd/string.ts +7 -5
- package/assembly/deserialize/simple/arbitrary.ts +12 -5
- package/assembly/deserialize/simple/array/arbitrary.ts +24 -7
- package/assembly/deserialize/simple/array/array.ts +8 -2
- package/assembly/deserialize/simple/array/bool.ts +8 -2
- package/assembly/deserialize/simple/array/box.ts +8 -2
- package/assembly/deserialize/simple/array/float.ts +8 -2
- package/assembly/deserialize/simple/array/integer.ts +8 -2
- package/assembly/deserialize/simple/array/map.ts +26 -6
- package/assembly/deserialize/simple/array/object.ts +26 -6
- package/assembly/deserialize/simple/array/raw.ts +42 -6
- package/assembly/deserialize/simple/array/string.ts +8 -2
- package/assembly/deserialize/simple/array/struct.ts +26 -6
- package/assembly/deserialize/simple/array.ts +5 -1
- package/assembly/deserialize/simple/bool.ts +6 -2
- package/assembly/deserialize/simple/integer.ts +4 -1
- package/assembly/deserialize/simple/map.ts +85 -17
- package/assembly/deserialize/simple/object.ts +64 -12
- package/assembly/deserialize/simple/raw.ts +4 -1
- package/assembly/deserialize/simple/set.ts +37 -11
- package/assembly/deserialize/simple/staticarray/array.ts +12 -3
- package/assembly/deserialize/simple/staticarray/bool.ts +6 -2
- package/assembly/deserialize/simple/staticarray/float.ts +12 -3
- package/assembly/deserialize/simple/staticarray/integer.ts +6 -2
- package/assembly/deserialize/simple/staticarray/string.ts +12 -4
- package/assembly/deserialize/simple/staticarray/struct.ts +30 -7
- package/assembly/deserialize/simple/staticarray.ts +11 -3
- package/assembly/deserialize/simple/string.ts +9 -3
- package/assembly/deserialize/simple/struct.ts +104 -16
- package/assembly/deserialize/swar/string.ts +13 -10
- package/assembly/index.d.ts +5 -3
- package/assembly/index.ts +183 -87
- package/assembly/serialize/simd/string.ts +70 -69
- package/assembly/serialize/simple/raw.ts +5 -1
- package/assembly/serialize/simple/string.ts +9 -10
- package/assembly/serialize/swar/string.ts +33 -32
- package/assembly/test.ts +28 -22
- package/assembly/tsconfig.json +16 -1
- package/assembly/util/concat.ts +5 -1
- package/assembly/util/masks.ts +5 -6
- package/assembly/util/snp.ts +4 -1
- package/assembly/util/swar.ts +5 -7
- package/eslint.config.js +34 -51
- package/lib/as-bs.ts +22 -18
- package/package.json +7 -6
- package/tools/assemblyscript-eslint-local.js +29 -0
- package/tools/assemblyscript-eslint.js +29 -0
- package/transform/lib/builder.d.ts.map +1 -1
- package/transform/lib/builder.js +13 -5
- package/transform/lib/builder.js.map +1 -1
- package/transform/lib/index.d.ts.map +1 -1
- package/transform/lib/index.js +690 -151
- package/transform/lib/index.js.map +1 -1
- package/transform/lib/linkers/alias.d.ts.map +1 -1
- package/transform/lib/linkers/alias.js.map +1 -1
- package/transform/lib/linkers/custom.d.ts.map +1 -1
- package/transform/lib/linkers/custom.js +9 -4
- package/transform/lib/linkers/custom.js.map +1 -1
- package/transform/lib/linkers/imports.d.ts.map +1 -1
- package/transform/lib/linkers/imports.js.map +1 -1
- package/transform/lib/types.d.ts.map +1 -1
- package/transform/lib/types.js +21 -8
- package/transform/lib/types.js.map +1 -1
- package/transform/lib/util.d.ts.map +1 -1
- package/transform/lib/util.js +1 -1
- package/transform/lib/util.js.map +1 -1
- package/transform/lib/visitor.d.ts.map +1 -1
- package/transform/lib/visitor.js +2 -1
- package/transform/lib/visitor.js.map +1 -1
- package/transform/tsconfig.json +2 -6
- package/.claude/settings.local.json +0 -9
|
@@ -12,7 +12,11 @@ import { deserializeBoxArray } from "./array/box";
|
|
|
12
12
|
import { deserializeRawArray } from "./array/raw";
|
|
13
13
|
|
|
14
14
|
// @ts-ignore: Decorator valid here
|
|
15
|
-
export function deserializeArray<T extends unknown[]>(
|
|
15
|
+
export function deserializeArray<T extends unknown[]>(
|
|
16
|
+
srcStart: usize,
|
|
17
|
+
srcEnd: usize,
|
|
18
|
+
dst: usize,
|
|
19
|
+
): T {
|
|
16
20
|
if (isString<valueof<T>>()) {
|
|
17
21
|
return <T>deserializeStringArray(srcStart, srcEnd, dst);
|
|
18
22
|
} else if (isBoolean<valueof<T>>()) {
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
// @ts-ignore: inline
|
|
2
|
-
@inline export function deserializeBoolean(
|
|
2
|
+
@inline export function deserializeBoolean(
|
|
3
|
+
srcStart: usize,
|
|
4
|
+
srcEnd: usize,
|
|
5
|
+
): boolean {
|
|
3
6
|
const block = load<u64>(srcStart);
|
|
4
7
|
if (block == 28429475166421108) return true;
|
|
5
|
-
else if (block == 32370086184550502 && load<u16>(srcStart, 8) == 101)
|
|
8
|
+
else if (block == 32370086184550502 && load<u16>(srcStart, 8) == 101)
|
|
9
|
+
return false;
|
|
6
10
|
return false; //throw new Error(`Expected to find boolean, but found "${data.slice(0, 100)}" instead!`);
|
|
7
11
|
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { atoi } from "../../util/atoi";
|
|
2
2
|
|
|
3
3
|
// @ts-ignore: inline
|
|
4
|
-
@inline export function deserializeInteger<T>(
|
|
4
|
+
@inline export function deserializeInteger<T>(
|
|
5
|
+
srcStart: usize,
|
|
6
|
+
srcEnd: usize,
|
|
7
|
+
): T {
|
|
5
8
|
return atoi<T>(srcStart, srcEnd);
|
|
6
9
|
}
|
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
import { JSON } from "../..";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
BACK_SLASH,
|
|
4
|
+
COMMA,
|
|
5
|
+
CHAR_F,
|
|
6
|
+
BRACE_LEFT,
|
|
7
|
+
BRACKET_LEFT,
|
|
8
|
+
CHAR_N,
|
|
9
|
+
QUOTE,
|
|
10
|
+
BRACE_RIGHT,
|
|
11
|
+
BRACKET_RIGHT,
|
|
12
|
+
CHAR_T,
|
|
13
|
+
COLON,
|
|
14
|
+
} from "../../custom/chars";
|
|
3
15
|
import { isSpace } from "../../util";
|
|
4
16
|
|
|
5
17
|
// @ts-ignore: Decorator is valid here
|
|
@@ -8,10 +20,21 @@ import { isSpace } from "../../util";
|
|
|
8
20
|
return JSON.__deserialize<T>(start, end);
|
|
9
21
|
}
|
|
10
22
|
|
|
11
|
-
export function deserializeMap<T extends Map<any, any>>(
|
|
12
|
-
|
|
23
|
+
export function deserializeMap<T extends Map<any, any>>(
|
|
24
|
+
srcStart: usize,
|
|
25
|
+
srcEnd: usize,
|
|
26
|
+
dst: usize,
|
|
27
|
+
): T {
|
|
28
|
+
const out = changetype<nonnull<T>>(
|
|
29
|
+
dst || changetype<usize>(instantiate<T>()),
|
|
30
|
+
);
|
|
13
31
|
// @ts-ignore: type
|
|
14
|
-
if (
|
|
32
|
+
if (
|
|
33
|
+
!isString<indexof<T>>() &&
|
|
34
|
+
!isInteger<indexof<T>>() &&
|
|
35
|
+
!isFloat<indexof<T>>()
|
|
36
|
+
)
|
|
37
|
+
throw new Error("Map key must also be a valid JSON key!");
|
|
15
38
|
|
|
16
39
|
let keyStart: usize = 0;
|
|
17
40
|
let keyEnd: usize = 0;
|
|
@@ -22,9 +45,18 @@ export function deserializeMap<T extends Map<any, any>>(srcStart: usize, srcEnd:
|
|
|
22
45
|
while (srcStart < srcEnd && isSpace(load<u16>(srcStart))) srcStart += 2;
|
|
23
46
|
while (srcEnd > srcStart && isSpace(load<u16>(srcEnd - 2))) srcEnd -= 2; // would like to optimize this later
|
|
24
47
|
|
|
25
|
-
if (srcStart - srcEnd == 0)
|
|
26
|
-
|
|
27
|
-
if (load<u16>(
|
|
48
|
+
if (srcStart - srcEnd == 0)
|
|
49
|
+
throw new Error("Input string had zero length or was all whitespace");
|
|
50
|
+
if (load<u16>(srcStart) != BRACE_LEFT)
|
|
51
|
+
throw new Error(
|
|
52
|
+
"Expected '{' at start of object at position " +
|
|
53
|
+
(srcEnd - srcStart).toString(),
|
|
54
|
+
);
|
|
55
|
+
if (load<u16>(srcEnd - 2) != BRACE_RIGHT)
|
|
56
|
+
throw new Error(
|
|
57
|
+
"Expected '}' at end of object at position " +
|
|
58
|
+
(srcEnd - srcStart).toString(),
|
|
59
|
+
);
|
|
28
60
|
|
|
29
61
|
srcStart += 2;
|
|
30
62
|
while (srcStart < srcEnd) {
|
|
@@ -37,7 +69,11 @@ export function deserializeMap<T extends Map<any, any>>(srcStart: usize, srcEnd:
|
|
|
37
69
|
// console.log("Key: " + ptrToStr(lastIndex, srcStart));
|
|
38
70
|
// console.log("Next: " + String.fromCharCode(load<u16>(srcStart + 2)));
|
|
39
71
|
while (isSpace((code = load<u16>((srcStart += 2))))) {}
|
|
40
|
-
if (code !== COLON)
|
|
72
|
+
if (code !== COLON)
|
|
73
|
+
throw new Error(
|
|
74
|
+
"Expected ':' after key at position " +
|
|
75
|
+
(srcEnd - srcStart).toString(),
|
|
76
|
+
);
|
|
41
77
|
isKey = false;
|
|
42
78
|
} else {
|
|
43
79
|
// console.log("Got key start");
|
|
@@ -56,7 +92,10 @@ export function deserializeMap<T extends Map<any, any>>(srcStart: usize, srcEnd:
|
|
|
56
92
|
if (code == QUOTE && load<u16>(srcStart - 2) !== BACK_SLASH) {
|
|
57
93
|
// console.log("Value (string): " + ptrToStr(lastIndex, srcStart + 2));
|
|
58
94
|
// @ts-ignore: type
|
|
59
|
-
out.set(
|
|
95
|
+
out.set(
|
|
96
|
+
normalizeQuotes<indexof<T>>(keyStart, keyEnd),
|
|
97
|
+
JSON.__deserialize<valueof<T>>(lastIndex, srcStart + 2),
|
|
98
|
+
);
|
|
60
99
|
// while (isSpace(load<u16>(srcStart))) srcStart += 2;
|
|
61
100
|
srcStart += 4;
|
|
62
101
|
// console.log("Next: " + String.fromCharCode(load<u16>(srcStart)));
|
|
@@ -73,7 +112,10 @@ export function deserializeMap<T extends Map<any, any>>(srcStart: usize, srcEnd:
|
|
|
73
112
|
if (code == COMMA || code == BRACE_RIGHT || isSpace(code)) {
|
|
74
113
|
// console.log("Value (number): " + ptrToStr(lastIndex, srcStart));
|
|
75
114
|
// @ts-ignore: type
|
|
76
|
-
out.set(
|
|
115
|
+
out.set(
|
|
116
|
+
normalizeQuotes<indexof<T>>(keyStart, keyEnd),
|
|
117
|
+
JSON.__deserialize<valueof<T>>(lastIndex, srcStart),
|
|
118
|
+
);
|
|
77
119
|
// while (isSpace(load<u16>((srcStart += 2)))) {
|
|
78
120
|
// /* empty */
|
|
79
121
|
// }
|
|
@@ -92,12 +134,21 @@ export function deserializeMap<T extends Map<any, any>>(srcStart: usize, srcEnd:
|
|
|
92
134
|
const code = load<u16>(srcStart);
|
|
93
135
|
if (code == QUOTE) {
|
|
94
136
|
srcStart += 2;
|
|
95
|
-
while (
|
|
137
|
+
while (
|
|
138
|
+
!(
|
|
139
|
+
load<u16>(srcStart) == QUOTE &&
|
|
140
|
+
load<u16>(srcStart - 2) != BACK_SLASH
|
|
141
|
+
)
|
|
142
|
+
)
|
|
143
|
+
srcStart += 2;
|
|
96
144
|
} else if (code == BRACE_RIGHT) {
|
|
97
145
|
if (--depth == 0) {
|
|
98
146
|
// console.log("Value (object): " + ptrToStr(lastIndex, srcStart + 2));
|
|
99
147
|
// @ts-ignore: type
|
|
100
|
-
out.set(
|
|
148
|
+
out.set(
|
|
149
|
+
normalizeQuotes<indexof<T>>(keyStart, keyEnd),
|
|
150
|
+
JSON.__deserialize<valueof<T>>(lastIndex, (srcStart += 2)),
|
|
151
|
+
);
|
|
101
152
|
// console.log("Next: " + String.fromCharCode(load<u16>(srcStart)));
|
|
102
153
|
keyStart = 0;
|
|
103
154
|
// while (isSpace(load<u16>(srcStart))) {
|
|
@@ -118,7 +169,10 @@ export function deserializeMap<T extends Map<any, any>>(srcStart: usize, srcEnd:
|
|
|
118
169
|
if (--depth == 0) {
|
|
119
170
|
// console.log("Value (array): " + ptrToStr(lastIndex, srcStart + 2));
|
|
120
171
|
// @ts-ignore: type
|
|
121
|
-
out.set(
|
|
172
|
+
out.set(
|
|
173
|
+
normalizeQuotes<indexof<T>>(keyStart, keyEnd),
|
|
174
|
+
JSON.__deserialize<valueof<T>>(lastIndex, (srcStart += 2)),
|
|
175
|
+
);
|
|
122
176
|
// console.log("Next: " + String.fromCharCode(load<u16>(srcStart)));
|
|
123
177
|
keyStart = 0;
|
|
124
178
|
// while (isSpace(load<u16>((srcStart += 2)))) {
|
|
@@ -133,7 +187,10 @@ export function deserializeMap<T extends Map<any, any>>(srcStart: usize, srcEnd:
|
|
|
133
187
|
if (load<u64>(srcStart) == 28429475166421108) {
|
|
134
188
|
// console.log("Value (bool): " + ptrToStr(srcStart, srcStart + 8));
|
|
135
189
|
// @ts-ignore: type
|
|
136
|
-
out.set(
|
|
190
|
+
out.set(
|
|
191
|
+
normalizeQuotes<indexof<T>>(keyStart, keyEnd),
|
|
192
|
+
JSON.__deserialize<valueof<T>>(srcStart, (srcStart += 8)),
|
|
193
|
+
);
|
|
137
194
|
// while (isSpace(load<u16>((srcStart += 2)))) {
|
|
138
195
|
// /* empty */
|
|
139
196
|
// }
|
|
@@ -145,7 +202,10 @@ export function deserializeMap<T extends Map<any, any>>(srcStart: usize, srcEnd:
|
|
|
145
202
|
if (load<u64>(srcStart, 2) == 28429466576093281) {
|
|
146
203
|
// console.log("Value (bool): " + ptrToStr(srcStart, srcStart + 10));
|
|
147
204
|
// @ts-ignore: type
|
|
148
|
-
out.set(
|
|
205
|
+
out.set(
|
|
206
|
+
normalizeQuotes<indexof<T>>(keyStart, keyEnd),
|
|
207
|
+
JSON.__deserialize<valueof<T>>(srcStart, (srcStart += 10)),
|
|
208
|
+
);
|
|
149
209
|
// while (isSpace(load<u16>((srcStart += 2)))) {
|
|
150
210
|
// /* empty */
|
|
151
211
|
// }
|
|
@@ -157,7 +217,10 @@ export function deserializeMap<T extends Map<any, any>>(srcStart: usize, srcEnd:
|
|
|
157
217
|
if (load<u64>(srcStart) == 30399761348886638) {
|
|
158
218
|
// console.log("Value (null): " + ptrToStr(srcStart, srcStart + 8));
|
|
159
219
|
// @ts-ignore: type
|
|
160
|
-
out.set(
|
|
220
|
+
out.set(
|
|
221
|
+
normalizeQuotes<indexof<T>>(keyStart, keyEnd),
|
|
222
|
+
JSON.__deserialize<valueof<T>>(srcStart, (srcStart += 8)),
|
|
223
|
+
);
|
|
161
224
|
// while (isSpace(load<u16>((srcStart += 2)))) {
|
|
162
225
|
/* empty */
|
|
163
226
|
// }
|
|
@@ -168,7 +231,12 @@ export function deserializeMap<T extends Map<any, any>>(srcStart: usize, srcEnd:
|
|
|
168
231
|
} else if (isSpace(code)) {
|
|
169
232
|
srcStart += 2;
|
|
170
233
|
} else {
|
|
171
|
-
throw new Error(
|
|
234
|
+
throw new Error(
|
|
235
|
+
"Unexpected character in JSON object '" +
|
|
236
|
+
String.fromCharCode(code) +
|
|
237
|
+
"' at position " +
|
|
238
|
+
(srcEnd - srcStart).toString(),
|
|
239
|
+
);
|
|
172
240
|
}
|
|
173
241
|
}
|
|
174
242
|
}
|
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
import { JSON } from "../..";
|
|
2
2
|
import { bs } from "../../../lib/as-bs";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
BACK_SLASH,
|
|
5
|
+
COMMA,
|
|
6
|
+
CHAR_F,
|
|
7
|
+
BRACE_LEFT,
|
|
8
|
+
BRACKET_LEFT,
|
|
9
|
+
CHAR_N,
|
|
10
|
+
QUOTE,
|
|
11
|
+
BRACE_RIGHT,
|
|
12
|
+
BRACKET_RIGHT,
|
|
13
|
+
CHAR_T,
|
|
14
|
+
COLON,
|
|
15
|
+
} from "../../custom/chars";
|
|
4
16
|
import { isSpace } from "../../util";
|
|
5
17
|
import { ptrToStr } from "../../util/ptrToStr";
|
|
6
18
|
import { deserializeString_SWAR } from "../swar/string";
|
|
@@ -10,7 +22,11 @@ import { deserializeBoolean } from "./bool";
|
|
|
10
22
|
import { deserializeFloat } from "./float";
|
|
11
23
|
import { deserializeString } from "./string";
|
|
12
24
|
|
|
13
|
-
export function deserializeObject(
|
|
25
|
+
export function deserializeObject(
|
|
26
|
+
srcStart: usize,
|
|
27
|
+
srcEnd: usize,
|
|
28
|
+
dst: usize,
|
|
29
|
+
): JSON.Obj {
|
|
14
30
|
const out = changetype<JSON.Obj>(dst || changetype<usize>(new JSON.Obj()));
|
|
15
31
|
|
|
16
32
|
let keyStart: usize = 0;
|
|
@@ -22,9 +38,18 @@ export function deserializeObject(srcStart: usize, srcEnd: usize, dst: usize): J
|
|
|
22
38
|
while (srcStart < srcEnd && isSpace(load<u16>(srcStart))) srcStart += 2;
|
|
23
39
|
while (srcEnd > srcStart && isSpace(load<u16>(srcEnd - 2))) srcEnd -= 2; // would like to optimize this later
|
|
24
40
|
|
|
25
|
-
if (srcStart - srcEnd == 0)
|
|
26
|
-
|
|
27
|
-
if (load<u16>(
|
|
41
|
+
if (srcStart - srcEnd == 0)
|
|
42
|
+
throw new Error("Input string had zero length or was all whitespace");
|
|
43
|
+
if (load<u16>(srcStart) != BRACE_LEFT)
|
|
44
|
+
throw new Error(
|
|
45
|
+
"Expected '{' at start of object at position " +
|
|
46
|
+
(srcEnd - srcStart).toString(),
|
|
47
|
+
);
|
|
48
|
+
if (load<u16>(srcEnd - 2) != BRACE_RIGHT)
|
|
49
|
+
throw new Error(
|
|
50
|
+
"Expected '}' at end of object at position " +
|
|
51
|
+
(srcEnd - srcStart).toString(),
|
|
52
|
+
);
|
|
28
53
|
|
|
29
54
|
srcStart += 2;
|
|
30
55
|
while (srcStart < srcEnd) {
|
|
@@ -37,7 +62,11 @@ export function deserializeObject(srcStart: usize, srcEnd: usize, dst: usize): J
|
|
|
37
62
|
// console.log("Key: " + ptrToStr(lastIndex, srcStart));
|
|
38
63
|
// console.log("Next: " + String.fromCharCode(load<u16>(srcStart + 2)));
|
|
39
64
|
while (isSpace((code = load<u16>((srcStart += 2))))) {}
|
|
40
|
-
if (code !== COLON)
|
|
65
|
+
if (code !== COLON)
|
|
66
|
+
throw new Error(
|
|
67
|
+
"Expected ':' after key at position " +
|
|
68
|
+
(srcEnd - srcStart).toString(),
|
|
69
|
+
);
|
|
41
70
|
isKey = false;
|
|
42
71
|
} else {
|
|
43
72
|
// console.log("Got key start");
|
|
@@ -55,7 +84,10 @@ export function deserializeObject(srcStart: usize, srcEnd: usize, dst: usize): J
|
|
|
55
84
|
const code = load<u16>(srcStart);
|
|
56
85
|
if (code == QUOTE && load<u16>(srcStart - 2) !== BACK_SLASH) {
|
|
57
86
|
// console.log("Value (string):-" + deserializeString_SWAR(lastIndex, srcStart + 2, 0) + "-");
|
|
58
|
-
out.set(
|
|
87
|
+
out.set(
|
|
88
|
+
ptrToStr(keyStart, keyEnd),
|
|
89
|
+
deserializeString(lastIndex, srcStart + 2),
|
|
90
|
+
);
|
|
59
91
|
// while (isSpace(load<u16>(srcStart))) srcStart += 2;
|
|
60
92
|
srcStart += 4;
|
|
61
93
|
// console.log("Next: " + String.fromCharCode(load<u16>(srcStart)));
|
|
@@ -71,7 +103,10 @@ export function deserializeObject(srcStart: usize, srcEnd: usize, dst: usize): J
|
|
|
71
103
|
const code = load<u16>(srcStart);
|
|
72
104
|
if (code == COMMA || code == BRACE_RIGHT || isSpace(code)) {
|
|
73
105
|
// console.log("Value (number): " + ptrToStr(lastIndex, srcStart));
|
|
74
|
-
out.set(
|
|
106
|
+
out.set(
|
|
107
|
+
ptrToStr(keyStart, keyEnd),
|
|
108
|
+
deserializeFloat<f64>(lastIndex, srcStart),
|
|
109
|
+
);
|
|
75
110
|
// while (isSpace(load<u16>((srcStart += 2)))) {
|
|
76
111
|
// /* empty */
|
|
77
112
|
// }
|
|
@@ -90,11 +125,20 @@ export function deserializeObject(srcStart: usize, srcEnd: usize, dst: usize): J
|
|
|
90
125
|
const code = load<u16>(srcStart);
|
|
91
126
|
if (code == QUOTE) {
|
|
92
127
|
srcStart += 2;
|
|
93
|
-
while (
|
|
128
|
+
while (
|
|
129
|
+
!(
|
|
130
|
+
load<u16>(srcStart) == QUOTE &&
|
|
131
|
+
load<u16>(srcStart - 2) != BACK_SLASH
|
|
132
|
+
)
|
|
133
|
+
)
|
|
134
|
+
srcStart += 2;
|
|
94
135
|
} else if (code == BRACE_RIGHT) {
|
|
95
136
|
if (--depth == 0) {
|
|
96
137
|
// console.log("Value (object): " + ptrToStr(lastIndex, srcStart + 2));
|
|
97
|
-
out.set(
|
|
138
|
+
out.set(
|
|
139
|
+
ptrToStr(keyStart, keyEnd),
|
|
140
|
+
deserializeObject(lastIndex, (srcStart += 2), 0),
|
|
141
|
+
);
|
|
98
142
|
// console.log("Next: " + String.fromCharCode(load<u16>(srcStart)));
|
|
99
143
|
keyStart = 0;
|
|
100
144
|
// while (isSpace(load<u16>(srcStart))) {
|
|
@@ -114,7 +158,10 @@ export function deserializeObject(srcStart: usize, srcEnd: usize, dst: usize): J
|
|
|
114
158
|
if (code == BRACKET_RIGHT) {
|
|
115
159
|
if (--depth == 0) {
|
|
116
160
|
// console.log("Value (array): " + ptrToStr(lastIndex, srcStart + 2));
|
|
117
|
-
out.set(
|
|
161
|
+
out.set(
|
|
162
|
+
ptrToStr(keyStart, keyEnd),
|
|
163
|
+
deserializeArray<JSON.Value[]>(lastIndex, (srcStart += 2), 0),
|
|
164
|
+
);
|
|
118
165
|
// console.log("Next: " + String.fromCharCode(load<u16>(srcStart)));
|
|
119
166
|
keyStart = 0;
|
|
120
167
|
// while (isSpace(load<u16>((srcStart += 2)))) {
|
|
@@ -164,7 +211,12 @@ export function deserializeObject(srcStart: usize, srcEnd: usize, dst: usize): J
|
|
|
164
211
|
} else if (isSpace(code)) {
|
|
165
212
|
srcStart += 2;
|
|
166
213
|
} else {
|
|
167
|
-
throw new Error(
|
|
214
|
+
throw new Error(
|
|
215
|
+
"Unexpected character in JSON object '" +
|
|
216
|
+
String.fromCharCode(code) +
|
|
217
|
+
"' at position " +
|
|
218
|
+
(srcEnd - srcStart).toString(),
|
|
219
|
+
);
|
|
168
220
|
}
|
|
169
221
|
}
|
|
170
222
|
}
|
|
@@ -2,6 +2,9 @@ import { JSON } from "../..";
|
|
|
2
2
|
import { ptrToStr } from "../../util/ptrToStr";
|
|
3
3
|
|
|
4
4
|
// @ts-ignore: inline
|
|
5
|
-
@inline export function deserializeRaw(
|
|
5
|
+
@inline export function deserializeRaw(
|
|
6
|
+
srcStart: usize,
|
|
7
|
+
srcEnd: usize,
|
|
8
|
+
): JSON.Raw {
|
|
6
9
|
return JSON.Raw.from(ptrToStr(srcStart, srcEnd));
|
|
7
10
|
}
|
|
@@ -1,16 +1,36 @@
|
|
|
1
1
|
import { JSON } from "../..";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
BACK_SLASH,
|
|
4
|
+
BRACKET_LEFT,
|
|
5
|
+
BRACKET_RIGHT,
|
|
6
|
+
BRACE_LEFT,
|
|
7
|
+
BRACE_RIGHT,
|
|
8
|
+
CHAR_F,
|
|
9
|
+
CHAR_N,
|
|
10
|
+
CHAR_T,
|
|
11
|
+
COMMA,
|
|
12
|
+
QUOTE,
|
|
13
|
+
} from "../../custom/chars";
|
|
3
14
|
import { isSpace, atoi } from "../../util";
|
|
4
15
|
|
|
5
|
-
export function deserializeSet<T extends Set<any>>(
|
|
6
|
-
|
|
16
|
+
export function deserializeSet<T extends Set<any>>(
|
|
17
|
+
srcStart: usize,
|
|
18
|
+
srcEnd: usize,
|
|
19
|
+
dst: usize,
|
|
20
|
+
): T {
|
|
21
|
+
const out = changetype<nonnull<T>>(
|
|
22
|
+
dst || changetype<usize>(instantiate<T>()),
|
|
23
|
+
);
|
|
7
24
|
|
|
8
25
|
while (srcStart < srcEnd && isSpace(load<u16>(srcStart))) srcStart += 2;
|
|
9
26
|
while (srcEnd > srcStart && isSpace(load<u16>(srcEnd - 2))) srcEnd -= 2;
|
|
10
27
|
|
|
11
|
-
if (srcStart >= srcEnd)
|
|
12
|
-
|
|
13
|
-
if (load<u16>(
|
|
28
|
+
if (srcStart >= srcEnd)
|
|
29
|
+
throw new Error("Input string had zero length or was all whitespace");
|
|
30
|
+
if (load<u16>(srcStart) != BRACKET_LEFT)
|
|
31
|
+
throw new Error("Expected '[' at start of set");
|
|
32
|
+
if (load<u16>(srcEnd - 2) != BRACKET_RIGHT)
|
|
33
|
+
throw new Error("Expected ']' at end of set");
|
|
14
34
|
|
|
15
35
|
srcStart += 2;
|
|
16
36
|
|
|
@@ -34,7 +54,7 @@ export function deserializeSet<T extends Set<any>>(srcStart: usize, srcEnd: usiz
|
|
|
34
54
|
srcStart += 2;
|
|
35
55
|
}
|
|
36
56
|
}
|
|
37
|
-
|
|
57
|
+
// @ts-ignore: type
|
|
38
58
|
} else if (isBoolean<indexof<T>>()) {
|
|
39
59
|
if (code == CHAR_T) {
|
|
40
60
|
// @ts-ignore: type
|
|
@@ -45,7 +65,7 @@ export function deserializeSet<T extends Set<any>>(srcStart: usize, srcEnd: usiz
|
|
|
45
65
|
out.add(<indexof<T>>false);
|
|
46
66
|
srcStart += 10;
|
|
47
67
|
}
|
|
48
|
-
|
|
68
|
+
// @ts-ignore: type
|
|
49
69
|
} else if (isInteger<indexof<T>>()) {
|
|
50
70
|
if (code - 48 <= 9 || code == 45) {
|
|
51
71
|
const lastIndex = srcStart;
|
|
@@ -60,7 +80,7 @@ export function deserializeSet<T extends Set<any>>(srcStart: usize, srcEnd: usiz
|
|
|
60
80
|
srcStart += 2;
|
|
61
81
|
}
|
|
62
82
|
}
|
|
63
|
-
|
|
83
|
+
// @ts-ignore: type
|
|
64
84
|
} else if (isFloat<indexof<T>>()) {
|
|
65
85
|
if (code - 48 <= 9 || code == 45) {
|
|
66
86
|
const lastIndex = srcStart;
|
|
@@ -75,7 +95,7 @@ export function deserializeSet<T extends Set<any>>(srcStart: usize, srcEnd: usiz
|
|
|
75
95
|
srcStart += 2;
|
|
76
96
|
}
|
|
77
97
|
}
|
|
78
|
-
|
|
98
|
+
// @ts-ignore: type
|
|
79
99
|
} else if (isManaged<indexof<T>>() || isReference<indexof<T>>()) {
|
|
80
100
|
// @ts-ignore: type
|
|
81
101
|
const type = changetype<nonnull<indexof<T>>>(0);
|
|
@@ -88,7 +108,13 @@ export function deserializeSet<T extends Set<any>>(srcStart: usize, srcEnd: usiz
|
|
|
88
108
|
const c = load<u16>(srcStart);
|
|
89
109
|
if (c == QUOTE) {
|
|
90
110
|
srcStart += 2;
|
|
91
|
-
while (
|
|
111
|
+
while (
|
|
112
|
+
!(
|
|
113
|
+
load<u16>(srcStart) == QUOTE &&
|
|
114
|
+
load<u16>(srcStart - 2) != BACK_SLASH
|
|
115
|
+
)
|
|
116
|
+
)
|
|
117
|
+
srcStart += 2;
|
|
92
118
|
} else if (c == BRACE_RIGHT) {
|
|
93
119
|
if (--depth == 0) {
|
|
94
120
|
srcStart += 2;
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { BRACKET_LEFT, BRACKET_RIGHT } from "../../../custom/chars";
|
|
2
2
|
import { JSON } from "../../../";
|
|
3
3
|
|
|
4
|
-
export function deserializeStaticArrayArray<T extends StaticArray<any>>(
|
|
4
|
+
export function deserializeStaticArrayArray<T extends StaticArray<any>>(
|
|
5
|
+
srcStart: usize,
|
|
6
|
+
srcEnd: usize,
|
|
7
|
+
dst: usize,
|
|
8
|
+
): T {
|
|
5
9
|
let count: i32 = 0;
|
|
6
10
|
let depth: u32 = 0;
|
|
7
11
|
let ptr = srcStart + 2;
|
|
@@ -15,7 +19,7 @@ export function deserializeStaticArrayArray<T extends StaticArray<any>>(srcStart
|
|
|
15
19
|
ptr += 2;
|
|
16
20
|
}
|
|
17
21
|
|
|
18
|
-
const outSize = <usize>count << alignof<valueof<T>>();
|
|
22
|
+
const outSize = (<usize>count) << alignof<valueof<T>>();
|
|
19
23
|
const out = changetype<nonnull<T>>(dst || __new(outSize, idof<T>()));
|
|
20
24
|
|
|
21
25
|
// Second pass: populate values
|
|
@@ -28,7 +32,12 @@ export function deserializeStaticArrayArray<T extends StaticArray<any>>(srcStart
|
|
|
28
32
|
if (code == BRACKET_LEFT && depth++ == 0) {
|
|
29
33
|
lastIndex = srcStart;
|
|
30
34
|
} else if (code == BRACKET_RIGHT && --depth == 0) {
|
|
31
|
-
unchecked(
|
|
35
|
+
unchecked(
|
|
36
|
+
(out[index++] = JSON.__deserialize<valueof<T>>(
|
|
37
|
+
lastIndex,
|
|
38
|
+
srcStart + 2,
|
|
39
|
+
)),
|
|
40
|
+
);
|
|
32
41
|
}
|
|
33
42
|
srcStart += 2;
|
|
34
43
|
}
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
export function deserializeStaticArrayBoolean<T extends StaticArray<any>>(
|
|
1
|
+
export function deserializeStaticArrayBoolean<T extends StaticArray<any>>(
|
|
2
|
+
srcStart: usize,
|
|
3
|
+
srcEnd: usize,
|
|
4
|
+
dst: usize,
|
|
5
|
+
): T {
|
|
2
6
|
// First pass: count elements using same logic as Array deserializer
|
|
3
7
|
let count: i32 = 0;
|
|
4
8
|
let ptr = srcStart + 2; // skip [
|
|
@@ -16,7 +20,7 @@ export function deserializeStaticArrayBoolean<T extends StaticArray<any>>(srcSta
|
|
|
16
20
|
}
|
|
17
21
|
|
|
18
22
|
// Allocate StaticArray with correct size
|
|
19
|
-
const outSize = <usize>count << alignof<valueof<T>>();
|
|
23
|
+
const outSize = (<usize>count) << alignof<valueof<T>>();
|
|
20
24
|
const out = changetype<nonnull<T>>(dst || __new(outSize, idof<T>()));
|
|
21
25
|
|
|
22
26
|
// Second pass: populate values
|
|
@@ -2,7 +2,11 @@ import { isSpace } from "../../../util";
|
|
|
2
2
|
import { COMMA, BRACKET_RIGHT } from "../../../custom/chars";
|
|
3
3
|
import { JSON } from "../../..";
|
|
4
4
|
|
|
5
|
-
export function deserializeStaticArrayFloat<T extends StaticArray<any>>(
|
|
5
|
+
export function deserializeStaticArrayFloat<T extends StaticArray<any>>(
|
|
6
|
+
srcStart: usize,
|
|
7
|
+
srcEnd: usize,
|
|
8
|
+
dst: usize,
|
|
9
|
+
): T {
|
|
6
10
|
let count: i32 = 0;
|
|
7
11
|
let ptr = srcStart;
|
|
8
12
|
while (ptr < srcEnd) {
|
|
@@ -19,7 +23,7 @@ export function deserializeStaticArrayFloat<T extends StaticArray<any>>(srcStart
|
|
|
19
23
|
ptr += 2;
|
|
20
24
|
}
|
|
21
25
|
|
|
22
|
-
const outSize = <usize>count << alignof<valueof<T>>();
|
|
26
|
+
const outSize = (<usize>count) << alignof<valueof<T>>();
|
|
23
27
|
const out = changetype<nonnull<T>>(dst || __new(outSize, idof<T>()));
|
|
24
28
|
|
|
25
29
|
let index = 0;
|
|
@@ -31,7 +35,12 @@ export function deserializeStaticArrayFloat<T extends StaticArray<any>>(srcStart
|
|
|
31
35
|
while (srcStart < srcEnd) {
|
|
32
36
|
const code = load<u16>(srcStart);
|
|
33
37
|
if (code == COMMA || code == BRACKET_RIGHT || isSpace(code)) {
|
|
34
|
-
unchecked(
|
|
38
|
+
unchecked(
|
|
39
|
+
(out[index++] = JSON.__deserialize<valueof<T>>(
|
|
40
|
+
lastIndex,
|
|
41
|
+
srcStart,
|
|
42
|
+
)),
|
|
43
|
+
);
|
|
35
44
|
break;
|
|
36
45
|
}
|
|
37
46
|
srcStart += 2;
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { atoi, isSpace } from "../../../util";
|
|
2
2
|
import { COMMA, BRACKET_RIGHT } from "../../../custom/chars";
|
|
3
3
|
|
|
4
|
-
export function deserializeStaticArrayInteger<T extends StaticArray<any>>(
|
|
4
|
+
export function deserializeStaticArrayInteger<T extends StaticArray<any>>(
|
|
5
|
+
srcStart: usize,
|
|
6
|
+
srcEnd: usize,
|
|
7
|
+
dst: usize,
|
|
8
|
+
): T {
|
|
5
9
|
let count: i32 = 0;
|
|
6
10
|
let ptr = srcStart;
|
|
7
11
|
while (ptr < srcEnd) {
|
|
@@ -18,7 +22,7 @@ export function deserializeStaticArrayInteger<T extends StaticArray<any>>(srcSta
|
|
|
18
22
|
ptr += 2;
|
|
19
23
|
}
|
|
20
24
|
|
|
21
|
-
const outSize = <usize>count << alignof<valueof<T>>();
|
|
25
|
+
const outSize = (<usize>count) << alignof<valueof<T>>();
|
|
22
26
|
const out = changetype<nonnull<T>>(dst || __new(outSize, idof<T>()));
|
|
23
27
|
|
|
24
28
|
// Second pass: populate values
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { JSON } from "../../..";
|
|
2
2
|
import { BACK_SLASH, QUOTE } from "../../../custom/chars";
|
|
3
3
|
|
|
4
|
-
export function deserializeStaticArrayString(
|
|
4
|
+
export function deserializeStaticArrayString(
|
|
5
|
+
srcStart: usize,
|
|
6
|
+
srcEnd: usize,
|
|
7
|
+
dst: usize,
|
|
8
|
+
): StaticArray<string> {
|
|
5
9
|
// First pass: count elements using same logic as Array deserializer
|
|
6
10
|
let count: i32 = 0;
|
|
7
11
|
let ptr = srcStart;
|
|
@@ -20,8 +24,10 @@ export function deserializeStaticArrayString(srcStart: usize, srcEnd: usize, dst
|
|
|
20
24
|
}
|
|
21
25
|
|
|
22
26
|
// Allocate StaticArray with correct size
|
|
23
|
-
const outSize = <usize>count << alignof<string>();
|
|
24
|
-
const out = changetype<StaticArray<string>>(
|
|
27
|
+
const outSize = (<usize>count) << alignof<string>();
|
|
28
|
+
const out = changetype<StaticArray<string>>(
|
|
29
|
+
dst || __new(outSize, idof<StaticArray<string>>()),
|
|
30
|
+
);
|
|
25
31
|
|
|
26
32
|
// Second pass: populate values
|
|
27
33
|
let index = 0;
|
|
@@ -34,7 +40,9 @@ export function deserializeStaticArrayString(srcStart: usize, srcEnd: usize, dst
|
|
|
34
40
|
inString = true;
|
|
35
41
|
lastPos = srcStart;
|
|
36
42
|
} else if (load<u16>(srcStart - 2) != BACK_SLASH) {
|
|
37
|
-
unchecked(
|
|
43
|
+
unchecked(
|
|
44
|
+
(out[index++] = JSON.__deserialize<string>(lastPos, srcStart + 2)),
|
|
45
|
+
);
|
|
38
46
|
inString = false;
|
|
39
47
|
}
|
|
40
48
|
}
|