
Christopher Kohlhoff wrote:
I see that enum endianness have a 'native' option. This looks a bit weird to me. If I want to use native endianness, why should I use a class named 'endian'?
You might be writing code that cares about endianness, and need to use native endianness in some places, and big- or little-endian integers in others.
One example is receiver makes right protocols, where the message is always transmitted using the sender's endianness. When a message is received it could be either big- or little-endian.
I failed to understand. In a 'receiver makes right' protocols, as you describe it, the sender sends the data it in its native endianness. I assume it probably also sends the type of its native endianness, big or little, otherwise the receiver won't be able to know it. Then, the receiver reads the endianness, and then reads all data according to it (which means run-time selection of endianness, hopefully possible using boost::variant). All of this is great, but I can't see the relevance to the existence of a 'native' option in the endianness enum, sorry. Can you elaborate, please? Yuval