json-as 1.1.15-preview.2 → 1.1.15-preview.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/assembly/deserialize/simple/array/map.ts +12 -2
- package/assembly/test.tmp.ts +6 -0
- package/assembly/test.ts +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,16 +1,26 @@
|
|
|
1
|
-
import { BRACE_LEFT, BRACE_RIGHT } from "../../../custom/chars";
|
|
1
|
+
import { BRACE_LEFT, BRACE_RIGHT, BRACKET_LEFT, BRACKET_RIGHT } from "../../../custom/chars";
|
|
2
2
|
import { JSON } from "../../..";
|
|
3
|
+
import { isSpace } from "util/string";
|
|
3
4
|
|
|
4
5
|
export function deserializeMapArray<T extends Map<any, any>[]>(srcStart: usize, srcEnd: usize, dst: usize): T {
|
|
5
6
|
const out = changetype<nonnull<T>>(dst || changetype<usize>(instantiate<T>()));
|
|
6
7
|
let lastIndex: usize = 0;
|
|
7
8
|
let depth: u32 = 0;
|
|
9
|
+
|
|
10
|
+
while (srcStart < srcEnd && isSpace(load<u16>(srcStart))) srcStart += 2;
|
|
11
|
+
while (srcEnd > srcStart && isSpace(load<u16>(srcEnd - 2))) srcEnd -= 2;
|
|
12
|
+
|
|
13
|
+
if (srcStart - srcEnd == 0) throw new Error("Input string had zero length or was all whitespace");
|
|
14
|
+
|
|
15
|
+
if (load<u16>(srcStart) != BRACKET_LEFT) throw new Error("Expected '[' at start of object at position " + (srcEnd - srcStart).toString());
|
|
16
|
+
if (load<u16>(srcEnd - 2) != BRACKET_RIGHT) throw new Error("Expected ']' at end of object at position " + (srcEnd - srcStart).toString());
|
|
17
|
+
|
|
8
18
|
while (srcStart < srcEnd) {
|
|
9
19
|
const code = load<u16>(srcStart);
|
|
10
20
|
if (code == BRACE_LEFT && depth++ == 0) {
|
|
11
21
|
lastIndex = srcStart;
|
|
12
22
|
} else if (code == BRACE_RIGHT && --depth == 0) {
|
|
13
|
-
out.push(JSON.__deserialize<valueof<T>>(lastIndex, srcStart));
|
|
23
|
+
out.push(JSON.__deserialize<valueof<T>>(lastIndex, (srcStart += 2)));
|
|
14
24
|
}
|
|
15
25
|
srcStart += 2;
|
|
16
26
|
}
|
package/assembly/test.tmp.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { bs } from "../lib/as-bs";
|
|
2
2
|
import { JSON } from ".";
|
|
3
3
|
|
|
4
|
+
|
|
4
5
|
@json
|
|
5
6
|
class GenericEnum<T> {
|
|
6
7
|
private tag: string = "";
|
|
@@ -22,6 +23,7 @@ class GenericEnum<T> {
|
|
|
22
23
|
return this.value;
|
|
23
24
|
}
|
|
24
25
|
|
|
26
|
+
|
|
25
27
|
@serializer
|
|
26
28
|
@inline
|
|
27
29
|
serialize<T>(self: GenericEnum<T>): string {
|
|
@@ -30,6 +32,7 @@ class GenericEnum<T> {
|
|
|
30
32
|
return `{${tagJson}:${valueJson}}`;
|
|
31
33
|
}
|
|
32
34
|
|
|
35
|
+
|
|
33
36
|
@deserializer
|
|
34
37
|
@inline
|
|
35
38
|
deserialize(data: string): GenericEnum<T> {
|
|
@@ -49,6 +52,7 @@ class GenericEnum<T> {
|
|
|
49
52
|
bs.offset += dataSize;
|
|
50
53
|
}
|
|
51
54
|
|
|
55
|
+
|
|
52
56
|
@inline
|
|
53
57
|
__INITIALIZE(): this {
|
|
54
58
|
this.tag = "";
|
|
@@ -60,6 +64,7 @@ class GenericEnum<T> {
|
|
|
60
64
|
}
|
|
61
65
|
}
|
|
62
66
|
|
|
67
|
+
|
|
63
68
|
@json
|
|
64
69
|
class Node<T> {
|
|
65
70
|
name: string;
|
|
@@ -88,6 +93,7 @@ class Node<T> {
|
|
|
88
93
|
bs.offset += 2;
|
|
89
94
|
}
|
|
90
95
|
|
|
96
|
+
|
|
91
97
|
@inline
|
|
92
98
|
__INITIALIZE(): this {
|
|
93
99
|
this.name = "";
|
package/assembly/test.ts
CHANGED
|
@@ -26,6 +26,7 @@ class GenericEnum<T> {
|
|
|
26
26
|
return this.value;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
|
|
29
30
|
@serializer
|
|
30
31
|
serialize<T>(self: GenericEnum<T>): string {
|
|
31
32
|
const tagJson = JSON.stringify(self.tag);
|
|
@@ -33,6 +34,7 @@ class GenericEnum<T> {
|
|
|
33
34
|
return `{${tagJson}:${valueJson}}`;
|
|
34
35
|
}
|
|
35
36
|
|
|
37
|
+
|
|
36
38
|
@deserializer
|
|
37
39
|
deserialize(data: string): GenericEnum<T> {
|
|
38
40
|
const parsed = JSON.parse<Map<string, JSON.Raw>>(data);
|