json-as 1.0.0-alpha.2 → 1.0.0-alpha.4
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/.prettierignore +6 -0
- package/.prettierrc.json +0 -1
- package/CHANGELOG +23 -1
- package/README.md +33 -21
- package/as-test.config.json +1 -1
- package/asconfig.json +1 -29
- package/assembly/__tests__/array.spec.ts +67 -0
- package/assembly/__tests__/bool.spec.ts +4 -12
- package/assembly/__tests__/box.spec.ts +37 -0
- package/assembly/__tests__/date.spec.ts +38 -0
- package/assembly/__tests__/float.spec.ts +11 -21
- package/assembly/__tests__/integer.spec.ts +7 -9
- package/assembly/__tests__/null.spec.ts +12 -0
- package/assembly/__tests__/obj.spec.ts +137 -3
- package/assembly/__tests__/simd/string.spec.ts +21 -21
- package/assembly/__tests__/string.spec.ts +6 -4
- package/assembly/__tests__/test.spec.ts +120 -191
- package/assembly/deserialize/simple/bool.ts +5 -8
- package/assembly/deserialize/simple/date.ts +2 -2
- package/assembly/deserialize/simple/map.ts +1 -1
- package/assembly/deserialize/simple/object.ts +3 -1
- package/assembly/deserialize/simple/string.ts +4 -3
- package/assembly/globals/tables.ts +74 -416
- package/assembly/index.ts +48 -25
- package/assembly/serialize/simd/string.ts +11 -11
- package/assembly/serialize/simple/array.ts +5 -4
- package/assembly/serialize/simple/bool.ts +2 -2
- package/assembly/serialize/simple/date.ts +1 -1
- package/assembly/serialize/simple/integer.ts +6 -1
- package/assembly/serialize/simple/map.ts +6 -6
- package/assembly/serialize/simple/string.ts +3 -3
- package/assembly/test.ts +30 -15
- package/assembly/util/bytes.ts +1 -1
- package/assembly/util/snp.ts +2 -2
- package/modules/as-bs/assembly/index.ts +73 -92
- package/modules/test/assembly/index.ts +22 -0
- package/package.json +6 -10
- package/run-tests.sh +15 -0
- package/transform/lib/builder.js +1340 -1262
- package/transform/lib/index.js +582 -512
- package/transform/lib/index.js.map +1 -1
- package/transform/lib/linker.js +12 -10
- package/transform/lib/types.js +19 -19
- package/transform/lib/util.js +34 -34
- package/transform/lib/visitor.js +529 -526
- package/transform/src/index.ts +22 -16
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { JSON } from "
|
|
2
|
-
import { describe, expect
|
|
1
|
+
import { JSON } from "..";
|
|
2
|
+
import { describe, expect } from "../../modules/test/assembly";
|
|
3
3
|
|
|
4
4
|
describe("Should serialize strings", () => {
|
|
5
5
|
expect(JSON.stringify("abcdefg")).toBe('"abcdefg"');
|
|
@@ -9,6 +9,8 @@ describe("Should serialize strings", () => {
|
|
|
9
9
|
expect(JSON.stringify('string "with random spa\nces and \nnewlines\n\n\n')).toBe('"string \\"with random spa\\nces and \\nnewlines\\n\\n\\n"');
|
|
10
10
|
|
|
11
11
|
expect(JSON.stringify('string with colon : comma , brace [ ] bracket { } and quote " and other quote \\"')).toBe('"string with colon : comma , brace [ ] bracket { } and quote \\" and other quote \\\\\\""');
|
|
12
|
+
|
|
13
|
+
expect(JSON.stringify("\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\u0008\u0009\u000a\u000b\u000c\u000d\u000e\u000f\u000f\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f")).toBe('"\\u0000\\u0001\\u0002\\u0003\\u0004\\u0005\\u0006\\u0007\\b\\t\\n\\u000b\\f\\r\\u000e\\u000f\\u000f\\u0011\\u0012\\u0013\\u0014\\u0015\\u0016\\u0017\\u0018\\u0019\\u001a\\u001b\\u001c\\u001d\\u001e\\u001f"');
|
|
12
14
|
});
|
|
13
15
|
|
|
14
16
|
describe("Should deserialize strings", () => {
|
|
@@ -19,6 +21,6 @@ describe("Should deserialize strings", () => {
|
|
|
19
21
|
expect(JSON.parse<string>('"\\"string \\\\\\"with random spa\\\\nces and \\\\nnewlines\\\\n\\\\n\\\\n\\""')).toBe('"string \\"with random spa\\nces and \\nnewlines\\n\\n\\n"');
|
|
20
22
|
|
|
21
23
|
expect(JSON.parse<string>('"\\"string with colon : comma , brace [ ] bracket { } and quote \\\\\\" and other quote \\\\\\\\\\"\\""')).toBe('"string with colon : comma , brace [ ] bracket { } and quote \\" and other quote \\\\""');
|
|
22
|
-
});
|
|
23
24
|
|
|
24
|
-
|
|
25
|
+
expect(JSON.parse<string>('"\\u0000\\u0001\\u0002\\u0003\\u0004\\u0005\\u0006\\u0007\\b\\t\\n\\u000b\\f\\r\\u000e\\u000f\\u000f\\u0011\\u0012\\u0013\\u0014\\u0015\\u0016\\u0017\\u0018\\u0019\\u001a\\u001b\\u001c\\u001d\\u001e\\u001f"')).toBe("\u0000\u0001\u0002\u0003\u0004\u0005\u0006\u0007\u0008\u0009\u000a\u000b\u000c\u000d\u000e\u000f\u000f\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001a\u001b\u001c\u001d\u001e\u001f");
|
|
26
|
+
});
|
|
@@ -1,193 +1,122 @@
|
|
|
1
|
-
import { JSON } from "
|
|
2
|
-
import { describe, expect
|
|
1
|
+
import { JSON } from "../";
|
|
2
|
+
import { describe, expect } from "../../modules/test/assembly/index";
|
|
3
3
|
import { DerivedObject, Null, ObjWithStrangeKey, ObjectWithFloat, OmitIf, Player, Vec3 } from "./types";
|
|
4
4
|
|
|
5
|
-
describe("Should serialize
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
describe("Should
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
describe("Should deserialize nulls", () => {
|
|
126
|
-
expect(JSON.stringify(JSON.parse<Null>("null"))).toBe("null");
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
describe("Should deserialize integer arrays", () => {
|
|
130
|
-
expect(JSON.stringify(JSON.parse<u32[]>("[0,100,101]"))).toBe(JSON.stringify([0, 100, 101]));
|
|
131
|
-
|
|
132
|
-
expect(JSON.stringify(JSON.parse<i32[]>("[0,100,101,-100,-101]"))).toBe(JSON.stringify([0, 100, 101, -100, -101]));
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
describe("Should deserialize float arrays", () => {
|
|
136
|
-
expect(JSON.stringify(JSON.parse<f64[]>("[7.23,1000.0,1000.0,1.23456,1.23456,0.0,7.23]"))).toBe(JSON.stringify([7.23, 1000.0, 1000.0, 1.23456, 1.23456, 0.0, 7.23]));
|
|
137
|
-
|
|
138
|
-
expect(JSON.stringify(JSON.parse<f64[]>("[1e+21,1e+22,1e-7,1e-8,1e-9]"))).toBe(JSON.stringify([1e21, 1e22, 1e-7, 1e-8, 1e-9]));
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
describe("Should deserialize boolean arrays", () => {
|
|
142
|
-
expect(JSON.stringify(JSON.parse<boolean[]>("[true,false]"))).toBe(JSON.stringify([true, false]));
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
describe("Should deserialize string arrays", () => {
|
|
146
|
-
expect(JSON.stringify(JSON.parse<string[]>('["string \\"with random spa\\nces and \\nnewlines\\n\\n\\n"]'))).toBe(JSON.stringify(['string "with random spa\nces and \nnewlines\n\n\n']));
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
describe("Should deserialize nested integer arrays", () => {
|
|
150
|
-
expect(JSON.stringify(JSON.parse<i64[][]>("[[100,101],[-100,-101],[0]]"))).toBe(JSON.stringify([[100, 101], [-100, -101], [0]]));
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
describe("Should deserialize nested float arrays", () => {
|
|
154
|
-
expect(JSON.stringify(JSON.parse<f64[][]>("[[7.23],[1000.0],[1000.0],[1.23456],[1.23456],[0.0],[7.23]]"))).toBe(JSON.stringify([[7.23], [1000.0], [1000.0], [1.23456], [1.23456], [0.0], [7.23]]));
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
describe("Should deserialize nested boolean arrays", () => {
|
|
158
|
-
expect(JSON.stringify(JSON.parse<boolean[][]>("[[true],[false]]"))).toBe(JSON.stringify([[true], [false]]));
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
describe("Should deserialize object arrays", () => {
|
|
162
|
-
expect(JSON.stringify(JSON.parse<Vec3[]>('[{"x":3.4,"y":1.2,"z":8.3},{"x":3.4,"y":-2.1,"z":9.3}]'))).toBe(
|
|
163
|
-
JSON.stringify(<Vec3[]>[
|
|
164
|
-
{ x: 3.4, y: 1.2, z: 8.3 },
|
|
165
|
-
{ x: 3.4, y: -2.1, z: 9.3 },
|
|
166
|
-
]),
|
|
167
|
-
);
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
describe("Should deserialize Objects", () => {
|
|
171
|
-
expect(JSON.stringify(JSON.parse<Vec3>('{"x":3.4,"y":1.2,"z":8.3}'))).toBe(JSON.stringify(<Vec3>{ x: 3.4, y: 1.2, z: 8.3 }));
|
|
172
|
-
|
|
173
|
-
expect(JSON.stringify(JSON.parse<Player>('{"firstName":"Emmet","lastName":"West","lastActive":[8,27,2022],"age":23,"pos":{"x":3.4,"y":1.2,"z":8.3},"isVerified":true}'))).toBe(
|
|
174
|
-
JSON.stringify(<Player>{
|
|
175
|
-
firstName: "Emmet",
|
|
176
|
-
lastName: "West",
|
|
177
|
-
lastActive: [8, 27, 2022],
|
|
178
|
-
age: 23,
|
|
179
|
-
pos: { x: 3.4, y: 1.2, z: 8.3 },
|
|
180
|
-
isVerified: true,
|
|
181
|
-
}),
|
|
182
|
-
);
|
|
183
|
-
|
|
184
|
-
expect(JSON.stringify(JSON.parse<ObjectWithFloat>('{"f":7.23}'))).toBe(JSON.stringify(<ObjectWithFloat>{ f: 7.23 }));
|
|
185
|
-
|
|
186
|
-
expect(JSON.stringify(JSON.parse<ObjectWithFloat>('{"f":0.000001}'))).toBe(JSON.stringify(<ObjectWithFloat>{ f: 0.000001 }));
|
|
187
|
-
|
|
188
|
-
expect(JSON.stringify(JSON.parse<ObjWithStrangeKey<string>>('{"a\\\\\\t\\"\\u0002b`c":"foo"}'))).toBe(JSON.stringify(<ObjWithStrangeKey<string>>{ data: "foo" }));
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
run({
|
|
192
|
-
log: true,
|
|
193
|
-
});
|
|
5
|
+
// describe("Should serialize objects", () => {
|
|
6
|
+
// expect(
|
|
7
|
+
// JSON.stringify<Vec3>({
|
|
8
|
+
// x: 3.4,
|
|
9
|
+
// y: 1.2,
|
|
10
|
+
// z: 8.3,
|
|
11
|
+
// }),
|
|
12
|
+
// ).toBe('{"x":3.4,"y":1.2,"z":8.3}');
|
|
13
|
+
|
|
14
|
+
// expect(
|
|
15
|
+
// JSON.stringify<Player>({
|
|
16
|
+
// firstName: "Emmet",
|
|
17
|
+
// lastName: "West",
|
|
18
|
+
// lastActive: [8, 27, 2022],
|
|
19
|
+
// age: 23,
|
|
20
|
+
// pos: {
|
|
21
|
+
// x: 3.4,
|
|
22
|
+
// y: 1.2,
|
|
23
|
+
// z: 8.3,
|
|
24
|
+
// },
|
|
25
|
+
// isVerified: true,
|
|
26
|
+
// }),
|
|
27
|
+
// ).toBe('{"firstName":"Emmet","lastName":"West","lastActive":[8,27,2022],"age":23,"pos":{"x":3.4,"y":1.2,"z":8.3},"isVerified":true}');
|
|
28
|
+
|
|
29
|
+
// expect(JSON.stringify<ObjectWithFloat>({ f: 7.23 })).toBe('{"f":7.23}');
|
|
30
|
+
|
|
31
|
+
// expect(JSON.stringify<ObjectWithFloat>({ f: 0.000001 })).toBe('{"f":0.000001}');
|
|
32
|
+
|
|
33
|
+
// expect(JSON.stringify<ObjectWithFloat>({ f: 1e-7 })).toBe('{"f":1e-7}');
|
|
34
|
+
|
|
35
|
+
// expect(JSON.stringify<ObjectWithFloat>({ f: 1e20 })).toBe('{"f":100000000000000000000.0}');
|
|
36
|
+
|
|
37
|
+
// expect(JSON.stringify<ObjectWithFloat>({ f: 1e21 })).toBe('{"f":1e+21}');
|
|
38
|
+
|
|
39
|
+
// expect(JSON.stringify<ObjWithStrangeKey<string>>({ data: "foo" })).toBe('{"a\\\\\\t\\"\\u0002b`c":"foo"}');
|
|
40
|
+
// });
|
|
41
|
+
|
|
42
|
+
// describe("Should serialize @omit'ed objects", () => {
|
|
43
|
+
// expect(
|
|
44
|
+
// JSON.stringify(<OmitIf>{
|
|
45
|
+
// y: 1,
|
|
46
|
+
// }),
|
|
47
|
+
// ).toBe('{"x":1,"y":1,"z":1}');
|
|
48
|
+
// });
|
|
49
|
+
// describe("Should deserialize class inheritance", () => {
|
|
50
|
+
// const jsonStr = '{"a":"1","b":"2"}';
|
|
51
|
+
// const obj = JSON.parse<DerivedObject>(jsonStr);
|
|
52
|
+
|
|
53
|
+
// expect((obj instanceof DerivedObject).toString()).toBe("true");
|
|
54
|
+
// expect(obj.a).toBe("1");
|
|
55
|
+
// expect(obj.b).toBe("2");
|
|
56
|
+
// });
|
|
57
|
+
|
|
58
|
+
// describe("Should deserialize nulls", () => {
|
|
59
|
+
// expect(JSON.stringify(JSON.parse<Null>("null"))).toBe("null");
|
|
60
|
+
// });
|
|
61
|
+
|
|
62
|
+
// describe("Should deserialize integer arrays", () => {
|
|
63
|
+
// expect(JSON.stringify(JSON.parse<u32[]>("[0,100,101]"))).toBe(JSON.stringify([0, 100, 101]));
|
|
64
|
+
|
|
65
|
+
// expect(JSON.stringify(JSON.parse<i32[]>("[0,100,101,-100,-101]"))).toBe(JSON.stringify([0, 100, 101, -100, -101]));
|
|
66
|
+
// });
|
|
67
|
+
|
|
68
|
+
// describe("Should deserialize float arrays", () => {
|
|
69
|
+
// expect(JSON.stringify(JSON.parse<f64[]>("[7.23,1000.0,1000.0,1.23456,1.23456,0.0,7.23]"))).toBe(JSON.stringify([7.23, 1000.0, 1000.0, 1.23456, 1.23456, 0.0, 7.23]));
|
|
70
|
+
|
|
71
|
+
// expect(JSON.stringify(JSON.parse<f64[]>("[1e+21,1e+22,1e-7,1e-8,1e-9]"))).toBe(JSON.stringify([1e21, 1e22, 1e-7, 1e-8, 1e-9]));
|
|
72
|
+
// });
|
|
73
|
+
|
|
74
|
+
// describe("Should deserialize boolean arrays", () => {
|
|
75
|
+
// expect(JSON.stringify(JSON.parse<boolean[]>("[true,false]"))).toBe(JSON.stringify([true, false]));
|
|
76
|
+
// });
|
|
77
|
+
|
|
78
|
+
// describe("Should deserialize string arrays", () => {
|
|
79
|
+
// expect(JSON.stringify(JSON.parse<string[]>('["string \\"with random spa\\nces and \\nnewlines\\n\\n\\n"]'))).toBe(JSON.stringify(['string "with random spa\nces and \nnewlines\n\n\n']));
|
|
80
|
+
// });
|
|
81
|
+
|
|
82
|
+
// describe("Should deserialize nested integer arrays", () => {
|
|
83
|
+
// expect(JSON.stringify(JSON.parse<i64[][]>("[[100,101],[-100,-101],[0]]"))).toBe(JSON.stringify([[100, 101], [-100, -101], [0]]));
|
|
84
|
+
// });
|
|
85
|
+
|
|
86
|
+
// describe("Should deserialize nested float arrays", () => {
|
|
87
|
+
// expect(JSON.stringify(JSON.parse<f64[][]>("[[7.23],[1000.0],[1000.0],[1.23456],[1.23456],[0.0],[7.23]]"))).toBe(JSON.stringify([[7.23], [1000.0], [1000.0], [1.23456], [1.23456], [0.0], [7.23]]));
|
|
88
|
+
// });
|
|
89
|
+
|
|
90
|
+
// describe("Should deserialize nested boolean arrays", () => {
|
|
91
|
+
// expect(JSON.stringify(JSON.parse<boolean[][]>("[[true],[false]]"))).toBe(JSON.stringify([[true], [false]]));
|
|
92
|
+
// });
|
|
93
|
+
|
|
94
|
+
// describe("Should deserialize object arrays", () => {
|
|
95
|
+
// expect(JSON.stringify(JSON.parse<Vec3[]>('[{"x":3.4,"y":1.2,"z":8.3},{"x":3.4,"y":-2.1,"z":9.3}]'))).toBe(
|
|
96
|
+
// JSON.stringify(<Vec3[]>[
|
|
97
|
+
// { x: 3.4, y: 1.2, z: 8.3 },
|
|
98
|
+
// { x: 3.4, y: -2.1, z: 9.3 },
|
|
99
|
+
// ]),
|
|
100
|
+
// );
|
|
101
|
+
// });
|
|
102
|
+
|
|
103
|
+
// describe("Should deserialize Objects", () => {
|
|
104
|
+
// expect(JSON.stringify(JSON.parse<Vec3>('{"x":3.4,"y":1.2,"z":8.3}'))).toBe(JSON.stringify(<Vec3>{ x: 3.4, y: 1.2, z: 8.3 }));
|
|
105
|
+
|
|
106
|
+
// expect(JSON.stringify(JSON.parse<Player>('{"firstName":"Emmet","lastName":"West","lastActive":[8,27,2022],"age":23,"pos":{"x":3.4,"y":1.2,"z":8.3},"isVerified":true}'))).toBe(
|
|
107
|
+
// JSON.stringify(<Player>{
|
|
108
|
+
// firstName: "Emmet",
|
|
109
|
+
// lastName: "West",
|
|
110
|
+
// lastActive: [8, 27, 2022],
|
|
111
|
+
// age: 23,
|
|
112
|
+
// pos: { x: 3.4, y: 1.2, z: 8.3 },
|
|
113
|
+
// isVerified: true,
|
|
114
|
+
// }),
|
|
115
|
+
// );
|
|
116
|
+
|
|
117
|
+
// expect(JSON.stringify(JSON.parse<ObjectWithFloat>('{"f":7.23}'))).toBe(JSON.stringify(<ObjectWithFloat>{ f: 7.23 }));
|
|
118
|
+
|
|
119
|
+
// expect(JSON.stringify(JSON.parse<ObjectWithFloat>('{"f":0.000001}'))).toBe(JSON.stringify(<ObjectWithFloat>{ f: 0.000001 }));
|
|
120
|
+
|
|
121
|
+
// expect(JSON.stringify(JSON.parse<ObjWithStrangeKey<string>>('{"a\\\\\\t\\"\\u0002b`c":"foo"}'))).toBe(JSON.stringify(<ObjWithStrangeKey<string>>{ data: "foo" }));
|
|
122
|
+
// });
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import { CHAR_F, CHAR_T } from "../../custom/chars";
|
|
2
|
-
|
|
3
1
|
export function deserializeBoolean(srcStart: usize, srcEnd: usize): boolean {
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
if (
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
2
|
+
const block = load<u64>(srcStart);
|
|
3
|
+
if (block == 28429475166421108) return true;
|
|
4
|
+
else if (block == 32370086184550502 && load<u16>(srcStart, 8) == 101) return false;
|
|
5
|
+
return false; //throw new Error(`Expected to find boolean, but found "${data.slice(0, 100)}" instead!`);
|
|
6
|
+
}
|
|
@@ -2,10 +2,10 @@ import { ptrToStr } from "../../util/ptrToStr";
|
|
|
2
2
|
|
|
3
3
|
export function deserializeDate(srcStart: usize, srcEnd: usize): Date {
|
|
4
4
|
// Use AssemblyScript's date parser
|
|
5
|
-
const d = Date.fromString(ptrToStr(srcStart, srcEnd));
|
|
5
|
+
const d = Date.fromString(ptrToStr(srcStart + 2, srcEnd - 2));
|
|
6
6
|
|
|
7
7
|
// Return a new object instead of the one that the parser returned.
|
|
8
|
-
// This may seem redundant, but
|
|
8
|
+
// This may seem redundant, but it addresses the issue when Date
|
|
9
9
|
// is globally aliased to wasi_Date (or some other superclass).
|
|
10
10
|
return new Date(d.getTime());
|
|
11
11
|
}
|
|
@@ -5,7 +5,7 @@ import { isSpace } from "../../util";
|
|
|
5
5
|
export function deserializeMap<T extends Map<any, any>>(srcStart: usize, srcEnd: usize, dst: usize): T {
|
|
6
6
|
const out = changetype<T>(dst || __new(offsetof<T>(), idof<T>()));
|
|
7
7
|
// @ts-ignore: type
|
|
8
|
-
if (!isString<indexof<T>>() && !isInteger<indexof<T>>() && !isFloat<indexof<T>>())
|
|
8
|
+
if (!isString<indexof<T>>() && !isInteger<indexof<T>>() && !isFloat<indexof<T>>()) throw new Error("Map key must also be a valid JSON key!");
|
|
9
9
|
|
|
10
10
|
const srcPtr = srcStart;
|
|
11
11
|
let key: string | null = null;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { JSON } from "../..";
|
|
1
2
|
import { BACK_SLASH, COMMA, CHAR_F, BRACE_LEFT, BRACKET_LEFT, CHAR_N, QUOTE, BRACE_RIGHT, BRACKET_RIGHT, CHAR_T } from "../../custom/chars";
|
|
2
3
|
import { isSpace } from "../../util";
|
|
4
|
+
import { ptrToStr } from "../../util/ptrToStr";
|
|
3
5
|
|
|
4
6
|
export function deserializeObject<T>(srcStart: usize, srcEnd: usize, dst: usize): T {
|
|
5
7
|
const out = changetype<nonnull<T>>(dst || __new(offsetof<T>(), idof<T>()));
|
|
@@ -60,9 +62,9 @@ export function deserializeObject<T>(srcStart: usize, srcEnd: usize, dst: usize)
|
|
|
60
62
|
while (srcStart < srcEnd) {
|
|
61
63
|
const code = load<u16>(srcStart);
|
|
62
64
|
if (code == COMMA || code == BRACE_RIGHT || isSpace(code)) {
|
|
65
|
+
// console.log("Value (number): " + ptrToStr(lastIndex, srcStart));
|
|
63
66
|
// @ts-ignore: exists
|
|
64
67
|
out.__DESERIALIZE(keyStart, keyEnd, lastIndex, srcStart, dst);
|
|
65
|
-
// console.log("Value (number): " + ptrToStr(lastIndex, srcStart));
|
|
66
68
|
// while (isSpace(load<u16>((srcStart += 2)))) {
|
|
67
69
|
// /* empty */
|
|
68
70
|
// }
|
|
@@ -4,13 +4,14 @@ import { DESERIALIZE_ESCAPE_TABLE, ESCAPE_HEX_TABLE } from "../../globals/tables
|
|
|
4
4
|
export function deserializeString(srcStart: usize, srcEnd: usize, dst: usize): string {
|
|
5
5
|
srcStart += 2;
|
|
6
6
|
srcEnd -= 2;
|
|
7
|
+
const startPtr = srcStart;
|
|
7
8
|
if (dst == 0) dst = __new(srcEnd - srcStart, idof<string>());
|
|
8
9
|
let dstPtr = dst;
|
|
9
10
|
let lastPtr = srcStart;
|
|
10
11
|
while (srcStart < srcEnd) {
|
|
11
12
|
let code = load<u16>(srcStart);
|
|
12
13
|
if (code == BACK_SLASH) {
|
|
13
|
-
code =
|
|
14
|
+
code = <u16>load<u8>(DESERIALIZE_ESCAPE_TABLE + load<u8>(srcStart, 2));
|
|
14
15
|
if (code == 117 && load<u32>(srcStart, 4) == 3145776) {
|
|
15
16
|
const block = load<u32>(srcStart, 8);
|
|
16
17
|
const codeA = block & 0xffff;
|
|
@@ -21,7 +22,7 @@ export function deserializeString(srcStart: usize, srcEnd: usize, dst: usize): s
|
|
|
21
22
|
const remBytes = srcStart - lastPtr;
|
|
22
23
|
memory.copy(dstPtr, lastPtr, remBytes);
|
|
23
24
|
dstPtr += remBytes;
|
|
24
|
-
store<u16>(
|
|
25
|
+
store<u16>(dstPtr, escaped);
|
|
25
26
|
dstPtr += 2;
|
|
26
27
|
srcStart += 12;
|
|
27
28
|
lastPtr = srcStart;
|
|
@@ -43,6 +44,6 @@ export function deserializeString(srcStart: usize, srcEnd: usize, dst: usize): s
|
|
|
43
44
|
memory.copy(dstPtr, lastPtr, remBytes);
|
|
44
45
|
dstPtr += remBytes;
|
|
45
46
|
|
|
46
|
-
if (lastPtr !=
|
|
47
|
+
if (lastPtr != startPtr) dst = __renew(dst, dstPtr - dst);
|
|
47
48
|
return changetype<string>(dst);
|
|
48
49
|
}
|