json-as 0.9.28 → 1.0.0-alpha.1
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/.github/workflows/nodejs.yml +0 -3
- package/.prettierrc.json +4 -1
- package/CHANGELOG +13 -0
- package/LICENSE +1 -1
- package/README.md +22 -7
- package/as-test.config.json +1 -1
- package/asconfig.json +2 -2
- package/assembly/__benches__/misc.bench.ts +17 -31
- package/assembly/__tests__/bool.spec.ts +1 -1
- package/assembly/__tests__/simd/string.spec.ts +32 -0
- package/assembly/__tests__/types.ts +17 -0
- package/assembly/custom/chars.ts +2 -2
- package/assembly/custom/memory.ts +25 -0
- package/assembly/custom/types.ts +1 -0
- package/assembly/custom/util.ts +59 -140
- package/assembly/deserialize/simd/string.ts +103 -0
- package/assembly/deserialize/simple/arbitrary.ts +17 -0
- package/assembly/deserialize/simple/array/arbitrary.ts +113 -0
- package/assembly/deserialize/simple/array/array.ts +18 -0
- package/assembly/deserialize/simple/array/bool.ts +17 -0
- package/assembly/deserialize/simple/array/float.ts +28 -0
- package/assembly/deserialize/simple/array/integer.ts +27 -0
- package/assembly/deserialize/simple/array/map.ts +18 -0
- package/assembly/deserialize/simple/array/object.ts +18 -0
- package/assembly/deserialize/simple/array/string.ts +22 -0
- package/assembly/deserialize/simple/array.ts +48 -0
- package/assembly/deserialize/simple/bool.ts +9 -0
- package/assembly/deserialize/simple/date.ts +11 -0
- package/assembly/deserialize/simple/float.ts +10 -0
- package/assembly/deserialize/simple/integer.ts +5 -0
- package/assembly/deserialize/simple/map.ts +154 -0
- package/assembly/deserialize/simple/object.ts +159 -0
- package/assembly/deserialize/simple/string.ts +48 -0
- package/assembly/globals/tables.ts +417 -0
- package/assembly/index.d.ts +9 -13
- package/assembly/index.ts +282 -158
- package/assembly/serialize/simd/string.ts +176 -0
- package/assembly/serialize/simple/arbitrary.ts +36 -0
- package/assembly/serialize/simple/array.ts +32 -0
- package/assembly/serialize/simple/bool.ts +19 -0
- package/assembly/serialize/simple/date.ts +13 -0
- package/assembly/serialize/simple/float.ts +7 -0
- package/assembly/serialize/simple/integer.ts +7 -0
- package/assembly/serialize/simple/map.ts +43 -0
- package/assembly/serialize/simple/object.ts +7 -0
- package/assembly/serialize/simple/string.ts +48 -0
- package/assembly/test.ts +43 -28
- package/assembly/tsconfig.json +2 -91
- package/assembly/types.ts +0 -0
- package/assembly/util/atoi.ts +35 -0
- package/assembly/util/bytes.ts +12 -0
- package/assembly/util/concat.ts +9 -0
- package/assembly/util/getArrayDepth.ts +17 -0
- package/assembly/util/index.ts +5 -0
- package/assembly/util/isSpace.ts +4 -0
- package/assembly/util/nextPowerOf2.ts +4 -0
- package/assembly/util/ptrToStr.ts +7 -0
- package/assembly/util/snp.ts +69 -0
- package/bench.js +5 -5
- package/modules/bs/index.ts +167 -0
- package/modules/tsconfig.json +8 -0
- package/package.json +42 -47
- package/transform/lib/builder.js +1353 -0
- package/transform/lib/builder.js.map +1 -0
- package/transform/lib/index.js +497 -395
- package/transform/lib/index.js.map +1 -1
- package/transform/lib/index.old.js +404 -0
- package/transform/lib/index.old.js.map +1 -0
- package/transform/lib/linker.js +18 -0
- package/transform/lib/linker.js.map +1 -0
- package/transform/lib/types.js +25 -0
- package/transform/lib/types.js.map +1 -0
- package/transform/lib/util.js +47 -0
- package/transform/lib/util.js.map +1 -0
- package/transform/lib/visitor.js +529 -446
- package/transform/lib/visitor.js.map +1 -0
- package/transform/package.json +1 -34
- package/transform/src/builder.ts +1371 -0
- package/transform/src/index.ts +571 -481
- package/transform/src/linker.ts +21 -0
- package/transform/src/types.ts +27 -0
- package/transform/src/util.ts +56 -0
- package/transform/src/visitor.ts +531 -0
- package/transform/tsconfig.json +3 -1
- package/assembly/__benches__/as-tral.d.ts +0 -1
- package/assembly/custom/bs.ts +0 -211
- package/assembly/deserialize/array/array.ts +0 -31
- package/assembly/deserialize/array/bool.ts +0 -19
- package/assembly/deserialize/array/float.ts +0 -24
- package/assembly/deserialize/array/integer.ts +0 -24
- package/assembly/deserialize/array/map.ts +0 -27
- package/assembly/deserialize/array/object.ts +0 -27
- package/assembly/deserialize/array/string.ts +0 -29
- package/assembly/deserialize/array.ts +0 -46
- package/assembly/deserialize/bool.ts +0 -34
- package/assembly/deserialize/date.ts +0 -19
- package/assembly/deserialize/float.ts +0 -21
- package/assembly/deserialize/integer.ts +0 -16
- package/assembly/deserialize/map.ts +0 -189
- package/assembly/deserialize/object.ts +0 -271
- package/assembly/deserialize/string.ts +0 -164
- package/assembly/serialize/array.ts +0 -51
- package/assembly/serialize/bool.ts +0 -10
- package/assembly/serialize/date.ts +0 -4
- package/assembly/serialize/float.ts +0 -4
- package/assembly/serialize/integer.ts +0 -5
- package/assembly/serialize/map.ts +0 -24
- package/assembly/serialize/object.ts +0 -13
- package/assembly/serialize/string.ts +0 -287
- package/logs/test.log.json +0 -1049
package/assembly/custom/bs.ts
DELETED
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
import { dtoa_buffered, itoa_buffered } from "util/number";
|
|
2
|
-
import { OBJECT, TOTAL_OVERHEAD } from "rt/common";
|
|
3
|
-
// @ts-ignore
|
|
4
|
-
@inline const MAX_LEN: usize = 65536;
|
|
5
|
-
const STORE: usize[] = [];
|
|
6
|
-
let STORE_LEN: usize = 0;
|
|
7
|
-
const CACHE = memory.data(i32(MAX_LEN));
|
|
8
|
-
// Configurable amount of referenceable strings
|
|
9
|
-
let POINTER = changetype<usize>(CACHE);
|
|
10
|
-
// @ts-ignore
|
|
11
|
-
@inline const MAX_CACHE = CACHE + MAX_LEN;
|
|
12
|
-
|
|
13
|
-
export namespace bs {
|
|
14
|
-
// @ts-ignore
|
|
15
|
-
@inline export function write_int<T extends number>(num: T): void {
|
|
16
|
-
POINTER += itoa_buffered(POINTER, num) << 1;
|
|
17
|
-
if (MAX_CACHE <= POINTER) bs.shrink();
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// @ts-ignore
|
|
21
|
-
@inline export function write_int_u<T extends number>(num: T): void {
|
|
22
|
-
POINTER += itoa_buffered(POINTER, num) << 1;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// @ts-ignore
|
|
26
|
-
@inline export function write_fl<T extends number>(num: T): void {
|
|
27
|
-
POINTER += dtoa_buffered(POINTER, num) << 1;
|
|
28
|
-
if (MAX_CACHE <= POINTER) bs.shrink();
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// @ts-ignore
|
|
32
|
-
@inline export function write_fl_u<T extends number>(num: T): void {
|
|
33
|
-
POINTER += dtoa_buffered(POINTER, num) << 1;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// @ts-ignore
|
|
37
|
-
@inline export function write_b(buf: usize, bytes: usize = changetype<OBJECT>(buf - TOTAL_OVERHEAD).rtSize): void {
|
|
38
|
-
memory.copy(POINTER, buf, bytes);
|
|
39
|
-
POINTER += bytes;
|
|
40
|
-
if (MAX_CACHE <= POINTER) bs.shrink();
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// @ts-ignore
|
|
44
|
-
@inline export function write_b_u(buf: usize, bytes: usize = changetype<OBJECT>(buf - TOTAL_OVERHEAD).rtSize): void {
|
|
45
|
-
memory.copy(POINTER, buf, bytes);
|
|
46
|
-
POINTER += bytes;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// @ts-ignore
|
|
50
|
-
@inline export function write_s(str: string, bytes: usize = changetype<OBJECT>(changetype<usize>(str) - TOTAL_OVERHEAD).rtSize): void {
|
|
51
|
-
memory.copy(POINTER, changetype<usize>(str), bytes);
|
|
52
|
-
POINTER += bytes;
|
|
53
|
-
if (MAX_CACHE <= POINTER) bs.shrink();
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// @ts-ignore
|
|
57
|
-
@inline export function write_s_u(str: string, bytes: usize = changetype<OBJECT>(changetype<usize>(str) - TOTAL_OVERHEAD).rtSize): void {
|
|
58
|
-
memory.copy(POINTER, changetype<usize>(str), bytes);
|
|
59
|
-
POINTER += bytes;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// @ts-ignore
|
|
63
|
-
@inline export function write_s_se(str: string, start: usize, end: usize): void {
|
|
64
|
-
const bytes = end - start;
|
|
65
|
-
memory.copy(POINTER, changetype<usize>(str) + start, bytes);
|
|
66
|
-
POINTER += bytes;
|
|
67
|
-
if (MAX_CACHE <= POINTER) bs.shrink();
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// @ts-ignore
|
|
71
|
-
@inline export function write_s_se_u(str: string, start: usize, end: usize): void {
|
|
72
|
-
const bytes = end - start;
|
|
73
|
-
memory.copy(POINTER, changetype<usize>(str) + start, bytes);
|
|
74
|
-
POINTER += bytes;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// @ts-ignore
|
|
78
|
-
@inline export function write_8(char: i32): void {
|
|
79
|
-
store<u8>(POINTER, char);
|
|
80
|
-
POINTER += 2;
|
|
81
|
-
if (MAX_CACHE <= POINTER) bs.shrink();
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// @ts-ignore
|
|
85
|
-
@inline export function write_8_u(char: i32): void {
|
|
86
|
-
store<u8>(POINTER, char);
|
|
87
|
-
//POINTER += 2;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// @ts-ignore
|
|
91
|
-
@inline export function write_16(char: i32): void {
|
|
92
|
-
store<u16>(POINTER, char);
|
|
93
|
-
POINTER += 2;
|
|
94
|
-
if (MAX_CACHE <= POINTER) bs.shrink();
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// @ts-ignore
|
|
98
|
-
@inline export function write_16_u(char: i32): void {
|
|
99
|
-
store<u16>(POINTER, char);
|
|
100
|
-
//POINTER += 2;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// @ts-ignore
|
|
104
|
-
@inline export function write_32(chars: i32): void {
|
|
105
|
-
store<u32>(POINTER, chars);
|
|
106
|
-
POINTER += 4;
|
|
107
|
-
if (MAX_CACHE <= POINTER) bs.shrink();
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// @ts-ignore
|
|
111
|
-
@inline export function write_32_u(chars: i32): void {
|
|
112
|
-
store<u32>(POINTER, chars);
|
|
113
|
-
//POINTER += 4;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// @ts-ignore
|
|
117
|
-
@inline export function write_64(chars: i64): void {
|
|
118
|
-
store<u64>(POINTER, chars);
|
|
119
|
-
POINTER += 8;
|
|
120
|
-
if (MAX_CACHE <= POINTER) bs.shrink();
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// @ts-ignore
|
|
124
|
-
@inline export function write_64_u(chars: i64): void {
|
|
125
|
-
store<u64>(POINTER, chars);
|
|
126
|
-
POINTER += 8;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// @ts-ignore
|
|
130
|
-
@inline export function write_128(chars: v128): void {
|
|
131
|
-
store<v128>(POINTER, chars);
|
|
132
|
-
POINTER += 16;
|
|
133
|
-
if (MAX_CACHE <= POINTER) bs.shrink();
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
// @ts-ignore
|
|
137
|
-
@inline export function write_128_n(chars: v128, n: usize): void {
|
|
138
|
-
store<v128>(POINTER, chars);
|
|
139
|
-
POINTER += n;
|
|
140
|
-
if (MAX_CACHE <= POINTER) bs.shrink();
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// @ts-ignore
|
|
144
|
-
@inline export function write_128_u(chars: v128): void {
|
|
145
|
-
store<v128>(POINTER, chars);
|
|
146
|
-
//POINTER += 16;
|
|
147
|
-
//if (MAX_CACHE <= POINTER) bs.shrink();
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
// @ts-ignore
|
|
151
|
-
@inline export function shrink(): void {
|
|
152
|
-
const len = POINTER - CACHE;
|
|
153
|
-
STORE_LEN += len;
|
|
154
|
-
const out = __new(
|
|
155
|
-
len,
|
|
156
|
-
idof<ArrayBuffer>()
|
|
157
|
-
);
|
|
158
|
-
memory.copy(out, CACHE, len);
|
|
159
|
-
bs.reset();
|
|
160
|
-
STORE.push(out);
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
// @ts-ignore
|
|
164
|
-
@inline export function out<T>(): T {
|
|
165
|
-
const len = POINTER - CACHE;
|
|
166
|
-
let out = __new(
|
|
167
|
-
len + STORE_LEN,
|
|
168
|
-
idof<T>()
|
|
169
|
-
);
|
|
170
|
-
|
|
171
|
-
memory.copy(out, CACHE, len);
|
|
172
|
-
if (STORE_LEN) {
|
|
173
|
-
out += len;
|
|
174
|
-
for (let i = 0; i < STORE.length; i++) {
|
|
175
|
-
const ptr = changetype<usize>(unchecked(STORE[i]));
|
|
176
|
-
const storeLen = changetype<OBJECT>(ptr - TOTAL_OVERHEAD).rtSize;
|
|
177
|
-
memory.copy(out, ptr, storeLen);
|
|
178
|
-
//__unpin(ptr);
|
|
179
|
-
out += storeLen;
|
|
180
|
-
}
|
|
181
|
-
STORE_LEN = 0;
|
|
182
|
-
}
|
|
183
|
-
bs.reset();
|
|
184
|
-
|
|
185
|
-
return changetype<T>(out);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
// @ts-ignore
|
|
189
|
-
@inline export function out_u<T>(): T {
|
|
190
|
-
const len = POINTER - CACHE;
|
|
191
|
-
const out = __new(
|
|
192
|
-
len + STORE_LEN,
|
|
193
|
-
idof<T>()
|
|
194
|
-
);
|
|
195
|
-
|
|
196
|
-
memory.copy(out, CACHE, len);
|
|
197
|
-
bs.reset();
|
|
198
|
-
|
|
199
|
-
return changetype<T>(out);
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
// @ts-ignore
|
|
203
|
-
@inline export function _out(out: usize): void {
|
|
204
|
-
memory.copy(out, CACHE, POINTER - CACHE);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
// @ts-ignore
|
|
208
|
-
@inline export function reset(): void {
|
|
209
|
-
POINTER = CACHE;
|
|
210
|
-
}
|
|
211
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { BRACKET_LEFT, BRACKET_RIGHT } from "../../custom/chars";
|
|
2
|
-
import { JSON } from "../..";
|
|
3
|
-
import { unsafeCharCodeAt } from "../../custom/util";
|
|
4
|
-
|
|
5
|
-
// @ts-ignore: Decorator valid here
|
|
6
|
-
@inline export function deserializeArrayArray<T extends unknown[][]>(data: string): T {
|
|
7
|
-
const result = instantiate<T>();
|
|
8
|
-
let lastPos = 0;
|
|
9
|
-
let depth = 0;
|
|
10
|
-
let i = 1;
|
|
11
|
-
// Find start of bracket
|
|
12
|
-
//for (; unsafeCharCodeAt(data, i) !== leftBracketCode; i++) {}
|
|
13
|
-
//i++;
|
|
14
|
-
for (; i < data.length - 1; i++) {
|
|
15
|
-
const char = unsafeCharCodeAt(data, i);
|
|
16
|
-
if (char === BRACKET_LEFT) {
|
|
17
|
-
if (depth === 0) {
|
|
18
|
-
lastPos = i;
|
|
19
|
-
}
|
|
20
|
-
// Shifting is 6% faster than incrementing
|
|
21
|
-
depth++;
|
|
22
|
-
} else if (char === BRACKET_RIGHT) {
|
|
23
|
-
depth--;
|
|
24
|
-
if (depth === 0) {
|
|
25
|
-
i++;
|
|
26
|
-
result.push(JSON.parse<valueof<T>>(data.slice(lastPos, i)));
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
return result;
|
|
31
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { CHAR_E, CHAR_F, CHAR_T } from "../../custom/chars";
|
|
2
|
-
import { unsafeCharCodeAt } from "../../custom/util";
|
|
3
|
-
import { deserializeBoolean } from "../bool";
|
|
4
|
-
|
|
5
|
-
// @ts-ignore: Decorator valid here
|
|
6
|
-
@inline export function deserializeBooleanArray<T extends boolean[]>(data: string): T {
|
|
7
|
-
const result = instantiate<T>();
|
|
8
|
-
let lastPos = 1;
|
|
9
|
-
for (let i = 1; i < data.length - 1; i++) {
|
|
10
|
-
const char = unsafeCharCodeAt(data, i);
|
|
11
|
-
if (char === CHAR_T || char === CHAR_F) {
|
|
12
|
-
lastPos = i;
|
|
13
|
-
} else if (char === CHAR_E) {
|
|
14
|
-
i++;
|
|
15
|
-
result.push(deserializeBoolean(data.slice(lastPos, i)));
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
return result;
|
|
19
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { isSpace } from "util/string";
|
|
2
|
-
import { unsafeCharCodeAt } from "../../custom/util";
|
|
3
|
-
import { COMMA, BRACKET_RIGHT } from "../../custom/chars";
|
|
4
|
-
import { deserializeFloat } from "../float";
|
|
5
|
-
|
|
6
|
-
// @ts-ignore: Decorator valid here
|
|
7
|
-
@inline export function deserializeFloatArray<T extends number[]>(data: string): T {
|
|
8
|
-
const result = instantiate<T>();
|
|
9
|
-
let lastPos = 0;
|
|
10
|
-
let i = 1;
|
|
11
|
-
let awaitingParse = false;
|
|
12
|
-
for (; i < data.length; i++) {
|
|
13
|
-
const char = unsafeCharCodeAt(data, i);
|
|
14
|
-
if (lastPos === 0 && ((char >= 48 && char <= 57) || char === 45)) {
|
|
15
|
-
awaitingParse = true;
|
|
16
|
-
lastPos = i;
|
|
17
|
-
} else if (awaitingParse && (isSpace(char) || char == COMMA || char == BRACKET_RIGHT) && lastPos > 0) {
|
|
18
|
-
awaitingParse = false;
|
|
19
|
-
result.push(deserializeFloat<valueof<T>>(data.slice(lastPos, i)));
|
|
20
|
-
lastPos = 0;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return result;
|
|
24
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { isSpace } from "util/string";
|
|
2
|
-
import { unsafeCharCodeAt } from "../../custom/util";
|
|
3
|
-
import { COMMA, BRACKET_RIGHT } from "../../custom/chars";
|
|
4
|
-
import { deserializeInteger } from "../integer";
|
|
5
|
-
|
|
6
|
-
// @ts-ignore: Decorator valid here
|
|
7
|
-
@inline export function deserializeIntegerArray<T extends number[]>(data: string): T {
|
|
8
|
-
const result = instantiate<T>();
|
|
9
|
-
let lastPos = 0;
|
|
10
|
-
let i = 1;
|
|
11
|
-
let awaitingParse = false;
|
|
12
|
-
for (; i < data.length; i++) {
|
|
13
|
-
const char = unsafeCharCodeAt(data, i);
|
|
14
|
-
if (lastPos === 0 && ((char >= 48 && char <= 57) || char === 45)) {
|
|
15
|
-
awaitingParse = true;
|
|
16
|
-
lastPos = i;
|
|
17
|
-
} else if (awaitingParse && (isSpace(char) || char == COMMA || char == BRACKET_RIGHT) && lastPos > 0) {
|
|
18
|
-
awaitingParse = false;
|
|
19
|
-
result.push(deserializeInteger<valueof<T>>(data.slice(lastPos, i)));
|
|
20
|
-
lastPos = 0;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return result;
|
|
24
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { BRACE_LEFT, BRACE_RIGHT } from "../../custom/chars";
|
|
2
|
-
import { JSON } from "../..";
|
|
3
|
-
import { unsafeCharCodeAt } from "../../custom/util";
|
|
4
|
-
|
|
5
|
-
// @ts-ignore: Decorator valid here
|
|
6
|
-
@inline export function deserializeMapArray<T extends unknown[]>(data: string): T {
|
|
7
|
-
const result = instantiate<T>();
|
|
8
|
-
let lastPos: u32 = 1;
|
|
9
|
-
let depth: u32 = 0;
|
|
10
|
-
for (let pos: u32 = 0; pos < <u32>data.length; pos++) {
|
|
11
|
-
const char = unsafeCharCodeAt(data, pos);
|
|
12
|
-
if (char === BRACE_LEFT) {
|
|
13
|
-
if (depth === 0) {
|
|
14
|
-
lastPos = pos;
|
|
15
|
-
}
|
|
16
|
-
depth++;
|
|
17
|
-
} else if (char === BRACE_RIGHT) {
|
|
18
|
-
depth--;
|
|
19
|
-
if (depth === 0) {
|
|
20
|
-
pos++;
|
|
21
|
-
result.push(JSON.parse<valueof<T>>(data.slice(lastPos, pos)));
|
|
22
|
-
//lastPos = pos + 2;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return result;
|
|
27
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { BRACE_LEFT, BRACE_RIGHT } from "../../custom/chars";
|
|
2
|
-
import { JSON } from "../..";
|
|
3
|
-
import { unsafeCharCodeAt } from "../../custom/util";
|
|
4
|
-
|
|
5
|
-
// @ts-ignore: Decorator valid here
|
|
6
|
-
@inline export function deserializeObjectArray<T extends unknown[]>(data: string): T {
|
|
7
|
-
const result = instantiate<T>();
|
|
8
|
-
let lastPos: u32 = 1;
|
|
9
|
-
let depth: u32 = 0;
|
|
10
|
-
for (let pos: u32 = 0; pos < <u32>data.length; pos++) {
|
|
11
|
-
const char = unsafeCharCodeAt(data, pos);
|
|
12
|
-
if (char === BRACE_LEFT) {
|
|
13
|
-
if (depth === 0) {
|
|
14
|
-
lastPos = pos;
|
|
15
|
-
}
|
|
16
|
-
depth++;
|
|
17
|
-
} else if (char === BRACE_RIGHT) {
|
|
18
|
-
depth--;
|
|
19
|
-
if (depth === 0) {
|
|
20
|
-
pos++;
|
|
21
|
-
result.push(JSON.parse<valueof<T>>(data.slice(lastPos, pos)));
|
|
22
|
-
//lastPos = pos + 2;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return result;
|
|
27
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { BACK_SLASH, QUOTE } from "../../custom/chars";
|
|
2
|
-
import { unsafeCharCodeAt } from "../../custom/util";
|
|
3
|
-
import { deserializeString } from "../string";
|
|
4
|
-
|
|
5
|
-
// @ts-ignore: Decorator valid here
|
|
6
|
-
@inline export function deserializeStringArray(data: string): string[] {
|
|
7
|
-
const result: string[] = [];
|
|
8
|
-
let lastPos = 0;
|
|
9
|
-
let instr = false;
|
|
10
|
-
let escaping = false;
|
|
11
|
-
for (let i = 1; i < data.length - 1; i++) {
|
|
12
|
-
const char = unsafeCharCodeAt(data, i);
|
|
13
|
-
if (char === BACK_SLASH && !escaping) {
|
|
14
|
-
escaping = true;
|
|
15
|
-
} else {
|
|
16
|
-
if (char === QUOTE && !escaping) {
|
|
17
|
-
if (instr === false) {
|
|
18
|
-
instr = true;
|
|
19
|
-
lastPos = i;
|
|
20
|
-
} else {
|
|
21
|
-
instr = false;
|
|
22
|
-
result.push(deserializeString(data, lastPos, i));
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
escaping = false;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
return result;
|
|
29
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { BRACKET_LEFT } from "../custom/chars";
|
|
2
|
-
import { isMap } from "../custom/util";
|
|
3
|
-
import { deserializeArrayArray } from "./array/array";
|
|
4
|
-
import { deserializeBooleanArray } from "./array/bool";
|
|
5
|
-
import { deserializeFloatArray } from "./array/float";
|
|
6
|
-
import { deserializeIntegerArray } from "./array/integer";
|
|
7
|
-
import { deserializeMapArray } from "./array/map";
|
|
8
|
-
import { deserializeObjectArray } from "./array/object";
|
|
9
|
-
import { deserializeStringArray } from "./array/string";
|
|
10
|
-
|
|
11
|
-
// @ts-ignore: Decorator valid here
|
|
12
|
-
export function deserializeArray<T extends unknown[]>(data: string): T {
|
|
13
|
-
if (isString<valueof<T>>()) {
|
|
14
|
-
return <T>deserializeStringArray(data);
|
|
15
|
-
} else if (isBoolean<valueof<T>>()) {
|
|
16
|
-
// @ts-ignore
|
|
17
|
-
return deserializeBooleanArray<T>(data);
|
|
18
|
-
} else if (isInteger<valueof<T>>()) {
|
|
19
|
-
// @ts-ignore
|
|
20
|
-
return deserializeIntegerArray<T>(data);
|
|
21
|
-
} else if (isFloat<valueof<T>>()) {
|
|
22
|
-
// @ts-ignore
|
|
23
|
-
return deserializeFloatArray<T>(data);
|
|
24
|
-
} else if (isArrayLike<valueof<T>>()) {
|
|
25
|
-
// @ts-ignore
|
|
26
|
-
return deserializeArrayArray<T>(data);
|
|
27
|
-
} else if (isMap<valueof<T>>()) {
|
|
28
|
-
return deserializeMapArray<T>(data);
|
|
29
|
-
} else if (isManaged<valueof<T>>() || isReference<valueof<T>>()) {
|
|
30
|
-
const type = changetype<nonnull<valueof<T>>>(0);
|
|
31
|
-
// @ts-ignore
|
|
32
|
-
if (isDefined(type.__DESERIALIZE)) {
|
|
33
|
-
return deserializeObjectArray<T>(data);
|
|
34
|
-
}
|
|
35
|
-
throw new Error("Could not parse array of type " + nameof<T>() + "! Make sure to add the @json decorator over classes!");
|
|
36
|
-
} else {
|
|
37
|
-
throw new Error("Could not parse array of type " + nameof<T>() + "!");
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// @ts-ignore: Decorator valid here
|
|
42
|
-
export function deserializeArray_Safe<T extends unknown[]>(data: string): T {
|
|
43
|
-
const firstChar = load<u8>(changetype<usize>(data));
|
|
44
|
-
if (firstChar != BRACKET_LEFT) throw new Error("Mismatched Types! Expected " + nameof<T>() + " but got \"" + data.slice(0, 100) + "\" instead!");
|
|
45
|
-
return deserializeArray<T>(data);
|
|
46
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { CHAR_F, CHAR_T } from "../custom/chars";
|
|
2
|
-
import { unsafeCharCodeAt } from "../custom/util";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Deserialize a string to type boolean
|
|
6
|
-
* @param data data to parse
|
|
7
|
-
* @returns boolean
|
|
8
|
-
*/
|
|
9
|
-
// @ts-ignore: Decorator valid here
|
|
10
|
-
@inline export function deserializeBoolean(data: string, start: i32 = 0, end: i32 = 0): boolean {
|
|
11
|
-
if (!end) end = data.length;
|
|
12
|
-
const len = end - start;
|
|
13
|
-
const ptr = changetype<usize>(data) + <usize>(start << 1);
|
|
14
|
-
const firstChar = unsafeCharCodeAt(data, start);
|
|
15
|
-
if (len === 4 && firstChar === CHAR_T && load<u64>(ptr) === 28429475166421108) return true;
|
|
16
|
-
else if (len === 5 && firstChar === CHAR_F && load<u64>(ptr, 2) === 28429466576093281) return false;
|
|
17
|
-
return false//ERROR(`Expected to find boolean, but found "${data.slice(0, 100)}" instead!`);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Deserialize a string to type boolean (safely)
|
|
22
|
-
* @param data data to parse
|
|
23
|
-
* @returns boolean
|
|
24
|
-
*/
|
|
25
|
-
// @ts-ignore: Decorator valid here
|
|
26
|
-
@inline export function deserializeBoolean_Safe(data: string, start: i32 = 0, end: i32 = 0): boolean {
|
|
27
|
-
if (!end) end = data.length;
|
|
28
|
-
const len = end - start;
|
|
29
|
-
const ptr = changetype<usize>(data) + <usize>(start << 1);
|
|
30
|
-
const firstChar = unsafeCharCodeAt(data, start);
|
|
31
|
-
if (len === 4 && firstChar === CHAR_T && load<u64>(ptr) === 28429475166421108) return true;
|
|
32
|
-
else if (len === 5 && firstChar === CHAR_F && load<u64>(ptr, 2) === 28429466576093281) return false;
|
|
33
|
-
throw new Error("Mismatched Types! Expected boolean but got \"" + data.slice(0, 100) + "\" instead!");
|
|
34
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { QUOTE } from "../custom/chars";
|
|
2
|
-
|
|
3
|
-
// @ts-ignore: Decorator valid here
|
|
4
|
-
@inline export function deserializeDate(dateTimeString: string): Date {
|
|
5
|
-
// Use AssemblyScript's date parser
|
|
6
|
-
const d = Date.fromString(dateTimeString);
|
|
7
|
-
|
|
8
|
-
// Return a new object instead of the one that the parser returned.
|
|
9
|
-
// This may seem redundant, but addreses the issue when Date
|
|
10
|
-
// is globally aliased to wasi_Date (or some other superclass).
|
|
11
|
-
return new Date(d.getTime());
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
// @ts-ignore: Decorator valid here
|
|
15
|
-
@inline export function deserializeDate_Safe(dateTimeString: string): Date {
|
|
16
|
-
const firstChar = load<u8>(changetype<usize>(dateTimeString));
|
|
17
|
-
if (firstChar != QUOTE) throw new Error("Mismatched Types! Expected Date but got \"" + dateTimeString.slice(0, 100) + "\" instead!");
|
|
18
|
-
return deserializeDate(dateTimeString);
|
|
19
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
// @ts-ignore: Decorator valid here
|
|
2
|
-
@inline export function deserializeFloat<T>(data: string): T {
|
|
3
|
-
// @ts-ignore
|
|
4
|
-
const type: T = 0;
|
|
5
|
-
// @ts-ignore
|
|
6
|
-
if (type instanceof f64) return f64.parse(data);
|
|
7
|
-
// @ts-ignore
|
|
8
|
-
return f32.parse(data);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
// @ts-ignore: Decorator valid here
|
|
12
|
-
@inline export function deserializeFloat_Safe<T>(data: string): T {
|
|
13
|
-
const firstChar = load<u8>(changetype<usize>(data));
|
|
14
|
-
if ((firstChar < 48 || firstChar > 57) && firstChar != 45) throw new Error("Mismatched Types! Expected float but got \""+data.slice(0, 100)+"\" instead!");
|
|
15
|
-
// @ts-ignore
|
|
16
|
-
const type: T = 0;
|
|
17
|
-
// @ts-ignore
|
|
18
|
-
if (type instanceof f64) return f64.parse(data);
|
|
19
|
-
// @ts-ignore
|
|
20
|
-
return f32.parse(data);
|
|
21
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { snip_fast } from "../custom/util";
|
|
2
|
-
|
|
3
|
-
// @ts-ignore: Decorator valid here
|
|
4
|
-
@inline export function deserializeInteger<T>(data: string): T {
|
|
5
|
-
// @ts-ignore
|
|
6
|
-
return snip_fast<T>(data);
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
// @ts-ignore: Decorator valid here
|
|
10
|
-
@inline export function deserializeInteger_Safe<T>(data: string): T {
|
|
11
|
-
const firstChar = load<u8>(changetype<usize>(data));
|
|
12
|
-
console.log(firstChar.toString())
|
|
13
|
-
if ((firstChar < 48 || firstChar > 57) && firstChar != 45) throw new Error("Mismatched Types! Expected " + nameof<T>() + " but got \""+data.slice(0, 100)+"\" instead!");
|
|
14
|
-
// @ts-ignore
|
|
15
|
-
return snip_fast<T>(data);
|
|
16
|
-
}
|