Skip to content

Commit

Permalink
Deserialize BigInts
Browse files Browse the repository at this point in the history
  • Loading branch information
bartblast committed Oct 19, 2024
1 parent 8472e43 commit 492253c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
4 changes: 4 additions & 0 deletions assets/js/deserializer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ export default class Deserializer {
return Type.atom(value.slice(9));
}

if (value.startsWith("__bigint__:")) {
return BigInt(value.slice(11));
}

if (value.startsWith("__binary__:")) {
return Type.bitstring(value.slice(11));
}
Expand Down
25 changes: 25 additions & 0 deletions test/javascript/deserializer_test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -229,5 +229,30 @@ describe("Deserializer", () => {
});
});
});

describe("JS terms", () => {
describe("BigInt", () => {
const bigint = 123n;

it("top-level", () => {
const serialized = serialize(bigint);

assert.equal(deserialize(serialized), bigint);
});

it("nested", () => {
const term = {a: bigint, b: 2};
const serialized = serialize(term);

assert.deepStrictEqual(deserialize(serialized), term);
});

it("not versioned", () => {
const serialized = serialize(bigint, true, false);

assert.equal(deserialize(serialized, false), bigint);
});
});
});
});
});

0 comments on commit 492253c

Please sign in to comment.