json-as 0.9.27 → 0.9.29

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.
Files changed (39) hide show
  1. package/.prettierrc.json +3 -1
  2. package/README.md +15 -68
  3. package/assembly/__benches__/misc.bench.ts +15 -14
  4. package/assembly/__tests__/date.spec.ts +12 -0
  5. package/assembly/__tests__/types.ts +17 -0
  6. package/assembly/custom/bs.ts +189 -198
  7. package/assembly/custom/chars.ts +2 -2
  8. package/assembly/custom/types.ts +1 -0
  9. package/assembly/custom/util.ts +47 -50
  10. package/assembly/deserialize/array/array.ts +24 -24
  11. package/assembly/deserialize/array/bool.ts +1 -1
  12. package/assembly/deserialize/array/float.ts +16 -16
  13. package/assembly/deserialize/array/integer.ts +16 -16
  14. package/assembly/deserialize/array/map.ts +20 -20
  15. package/assembly/deserialize/array/object.ts +20 -20
  16. package/assembly/deserialize/array/string.ts +1 -1
  17. package/assembly/deserialize/array.ts +2 -2
  18. package/assembly/deserialize/bool.ts +15 -15
  19. package/assembly/deserialize/date.ts +4 -4
  20. package/assembly/deserialize/float.ts +15 -15
  21. package/assembly/deserialize/integer.ts +8 -8
  22. package/assembly/deserialize/map.ts +111 -161
  23. package/assembly/deserialize/object.ts +16 -76
  24. package/assembly/deserialize/string.ts +70 -85
  25. package/assembly/index.ts +25 -24
  26. package/assembly/serialize/array.ts +37 -44
  27. package/assembly/serialize/bool.ts +2 -2
  28. package/assembly/serialize/date.ts +2 -2
  29. package/assembly/serialize/float.ts +2 -2
  30. package/assembly/serialize/integer.ts +3 -3
  31. package/assembly/serialize/map.ts +16 -16
  32. package/assembly/serialize/object.ts +4 -4
  33. package/assembly/serialize/string.ts +60 -63
  34. package/assembly/test.ts +3 -2
  35. package/package.json +2 -1
  36. package/transform/lib/index.js +29 -92
  37. package/transform/lib/index.js.map +1 -1
  38. package/transform/package.json +1 -1
  39. package/transform/src/index.ts +53 -186
@@ -1,3 +1,4 @@
1
+
1
2
  @json
2
3
  export class Vec3 {
3
4
  x: f64 = 1.0;
@@ -21,10 +21,7 @@ export function isMap<T>(): bool {
21
21
  for (let i = 0; i < data.length; i++) {
22
22
  const char = unsafeCharCodeAt(data, i);
23
23
  if (instr === false && char === QUOTE) instr = true;
24
- else if (
25
- instr === true && char === QUOTE
26
- && unsafeCharCodeAt(data, i - 1) !== BACK_SLASH
27
- ) instr = false;
24
+ else if (instr === true && char === QUOTE && unsafeCharCodeAt(data, i - 1) !== BACK_SLASH) instr = false;
28
25
 
29
26
  if (instr === false) {
30
27
  if (!isSpace(char)) result.write(data.charAt(i));
@@ -82,17 +79,17 @@ export function getArrayDepth<T extends ArrayLike>(depth: i32 = 1): i32 {
82
79
  * Loads 32 bits and retrieves the high/low bits.
83
80
  * The reason why we only load 4 bytes at a time is that numbers in the 32-bit range are 7 chars long at most.
84
81
  * Using SIMD or 64 bit loads would only work well when parsing large 128+ numbers.
85
- *
82
+ *
86
83
  * Here are some benchmarks
87
- * Parsing: "12345"
84
+ * Parsing: "12345"
88
85
  * Results are spread over 5000ms
89
- *
86
+ *
90
87
  * SNIP: 270M iterations
91
88
  * ATOI: 285M iterations
92
- * ParseInt: 176M iterations
93
- *
89
+ * ParseInt: 176M iterations
90
+ *
94
91
  * @param str - Any number. Can include scientific notation.
95
- */
92
+ */
96
93
  // @ts-ignore: Decorator
97
94
  @inline export function snip_fast<T extends number>(str: string, len: u32 = 0, offset: u32 = 0): T {
98
95
  if (isSigned<T>()) {
@@ -105,31 +102,31 @@ export function getArrayDepth<T extends ArrayLike>(depth: i32 = 1): i32 {
105
102
  offset += 2;
106
103
  if (len >= 4) {
107
104
  // 32-bit route
108
- for (; offset < (len - 3); offset += 4) {
105
+ for (; offset < len - 3; offset += 4) {
109
106
  const ch = load<u32>(changetype<usize>(str) + <usize>offset);
110
- const low = ch & 0xFFFF;
107
+ const low = ch & 0xffff;
111
108
  const high = ch >> 16;
112
109
  // 9 is 57. The highest group of two numbers is 114, so if a e or an E is included, this will fire.
113
110
  if (low > 57) {
114
111
  // The first char (f) is E or e
115
112
  // We push the offset up by two and apply the notation.
116
113
  if (load<u16>(changetype<usize>(str) + <usize>offset + 2) == 45) {
117
- return -(val / (10 ** (__atoi_fast<u32>(str, offset + 6, offset + 8) - 1))) as T;
114
+ return -(val / 10 ** (__atoi_fast<u32>(str, offset + 6, offset + 8) - 1)) as T;
118
115
  } else {
119
116
  // Inlined this operation instead of using a loop
120
- return -(val * (10 ** (__atoi_fast<u32>(str, offset + 2, offset + 4) + 1))) as T;
117
+ return -(val * 10 ** (__atoi_fast<u32>(str, offset + 2, offset + 4) + 1)) as T;
121
118
  }
122
119
  } else if (high > 57) {
123
120
  // The first char (f) is E or e
124
121
  // We push the offset up by two and apply the notation.
125
122
  if (load<u16>(changetype<usize>(str) + <usize>offset + 4) == 45) {
126
- return -(val / (10 ** (__atoi_fast<u32>(str, offset + 6, offset + 8) - 1))) as T;
123
+ return -(val / 10 ** (__atoi_fast<u32>(str, offset + 6, offset + 8) - 1)) as T;
127
124
  } else {
128
125
  // Inlined this operation instead of using a loop
129
- return -(val * (10 ** (__atoi_fast<u32>(str, offset + 4, offset + 6) + 1))) as T;
126
+ return -(val * 10 ** (__atoi_fast<u32>(str, offset + 4, offset + 6) + 1)) as T;
130
127
  }
131
128
  } else {
132
- val = (val * 100 + ((low - 48) * 10) + (high - 48)) as T;
129
+ val = (val * 100 + (low - 48) * 10 + (high - 48)) as T;
133
130
  }
134
131
  }
135
132
  }
@@ -141,43 +138,43 @@ export function getArrayDepth<T extends ArrayLike>(depth: i32 = 1): i32 {
141
138
  // The first char (f) is E or e
142
139
  // We push the offset up by two and apply the notation.
143
140
  if (load<u16>(changetype<usize>(str) + <usize>offset + 2) == 45) {
144
- return -(val / (10 ** (__atoi_fast<u32>(str, offset + 6, offset + 8) - 1))) as T;
141
+ return -(val / 10 ** (__atoi_fast<u32>(str, offset + 6, offset + 8) - 1)) as T;
145
142
  } else {
146
143
  // Inlined this operation instead of using a loop
147
- return -(val * (10 ** (__atoi_fast<u32>(str, offset + 2, offset + 4) + 1))) as T;
144
+ return -(val * 10 ** (__atoi_fast<u32>(str, offset + 2, offset + 4) + 1)) as T;
148
145
  }
149
146
  } else {
150
- val = (val * 10) + (ch - 48) as T;
147
+ val = (val * 10 + (ch - 48)) as T;
151
148
  }
152
149
  }
153
150
  return -val as T;
154
151
  } else {
155
152
  if (len >= 4) {
156
153
  // Duplet 16 bit lane load
157
- for (; offset < (len - 3); offset += 4) {
154
+ for (; offset < len - 3; offset += 4) {
158
155
  const ch = load<u32>(changetype<usize>(str) + <usize>offset);
159
- const low = ch & 0xFFFF;
156
+ const low = ch & 0xffff;
160
157
  const high = ch >> 16;
161
158
  // 9 is 57. The highest group of two numbers is 114, so if a e or an E is included, this will fire.
162
159
  if (low > 57) {
163
160
  // The first char (f) is E or e
164
161
  // We push the offset up by two and apply the notation.
165
162
  if (load<u16>(changetype<usize>(str) + <usize>offset + 2) == 45) {
166
- return (val / (10 ** (__atoi_fast<u32>(str, offset + 6, offset + 8) - 1))) as T;
163
+ return (val / 10 ** (__atoi_fast<u32>(str, offset + 6, offset + 8) - 1)) as T;
167
164
  } else {
168
165
  // Inlined this operation instead of using a loop
169
- return (val * (10 ** (__atoi_fast<u32>(str, offset + 2, offset + 4) + 1))) as T;
166
+ return (val * 10 ** (__atoi_fast<u32>(str, offset + 2, offset + 4) + 1)) as T;
170
167
  }
171
168
  } else if (high > 57) {
172
169
  if (load<u16>(changetype<usize>(str) + <usize>offset + 4) == 45) {
173
- return (val / (10 ** (__atoi_fast<u32>(str, offset + 6, offset + 8) - 1))) as T;
170
+ return (val / 10 ** (__atoi_fast<u32>(str, offset + 6, offset + 8) - 1)) as T;
174
171
  } else {
175
172
  // Inlined this operation instead of using a loop
176
- return (val * (10 ** (__atoi_fast<u32>(str, offset + 4, offset + 6) + 1))) as T;
173
+ return (val * 10 ** (__atoi_fast<u32>(str, offset + 4, offset + 6) + 1)) as T;
177
174
  }
178
175
  } else {
179
176
  // Optimized with multiplications and shifts.
180
- val = (val * 100 + ((low - 48) * 10) + (high - 48)) as T;
177
+ val = (val * 100 + (low - 48) * 10 + (high - 48)) as T;
181
178
  }
182
179
  }
183
180
  }
@@ -188,14 +185,14 @@ export function getArrayDepth<T extends ArrayLike>(depth: i32 = 1): i32 {
188
185
  // e is 101 and E is 69.
189
186
  if (ch > 57) {
190
187
  if (load<u16>(changetype<usize>(str) + <usize>offset + 2) == 45) {
191
- val = (val / (10 ** (__atoi_fast<u32>(str, offset + 6, offset + 8) - 1))) as T;
188
+ val = (val / 10 ** (__atoi_fast<u32>(str, offset + 6, offset + 8) - 1)) as T;
192
189
  } else {
193
190
  // Inlined this operation instead of using a loop
194
- val = (val * (10 ** (__atoi_fast<u32>(str, offset + 2, offset + 4) + 1))) as T;
191
+ val = (val * 10 ** (__atoi_fast<u32>(str, offset + 2, offset + 4) + 1)) as T;
195
192
  }
196
193
  return val as T;
197
194
  } else {
198
- val = (val * 10) + (ch - 48) as T;
195
+ val = (val * 10 + (ch - 48)) as T;
199
196
  }
200
197
  }
201
198
  return val as T;
@@ -207,30 +204,30 @@ export function getArrayDepth<T extends ArrayLike>(depth: i32 = 1): i32 {
207
204
  if (len == 0) len = u32(str.length << 1);
208
205
  if (len >= 4) {
209
206
  // Duplet 16 bit lane load
210
- for (; offset < (len - 3); offset += 4) {
207
+ for (; offset < len - 3; offset += 4) {
211
208
  const ch = load<u32>(changetype<usize>(str) + <usize>offset);
212
- const low = ch & 0xFFFF;
209
+ const low = ch & 0xffff;
213
210
  const high = ch >> 16;
214
211
  // 9 is 57. The highest group of two numbers is 114, so if a e or an E is included, this will fire.
215
212
  if (low > 57) {
216
213
  // The first char (f) is E or e
217
214
  // We push the offset up by two and apply the notation.
218
215
  if (load<u16>(changetype<usize>(str) + <usize>offset + 2) == 45) {
219
- return (val / (10 ** (__atoi_fast<u32>(str, offset + 6, offset + 8) - 1))) as T;
216
+ return (val / 10 ** (__atoi_fast<u32>(str, offset + 6, offset + 8) - 1)) as T;
220
217
  } else {
221
218
  // Inlined this operation instead of using a loop
222
- return (val * (10 ** (__atoi_fast<u32>(str, offset + 2, offset + 4) + 1))) as T;
219
+ return (val * 10 ** (__atoi_fast<u32>(str, offset + 2, offset + 4) + 1)) as T;
223
220
  }
224
221
  } else if (high > 57) {
225
222
  if (load<u16>(changetype<usize>(str) + <usize>offset + 4) == 45) {
226
- return (val / (10 ** (__atoi_fast<u32>(str, offset + 6, offset + 8) - 1))) as T;
223
+ return (val / 10 ** (__atoi_fast<u32>(str, offset + 6, offset + 8) - 1)) as T;
227
224
  } else {
228
225
  // Inlined this operation instead of using a loop
229
- return (val * (10 ** (__atoi_fast<u32>(str, offset + 4, offset + 6) + 1))) as T;
226
+ return (val * 10 ** (__atoi_fast<u32>(str, offset + 4, offset + 6) + 1)) as T;
230
227
  }
231
228
  } else {
232
229
  // Optimized with multiplications and shifts.
233
- val = (val * 100 + ((low - 48) * 10) + (high - 48)) as T;
230
+ val = (val * 100 + (low - 48) * 10 + (high - 48)) as T;
234
231
  }
235
232
  }
236
233
  }
@@ -241,13 +238,13 @@ export function getArrayDepth<T extends ArrayLike>(depth: i32 = 1): i32 {
241
238
  // e is 101 and E is 69.
242
239
  if (ch > 57) {
243
240
  if (load<u16>(changetype<usize>(str) + <usize>offset + 2) == 45) {
244
- return (val / (10 ** (__atoi_fast<u32>(str, offset + 6, offset + 8) - 1))) as T;
241
+ return (val / 10 ** (__atoi_fast<u32>(str, offset + 6, offset + 8) - 1)) as T;
245
242
  } else {
246
243
  // Inlined this operation instead of using a loop
247
- return (val * (10 ** (__atoi_fast<u32>(str, offset + 2, offset + 4) + 1))) as T;
244
+ return (val * 10 ** (__atoi_fast<u32>(str, offset + 2, offset + 4) + 1)) as T;
248
245
  }
249
246
  } else {
250
- val = (val * 10) + (ch - 48) as T;
247
+ val = (val * 10 + (ch - 48)) as T;
251
248
  }
252
249
  }
253
250
  return val as T;
@@ -268,18 +265,18 @@ export function getArrayDepth<T extends ArrayLike>(depth: i32 = 1): i32 {
268
265
  if (load<u16>(changetype<usize>(str) + <usize>start) === 45) {
269
266
  start += 2;
270
267
  for (; start < end; start += 2) {
271
- val = (val * 10) + (load<u16>(changetype<usize>(str) + <usize>start) - 48) as T;
268
+ val = (val * 10 + (load<u16>(changetype<usize>(str) + <usize>start) - 48)) as T;
272
269
  }
273
270
  return -val as T;
274
271
  } else {
275
272
  for (; start < end; start += 2) {
276
- val = ((val * 10) + (load<u16>(changetype<usize>(str) + <usize>start) - 48)) as T;
273
+ val = (val * 10 + (load<u16>(changetype<usize>(str) + <usize>start) - 48)) as T;
277
274
  }
278
275
  return val as T;
279
276
  }
280
277
  } else {
281
278
  for (; start < end; start += 2) {
282
- val = ((val * 10) + (load<u16>(changetype<usize>(str) + <usize>start) - 48)) as T;
279
+ val = (val * 10 + (load<u16>(changetype<usize>(str) + <usize>start) - 48)) as T;
283
280
  }
284
281
  return val as T;
285
282
  }
@@ -351,7 +348,7 @@ export function getArrayDepth<T extends ArrayLike>(depth: i32 = 1): i32 {
351
348
  const p2_len = p2_end - p2_start;
352
349
  if (p1_len != p2_len) return false;
353
350
  if (p1_len == 2) {
354
- return load<u16>(changetype<usize>(p1_data) + p1_start) == load<u16>(changetype<usize>(p2_data) + p2_start)
351
+ return load<u16>(changetype<usize>(p1_data) + p1_start) == load<u16>(changetype<usize>(p2_data) + p2_start);
355
352
  }
356
353
  return memory.compare(changetype<usize>(p1_data) + p1_start, changetype<usize>(p2_data) + p2_start, p1_len) === 0;
357
354
  }
@@ -378,18 +375,18 @@ export function getArrayDepth<T extends ArrayLike>(depth: i32 = 1): i32 {
378
375
  // @ts-ignore: Decorator
379
376
  @inline export function intTo16(int: i32): i32 {
380
377
  const high = int >> 4;
381
- const low = int & 0x0F;
378
+ const low = int & 0x0f;
382
379
  if (low < 10) {
383
380
  if (high < 10) {
384
- return ((48 + low) << 16) | 48 + high;
381
+ return ((48 + low) << 16) | (48 + high);
385
382
  } else {
386
- return ((48 + low) << 16) | 87 + high;
383
+ return ((48 + low) << 16) | (87 + high);
387
384
  }
388
385
  } else {
389
386
  if (high < 10) {
390
- return ((87 + low) << 16) | 48 + high;
387
+ return ((87 + low) << 16) | (48 + high);
391
388
  } else {
392
- return ((87 + low) << 16) | 87 + high;
389
+ return ((87 + low) << 16) | (87 + high);
393
390
  }
394
391
  }
395
- }
392
+ }
@@ -4,28 +4,28 @@ import { unsafeCharCodeAt } from "../../custom/util";
4
4
 
5
5
  // @ts-ignore: Decorator valid here
6
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
- }
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
+ }
29
28
  }
30
- return result;
31
- }
29
+ }
30
+ return result;
31
+ }
@@ -16,4 +16,4 @@ import { deserializeBoolean } from "../bool";
16
16
  }
17
17
  }
18
18
  return result;
19
- }
19
+ }
@@ -5,20 +5,20 @@ import { deserializeFloat } from "../float";
5
5
 
6
6
  // @ts-ignore: Decorator valid here
7
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
- }
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;
22
21
  }
23
- return result;
24
- }
22
+ }
23
+ return result;
24
+ }
@@ -5,20 +5,20 @@ import { deserializeInteger } from "../integer";
5
5
 
6
6
  // @ts-ignore: Decorator valid here
7
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
- }
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;
22
21
  }
23
- return result;
24
- }
22
+ }
23
+ return result;
24
+ }
@@ -4,24 +4,24 @@ import { unsafeCharCodeAt } from "../../custom/util";
4
4
 
5
5
  // @ts-ignore: Decorator valid here
6
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
- }
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
+ }
25
24
  }
26
- return result;
27
- }
25
+ }
26
+ return result;
27
+ }
@@ -4,24 +4,24 @@ import { unsafeCharCodeAt } from "../../custom/util";
4
4
 
5
5
  // @ts-ignore: Decorator valid here
6
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
- }
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
+ }
25
24
  }
26
- return result;
27
- }
25
+ }
26
+ return result;
27
+ }
@@ -26,4 +26,4 @@ import { deserializeString } from "../string";
26
26
  }
27
27
  }
28
28
  return result;
29
- }
29
+ }
@@ -41,6 +41,6 @@ export function deserializeArray<T extends unknown[]>(data: string): T {
41
41
  // @ts-ignore: Decorator valid here
42
42
  export function deserializeArray_Safe<T extends unknown[]>(data: string): T {
43
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!");
44
+ if (firstChar != BRACKET_LEFT) throw new Error("Mismatched Types! Expected " + nameof<T>() + ' but got "' + data.slice(0, 100) + '" instead!');
45
45
  return deserializeArray<T>(data);
46
- }
46
+ }
@@ -8,13 +8,13 @@ import { unsafeCharCodeAt } from "../custom/util";
8
8
  */
9
9
  // @ts-ignore: Decorator valid here
10
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!`);
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
18
  }
19
19
 
20
20
  /**
@@ -24,11 +24,11 @@ import { unsafeCharCodeAt } from "../custom/util";
24
24
  */
25
25
  // @ts-ignore: Decorator valid here
26
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
- }
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
+ }
@@ -3,10 +3,10 @@ import { QUOTE } from "../custom/chars";
3
3
  // @ts-ignore: Decorator valid here
4
4
  @inline export function deserializeDate(dateTimeString: string): Date {
5
5
  // Use AssemblyScript's date parser
6
- const d = Date.fromString(dateTimeString);
6
+ const d = Date.fromString(dateTimeString.slice(1, -1));
7
7
 
8
8
  // Return a new object instead of the one that the parser returned.
9
- // This may seem redundant, but addreses the issue when Date
9
+ // This may seem redundant, but addresses the issue when Date
10
10
  // is globally aliased to wasi_Date (or some other superclass).
11
11
  return new Date(d.getTime());
12
12
  }
@@ -14,6 +14,6 @@ import { QUOTE } from "../custom/chars";
14
14
  // @ts-ignore: Decorator valid here
15
15
  @inline export function deserializeDate_Safe(dateTimeString: string): Date {
16
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!");
17
+ if (firstChar != QUOTE) throw new Error('Mismatched Types! Expected Date but got "' + dateTimeString.slice(0, 100) + '" instead!');
18
18
  return deserializeDate(dateTimeString);
19
- }
19
+ }
@@ -1,21 +1,21 @@
1
1
  // @ts-ignore: Decorator valid here
2
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);
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
9
  }
10
10
 
11
11
  // @ts-ignore: Decorator valid here
12
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
- }
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
+ }
@@ -2,15 +2,15 @@ import { snip_fast } from "../custom/util";
2
2
 
3
3
  // @ts-ignore: Decorator valid here
4
4
  @inline export function deserializeInteger<T>(data: string): T {
5
- // @ts-ignore
6
- return snip_fast<T>(data);
5
+ // @ts-ignore
6
+ return snip_fast<T>(data);
7
7
  }
8
8
 
9
9
  // @ts-ignore: Decorator valid here
10
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
- }
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
+ }