Remix.run Logo
j16sdiz 4 hours ago

If you comes to low level network protocol (e.g. writing a TCP stack), the "network byte order" is always big-endian.

edflsafoiewq 2 hours ago | parent | next [-]

That's a serialization format.

7jjjjjjj 2 hours ago | parent | prev | next [-]

It goes without saying that all binary network protocols should document their byte order, and that if you're implementing a protocol documented as big endian you should use ntohl and friends to ensure correctness.

However if designing a new network protocol, choosing big endian is insanity. Use little endian, skip the macros, and just add

  #ifndef LITTLE_ENDIAN
    #error
Or the like to a header somewhere.
AnthonyMouse an hour ago | parent [-]

What does it actually cost you to define a macro which is a no-op on little endian architectures and then use it at the point of serialization/deserialization?

kccqzy 15 minutes ago | parent [-]

A lot because to the compiler a no-op macro is the same as not having the macro in the same place so it won’t catch cases where you should use the macro but didn’t. Then you just give yourself a false sense of security unless you actually test on big endian.

whizzter 2 hours ago | parent | prev | next [-]

And honestly at this point it's mostly a historical artifact, if we write that kind of stuff then sure we need to care but to produce modern stuff is a honestly massive waste of time at this point.

FWIW I doing hobby-stuff for Amiga's (68k big-endian) but that's just that, hobby stuff.

skrtskrt 4 hours ago | parent | prev [-]

Prometheus index format is also a big-endian binary file - haven’t found any reference to why it was chosen.