ekmett / bytes

Serialization primitives that work with both cereal and binary.
http://hackage.haskell.org/package/bytes
Other
22 stars 13 forks source link

Adding a standard way to define Serial instances that depend on endianness #8

Closed Ericson2314 closed 11 years ago

Ericson2314 commented 11 years ago

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.

ekmett commented 11 years ago

Closing this without merging based on our discussion on IRC.