json-as 0.9.11 → 0.9.13

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/CHANGELOG CHANGED
@@ -17,8 +17,10 @@ v0.9.8a - Fix #80 - Empty Maps were not serialized to {}, instead, threw memory
17
17
  v0.9.8b - Fix #81 - Revert transform
18
18
  v0.9.9 - Fix #82 - Initialize maps
19
19
  v0.9.9a - Remove extraneous logs from transform
20
- v0.9.11 - Fix transform type checks. switch to nodekind checks
20
+ v0.9.10 - Fix transform type checks. switch to nodekind checks
21
21
  v0.9.11 - Remove MpZ--implement custom serializers and deserializers in the works
22
+ v0.9.12 - Add compat with aspect
23
+ v0.9.13 - Fix empty strings not indexing correctly
22
24
 
23
25
  [UNRELEASED] v1.0.0
24
26
  - Allow nullable primitives
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  __| || __|| || | | ___ | _ || __|
4
4
  | | ||__ || | || | | ||___|| ||__ |
5
5
  |_____||_____||_____||_|___| |__|__||_____|
6
- v0.9.11
6
+ v0.9.13
7
7
  </pre>
8
8
  </h5>
9
9
 
@@ -0,0 +1,155 @@
1
+ import { dtoa_buffered, itoa_buffered } from "util/number";
2
+ import { OBJECT, TOTAL_OVERHEAD } from "rt/common";
3
+ @inline const MAX_LEN: usize = 65536;
4
+ const STORE: usize[] = [];
5
+ let STORE_LEN: usize = 0;
6
+ const CACHE = memory.data(i32(MAX_LEN));
7
+ // Configurable amount of referenceable strings
8
+ let POINTER = changetype<usize>(CACHE);
9
+ @inline const MAX_CACHE = CACHE + MAX_LEN;
10
+
11
+ export namespace bs {
12
+ @inline export function write_int<T extends number>(num: T): void {
13
+ POINTER += itoa_buffered(POINTER, num) << 1;
14
+ if (MAX_CACHE <= POINTER) bs.shrink();
15
+ }
16
+ @inline export function write_int_u<T extends number>(num: T): void {
17
+ POINTER += itoa_buffered(POINTER, num) << 1;
18
+ }
19
+
20
+ @inline export function write_fl<T extends number>(num: T): void {
21
+ POINTER += dtoa_buffered(POINTER, num) << 1;
22
+ if (MAX_CACHE <= POINTER) bs.shrink();
23
+ }
24
+ @inline export function write_fl_u<T extends number>(num: T): void {
25
+ POINTER += dtoa_buffered(POINTER, num) << 1;
26
+ }
27
+
28
+ @inline export function write_b(buf: usize, bytes: usize = changetype<OBJECT>(buf - TOTAL_OVERHEAD).rtSize): void {
29
+ memory.copy(POINTER, buf, bytes);
30
+ POINTER += bytes;
31
+ if (MAX_CACHE <= POINTER) bs.shrink();
32
+ }
33
+ @inline export function write_b_u(buf: usize, bytes: usize = changetype<OBJECT>(buf - TOTAL_OVERHEAD).rtSize): void {
34
+ memory.copy(POINTER, buf, bytes);
35
+ POINTER += bytes;
36
+ }
37
+
38
+ @inline export function write_s(str: string, bytes: usize = changetype<OBJECT>(changetype<usize>(str) - TOTAL_OVERHEAD).rtSize): void {
39
+ memory.copy(POINTER, changetype<usize>(str), bytes);
40
+ POINTER += bytes;
41
+ if (MAX_CACHE <= POINTER) bs.shrink();
42
+ }
43
+ @inline export function write_s_u(str: string, bytes: usize = changetype<OBJECT>(changetype<usize>(str) - TOTAL_OVERHEAD).rtSize): void {
44
+ memory.copy(POINTER, changetype<usize>(str), bytes);
45
+ POINTER += bytes;
46
+ }
47
+
48
+ @inline export function write_s_se(str: string, start: usize, end: usize): void {
49
+ const bytes = end - start;
50
+ memory.copy(POINTER, changetype<usize>(str) + start, bytes);
51
+ POINTER += bytes;
52
+ if (MAX_CACHE <= POINTER) bs.shrink();
53
+ }
54
+ @inline export function write_s_se_u(str: string, start: usize, end: usize): void {
55
+ const bytes = end - start;
56
+ memory.copy(POINTER, changetype<usize>(str) + start, bytes);
57
+ POINTER += bytes;
58
+ }
59
+
60
+ @inline export function write_16(char: i32): void {
61
+ store<u16>(POINTER, char);
62
+ POINTER += 2;
63
+ if (MAX_CACHE <= POINTER) bs.shrink();
64
+ }
65
+ @inline export function write_16_u(char: i32): void {
66
+ store<u16>(POINTER, char);
67
+ //POINTER += 2;
68
+ }
69
+
70
+ @inline export function write_32(chars: i32): void {
71
+ store<u32>(POINTER, chars);
72
+ POINTER += 4;
73
+ if (MAX_CACHE <= POINTER) bs.shrink();
74
+ }
75
+ @inline export function write_32_u(chars: i32): void {
76
+ store<u32>(POINTER, chars);
77
+ //POINTER += 4;
78
+ }
79
+
80
+ @inline export function write_64(chars: i64): void {
81
+ store<u64>(POINTER, chars);
82
+ POINTER += 8;
83
+ if (MAX_CACHE <= POINTER) bs.shrink();
84
+ }
85
+
86
+ @inline export function write_64_u(chars: i64): void {
87
+ store<u64>(POINTER, chars);
88
+ POINTER += 8;
89
+ }
90
+
91
+ @inline export function write_128(chars: v128): void {
92
+ store<v128>(POINTER, chars);
93
+ POINTER += 16;
94
+ if (MAX_CACHE <= POINTER) bs.shrink();
95
+ }
96
+ @inline export function write_128_u(chars: v128): void {
97
+ store<v128>(POINTER, chars);
98
+ //POINTER += 16;
99
+ //if (MAX_CACHE <= POINTER) bs.shrink();
100
+ }
101
+ @inline export function shrink(): void {
102
+ const len = POINTER - CACHE;
103
+ STORE_LEN += len;
104
+ const out = __new(
105
+ len,
106
+ idof<ArrayBuffer>()
107
+ );
108
+ memory.copy(out, CACHE, len);
109
+ bs.reset();
110
+ STORE.push(out);
111
+ }
112
+ @inline export function out<T>(): T {
113
+ const len = POINTER - CACHE;
114
+ let out = __new(
115
+ len + STORE_LEN,
116
+ idof<T>()
117
+ );
118
+
119
+ memory.copy(out, CACHE, len);
120
+ if (STORE_LEN) {
121
+ out += len;
122
+ for (let i = 0; i < STORE.length; i++) {
123
+ const ptr = changetype<usize>(unchecked(STORE[i]));
124
+ const storeLen = changetype<OBJECT>(ptr - TOTAL_OVERHEAD).rtSize;
125
+ memory.copy(out, ptr, storeLen);
126
+ //__unpin(ptr);
127
+ out += storeLen;
128
+ }
129
+ STORE_LEN = 0;
130
+ }
131
+ bs.reset();
132
+
133
+ return changetype<T>(out);
134
+ }
135
+
136
+ @inline export function out_u<T>(): T {
137
+ const len = POINTER - CACHE;
138
+ const out = __new(
139
+ len + STORE_LEN,
140
+ idof<T>()
141
+ );
142
+
143
+ memory.copy(out, CACHE, len);
144
+ bs.reset();
145
+
146
+ return changetype<T>(out);
147
+ }
148
+
149
+ @inline export function _out(out: usize): void {
150
+ memory.copy(out, CACHE, POINTER - CACHE);
151
+ }
152
+ @inline export function reset(): void {
153
+ POINTER = CACHE;
154
+ }
155
+ }
@@ -362,3 +362,31 @@ export function containsCodePoint(str: string, code: u32, start: i32, end: i32):
362
362
  }
363
363
  return false;
364
364
  }
365
+
366
+ export function _intTo16(int: i32): i32 {
367
+ if (int < 10) {
368
+ // 0-10
369
+ return 48 + int;
370
+ } else {
371
+ // a-f
372
+ return 87 + int;
373
+ }
374
+ }
375
+
376
+ @inline export function intTo16(int: i32): i32 {
377
+ const high = int >> 4;
378
+ const low = int & 0x0F;
379
+ if (low < 10) {
380
+ if (high < 10) {
381
+ return ((48 + low) << 16) | 48 + high;
382
+ } else {
383
+ return ((48 + low) << 16) | 87 + high;
384
+ }
385
+ } else {
386
+ if (high < 10) {
387
+ return ((87 + low) << 16) | 48 + high;
388
+ } else {
389
+ return ((87 + low) << 16) | 87 + high;
390
+ }
391
+ }
392
+ }
@@ -1,6 +1,6 @@
1
- import { BRACKET_LEFT, BRACKET_RIGHT } from "../../chars";
1
+ import { BRACKET_LEFT, BRACKET_RIGHT } from "../../custom/chars";
2
2
  import { JSON } from "../..";
3
- import { unsafeCharCodeAt } from "../../util";
3
+ 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 {
@@ -1,5 +1,5 @@
1
- import { CHAR_E, CHAR_F, CHAR_T } from "../../chars";
2
- import { unsafeCharCodeAt } from "../../util";
1
+ import { CHAR_E, CHAR_F, CHAR_T } from "../../custom/chars";
2
+ import { unsafeCharCodeAt } from "../../custom/util";
3
3
  import { deserializeBoolean } from "../bool";
4
4
 
5
5
  // @ts-ignore: Decorator valid here
@@ -1,6 +1,6 @@
1
1
  import { isSpace } from "util/string";
2
- import { unsafeCharCodeAt } from "../../util";
3
- import { COMMA, BRACKET_RIGHT } from "../../chars";
2
+ import { unsafeCharCodeAt } from "../../custom/util";
3
+ import { COMMA, BRACKET_RIGHT } from "../../custom/chars";
4
4
  import { deserializeFloat } from "../float";
5
5
 
6
6
  // @ts-ignore: Decorator valid here
@@ -1,6 +1,6 @@
1
1
  import { isSpace } from "util/string";
2
- import { unsafeCharCodeAt } from "../../util";
3
- import { COMMA, BRACKET_RIGHT } from "../../chars";
2
+ import { unsafeCharCodeAt } from "../../custom/util";
3
+ import { COMMA, BRACKET_RIGHT } from "../../custom/chars";
4
4
  import { deserializeInteger } from "../integer";
5
5
 
6
6
  // @ts-ignore: Decorator valid here
@@ -1,6 +1,6 @@
1
- import { BRACE_LEFT, BRACE_RIGHT } from "../../chars";
1
+ import { BRACE_LEFT, BRACE_RIGHT } from "../../custom/chars";
2
2
  import { JSON } from "../..";
3
- import { unsafeCharCodeAt } from "../../util";
3
+ 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 {
@@ -1,6 +1,6 @@
1
- import { BRACE_LEFT, BRACE_RIGHT } from "../../chars";
1
+ import { BRACE_LEFT, BRACE_RIGHT } from "../../custom/chars";
2
2
  import { JSON } from "../..";
3
- import { unsafeCharCodeAt } from "../../util";
3
+ 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 {
@@ -1,5 +1,5 @@
1
- import { BACK_SLASH, QUOTE } from "../../chars";
2
- import { unsafeCharCodeAt } from "../../util";
1
+ import { BACK_SLASH, QUOTE } from "../../custom/chars";
2
+ import { unsafeCharCodeAt } from "../../custom/util";
3
3
  import { deserializeString } from "../string";
4
4
 
5
5
  // @ts-ignore: Decorator valid here
@@ -1,4 +1,4 @@
1
- import { isMap } from "../util";
1
+ import { isMap } from "../custom/util";
2
2
  import { deserializeArrayArray } from "./array/array";
3
3
  import { deserializeBooleanArray } from "./array/bool";
4
4
  import { deserializeFloatArray } from "./array/float";
@@ -1,5 +1,5 @@
1
- import { CHAR_F, CHAR_T } from "../chars";
2
- import { unsafeCharCodeAt } from "../util";
1
+ import { CHAR_F, CHAR_T } from "../custom/chars";
2
+ import { unsafeCharCodeAt } from "../custom/util";
3
3
 
4
4
  /**
5
5
  * Deserialize a string to type boolean
@@ -1,4 +1,4 @@
1
- import { snip_fast } from "../util";
1
+ 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 {
@@ -1,5 +1,5 @@
1
1
  import { Virtual } from "as-virtual/assembly";
2
- import { containsCodePoint, unsafeCharCodeAt } from "../util";
2
+ import { containsCodePoint, unsafeCharCodeAt } from "../custom/util";
3
3
  import {
4
4
  CHAR_A,
5
5
  BACK_SLASH,
@@ -18,7 +18,7 @@ import {
18
18
  CHAR_S,
19
19
  CHAR_T,
20
20
  CHAR_U
21
- } from "../chars";
21
+ } from "../custom/chars";
22
22
  import { deserializeBoolean } from "./bool";
23
23
  import { JSON } from "..";
24
24
  import { deserializeString } from "./string";
@@ -72,8 +72,6 @@ import { deserializeFloat } from "./float";
72
72
  depth--;
73
73
  if (depth === 0) {
74
74
  ++objectValueIndex;
75
- console.log("Index: " + nameof<indexof<T>>());
76
- console.log("Value: " + nameof<valueof<T>>());
77
75
  map.set(deserializeMapKey<indexof<T>>(key), JSON.parse<valueof<T>>(data.slice(outerLoopIndex, objectValueIndex)));
78
76
  outerLoopIndex = objectValueIndex;
79
77
  isKey = false;
@@ -181,4 +179,4 @@ function deserializeMapKey<T>(key: Virtual<string>): T {
181
179
  }
182
180
 
183
181
  throw new Error(`JSON: Cannot parse JSON object to a Map with a key of type ${nameof<T>()}`);
184
- }
182
+ }
@@ -1,5 +1,5 @@
1
- import { unsafeCharCodeAt } from "../util";
2
- import { CHAR_A, BACK_SLASH, COMMA, CHAR_E, CHAR_F, CHAR_L, BRACE_LEFT, BRACKET_LEFT, CHAR_N, QUOTE, CHAR_R, BRACE_RIGHT, BRACKET_RIGHT, CHAR_S, CHAR_T, CHAR_U } from "../chars";
1
+ import { unsafeCharCodeAt } from "../custom/util";
2
+ import { CHAR_A, BACK_SLASH, COMMA, CHAR_E, CHAR_F, CHAR_L, BRACE_LEFT, BRACKET_LEFT, CHAR_N, QUOTE, CHAR_R, BRACE_RIGHT, BRACKET_RIGHT, CHAR_S, CHAR_T, CHAR_U } from "../custom/chars";
3
3
  import { isSpace } from "util/string";
4
4
 
5
5
  // @ts-ignore: Decorator valid here
@@ -13,9 +13,9 @@ import {
13
13
  CHAR_T,
14
14
  TAB,
15
15
  CHAR_U
16
- } from "../chars";
17
- import { Sink } from "../sink";
18
- import { unsafeCharCodeAt } from "../util";
16
+ } from "../custom/chars";
17
+ import { Sink } from "../custom/sink";
18
+ import { unsafeCharCodeAt } from "../custom/util";
19
19
 
20
20
  // @ts-ignore: Decorator valid here
21
21
  @inline export function deserializeString(data: string, start: i32 = 0, end: i32 = 0): string {
package/assembly/index.ts CHANGED
@@ -13,7 +13,7 @@ import { deserializeFloat } from "./deserialize/float";
13
13
  import { deserializeObject } from "./deserialize/object";
14
14
  import { deserializeMap } from "./deserialize/map";
15
15
  import { deserializeDate } from "./deserialize/date";
16
- import { NULL_WORD } from "./chars";
16
+ import { NULL_WORD } from "./custom/chars";
17
17
  import { deserializeInteger } from "./deserialize/integer";
18
18
  import { deserializeString } from "./deserialize/string";
19
19
 
@@ -6,8 +6,8 @@ import {
6
6
  BRACKET_LEFT_WORD,
7
7
  BRACKET_RIGHT,
8
8
  BRACKET_RIGHT_WORD
9
- } from "../chars";
10
- import { Sink } from "../sink";
9
+ } from "../custom/chars";
10
+ import { Sink } from "../custom/sink";
11
11
  import { serializeString } from "./string";
12
12
 
13
13
  // @ts-ignore: Decorator valid here
@@ -1,6 +1,6 @@
1
- import { COLON, COMMA, BRACE_LEFT_WORD, BRACE_RIGHT } from "../chars";
1
+ import { COLON, COMMA, BRACE_LEFT_WORD, BRACE_RIGHT } from "../custom/chars";
2
2
  import { JSON } from "..";
3
- import { Sink } from "../sink";
3
+ import { Sink } from "../custom/sink";
4
4
 
5
5
  // @ts-ignore: Decorator valid here
6
6
  @inline export function serializeMap<T extends Map<any, any>>(data: T): string {
@@ -5,69 +5,80 @@ import {
5
5
  FORM_FEED,
6
6
  NEW_LINE,
7
7
  QUOTE,
8
- QUOTE_WORD,
9
8
  TAB
10
- } from "../chars";
11
- import { Sink } from "../sink";
12
- import { unsafeCharCodeAt } from "../util";
9
+ } from "../custom/chars";
10
+ import { OBJECT, TOTAL_OVERHEAD } from "rt/common";
11
+ import { bs } from "../custom/bs";
12
+ import { _intTo16, intTo16 } from "../custom/util";
13
13
 
14
14
  // @ts-ignore: Decorator valid here
15
15
  @inline export function serializeString(data: string): string {
16
- if (data.length === 0) {
17
- return QUOTE_WORD + QUOTE_WORD;
16
+ const len = data.length << 1;
17
+ if (len === 0) {
18
+ bs.write_32(2228258); /* "" */
19
+ return bs.out<string>();
18
20
  }
19
21
 
20
- let result = Sink.fromString(QUOTE_WORD, data.length);
22
+ bs.write_16(QUOTE);
21
23
 
22
24
  let last: i32 = 0;
23
- for (let i = 0; i < data.length; i++) {
24
- const char = unsafeCharCodeAt(<string>data, i);
25
- if (char === QUOTE || char === BACK_SLASH) {
26
- result.write(<string>data, last, i);
27
- result.writeCodePoint(BACK_SLASH);
28
- last = i;
29
- } else if (16 > char) {
30
- result.write(<string>data, last, i);
31
- last = i + 1;
32
- switch (char) {
33
- case BACKSPACE: {
34
- result.write("\\b");
35
- break;
36
- }
37
- case TAB: {
38
- result.write("\\t");
39
- break;
40
- }
41
- case NEW_LINE: {
42
- result.write("\\n");
43
- break;
44
- }
45
- case FORM_FEED: {
46
- result.write("\\f");
47
- break;
48
- }
49
- case CARRIAGE_RETURN: {
50
- result.write("\\r");
51
- break;
52
- }
53
- default: {
25
+ for (let i = 0; i < len; i += 2) {
26
+ const char = load<u16>(changetype<usize>(data) + i);
27
+ if (char < 35) {
28
+ if (char === QUOTE) {
29
+ bs.write_s_se(<string>data, last, i);
30
+ bs.write_16(BACK_SLASH);
31
+ last = i;
32
+ continue;
33
+ } else if (char < 32) {
34
+ if (char < 16) {
35
+ bs.write_s_se(<string>data, last, i);
36
+ last = i + 2;
37
+ switch (char) {
38
+ case BACKSPACE: {
39
+ bs.write_32(6422620);
40
+ continue;
41
+ }
42
+ case TAB: {
43
+ bs.write_32(7602268);
44
+ continue;
45
+ }
46
+ case NEW_LINE: {
47
+ bs.write_32(7209052);
48
+ continue;
49
+ }
50
+ case FORM_FEED: {
51
+ bs.write_32(6684764);
52
+ continue;
53
+ }
54
+ case CARRIAGE_RETURN: {
55
+ bs.write_32(7471196);
56
+ continue;
57
+ }
58
+ default: {
59
+ // all chars 0-31 must be encoded as a four digit unicode escape sequence
60
+ // \u0000 to \u000f handled here
61
+ bs.write_64(13511005048209500) /* \\u00 */
62
+ bs.write_32((_intTo16(char) << 16) | 48); /* 0_ */
63
+ continue;
64
+ }
65
+ }
66
+ } else {
67
+ bs.write_s_se(<string>data, last, i);
68
+ last = i + 2;
54
69
  // all chars 0-31 must be encoded as a four digit unicode escape sequence
55
- // \u0000 to \u000f handled here
56
- result.write("\\u000");
57
- result.write(char.toString(16));
58
- break;
70
+ // \u0010 to \u001f handled here
71
+ bs.write_64(13511005048209500) /* \\u00 */
72
+ bs.write_32((intTo16(char) << 16) | 48); /* 0_ */
59
73
  }
60
74
  }
61
- } else if (32 > char) {
62
- result.write(<string>data, last, i);
63
- last = i + 1;
64
- // all chars 0-31 must be encoded as a four digit unicode escape sequence
65
- // \u0010 to \u001f handled here
66
- result.write("\\u00");
67
- result.write(char.toString(16));
75
+ } else if (char === BACK_SLASH) {
76
+ bs.write_s_se(<string>data, last, i);
77
+ bs.write_16(BACK_SLASH);
78
+ last = i;
68
79
  }
69
80
  }
70
- result.write(<string>data, last);
71
- result.writeCodePoint(QUOTE);
72
- return result.toString();
81
+ bs.write_s_se_u(<string>data, last, changetype<OBJECT>(changetype<usize>(data) - TOTAL_OVERHEAD).rtSize);
82
+ bs.write_16(QUOTE);
83
+ return bs.out<string>();
73
84
  }
package/assembly/test.ts CHANGED
@@ -1,38 +1,42 @@
1
- import { JSON } from ".";
2
- @json
3
- class Vec3 {
4
- x: f32 = 0.0;
5
- y: f32 = 0.0;
6
- z: f32 = 0.0;
7
- }
1
+ // import { JSON } from ".";
2
+ import { bs } from "./custom/bs";
3
+ // @json
4
+ // class Vec3 {
5
+ // x: f32 = 0.0;
6
+ // y: f32 = 0.0;
7
+ // z: f32 = 0.0;
8
+ // }
8
9
 
9
- @json
10
- class Player {
11
- @alias("first name")
12
- firstName!: string;
13
- lastName!: string;
14
- lastActive!: i32[];
15
- // Drop in a code block, function, or expression that evaluates to a boolean
16
- @omitif("this.age < 18")
17
- age!: i32;
18
- @omitnull()
19
- pos!: Vec3 | null;
20
- isVerified!: boolean;
21
- }
10
+ // @json
11
+ // class Player {
12
+ // @alias("first name")
13
+ // firstName!: string;
14
+ // lastName!: string;
15
+ // lastActive!: i32[];
16
+ // // Drop in a code block, function, or expression that evaluates to a boolean
17
+ // @omitif("this.age < 18")
18
+ // age!: i32;
19
+ // @omitnull()
20
+ // pos!: Vec3 | null;
21
+ // isVerified!: boolean;
22
+ // }
22
23
 
23
- const player: Player = {
24
- firstName: "Emmet",
25
- lastName: "West",
26
- lastActive: [8, 27, 2022],
27
- age: 23,
28
- pos: {
29
- x: 3.4,
30
- y: 1.2,
31
- z: 8.3
32
- },
33
- isVerified: true
34
- };
24
+ // const player: Player = {
25
+ // firstName: "Emmet",
26
+ // lastName: "West",
27
+ // lastActive: [8, 27, 2022],
28
+ // age: 23,
29
+ // pos: {
30
+ // x: 3.4,
31
+ // y: 1.2,
32
+ // z: 8.3
33
+ // },
34
+ // isVerified: true
35
+ // };
35
36
 
36
- const stringified = JSON.stringify<Player>(player);
37
+ // const stringified = JSON.stringify<Player>(player);
37
38
 
38
- const parsed = JSON.parse<Player>(stringified);
39
+ // const parsed = JSON.parse<Player>(stringified);
40
+
41
+ bs.write_32(6422620);
42
+ console.log(bs.out<string>())
@@ -1,19 +1,32 @@
1
- import { bench, blackbox } from "as-bench/assembly/bench";
2
- import { __atoi_fast } from "../assembly/util";
3
- import { JSON } from "../assembly";
1
+ import { bench } from "as-bench/assembly/bench";
2
+ import { serializeString } from "../assembly/serialize/string";
3
+ import { bs } from "../assembly/custom/bs";
4
4
 
5
5
  @json
6
6
  class Vec3 {
7
7
  x: i32;
8
8
  y: i32;
9
9
  z: i32;
10
+ __SERIALIZE_BS(): void {
11
+ bs.write_128_u(i16x8(123, 34, 120, 34, 58, 49, 44, 34)); /* {"x":1," */
12
+ bs.write_128_u(i16x8(121, 34, 58, 50, 44, 34, 122, 34)); /* y":2,"z" */
13
+ bs.write_32_u(3342394); /* :3 */
14
+ bs.write_16_u(125); /* } */
15
+ }
10
16
  }
11
-
17
+ const out = memory.data(1000);
12
18
  const vec: Vec3 = {
13
19
  x: 3,
14
20
  y: 1,
15
21
  z: 8,
16
22
  }
23
+ bench("Stringify Vec3", () => {
24
+ vec.__SERIALIZE_BS();
25
+ //bs.reset()
26
+ })
27
+ bench("Stringify String", () => {
28
+ serializeString('Hello World');
29
+ });
17
30
  /*
18
31
  bench("Parse Number SNIP", () => {
19
32
  blackbox<i32>(snip_fast<i32>("12345"));
@@ -29,7 +42,7 @@ bench("Parse Number STDLIB", () => {
29
42
 
30
43
  bench("Stringify Object (Vec3)", () => {
31
44
  blackbox<string>(JSON.stringify(vec));
32
- });*/
45
+ });
33
46
 
34
47
  bench("Parse Object (Vec3)", () => {
35
48
  blackbox<Vec3>(JSON.parse<Vec3>('{"x":0,"y":0,"z":0}'));
Binary file
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "json-as",
3
- "version": "0.9.11",
4
- "description": "JSON encoder/decoder for AssemblyScript",
3
+ "version": "0.9.13",
4
+ "description": "The only JSON library you'll need for AssemblyScript. SIMD enabled",
5
5
  "types": "assembly/index.ts",
6
6
  "author": "Jairus Tanaka",
7
7
  "contributors": [
@@ -15,10 +15,10 @@
15
15
  ],
16
16
  "license": "MIT",
17
17
  "scripts": {
18
- "test": "ast test",
18
+ "test": "ast test && rm -rf ./build/",
19
19
  "pretest": "rm -rf ./build/ && ast build",
20
20
  "build:test": "rm -rf ./build/ && JSON_DEBUG=true asc assembly/test.ts --transform ./transform -o ./build/test.wasm",
21
- "build:bench": "asc bench/benchmark.ts -o bench/benchmark.wasm --transform ./transform --optimizeLevel 3 --shrinkLevel 0 --converge --noAssert --uncheckedBehavior always --runtime stub",
21
+ "build:bench": "asc bench/benchmark.ts -o bench/benchmark.wasm --transform ./transform --optimizeLevel 3 --shrinkLevel 0 --converge --noAssert --uncheckedBehavior always --runtime stub --enable simd",
22
22
  "bench:wasmtime": "wasmtime ./bench/benchmark.wasm",
23
23
  "bench:wasmer": "wasmer --llvm ./bench/benchmark.wasm",
24
24
  "build:transform": "tsc -p ./transform",
@@ -32,8 +32,8 @@
32
32
  "@assemblyscript/wasi-shim": "^0.1.0",
33
33
  "as-bench": "^0.0.0-alpha",
34
34
  "as-console": "^7.0.0",
35
- "as-test": "0.1.7",
36
- "assemblyscript": "^0.27.28",
35
+ "as-test": "0.1.9",
36
+ "assemblyscript": "^0.27.29",
37
37
  "assemblyscript-prettier": "^3.0.1",
38
38
  "benchmark": "^2.1.4",
39
39
  "microtime": "^3.1.1",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@json-as/transform",
3
- "version": "0.9.11",
4
- "description": "JSON encoder/decoder for AssemblyScript",
3
+ "version": "0.9.13",
4
+ "description": "The only JSON library you'll need for AssemblyScript. SIMD enabled",
5
5
  "main": "./lib/index.js",
6
6
  "author": "Jairus Tanaka",
7
7
  "contributors": [
@@ -1,45 +0,0 @@
1
- import { JSON } from "..";
2
- import { Sink } from "../sink";
3
- import { __atoi_fast } from "../util";
4
- import { serializeBool } from "./bool";
5
- import { serializeFloat } from "./float";
6
- import { serializeInteger } from "./integer";
7
- import { serializeString } from "./string";
8
-
9
- /**
10
- * Serializes unknown values into their correct serializer and returns the data.
11
- *
12
- * @param data - The JSON.Value to be serialized.
13
- * @returns The serialized result.
14
- */
15
- // @ts-ignore: Decorator valid here
16
- @inline export function serializeUnknown(data: JSON.Value): string {
17
- const type = data.type;
18
- switch (type) {
19
- case JSON.Types.String: {
20
- return serializeString(data.get<string>());
21
- }
22
- case JSON.Types.Bool: {
23
- return serializeBool(data.get<bool>());
24
- }
25
- case JSON.Types.U8: {
26
- return serializeInteger(data.get<u8>());
27
- }
28
- case JSON.Types.U16: {
29
- return serializeInteger(data.get<u16>());
30
- }
31
- case JSON.Types.U32: {
32
- return serializeInteger(data.get<u32>());
33
- }
34
- case JSON.Types.U64: {
35
- return serializeInteger(data.get<u64>());
36
- }
37
- case JSON.Types.F32: {
38
- return serializeFloat(data.get<f32>());
39
- }
40
- case JSON.Types.F64: {
41
- return serializeFloat(data.get<f64>());
42
- }
43
- }
44
- return "ERROR"//serializeUnknownArray(data.get<JSON.Value[]>());
45
- }
File without changes
File without changes
File without changes