module Data.MessagePack (
pack
, unpack
, module X
) where
import Control.Applicative (Applicative)
import Control.Monad ((>=>))
import Data.Binary (decodeOrFail, encode)
import qualified Data.ByteString.Lazy as L
import Data.MessagePack.Assoc as X
import Data.MessagePack.Class as X
import Data.MessagePack.Generic ()
import Data.MessagePack.Get as X
import Data.MessagePack.Object as X
import Data.MessagePack.Put as X
pack :: MessagePack a => a -> L.ByteString
pack = encode . toObject
unpack :: (Applicative m, Monad m, MessagePack a)
=> L.ByteString -> m a
unpack = eitherToM . decodeOrFail >=> fromObject
where
eitherToM (Left (_, _, msg)) = fail msg
eitherToM (Right (_, _, res)) = return res