module Network.MessagePack.Types.Spec ( Request , Response , packRequest , packResponse , unpackRequest , unpackResponse ) where import qualified Data.ByteString.Lazy as L import qualified Data.List as List import Data.MessagePack (MessagePack, Object, fromObject, pack) type Request ix = (Int, Int, ix, [Object]) type Response = (Int, Int, Object, Object) packRequest :: (Eq mth, MessagePack mth) => [mth] -> Request mth -> L.ByteString packRequest :: [mth] -> Request mth -> ByteString packRequest [] Request mth req = Request mth -> ByteString forall a. MessagePack a => a -> ByteString pack Request mth req packRequest [mth] mths req :: Request mth req@(Int rtype, Int msgid, mth mth, [Object] obj) = case mth -> [mth] -> Maybe Int forall a. Eq a => a -> [a] -> Maybe Int List.elemIndex mth mth [mth] mths of Maybe Int Nothing -> Request mth -> ByteString forall a. MessagePack a => a -> ByteString pack Request mth req Just Int ix -> (Int, Int, Int, [Object]) -> ByteString forall a. MessagePack a => a -> ByteString pack (Int rtype, Int msgid, Int ix, [Object] obj) packResponse :: Response -> L.ByteString packResponse :: Response -> ByteString packResponse = Response -> ByteString forall a. MessagePack a => a -> ByteString pack unpackResponse :: Object -> Maybe Response unpackResponse :: Object -> Maybe Response unpackResponse = Object -> Maybe Response forall a (m :: * -> *). (MessagePack a, Applicative m, Monad m, MonadFail m) => Object -> m a fromObject unpackRequest :: MessagePack ix => Object -> Maybe (Request ix) unpackRequest :: Object -> Maybe (Request ix) unpackRequest = Object -> Maybe (Request ix) forall a (m :: * -> *). (MessagePack a, Applicative m, Monad m, MonadFail m) => Object -> m a fromObject