Support selecting endianness for numeric types
ygale opened this issue · 4 comments
Make it possible to specify the endianness of the serialization for numeric types.
This could be implemented as newtype wrappers LitteEndian
, BigEndian
, and HostEndian
. Or it could be a bunch of separate combinators, as in binary and cereal.
Good ideas!
Newtype wrappers
LitteEndian
,BigEndian
, andHostEndian
This would enable TH / generics to write your serialization definitions. I'm not sure how to make these work on larger datatypes (LittleEndian MyADT
), or whether one would even want that.
HostEndian
should be assumed. So that leaves us with explicit LittleEndian
/ BigEndian
for the numeric types (probably everything Storable
).
Or it could be a bunch of separate combinators, as in binary and cereal.
It makes a lot of sense to expose getInt32
/ getInt32be
operators from some module. This will allow for processing existing binary formats. While it'd be more consistent for these to start with peek
, this would make it compatible with binary
/ cereal
to aid porting! I've opened #35 on this topic.
The only reason I included HostEndian
is so that the current built-in default endianness is not exposed. That way it could later be changed without breaking code for people who care about endianness. Up to you whether that is worth the bit of extra noise.
Right, these only make sense for specific types that have built-in support for endianness. We could enforce that in the types if you want.