Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

msgpack: haskell & python

I'm confused by the differences between haskell and python clients for msgpack. This:

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

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

and this:

import msgpack

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

give me the different files:

$ diff test_haskell test_python
Binary files test_haskell and test_python differ

Can anybody explain, what I'm doing wrong? Maybe I misunderstood something about ByteString usage?

like image 255
erthalion Avatar asked Jan 09 '23 18:01

erthalion


1 Answers

The empty tuple () in Haskell is not like empty tuple or empty list in Python. It's similar to None in Python. (in the context of msgpack).

So to get the same result, change the haskell program as:

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

Or change the python program as:

f.write(msgpack.packb([0, 2, 28, None]))

See a demo.

like image 81
falsetru Avatar answered Jan 18 '23 10:01

falsetru