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 +1 -0
- package/README.md +1 -1
- package/assembly/index.ts +10 -0
- package/assembly/test.ts +9 -80
- package/build/test.spec.wasm +0 -0
- package/build/test.spec.wasm.map +1 -1
- package/build/test.spec.wat +9514 -11878
- package/build/test.wasm +0 -0
- package/build/test.wasm.map +1 -1
- package/build/test.wat +4677 -3358
- package/package.json +3 -2
- package/transform/lib/index.js +21 -256
- package/transform/package.json +1 -1
- package/transform/src/index.ts +25 -360
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
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
|
-
|
|
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
|
|
12
|
-
|
|
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
|
-
|
|
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
|
-
|
|
84
|
-
|
|
85
|
-
console.log(
|
|
12
|
+
let y = new Yo();
|
|
13
|
+
y.map.set("bhavya", 3000);
|
|
14
|
+
console.log(JSON.stringify(y));
|
package/build/test.spec.wasm
CHANGED
|
Binary file
|