{-# LANGUAGE Safe #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Data.MessagePack (
pack
, unpack
, module X
) where
import Control.Applicative (Applicative)
import Control.Monad ((>=>))
import Data.Binary (Binary (..), decodeOrFail, encode)
import qualified Data.ByteString.Lazy as L
import Data.MessagePack.Get as X
import Data.MessagePack.Put as X
import Data.MessagePack.Types 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
instance Binary Object where
get = getObject
{-# INLINE get #-}
put = putObject
{-# INLINE put #-}