-
-
Notifications
You must be signed in to change notification settings - Fork 147
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
Consider adding runtime-defined endianness #41
Comments
@netvl Hmm, is there any particular reason why |
@netvl Oh, I misread your question. I guess I'm not following. What code have you tried? You should be able to invoke either endianness by calling e.g., |
I'd like to pass the actual endianness to read functions at runtime, something like let byte_order = if <some check> { LittleEndian } else { BigEndian };
let n = source.read_u16(byte_order); Here the required byte order is determined at runtime. I also can't use |
@netvl Define some helper functions? e.g., enum Endian { Little, Big }
fn read_u16(source: &[u8], endian: Endian) -> byteorder::Result<u16> {
match endian {
Endian::Little => byteorder::LittleEndian::read_u16(source),
Endian::Big => byteorder::BigEndian::read_u16(source),
}
}
read_u16(&[...], Endian::Little) |
Well, yes, that's what I've done. I've written an extension trait for |
@netvl I see. I'm not totally convinced the added API surface is really worth it ("I'm trying to use byteorder but there are three different ways to read a big endian number, which one should I use?"). I can see how they would be useful occasionally though. |
Maybe this problem is solved by the proper documentation. Something along the following lines:
|
copied from: https://github.com/netvl/immeta/blob/4460ee/src/utils.rs workaround for: BurntSushi/byteorder#41
I still personally feel like expecting one to write a helper function for this is perfectly fine. I'd really rather not make the API more complex than it already is. |
copied from: https://github.com/netvl/immeta/blob/4460ee/src/utils.rs workaround for: BurntSushi/byteorder#41
copied from: https://github.com/netvl/immeta/blob/4460ee/src/utils.rs workaround for: BurntSushi/byteorder#41
copied from: https://github.com/netvl/immeta/blob/4460ee/src/utils.rs workaround for: BurntSushi/byteorder#41
Sometimes it is impossible to statically determine required endianness in advance. For example, TIFF image format defines endianness in the first byte of an input file, so it may be either big or little but which exactly is unknown statically. It would be nice if I could use
byteorder
for this task too.The text was updated successfully, but these errors were encountered: