On platform where int are 32 bits, toFlatty (or fromFlatty depending on your POV) is incorrect.
fromFlatty always assumes that an int is 64 bits.
proc fromFlatty*(s: string, i: var int, x: var int) =
x = s.readInt64(i).int
i += 8
But toFlatty(s: var string, x: int) does not exist, so when serializing, int32 is picked, which is incorrect.
This leads to a crash during deserialization.
While most computers are 64 bits nowadays, this is an issue when compiling for webassembly.
The simplest solution would be to write a toFlatty(s: var string, x: int) function that calls the correct function depending on the platform.
This should have no performance cost.
On platform where
intare 32 bits,toFlatty(orfromFlattydepending on your POV) is incorrect.fromFlattyalways assumes that an int is 64 bits.But
toFlatty(s: var string, x: int)does not exist, so when serializing, int32 is picked, which is incorrect.This leads to a crash during deserialization.
While most computers are 64 bits nowadays, this is an issue when compiling for webassembly.
The simplest solution would be to write a
toFlatty(s: var string, x: int)function that calls the correct function depending on the platform.This should have no performance cost.