为什么我的 ByteString 在我的 x86_64 架构上是 BigEndian 格式?

Why is my ByteString in BigEndian Format on my x86_64 architecture?

此代码:

import Data.Binary
import qualified Data.ByteString.Internal as BS (c2w, w2c)
import qualified Data.ByteString.Lazy as B
import Data.Int

main :: IO ()
main = do
  B.putStr $ encode $ (0x01020304 :: Int32)

在我的机器上产生这个输出(运行 到 xxd):

00000000: 0102 0304                                ....

这告诉我它是按大端顺序输出的,但是我有一个 x86_64 系统,所以...这是怎么回事?

Data.Binary模块在documentation中指定:

Values encoded using the Binary class are always encoded in network order (big endian) form, and encoded data should be portable across machine endianness, word size, or compiler version. For example, data encoded using the Binary class could be written on any machine, and read back on any another.

因此它不适用于机器的 then endianess,但总是使用 big endian,这样编码一个对象到 ByteString,也可以用另一台机器解码。