Skip to content

Commit

Permalink
fix: #69
Browse files Browse the repository at this point in the history
  • Loading branch information
JairusSW committed May 16, 2024
1 parent 4e39b94 commit d814684
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
5 changes: 5 additions & 0 deletions assembly/__tests__/as-json.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ describe("Ser/de Array", () => {

canSerde<i32[]>([0, 100, 101, -100, -101]);
canSerde<i64[]>([0, 100, 101, -100, -101]);
canDeser<i32[]>(`[
1,
2,
3
]`, [1,2,3]);
});

it("should ser/de float arrays", () => {
Expand Down
14 changes: 5 additions & 9 deletions assembly/src/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -808,22 +808,18 @@ export namespace JSON {
const result = instantiate<T>();
let lastPos = 0;
let i = 1;
for (; i < data.length - 1; i++) {
let awaitingParse = false;
for (; i < data.length; i++) {
const char = unsafeCharCodeAt(data, i);
if (lastPos === 0 && ((char >= 48 && char <= 57) || char === 45)) {
awaitingParse = true;
lastPos = i;
} else if ((isSpace(char) || char == commaCode) && lastPos > 0) {
} else if (awaitingParse && (isSpace(char) || char == commaCode || char == rightBracketCode) && lastPos > 0) {
awaitingParse = false;
result.push(parseNumber<valueof<T>>(data.slice(lastPos, i)));
lastPos = 0;
}
}
for (; i > lastPos - 1; i--) {
const char = unsafeCharCodeAt(data, i);
if (char !== rightBracketCode) {
result.push(parseNumber<valueof<T>>(data.slice(lastPos, i + 1)));
break;
}
}
return result;
}

Expand Down
12 changes: 6 additions & 6 deletions assembly/test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { JSON } from "./src/json";
import { Person } from "./p"
const person = new Person(1);
person.staticprng = 32
let result = JSON.stringify<Person>(person);
console.log(JSON.stringify(JSON.parse<Person>(result)));
console.log(result);

console.log(JSON.stringify(JSON.parse<f64[]>(`[
1,
2,
3
]`)));

0 comments on commit d814684

Please sign in to comment.