Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support selecting endianness for numeric types #31

Open
ygale opened this issue May 26, 2016 · 4 comments
Open

Support selecting endianness for numeric types #31

ygale opened this issue May 26, 2016 · 4 comments

Comments

@ygale
Copy link

ygale commented May 26, 2016

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.

@mgsloan
Copy link
Owner

mgsloan commented May 31, 2016

Good ideas!

Newtype wrappers LitteEndian, BigEndian, and HostEndian

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.

@mgsloan
Copy link
Owner

mgsloan commented May 31, 2016

One of the primary reasons store does not yet have machine independent serialization stuff is that I'd like to support it safely - #36 - and that's a fair chunk of work. It gets particularly complicated with better support for alignment #37

@ygale
Copy link
Author

ygale commented Jun 1, 2016

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.

@mgsloan
Copy link
Owner

mgsloan commented Jun 1, 2016

Based on the design in #36, LittleEndian would also be unnecessary, as it would be assumed and equivalent to HostEndian. So that leaves us with just a BigEndian that could be applied to numeric types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants