A problem with Binary and Cereal, inherited by bytes, is that there is no good way to define endianness-dependant instances. One can use functions like putWord8be in an instance, but then nothing but commenting can indicate the endianness assumptions of that instance, not can another instance be made supporting a different endianness.
My solution is to separate dealing with endianness from dealing with serialization. Another library is used to convert the endianness various types (a library forked/made by myself, I'll admit less anybody accuse me of sneaky self-promotion). fix-endianness types are projected with a polymorphic newtype to avoid mixing up native and fix-endian values.
4 functions are defined, conditioned on a type having instances of both EndianSensitive from my library, and Serial, which prove a short hand for (de)serializing values with a specific endianness. Alternatively, those functions could be put in a typeclass, and the definitions using my library be provided as default instances.
A problem with Binary and Cereal, inherited by bytes, is that there is no good way to define endianness-dependant instances. One can use functions like
putWord8be
in an instance, but then nothing but commenting can indicate the endianness assumptions of that instance, not can another instance be made supporting a different endianness.My solution is to separate dealing with endianness from dealing with serialization. Another library is used to convert the endianness various types (a library forked/made by myself, I'll admit less anybody accuse me of sneaky self-promotion). fix-endianness types are projected with a polymorphic newtype to avoid mixing up native and fix-endian values.
4 functions are defined, conditioned on a type having instances of both EndianSensitive from my library, and Serial, which prove a short hand for (de)serializing values with a specific endianness. Alternatively, those functions could be put in a typeclass, and the definitions using my library be provided as default instances.