dmendel / bindata

BinData - Reading and Writing Binary Data in Ruby
BSD 2-Clause "Simplified" License
577 stars 55 forks source link

Native endianness #92

Closed vihai closed 7 years ago

vihai commented 7 years ago

Hello,

There are cases, for example the NetLink protocol, that use the native system endianness. It would be convenient to be able to specify a "native" endianness. Now I'm using a workaround like:

    endian ([1].pack("S") == "\x00\x01") ? :big : :little
dmendel commented 7 years ago

If you are writing for a single architecture, then specify either :little or :big as appropriate.

In the rare case that you are writing for multiple architectures, then your above workaround is fine.

I am deliberately not supporting endian :native, as native endian is often a source of bugs. The complicated declaration reminds the reader that it is not a simple as :little or :big.

vihai commented 7 years ago

I am writing a pure ruby gem thus I don't know in advance on what architecture it will be run. The NetLink protocol is spoken between userland and the kernel and it uses the native endianness since it is strictly local.

I honestly don't see why you don't want to support these legitimate cases but it's not a big issue, it's just that the workaround is very, very ugly.