json-as 0.9.8-a → 0.9.8-b

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
@@ -14,6 +14,7 @@ v0.9.6 - Fix bugs
14
14
  v0.9.7 - Update testing framework and readme logo
15
15
  v0.9.8 - Update dependencies
16
16
  v0.9.8a - Fix #80 - Empty Maps were not serialized to {}, instead, threw memory out of bounds
17
+ v0.9.8b - Fix #81 - Revert transform
17
18
  [UNRELEASED] v0.9.9
18
19
  - Allow nullable primitives
19
20
  - Port over JSON.Value
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  __| || __|| || | | ___ | _ || __|
4
4
  | | ||__ || | || | | ||___|| ||__ |
5
5
  |_____||_____||_____||_|___| |__|__||_____|
6
- v0.9.8a
6
+ v0.9.8b
7
7
  </pre>
8
8
  </h5>
9
9
 
package/assembly/index.ts CHANGED
@@ -302,4 +302,14 @@ export namespace JSON {
302
302
  );
303
303
  }
304
304
  }
305
+ }
306
+
307
+ // This allows JSON.stringify and JSON.parse to be available globally through an alias
308
+ // @ts-ignore: Decorator
309
+ @global function __SERIALIZE<T>(data: T): string {
310
+ return JSON.stringify(data);
311
+ }
312
+ // @ts-ignore: Decorator
313
+ @global function __DESERIALIZE<T>(data: string): T {
314
+ return JSON.parse<T>(data);
305
315
  }
package/assembly/test.ts CHANGED
@@ -1,85 +1,14 @@
1
- import {
2
- __atoi_fast
3
- } from "json-as/assembly/util";
4
- import {
5
- JSON as __JSON
6
- } from "json-as/assembly";
7
- import {
8
- JSON
9
- } from ".";
1
+ import { JSON } from "json-as/assembly";
2
+ import * as console from "as-console";
10
3
  @json
11
- class Inner {
12
- name: string;
13
- constructor(name: string) {
14
- this.name = name;
15
- }
16
- __SERIALIZE(): string {
17
- let out = `{"name":${__JSON.stringify<string>(this.name)},`;
18
- store<u16>(changetype<usize>(out) + ((out.length - 1) << 1), 125);
19
- return out;
20
- }
21
- __INITIALIZE(): this {
22
- return this;
23
- }
24
- __DESERIALIZE(data: string, key_start: i32, key_end: i32, value_start: i32, value_end: i32): boolean {
25
- const len = key_end - key_start;
26
- if (4 === len) {
27
- const code = load<u64>(changetype<usize>(data) + (key_start << 1));
28
- if (28429440805568622 === code) {
29
- this.name = __JSON.parse<string>(data.substring(value_start, value_end));
30
- return true;
31
- } else {
32
- return false;
33
- }
34
- }
35
- return false;
36
- }
37
- }
38
- @json
39
- class Outer {
40
- name: string;
41
- m: Map<string, Inner>;
42
- constructor(name: string) {
43
- this.name = name;
44
- this.m = new Map<string, Inner>();
45
- }
46
- __SERIALIZE(): string {
47
- let out = `{"name":${__JSON.stringify<string>(this.name)},"m":${__JSON.stringify<Map<string, Inner>>(this.m)},`;
48
- store<u16>(changetype<usize>(out) + ((out.length - 1) << 1), 125);
49
- return out;
50
- }
51
- __INITIALIZE(): this {
52
- return this;
53
- }
54
- __DESERIALIZE(data: string, key_start: i32, key_end: i32, value_start: i32, value_end: i32): boolean {
55
- const len = key_end - key_start;
56
- if (1 === len) {
57
- switch (load<u16>(changetype<usize>(data) + (key_start << 1))) {
58
- case 109:
59
- {
60
- this.m = __JSON.parse<Map<string, Inner>>(data.substring(value_start, value_end));
61
- return true;
62
- }
4
+ class Yo {
5
+ map: Map<string, u64>;
63
6
 
64
- default:
65
- {
66
- return false;
67
- }
68
-
69
- }
70
- } else if (4 === len) {
71
- const code = load<u64>(changetype<usize>(data) + (key_start << 1));
72
- if (28429440805568622 === code) {
73
- this.name = __JSON.parse<string>(data.substring(value_start, value_end));
74
- return true;
75
- } else {
76
- return false;
77
- }
78
- }
79
- return false;
7
+ constructor() {
8
+ this.map = new Map();
80
9
  }
81
10
  }
82
11
 
83
- console.log(JSON.stringify(new Map<string, Inner>()))
84
- let serializedState = JSON.stringify(new Outer("haadf"));
85
- console.log(serializedState);
12
+ let y = new Yo();
13
+ y.map.set("bhavya", 3000);
14
+ console.log(JSON.stringify(y));
Binary file