Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
JairusSW committed May 13, 2024
1 parent ca62bf3 commit 68d9ce3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
7 changes: 4 additions & 3 deletions assembly/deserialize/boolean.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Result } from "as-container";
import { fCode, tCode } from "../src/chars";
import { unsafeCharCodeAt } from "../src/util";

// @ts-ignore: Decorator
@inline export function deserializeBoolean(data: string): boolean {
@inline export function deserializeBoolean(data: string): Result<boolean, string> {
const firstChar = unsafeCharCodeAt(data, 0);
if (firstChar === tCode && load<u64>(changetype<usize>(data)) === 28429475166421108) return true;
else if (firstChar === fCode && load<u64>(changetype<usize>(data), 2) === 28429466576093281) return false;
if (firstChar === tCode && load<u64>(changetype<usize>(data)) === 28429475166421108) return Result.Ok(true);
else if (firstChar === fCode && load<u64>(changetype<usize>(data), 2) === 28429466576093281) return Result.Ok(false);
else throw new Error(`JSON: Cannot parse "${data}" as boolean`);
}
2 changes: 1 addition & 1 deletion assembly/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export namespace JSON {
return __atoi_fast<T>(data);
} else if (idof<T>() === idof<JSON.Value>()) {
// @ts-ignore: Returns T
return deserializeUnknown(data).unwrap();
return deserializeUnknown(data);
}
throw new Error(`Could not deserialize data of type ${nameof<T>()}`);
}
Expand Down
4 changes: 3 additions & 1 deletion assembly/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,6 @@ map.set("y", JSON.Value.from<f64>(1.2));
map.set("z", JSON.Value.from<f64>(-5.6));

console.log(JSON.serialize(vec).toString());
console.log(JSON.serialize(map).toString());
console.log(JSON.serialize(map).toString());

console.log(JSON.parse<string>("\"hello world\"").unwrap());

0 comments on commit 68d9ce3

Please sign in to comment.