composewell / streamly

High performance, concurrent functional programming abstractions
https://streamly.composewell.com
Other
859 stars 65 forks source link

Byte-ordering in serialization #2707

Open harendra-kumar opened 8 months ago

harendra-kumar commented 8 months ago

The Unbox type class is meant to serialize the Haskell data structures in the host memory. There is absolutely no need to change the endianness in this case when copying structures to/from host memory.

When we designed the Serialize type class we modeled it on Unbox and kept is compatible with Unbox. Though there is no need to do that. The Serialize type class also uses the host byte order when serializing. But we can support portable byte-ordering as well if there is a need for that. One way is to fix the byte-ordering of the Serialize type class to LE or have SerializeLE or SerializeBE type classes for that purpose. Another way is to use BE/LE as an option in Serialize deriving.