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
package/.prettierrc.json CHANGED
@@ -1,4 +1,6 @@
1
1
  {
2
2
  "singleQuote": false,
3
- "printWidth": 65536
3
+ "printWidth": 65536,
4
+ "pluginSearchDirs": ["node_modules"],
5
+ "plugins": ["assemblyscript-prettier"]
4
6
  }
package/README.md CHANGED
@@ -1,19 +1,22 @@
1
1
  <h5 align="center">
2
- <pre> __ _____ _____ _____ _____ _____
3
- __| || __|| || | | ___ | _ || __|
4
- | | ||__ || | || | | ||___|| ||__ |
5
- |_____||_____||_____||_|___| |__|__||_____|
6
- v0.9.27
7
- </pre>
2
+ <pre>
3
+ <span style="font-size: 0.8em;"> ██ ███████ ██████ ███ ██ █████ ███████
4
+ ██ ██ ██ ██ ████ ██ ██ ██ ██
5
+ ██ ███████ ██ ██ ██ ██ ██ █████ ███████ ███████
6
+ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
7
+ █████ ███████ ██████ ██ ████ ██ ██ ███████
8
+ </span>
9
+ AssemblyScript - v0.9.29
10
+ </pre>
8
11
  </h5>
9
12
 
10
13
  ## Installation
11
14
 
12
15
  ```bash
13
- npm install json-as
16
+ npm install json-as visitor-as
14
17
  ```
15
18
 
16
- Add the transform to your `asc` command (e.g. in package.json)
19
+ Add the `--transform` to your `asc` command (e.g. in package.json)
17
20
 
18
21
  ```bash
19
22
  --transform json-as/transform
@@ -21,7 +24,7 @@ Add the transform to your `asc` command (e.g. in package.json)
21
24
 
22
25
  Alternatively, add it to your `asconfig.json`
23
26
 
24
- ```
27
+ ```json
25
28
  {
26
29
  // ...
27
30
  "options": {
@@ -107,69 +110,13 @@ const serialized = JSON.stringify(arr);
107
110
  const parsed = JSON.parse<Base[]>(serialized);
108
111
  ```
109
112
 
110
- You can also add it to your `asconfig.json`
111
-
112
- ```json
113
- {
114
- // ...
115
- "options": {
116
- "transform": ["json-as/transform"]
117
- }
118
- }
119
- ```
120
-
121
113
  If you use this project in your codebase, consider dropping a [star](https://github.com/JairusSW/as-json). I would really appreciate it!
122
114
 
123
- ## Notes
124
-
125
- If you want a feature, drop an issue (and again, maybe a star). I'll likely add it in less than 7 days.
126
-
127
115
  ## Contact
128
116
 
129
- Contact me at:
130
-
131
- Email: `me@jairus.dev`
132
- GitHub: `JairusSW`
133
- Discord: `jairussw`
134
-
135
- ## Performance
136
-
137
- Run or view the benchmarks [here](https://github.com/JairusSW/as-json/tree/master/bench)
138
-
139
- Below are benchmark results comparing JavaScript's built-in JSON implementation and `JSON-AS`
140
-
141
- My library beats JSON (written in C++) on all counts _and_, I see many places where I can pull at least a 60% uplift in performance if I implement it.
142
-
143
- Note: SIMD is in-development and only available on the `v1` branch on GitHub
144
-
145
- Serialization Benchmarks:
146
-
147
- | Value | JavaScript (ops/s) | JSON-AS (ops/s) | JSON-AS (Pages) | JSON-AS (SIMD+Pages) | Max Throughput |
148
- | -------------------------- | ------------------ | ------------------ | ------------------- | -------------------- | -------------- |
149
- | "hello world" | 7,124,361 | 44,290,480 (6.2x) | 73,601,235 (10.3x) | NOT IMPLEMENTED | 1.91 GB/s |
150
- | 12345 | 9,611,677 | 66,900,642 (6.9x) | 145,924,333 (15.2x) | NOT IMPLEMENTED | 0.58 GB/s |
151
- | 1.2345 | 7,227,259 | 20,322,939 (2.8x) | NOT IMPLEMENTED | NOT IMPLEMENTED | 0.16 GB/s |
152
- | [[],[[]],[[],[[]]]] | 5,655,429 | 34,453,102 (6.0x) | NOT IMPLEMENTED | NOT IMPLEMENTED | 1.32 GB/s |
153
- | { x: f64, y: f64, z: f64 } | 3,878,604 | 44,557,996 (11.5x) | 113,203,242 (29.2x) | 172,023,231 (44.4x) | 8.61 GB/s |
154
-
155
- Deserialization Benchmarks:
156
-
157
- | Value | JavaScript (ops/s) | JSON-AS (ops/s) | Difference |
158
- | -------------------------- | ------------------ | --------------- | ---------- |
159
- | "hello world" | 12,210,131 | 24,274,496 | + 98% |
160
- | "12345" | 21,376,873 | 254,640,930 | + 1,191% |
161
- | 1.2345 | 23,193,902 | 221,869,840 | + 987% |
162
- | [[],[[]],[[],[[]]]] | 4,777,227 | 74,921,123 | + 1,568% |
163
- | { x: f64, y: f64, z: f64 } | 10,973,723 | 25,214,019 | + 230% |
164
-
165
- And my PC specs:
166
-
167
- | Component | Specification |
168
- | -------------- | ------------------------------ |
169
- | Wasmer Version | v4.3.0 |
170
- | CPU | AMD Ryzen 7 7800x3D @ 6.00 GHz |
171
- | Memory | T-Force DDR5 6000 MHz |
172
- | OS | Ubuntu WSL2 |
117
+ - [Email](mailto:me@jairus.dev)
118
+ - [GitHub](https://github.com/JairusSW)
119
+ - [Discord](discord.com/users/600700584038760448)
173
120
 
174
121
  ## Issues
175
122
 
@@ -2,32 +2,33 @@ import { JSON } from "..";
2
2
  import { BRACE_LEFT, BRACKET_LEFT, CHAR_F, CHAR_T, QUOTE } from "../custom/chars";
3
3
 
4
4
  bench("Match Type (string)", () => {
5
- blackbox<boolean>(matchType(blackbox<string>("\""), JSON.Types.String));
5
+ blackbox<boolean>(matchType(blackbox<string>('"'), JSON.Types.String));
6
6
  });
7
7
 
8
8
  bench("Match Type (bool)", () => {
9
- blackbox<boolean>(matchType(blackbox<string>("t"), JSON.Types.Bool));
9
+ blackbox<boolean>(matchType(blackbox<string>("t"), JSON.Types.Bool));
10
10
  });
11
11
 
12
12
  bench("Match Type (array)", () => {
13
- blackbox<boolean>(matchType(blackbox<string>("["), JSON.Types.Array));
13
+ blackbox<boolean>(matchType(blackbox<string>("["), JSON.Types.Array));
14
14
  });
15
15
 
16
16
  bench("Match Type (struct)", () => {
17
- blackbox<boolean>(matchType(blackbox<string>("{"), JSON.Types.Obj));
17
+ blackbox<boolean>(matchType(blackbox<string>("{"), JSON.Types.Obj));
18
18
  });
19
19
 
20
20
  bench("Match Type (raw)", () => {
21
- blackbox<boolean>(matchType(blackbox<string>("\""), JSON.Types.Raw));
21
+ blackbox<boolean>(matchType(blackbox<string>('"'), JSON.Types.Raw));
22
22
  });
23
23
 
24
+
24
25
  @inline function matchType(data: string, type: JSON.Types): boolean {
25
- const firstChar = load<u8>(changetype<usize>(data));
26
- if (JSON.Types.String == type && firstChar == QUOTE) return true;
27
- else if (JSON.Types.Bool == type && (firstChar == CHAR_T || firstChar == CHAR_F)) return true;
28
- else if (JSON.Types.Array == type && firstChar == BRACKET_LEFT) return true;
29
- else if (JSON.Types.Obj == type && firstChar == BRACE_LEFT) return true;
30
- else if (type < 7 && type > 0 && (firstChar < 58 && firstChar > 46)) return true;
31
- else if (JSON.Types.Raw == type) return true;
32
- else return false;
33
- }
26
+ const firstChar = load<u8>(changetype<usize>(data));
27
+ if (JSON.Types.String == type && firstChar == QUOTE) return true;
28
+ else if (JSON.Types.Bool == type && (firstChar == CHAR_T || firstChar == CHAR_F)) return true;
29
+ else if (JSON.Types.Array == type && firstChar == BRACKET_LEFT) return true;
30
+ else if (JSON.Types.Obj == type && firstChar == BRACE_LEFT) return true;
31
+ else if (type < 7 && type > 0 && firstChar < 58 && firstChar > 46) return true;
32
+ else if (JSON.Types.Raw == type) return true;
33
+ else return false;
34
+ }
@@ -0,0 +1,12 @@
1
+ import { JSON } from "json-as";
2
+ import { describe, expect, run } from "as-test/assembly";
3
+
4
+ describe("Should serialize dates", () => {
5
+ expect(JSON.stringify(new Date(1767184496789))).toBe('"2025-12-31T12:34:56.789Z"');
6
+ });
7
+
8
+ describe("Should deserialize dates", () => {
9
+ expect(JSON.parse<Date>('"2025-12-31T12:34:56.789Z"').getTime()).toBe(1767184496789);
10
+ });
11
+
12
+ run();
@@ -1,28 +1,36 @@
1
+
1
2
  @json
2
3
  export class ObjWithString {
3
4
  s!: string;
4
5
  }
5
6
 
7
+
6
8
  @json
7
9
  export class ObjWithStrangeKey<T> {
10
+
8
11
  @alias('a\\\t"\x02b`c')
9
12
  data!: T;
10
13
  }
14
+
15
+
11
16
  @json
12
17
  export class ObjectWithStringArray {
13
18
  sa!: string[];
14
19
  }
15
20
 
21
+
16
22
  @json
17
23
  export class ObjectWithFloat {
18
24
  f!: f64;
19
25
  }
20
26
 
27
+
21
28
  @json
22
29
  export class ObjectWithFloatArray {
23
30
  fa!: f64[];
24
31
  }
25
32
 
33
+
26
34
  @json
27
35
  export class BaseObject {
28
36
  a: string;
@@ -31,6 +39,7 @@ export class BaseObject {
31
39
  }
32
40
  }
33
41
 
42
+
34
43
  @json
35
44
  export class DerivedObject extends BaseObject {
36
45
  b: string;
@@ -40,6 +49,7 @@ export class DerivedObject extends BaseObject {
40
49
  }
41
50
  }
42
51
 
52
+
43
53
  @json
44
54
  export class Map4 {
45
55
  a: string;
@@ -48,6 +58,7 @@ export class Map4 {
48
58
  d: string;
49
59
  }
50
60
 
61
+
51
62
  @json
52
63
  export class Vec3 {
53
64
  x: f64;
@@ -57,6 +68,7 @@ export class Vec3 {
57
68
  static shouldIgnore: string = "should not be serialized";
58
69
  }
59
70
 
71
+
60
72
  @json
61
73
  export class Player {
62
74
  firstName: string;
@@ -70,12 +82,17 @@ export class Player {
70
82
  export class Nullable {}
71
83
  export type Null = Nullable | null;
72
84
 
85
+
73
86
  @json
74
87
  export class OmitIf {
75
88
  x: i32 = 1;
89
+
90
+
76
91
  @omitif("this.y == -1")
77
92
  y: i32 = -1;
78
93
  z: i32 = 1;
94
+
95
+
79
96
  @omitnull()
80
97
  foo: string | null = null;
81
98
  }
@@ -11,201 +11,192 @@ let POINTER = changetype<usize>(CACHE);
11
11
  @inline const MAX_CACHE = CACHE + MAX_LEN;
12
12
 
13
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
- }
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(len, idof<ArrayBuffer>());
155
+ memory.copy(out, CACHE, len);
156
+ bs.reset();
157
+ STORE.push(out);
158
+ }
159
+
160
+ // @ts-ignore
161
+ @inline export function out<T>(): T {
162
+ const len = POINTER - CACHE;
163
+ let out = __new(len + STORE_LEN, idof<T>());
164
+
165
+ memory.copy(out, CACHE, len);
166
+ if (STORE_LEN) {
167
+ out += len;
168
+ for (let i = 0; i < STORE.length; i++) {
169
+ const ptr = changetype<usize>(unchecked(STORE[i]));
170
+ const storeLen = changetype<OBJECT>(ptr - TOTAL_OVERHEAD).rtSize;
171
+ memory.copy(out, ptr, storeLen);
172
+ //__unpin(ptr);
173
+ out += storeLen;
174
+ }
175
+ STORE_LEN = 0;
176
+ }
177
+ bs.reset();
178
+
179
+ return changetype<T>(out);
180
+ }
181
+
182
+ // @ts-ignore
183
+ @inline export function out_u<T>(): T {
184
+ const len = POINTER - CACHE;
185
+ const out = __new(len + STORE_LEN, idof<T>());
186
+
187
+ memory.copy(out, CACHE, len);
188
+ bs.reset();
189
+
190
+ return changetype<T>(out);
191
+ }
192
+
193
+ // @ts-ignore
194
+ @inline export function _out(out: usize): void {
195
+ memory.copy(out, CACHE, POINTER - CACHE);
196
+ }
197
+
198
+ // @ts-ignore
199
+ @inline export function reset(): void {
200
+ POINTER = CACHE;
201
+ }
202
+ }
@@ -59,9 +59,9 @@
59
59
  // @ts-ignore: Decorator is valid here
60
60
  @inline export const BRACKET_RIGHT_WORD = "]";
61
61
  // @ts-ignore: Decorator is valid here
62
- @inline export const QUOTE_WORD = "\"";
62
+ @inline export const QUOTE_WORD = '"';
63
63
  // @ts-ignore: Decorator is valid here
64
- @inline export const EMPTY_QUOTE_WORD = "\"\"";
64
+ @inline export const EMPTY_QUOTE_WORD = '""';
65
65
 
66
66
  // Escape Codes
67
67
  // @ts-ignore: Decorator is valid here