json-as 0.5.19 → 0.5.20
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/README.md +2 -20
- package/asconfig.json +2 -5
- package/assembly/__tests__/as-json.spec.ts +4 -3
- package/assembly/src/json.ts +8 -8
- package/assembly/test.ts +9 -1
- package/package.json +3 -3
- package/transform/package.json +1 -1
- package/assembly/Candle.ts +0 -18
package/README.md
CHANGED
|
@@ -73,28 +73,10 @@ const stringified = JSON.stringify<Player>(player);
|
|
|
73
73
|
const parsed = JSON.parse<Player>(stringified);
|
|
74
74
|
```
|
|
75
75
|
|
|
76
|
-
#
|
|
76
|
+
# Notes
|
|
77
77
|
|
|
78
|
-
|
|
78
|
+
Performance is nearly equal to the JavaScript JSON implementation which is in C++.
|
|
79
79
|
|
|
80
|
-
Yes, it does. However, dynamic objects and arrays are not supported, but planned in the near future.
|
|
81
|
-
|
|
82
|
-
**Is it fast?**
|
|
83
|
-
|
|
84
|
-
Look below
|
|
85
|
-
|
|
86
|
-
**How does it compare to other libs?**
|
|
87
|
-
|
|
88
|
-
Its pretty much the same as the other libraries out there (near/assemblyscript-json and @serial-as/json), but it focuses highly on performance
|
|
89
|
-
|
|
90
|
-
**Will it catch invalid JSON?**
|
|
91
|
-
|
|
92
|
-
No, it does not check for invalid JSON, but gives its best shot at parsing instead. Will probably throw an error.
|
|
93
|
-
|
|
94
|
-
**How does it compare performance-wise to other libraries?**
|
|
95
|
-
|
|
96
|
-
In my testing, parsing a Vector 2 runs at 2.2m ops/s with as-json and around 10,000 ops/s with assemblyscript-json and @serial-as/json.
|
|
97
|
-
Both are great libraries however.
|
|
98
80
|
## Performance
|
|
99
81
|
|
|
100
82
|
**Serialize Object (Vec2):** ~7.20m ops/s
|
package/asconfig.json
CHANGED
|
@@ -9,9 +9,9 @@ function canSerde<T>(data: T): void {
|
|
|
9
9
|
// @ts-ignore
|
|
10
10
|
@json
|
|
11
11
|
class Vec3 {
|
|
12
|
-
x:
|
|
13
|
-
y:
|
|
14
|
-
z:
|
|
12
|
+
x: f64;
|
|
13
|
+
y: f64;
|
|
14
|
+
z: f64;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
// @ts-ignore
|
|
@@ -136,6 +136,7 @@ describe("Ser/de Array", () => {
|
|
|
136
136
|
});
|
|
137
137
|
|
|
138
138
|
it("should ser/de string arrays", () => {
|
|
139
|
+
// ["abcdefg","st\\"ring\\" w\\"\\"ith quotes\\"","string \\t\\r\\"with ran\\tdom spa\\nces and \\nnewlines\\n\\n\\n","string with colon : comma , brace [ ] bracket { } and quote \\" and other quote \\""]
|
|
139
140
|
canSerde<string[]>([
|
|
140
141
|
"abcdefg",
|
|
141
142
|
'st"ring" w""ith quotes"',
|
package/assembly/src/json.ts
CHANGED
|
@@ -241,7 +241,7 @@ export function parseNumber<T>(data: string): T {
|
|
|
241
241
|
// @ts-ignore
|
|
242
242
|
const type: T = 0;
|
|
243
243
|
// @ts-ignore
|
|
244
|
-
if (type instanceof f64) return
|
|
244
|
+
if (type instanceof f64) return f64.parse(data);
|
|
245
245
|
// @ts-ignore
|
|
246
246
|
else if (type instanceof f32) return f32.parse(data);
|
|
247
247
|
// @ts-ignore
|
|
@@ -268,7 +268,7 @@ function parseObject<T>(data: string): T {
|
|
|
268
268
|
let schema: nonnull<T> = changetype<nonnull<T>>(__new(offsetof<nonnull<T>>(), idof<nonnull<T>>()));
|
|
269
269
|
let key = "";
|
|
270
270
|
let isKey = false;
|
|
271
|
-
let depth =
|
|
271
|
+
let depth = 0;
|
|
272
272
|
let char = 0;
|
|
273
273
|
let outerLoopIndex = 1;
|
|
274
274
|
for (; outerLoopIndex < data.length - 1; outerLoopIndex++) {
|
|
@@ -281,10 +281,10 @@ function parseObject<T>(data: string): T {
|
|
|
281
281
|
) {
|
|
282
282
|
char = unsafeCharCodeAt(data, arrayValueIndex);
|
|
283
283
|
if (char === leftBracketCode) {
|
|
284
|
-
depth
|
|
284
|
+
depth++;
|
|
285
285
|
} else if (char === rightBracketCode) {
|
|
286
|
-
depth
|
|
287
|
-
if (depth ===
|
|
286
|
+
depth--;
|
|
287
|
+
if (depth === 0) {
|
|
288
288
|
++arrayValueIndex;
|
|
289
289
|
// @ts-ignore
|
|
290
290
|
schema.__JSON_Set_Key(key, data.slice(outerLoopIndex, arrayValueIndex));
|
|
@@ -302,10 +302,10 @@ function parseObject<T>(data: string): T {
|
|
|
302
302
|
) {
|
|
303
303
|
char = unsafeCharCodeAt(data, objectValueIndex);
|
|
304
304
|
if (char === leftBraceCode) {
|
|
305
|
-
depth
|
|
305
|
+
depth++;
|
|
306
306
|
} else if (char === rightBraceCode) {
|
|
307
|
-
depth
|
|
308
|
-
if (depth ===
|
|
307
|
+
depth--;
|
|
308
|
+
if (depth === 0) {
|
|
309
309
|
++objectValueIndex;
|
|
310
310
|
// @ts-ignore
|
|
311
311
|
schema.__JSON_Set_Key(key, data.slice(outerLoopIndex, objectValueIndex));
|
package/assembly/test.ts
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import { u128 } from "as-bignum/assembly";
|
|
2
|
-
import { Candle } from "./Candle";
|
|
3
2
|
import {
|
|
4
3
|
JSON
|
|
5
4
|
} from ".";
|
|
6
5
|
|
|
6
|
+
const exp = `["abcdefg","st\\"ring\\" w\\"\\"ith quotes\\"","string \\t\\r\\"with ran\\tdom spa\\nces and \\nnewlines\\n\\n\\n","string with colon : comma , brace [ ] bracket { } and quote \\" and other quote \\""]`;
|
|
7
|
+
|
|
8
|
+
console.log(exp);
|
|
9
|
+
console.log(JSON.stringify([
|
|
10
|
+
"abcdefg",
|
|
11
|
+
'st"ring" w""ith quotes"',
|
|
12
|
+
'string \t\r"with ran\tdom spa\nces and \nnewlines\n\n\n',
|
|
13
|
+
'string with colon : comma , brace [ ] bracket { } and quote " and other quote "',
|
|
14
|
+
]))
|
|
7
15
|
// @ts-ignore
|
|
8
16
|
@JSON
|
|
9
17
|
class Vec3 {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "json-as",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.20",
|
|
4
4
|
"description": "JSON encoder/decoder for AssemblyScript",
|
|
5
5
|
"types": "assembly/index.ts",
|
|
6
6
|
"author": "Jairus Tanaka",
|
|
@@ -25,7 +25,6 @@
|
|
|
25
25
|
"@as-tral/cli": "^2.0.0",
|
|
26
26
|
"@assemblyscript/loader": "^0.27.0",
|
|
27
27
|
"@assemblyscript/wasi-shim": "^0.1.0",
|
|
28
|
-
"as-bignum": "^0.2.23",
|
|
29
28
|
"assemblyscript": "^0.27.0",
|
|
30
29
|
"assemblyscript-prettier": "^1.0.7",
|
|
31
30
|
"prettier": "^2.8.3",
|
|
@@ -34,7 +33,8 @@
|
|
|
34
33
|
},
|
|
35
34
|
"dependencies": {
|
|
36
35
|
"as-string-sink": "^0.5.0",
|
|
37
|
-
"as-variant": "^0.4.1"
|
|
36
|
+
"as-variant": "^0.4.1",
|
|
37
|
+
"as-bignum": "^0.2.23"
|
|
38
38
|
},
|
|
39
39
|
"repository": {
|
|
40
40
|
"type": "git",
|
package/transform/package.json
CHANGED
package/assembly/Candle.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
JSON
|
|
3
|
-
} from ".";
|
|
4
|
-
@json
|
|
5
|
-
export class Candle {
|
|
6
|
-
timestamp!: i64;
|
|
7
|
-
high!: f64;
|
|
8
|
-
low!: f64;
|
|
9
|
-
open!: f64;
|
|
10
|
-
close!: f64;
|
|
11
|
-
constructor(timestamp: i64, high: f64, low: f64, open: f64, close: f64) {
|
|
12
|
-
this.timestamp = timestamp;
|
|
13
|
-
this.high = high;
|
|
14
|
-
this.low = low;
|
|
15
|
-
this.open = open;
|
|
16
|
-
this.close = close;
|
|
17
|
-
}
|
|
18
|
-
}
|