我对 msgpack 的 haskellpython 客户端之间的差异感到困惑。
这:

import Data.MessagePack as MP
import Data.ByteString.Lazy as BL

BL.writeFile "test_haskell" $ MP.pack (0, 2, 28, ())

和这个:
import msgpack

with open("test_python", "w") as f:
    f.write(msgpack.packb([0, 2, 28, []]))

给我不同的文件:
$ diff test_haskell test_python
Binary files test_haskell and test_python differ

谁能解释一下,我做错了什么?也许我误解了 ByteString 的用法?

最佳答案

Haskell 中的空元组 () 与 Python 中的空元组或空列表不同。它类似于 Python 中的 None。 (在 msgpack 的上下文中)。

因此,要获得相同的结果,请将 haskell 程序更改为:

MP.pack (0, 2, 28, [])  -- empty list

或者将python程序更改为:
f.write(msgpack.packb([0, 2, 28, None]))

See a demo.

关于python - msgpack:haskell 和 python,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25950447/

10-10 11:08