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

Add optional Little Endian support #45

Closed
TyOverby opened this issue Sep 30, 2015 · 10 comments
Closed

Add optional Little Endian support #45

TyOverby opened this issue Sep 30, 2015 · 10 comments
Milestone

Comments

@TyOverby
Copy link
Collaborator

Once RFC 213 is implemented, we should allow optional endiannes to be added to the bincode encoders and decoders.

bincode::encode(something);
bincode::encode::<LittleEndian>(something);
@emberian
Copy link

Why is it big endian by default anyway?

@TyOverby
Copy link
Collaborator Author

@cmr: something about network byte order. Was probably a mistake. In the next breaking change I'll likely fix it.

@aldanor
Copy link

aldanor commented Jan 30, 2017

Looking forward to this as well. It looks like RFC 213 is a good while from being stabilised due to uncertainty re: integer fallback, so maybe providing an explicit endianness parameter (or type parameter), or even encode_be(), encode_le() would be great.

@TyOverby
Copy link
Collaborator Author

@aldanor

What would you think about having the default methods use big-endian, but have an module with endian-choice methods?

once 213 lands, it would be easy to deprecate that module, but in the meantime, it wouldn't hurt new users that don't care about endianness.

Or maybe choosing endianness isn't that big of a deal and we should just make everyone do it until default method parameters land?

@mikedilger
Copy link
Contributor

I'd be using this too. I'd be happy with a temporary separate module.

@aldanor
Copy link

aldanor commented Jan 31, 2017

There's a few equally valid choices here; I personally think it's also important to be able to serialise with native endianness (use case: serialising a sequence of structs to disk and them reading them back via python/numpy or other process on the same box/cpu which would use the native byte order by default). byteorder already provides NativeEndian so that's easy.

Off top of my head, I would probably expect a binary serialisation library to use native byte order unless explicit endianness is specified by the user. This has most chances to work for careless cross-process communication. Second best would be little endian since that's what all Intel CPUs are... most unexpected would probably be big endian (for general-purpose encoding/decoding, that is).

I wouldn't mind having to provide endianness explicitly though, until 213 lands (if it lands); then it's a separate choice of selecting a sensible default :)

@TyOverby
Copy link
Collaborator Author

TyOverby commented Jan 31, 2017

Honestly I'm leaning towards explicit endianness right now. It doesn't seem like a huge hit to usability and makes it pretty obvious what's going on.

@TyOverby
Copy link
Collaborator Author

I'm just hoping that I don't get hit with bugs from people using different endianness for encoding and decoding...

@burdges
Copy link

burdges commented Feb 18, 2017

In C, there is a slight advantage to using "network byte order" aka big endian because you must write every endian conversion manually, so if you leave one out then it breaks on your little endian development machine, but this does not apply to Rust. In Rust, one should probably specify the endianness in a type parameter, not sure all type parameters accept defaults though.

@aldanor
Copy link

aldanor commented Feb 18, 2017

cf. #103

@TyOverby TyOverby modified the milestone: 1.0 Feb 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants