{-# LANGUAGE CPP #-}
{-# LANGUAGE DefaultSignatures #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE IncoherentInstances #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE Trustworthy #-}
module Data.MessagePack.Types.Class
( MessagePack (..)
, GMessagePack (..)
) where
import Control.Applicative (Applicative, (<$>), (<*>))
import Control.Arrow ((***))
import qualified Data.ByteString as S
import qualified Data.ByteString.Lazy as L
import qualified Data.HashMap.Strict as HashMap
import Data.Hashable (Hashable)
import Data.Int (Int16, Int32, Int64, Int8)
import qualified Data.IntMap.Strict as IntMap
import qualified Data.Map as Map
import qualified Data.Text as T
import qualified Data.Text.Lazy as LT
import qualified Data.Vector as V
import qualified Data.Vector.Storable as VS
import qualified Data.Vector.Unboxed as VU
import Data.Word (Word, Word16, Word32, Word64,
Word8)
import GHC.Generics (Generic, Rep, from, to)
import Data.MessagePack.Types.Assoc (Assoc (..))
import Data.MessagePack.Types.Object (Object (..))
class GMessagePack f where
gToObject :: f a -> Object
gFromObject
:: ( Applicative m
, Monad m
#if (MIN_VERSION_base(4,13,0))
, MonadFail m
#endif
)
=> Object
-> m (f a)
class MessagePack a where
toObject :: a -> Object
fromObject
:: ( Applicative m
, Monad m
#if (MIN_VERSION_base(4,13,0))
, MonadFail m
#endif
)
=> Object
-> m a
default toObject :: (Generic a, GMessagePack (Rep a)) => a -> Object
toObject = a -> Object
forall a. (Generic a, GMessagePack (Rep a)) => a -> Object
genericToObject
default fromObject
:: ( Applicative m
, Monad m
#if (MIN_VERSION_base(4,13,0))
, MonadFail m
#endif
, Generic a, GMessagePack (Rep a))
=> Object
-> m a
fromObject = Object -> m a
forall (m :: * -> *) a.
(Applicative m, Monad m, MonadFail m, Generic a,
GMessagePack (Rep a)) =>
Object -> m a
genericFromObject
genericToObject :: (Generic a, GMessagePack (Rep a)) => a -> Object
genericToObject :: a -> Object
genericToObject = Rep a Any -> Object
forall (f :: * -> *) a. GMessagePack f => f a -> Object
gToObject (Rep a Any -> Object) -> (a -> Rep a Any) -> a -> Object
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Rep a Any
forall a x. Generic a => a -> Rep a x
from
genericFromObject
:: ( Applicative m
, Monad m
#if (MIN_VERSION_base(4,13,0))
, MonadFail m
#endif
, Generic a
, GMessagePack (Rep a)
)
=> Object
-> m a
genericFromObject :: Object -> m a
genericFromObject Object
x = Rep a Any -> a
forall a x. Generic a => Rep a x -> a
to (Rep a Any -> a) -> m (Rep a Any) -> m a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object -> m (Rep a Any)
forall (f :: * -> *) (m :: * -> *) a.
(GMessagePack f, Applicative m, Monad m, MonadFail m) =>
Object -> m (f a)
gFromObject Object
x
toInt :: Integral a => a -> Int64
toInt :: a -> Int64
toInt = a -> Int64
forall a b. (Integral a, Num b) => a -> b
fromIntegral
fromInt :: Integral a => Int64 -> a
fromInt :: Int64 -> a
fromInt = Int64 -> a
forall a b. (Integral a, Num b) => a -> b
fromIntegral
toWord :: Integral a => a -> Word64
toWord :: a -> Word64
toWord = a -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral
fromWord :: Integral a => Word64 -> a
fromWord :: Word64 -> a
fromWord = Word64 -> a
forall a b. (Integral a, Num b) => a -> b
fromIntegral
instance MessagePack Int64 where
toObject :: Int64 -> Object
toObject Int64
i | Int64
i Int64 -> Int64 -> Bool
forall a. Ord a => a -> a -> Bool
< Int64
0 = Int64 -> Object
ObjectInt Int64
i
| Bool
otherwise = Word64 -> Object
ObjectWord (Word64 -> Object) -> Word64 -> Object
forall a b. (a -> b) -> a -> b
$ Int64 -> Word64
forall a. Integral a => a -> Word64
toWord Int64
i
fromObject :: Object -> m Int64
fromObject = \case
ObjectInt Int64
n -> Int64 -> m Int64
forall (m :: * -> *) a. Monad m => a -> m a
return Int64
n
ObjectWord Word64
n -> Int64 -> m Int64
forall (m :: * -> *) a. Monad m => a -> m a
return (Int64 -> m Int64) -> Int64 -> m Int64
forall a b. (a -> b) -> a -> b
$ Word64 -> Int64
forall a. Integral a => a -> Int64
toInt Word64
n
Object
_ -> String -> m Int64
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"invalid encoding for integer type"
instance MessagePack Word64 where
toObject :: Word64 -> Object
toObject = Word64 -> Object
ObjectWord
fromObject :: Object -> m Word64
fromObject = \case
ObjectWord Word64
n -> Word64 -> m Word64
forall (m :: * -> *) a. Monad m => a -> m a
return Word64
n
Object
_ -> String -> m Word64
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"invalid encoding for integer type"
instance MessagePack Int where { toObject :: Int -> Object
toObject = Int64 -> Object
forall a. MessagePack a => a -> Object
toObject (Int64 -> Object) -> (Int -> Int64) -> Int -> Object
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Int64
forall a. Integral a => a -> Int64
toInt; fromObject :: Object -> m Int
fromObject Object
o = Int64 -> Int
forall a. Integral a => Int64 -> a
fromInt (Int64 -> Int) -> m Int64 -> m Int
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object -> m Int64
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m, MonadFail m) =>
Object -> m a
fromObject Object
o }
instance MessagePack Int8 where { toObject :: Int8 -> Object
toObject = Int64 -> Object
forall a. MessagePack a => a -> Object
toObject (Int64 -> Object) -> (Int8 -> Int64) -> Int8 -> Object
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int8 -> Int64
forall a. Integral a => a -> Int64
toInt; fromObject :: Object -> m Int8
fromObject Object
o = Int64 -> Int8
forall a. Integral a => Int64 -> a
fromInt (Int64 -> Int8) -> m Int64 -> m Int8
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object -> m Int64
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m, MonadFail m) =>
Object -> m a
fromObject Object
o }
instance MessagePack Int16 where { toObject :: Int16 -> Object
toObject = Int64 -> Object
forall a. MessagePack a => a -> Object
toObject (Int64 -> Object) -> (Int16 -> Int64) -> Int16 -> Object
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int16 -> Int64
forall a. Integral a => a -> Int64
toInt; fromObject :: Object -> m Int16
fromObject Object
o = Int64 -> Int16
forall a. Integral a => Int64 -> a
fromInt (Int64 -> Int16) -> m Int64 -> m Int16
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object -> m Int64
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m, MonadFail m) =>
Object -> m a
fromObject Object
o }
instance MessagePack Int32 where { toObject :: Int32 -> Object
toObject = Int64 -> Object
forall a. MessagePack a => a -> Object
toObject (Int64 -> Object) -> (Int32 -> Int64) -> Int32 -> Object
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int32 -> Int64
forall a. Integral a => a -> Int64
toInt; fromObject :: Object -> m Int32
fromObject Object
o = Int64 -> Int32
forall a. Integral a => Int64 -> a
fromInt (Int64 -> Int32) -> m Int64 -> m Int32
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object -> m Int64
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m, MonadFail m) =>
Object -> m a
fromObject Object
o }
instance MessagePack Word where { toObject :: Word -> Object
toObject = Word64 -> Object
forall a. MessagePack a => a -> Object
toObject (Word64 -> Object) -> (Word -> Word64) -> Word -> Object
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word -> Word64
forall a. Integral a => a -> Word64
toWord; fromObject :: Object -> m Word
fromObject Object
o = Word64 -> Word
forall a. Integral a => Word64 -> a
fromWord (Word64 -> Word) -> m Word64 -> m Word
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object -> m Word64
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m, MonadFail m) =>
Object -> m a
fromObject Object
o }
instance MessagePack Word8 where { toObject :: Word8 -> Object
toObject = Word64 -> Object
forall a. MessagePack a => a -> Object
toObject (Word64 -> Object) -> (Word8 -> Word64) -> Word8 -> Object
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word8 -> Word64
forall a. Integral a => a -> Word64
toWord; fromObject :: Object -> m Word8
fromObject Object
o = Word64 -> Word8
forall a. Integral a => Word64 -> a
fromWord (Word64 -> Word8) -> m Word64 -> m Word8
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object -> m Word64
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m, MonadFail m) =>
Object -> m a
fromObject Object
o }
instance MessagePack Word16 where { toObject :: Word16 -> Object
toObject = Word64 -> Object
forall a. MessagePack a => a -> Object
toObject (Word64 -> Object) -> (Word16 -> Word64) -> Word16 -> Object
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word16 -> Word64
forall a. Integral a => a -> Word64
toWord; fromObject :: Object -> m Word16
fromObject Object
o = Word64 -> Word16
forall a. Integral a => Word64 -> a
fromWord (Word64 -> Word16) -> m Word64 -> m Word16
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object -> m Word64
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m, MonadFail m) =>
Object -> m a
fromObject Object
o }
instance MessagePack Word32 where { toObject :: Word32 -> Object
toObject = Word64 -> Object
forall a. MessagePack a => a -> Object
toObject (Word64 -> Object) -> (Word32 -> Word64) -> Word32 -> Object
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word32 -> Word64
forall a. Integral a => a -> Word64
toWord; fromObject :: Object -> m Word32
fromObject Object
o = Word64 -> Word32
forall a. Integral a => Word64 -> a
fromWord (Word64 -> Word32) -> m Word64 -> m Word32
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object -> m Word64
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m, MonadFail m) =>
Object -> m a
fromObject Object
o }
instance MessagePack Object where
toObject :: Object -> Object
toObject = Object -> Object
forall a. a -> a
id
fromObject :: Object -> m Object
fromObject = Object -> m Object
forall (m :: * -> *) a. Monad m => a -> m a
return
instance MessagePack () where
toObject :: () -> Object
toObject ()
_ = Object
ObjectNil
fromObject :: Object -> m ()
fromObject = \case
Object
ObjectNil -> () -> m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
ObjectArray [] -> () -> m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
Object
_ -> String -> m ()
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"invalid encoding for ()"
instance MessagePack Bool where
toObject :: Bool -> Object
toObject = Bool -> Object
ObjectBool
fromObject :: Object -> m Bool
fromObject = \case
ObjectBool Bool
b -> Bool -> m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
b
Object
_ -> String -> m Bool
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"invalid encoding for Bool"
instance MessagePack Float where
toObject :: Float -> Object
toObject = Float -> Object
ObjectFloat
fromObject :: Object -> m Float
fromObject = \case
ObjectInt Int64
n -> Float -> m Float
forall (m :: * -> *) a. Monad m => a -> m a
return (Float -> m Float) -> Float -> m Float
forall a b. (a -> b) -> a -> b
$ Int64 -> Float
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int64
n
ObjectWord Word64
n -> Float -> m Float
forall (m :: * -> *) a. Monad m => a -> m a
return (Float -> m Float) -> Float -> m Float
forall a b. (a -> b) -> a -> b
$ Word64 -> Float
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word64
n
ObjectFloat Float
f -> Float -> m Float
forall (m :: * -> *) a. Monad m => a -> m a
return Float
f
ObjectDouble Double
d -> Float -> m Float
forall (m :: * -> *) a. Monad m => a -> m a
return (Float -> m Float) -> Float -> m Float
forall a b. (a -> b) -> a -> b
$ Double -> Float
forall a b. (Real a, Fractional b) => a -> b
realToFrac Double
d
Object
_ -> String -> m Float
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"invalid encoding for Float"
instance MessagePack Double where
toObject :: Double -> Object
toObject = Double -> Object
ObjectDouble
fromObject :: Object -> m Double
fromObject = \case
ObjectInt Int64
n -> Double -> m Double
forall (m :: * -> *) a. Monad m => a -> m a
return (Double -> m Double) -> Double -> m Double
forall a b. (a -> b) -> a -> b
$ Int64 -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int64
n
ObjectWord Word64
n -> Double -> m Double
forall (m :: * -> *) a. Monad m => a -> m a
return (Double -> m Double) -> Double -> m Double
forall a b. (a -> b) -> a -> b
$ Word64 -> Double
forall a b. (Integral a, Num b) => a -> b
fromIntegral Word64
n
ObjectFloat Float
f -> Double -> m Double
forall (m :: * -> *) a. Monad m => a -> m a
return (Double -> m Double) -> Double -> m Double
forall a b. (a -> b) -> a -> b
$ Float -> Double
forall a b. (Real a, Fractional b) => a -> b
realToFrac Float
f
ObjectDouble Double
d -> Double -> m Double
forall (m :: * -> *) a. Monad m => a -> m a
return Double
d
Object
_ -> String -> m Double
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"invalid encoding for Double"
instance MessagePack String where
toObject :: String -> Object
toObject = Text -> Object
forall a. MessagePack a => a -> Object
toObject (Text -> Object) -> (String -> Text) -> String -> Object
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack
fromObject :: Object -> m String
fromObject Object
obj = Text -> String
T.unpack (Text -> String) -> m Text -> m String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object -> m Text
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m, MonadFail m) =>
Object -> m a
fromObject Object
obj
instance MessagePack S.ByteString where
toObject :: ByteString -> Object
toObject = ByteString -> Object
ObjectBin
fromObject :: Object -> m ByteString
fromObject = \case
ObjectBin ByteString
r -> ByteString -> m ByteString
forall (m :: * -> *) a. Monad m => a -> m a
return ByteString
r
Object
_ -> String -> m ByteString
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"invalid encoding for ByteString"
instance MessagePack L.ByteString where
toObject :: ByteString -> Object
toObject = ByteString -> Object
ObjectBin (ByteString -> Object)
-> (ByteString -> ByteString) -> ByteString -> Object
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> ByteString
L.toStrict
fromObject :: Object -> m ByteString
fromObject Object
obj = ByteString -> ByteString
L.fromStrict (ByteString -> ByteString) -> m ByteString -> m ByteString
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object -> m ByteString
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m, MonadFail m) =>
Object -> m a
fromObject Object
obj
instance MessagePack T.Text where
toObject :: Text -> Object
toObject = Text -> Object
ObjectStr
fromObject :: Object -> m Text
fromObject = \case
ObjectStr Text
s -> Text -> m Text
forall (m :: * -> *) a. Monad m => a -> m a
return Text
s
Object
_ -> String -> m Text
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"invalid encoding for Text"
instance MessagePack LT.Text where
toObject :: Text -> Object
toObject = Text -> Object
forall a. MessagePack a => a -> Object
toObject (Text -> Object) -> (Text -> Text) -> Text -> Object
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
LT.toStrict
fromObject :: Object -> m Text
fromObject Object
obj = Text -> Text
LT.fromStrict (Text -> Text) -> m Text -> m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object -> m Text
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m, MonadFail m) =>
Object -> m a
fromObject Object
obj
instance MessagePack a => MessagePack [a] where
toObject :: [a] -> Object
toObject = [Object] -> Object
ObjectArray ([Object] -> Object) -> ([a] -> [Object]) -> [a] -> Object
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Object) -> [a] -> [Object]
forall a b. (a -> b) -> [a] -> [b]
map a -> Object
forall a. MessagePack a => a -> Object
toObject
fromObject :: Object -> m [a]
fromObject = \case
ObjectArray [Object]
xs -> (Object -> m a) -> [Object] -> m [a]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Object -> m a
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m, MonadFail m) =>
Object -> m a
fromObject [Object]
xs
Object
_ -> String -> m [a]
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"invalid encoding for list"
instance MessagePack a => MessagePack (V.Vector a) where
toObject :: Vector a -> Object
toObject = [Object] -> Object
ObjectArray ([Object] -> Object)
-> (Vector a -> [Object]) -> Vector a -> Object
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Object) -> [a] -> [Object]
forall a b. (a -> b) -> [a] -> [b]
map a -> Object
forall a. MessagePack a => a -> Object
toObject ([a] -> [Object]) -> (Vector a -> [a]) -> Vector a -> [Object]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector a -> [a]
forall a. Vector a -> [a]
V.toList
fromObject :: Object -> m (Vector a)
fromObject = \case
ObjectArray [Object]
o -> [a] -> Vector a
forall a. [a] -> Vector a
V.fromList ([a] -> Vector a) -> m [a] -> m (Vector a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Object -> m a) -> [Object] -> m [a]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Object -> m a
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m, MonadFail m) =>
Object -> m a
fromObject [Object]
o
Object
_ -> String -> m (Vector a)
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"invalid encoding for Vector"
instance (MessagePack a, VU.Unbox a) => MessagePack (VU.Vector a) where
toObject :: Vector a -> Object
toObject = [Object] -> Object
ObjectArray ([Object] -> Object)
-> (Vector a -> [Object]) -> Vector a -> Object
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Object) -> [a] -> [Object]
forall a b. (a -> b) -> [a] -> [b]
map a -> Object
forall a. MessagePack a => a -> Object
toObject ([a] -> [Object]) -> (Vector a -> [a]) -> Vector a -> [Object]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector a -> [a]
forall a. Unbox a => Vector a -> [a]
VU.toList
fromObject :: Object -> m (Vector a)
fromObject = \case
ObjectArray [Object]
o -> [a] -> Vector a
forall a. Unbox a => [a] -> Vector a
VU.fromList ([a] -> Vector a) -> m [a] -> m (Vector a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Object -> m a) -> [Object] -> m [a]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Object -> m a
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m, MonadFail m) =>
Object -> m a
fromObject [Object]
o
Object
_ -> String -> m (Vector a)
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"invalid encoding for Unboxed Vector"
instance (MessagePack a, VS.Storable a) => MessagePack (VS.Vector a) where
toObject :: Vector a -> Object
toObject = [Object] -> Object
ObjectArray ([Object] -> Object)
-> (Vector a -> [Object]) -> Vector a -> Object
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Object) -> [a] -> [Object]
forall a b. (a -> b) -> [a] -> [b]
map a -> Object
forall a. MessagePack a => a -> Object
toObject ([a] -> [Object]) -> (Vector a -> [a]) -> Vector a -> [Object]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector a -> [a]
forall a. Storable a => Vector a -> [a]
VS.toList
fromObject :: Object -> m (Vector a)
fromObject = \case
ObjectArray [Object]
o -> [a] -> Vector a
forall a. Storable a => [a] -> Vector a
VS.fromList ([a] -> Vector a) -> m [a] -> m (Vector a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Object -> m a) -> [Object] -> m [a]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM Object -> m a
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m, MonadFail m) =>
Object -> m a
fromObject [Object]
o
Object
_ -> String -> m (Vector a)
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"invalid encoding for Storable Vector"
instance (MessagePack a, MessagePack b) => MessagePack (Assoc [(a, b)]) where
toObject :: Assoc [(a, b)] -> Object
toObject (Assoc [(a, b)]
xs) = [(Object, Object)] -> Object
ObjectMap ([(Object, Object)] -> Object) -> [(Object, Object)] -> Object
forall a b. (a -> b) -> a -> b
$ ((a, b) -> (Object, Object)) -> [(a, b)] -> [(Object, Object)]
forall a b. (a -> b) -> [a] -> [b]
map (a -> Object
forall a. MessagePack a => a -> Object
toObject (a -> Object) -> (b -> Object) -> (a, b) -> (Object, Object)
forall (a :: * -> * -> *) b c b' c'.
Arrow a =>
a b c -> a b' c' -> a (b, b') (c, c')
*** b -> Object
forall a. MessagePack a => a -> Object
toObject) [(a, b)]
xs
fromObject :: Object -> m (Assoc [(a, b)])
fromObject = \case
ObjectMap [(Object, Object)]
xs ->
[(a, b)] -> Assoc [(a, b)]
forall a. a -> Assoc a
Assoc ([(a, b)] -> Assoc [(a, b)]) -> m [(a, b)] -> m (Assoc [(a, b)])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ((Object, Object) -> m (a, b)) -> [(Object, Object)] -> m [(a, b)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (\(Object
k, Object
v) -> (,) (a -> b -> (a, b)) -> m a -> m (b -> (a, b))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object -> m a
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m, MonadFail m) =>
Object -> m a
fromObject Object
k m (b -> (a, b)) -> m b -> m (a, b)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object -> m b
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m, MonadFail m) =>
Object -> m a
fromObject Object
v) [(Object, Object)]
xs
Object
_ -> String -> m (Assoc [(a, b)])
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"invalid encoding for Assoc"
instance (MessagePack k, MessagePack v, Ord k) => MessagePack (Map.Map k v) where
toObject :: Map k v -> Object
toObject = Assoc [(k, v)] -> Object
forall a. MessagePack a => a -> Object
toObject (Assoc [(k, v)] -> Object)
-> (Map k v -> Assoc [(k, v)]) -> Map k v -> Object
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(k, v)] -> Assoc [(k, v)]
forall a. a -> Assoc a
Assoc ([(k, v)] -> Assoc [(k, v)])
-> (Map k v -> [(k, v)]) -> Map k v -> Assoc [(k, v)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Map k v -> [(k, v)]
forall k a. Map k a -> [(k, a)]
Map.toList
fromObject :: Object -> m (Map k v)
fromObject Object
obj = [(k, v)] -> Map k v
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList ([(k, v)] -> Map k v)
-> (Assoc [(k, v)] -> [(k, v)]) -> Assoc [(k, v)] -> Map k v
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Assoc [(k, v)] -> [(k, v)]
forall a. Assoc a -> a
unAssoc (Assoc [(k, v)] -> Map k v) -> m (Assoc [(k, v)]) -> m (Map k v)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object -> m (Assoc [(k, v)])
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m, MonadFail m) =>
Object -> m a
fromObject Object
obj
instance MessagePack v => MessagePack (IntMap.IntMap v) where
toObject :: IntMap v -> Object
toObject = Assoc [(Int, v)] -> Object
forall a. MessagePack a => a -> Object
toObject (Assoc [(Int, v)] -> Object)
-> (IntMap v -> Assoc [(Int, v)]) -> IntMap v -> Object
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(Int, v)] -> Assoc [(Int, v)]
forall a. a -> Assoc a
Assoc ([(Int, v)] -> Assoc [(Int, v)])
-> (IntMap v -> [(Int, v)]) -> IntMap v -> Assoc [(Int, v)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IntMap v -> [(Int, v)]
forall a. IntMap a -> [(Int, a)]
IntMap.toList
fromObject :: Object -> m (IntMap v)
fromObject Object
obj = [(Int, v)] -> IntMap v
forall a. [(Int, a)] -> IntMap a
IntMap.fromList ([(Int, v)] -> IntMap v)
-> (Assoc [(Int, v)] -> [(Int, v)]) -> Assoc [(Int, v)] -> IntMap v
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Assoc [(Int, v)] -> [(Int, v)]
forall a. Assoc a -> a
unAssoc (Assoc [(Int, v)] -> IntMap v)
-> m (Assoc [(Int, v)]) -> m (IntMap v)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object -> m (Assoc [(Int, v)])
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m, MonadFail m) =>
Object -> m a
fromObject Object
obj
instance (MessagePack k, MessagePack v, Hashable k, Eq k) => MessagePack (HashMap.HashMap k v) where
toObject :: HashMap k v -> Object
toObject = Assoc [(k, v)] -> Object
forall a. MessagePack a => a -> Object
toObject (Assoc [(k, v)] -> Object)
-> (HashMap k v -> Assoc [(k, v)]) -> HashMap k v -> Object
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(k, v)] -> Assoc [(k, v)]
forall a. a -> Assoc a
Assoc ([(k, v)] -> Assoc [(k, v)])
-> (HashMap k v -> [(k, v)]) -> HashMap k v -> Assoc [(k, v)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HashMap k v -> [(k, v)]
forall k v. HashMap k v -> [(k, v)]
HashMap.toList
fromObject :: Object -> m (HashMap k v)
fromObject Object
obj = [(k, v)] -> HashMap k v
forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
HashMap.fromList ([(k, v)] -> HashMap k v)
-> (Assoc [(k, v)] -> [(k, v)]) -> Assoc [(k, v)] -> HashMap k v
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Assoc [(k, v)] -> [(k, v)]
forall a. Assoc a -> a
unAssoc (Assoc [(k, v)] -> HashMap k v)
-> m (Assoc [(k, v)]) -> m (HashMap k v)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object -> m (Assoc [(k, v)])
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m, MonadFail m) =>
Object -> m a
fromObject Object
obj
instance (MessagePack a1, MessagePack a2) => MessagePack (a1, a2) where
toObject :: (a1, a2) -> Object
toObject (a1
a1, a2
a2) = [Object] -> Object
ObjectArray [a1 -> Object
forall a. MessagePack a => a -> Object
toObject a1
a1, a2 -> Object
forall a. MessagePack a => a -> Object
toObject a2
a2]
fromObject :: Object -> m (a1, a2)
fromObject (ObjectArray [Object
a1, Object
a2]) = (,) (a1 -> a2 -> (a1, a2)) -> m a1 -> m (a2 -> (a1, a2))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object -> m a1
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m, MonadFail m) =>
Object -> m a
fromObject Object
a1 m (a2 -> (a1, a2)) -> m a2 -> m (a1, a2)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object -> m a2
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m, MonadFail m) =>
Object -> m a
fromObject Object
a2
fromObject Object
_ = String -> m (a1, a2)
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"invalid encoding for tuple"
instance (MessagePack a1, MessagePack a2, MessagePack a3) => MessagePack (a1, a2, a3) where
toObject :: (a1, a2, a3) -> Object
toObject (a1
a1, a2
a2, a3
a3) = [Object] -> Object
ObjectArray [a1 -> Object
forall a. MessagePack a => a -> Object
toObject a1
a1, a2 -> Object
forall a. MessagePack a => a -> Object
toObject a2
a2, a3 -> Object
forall a. MessagePack a => a -> Object
toObject a3
a3]
fromObject :: Object -> m (a1, a2, a3)
fromObject (ObjectArray [Object
a1, Object
a2, Object
a3]) = (,,) (a1 -> a2 -> a3 -> (a1, a2, a3))
-> m a1 -> m (a2 -> a3 -> (a1, a2, a3))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object -> m a1
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m, MonadFail m) =>
Object -> m a
fromObject Object
a1 m (a2 -> a3 -> (a1, a2, a3)) -> m a2 -> m (a3 -> (a1, a2, a3))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object -> m a2
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m, MonadFail m) =>
Object -> m a
fromObject Object
a2 m (a3 -> (a1, a2, a3)) -> m a3 -> m (a1, a2, a3)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object -> m a3
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m, MonadFail m) =>
Object -> m a
fromObject Object
a3
fromObject Object
_ = String -> m (a1, a2, a3)
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"invalid encoding for tuple"
instance (MessagePack a1, MessagePack a2, MessagePack a3, MessagePack a4) => MessagePack (a1, a2, a3, a4) where
toObject :: (a1, a2, a3, a4) -> Object
toObject (a1
a1, a2
a2, a3
a3, a4
a4) = [Object] -> Object
ObjectArray [a1 -> Object
forall a. MessagePack a => a -> Object
toObject a1
a1, a2 -> Object
forall a. MessagePack a => a -> Object
toObject a2
a2, a3 -> Object
forall a. MessagePack a => a -> Object
toObject a3
a3, a4 -> Object
forall a. MessagePack a => a -> Object
toObject a4
a4]
fromObject :: Object -> m (a1, a2, a3, a4)
fromObject (ObjectArray [Object
a1, Object
a2, Object
a3, Object
a4]) = (,,,) (a1 -> a2 -> a3 -> a4 -> (a1, a2, a3, a4))
-> m a1 -> m (a2 -> a3 -> a4 -> (a1, a2, a3, a4))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object -> m a1
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m, MonadFail m) =>
Object -> m a
fromObject Object
a1 m (a2 -> a3 -> a4 -> (a1, a2, a3, a4))
-> m a2 -> m (a3 -> a4 -> (a1, a2, a3, a4))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object -> m a2
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m, MonadFail m) =>
Object -> m a
fromObject Object
a2 m (a3 -> a4 -> (a1, a2, a3, a4))
-> m a3 -> m (a4 -> (a1, a2, a3, a4))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object -> m a3
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m, MonadFail m) =>
Object -> m a
fromObject Object
a3 m (a4 -> (a1, a2, a3, a4)) -> m a4 -> m (a1, a2, a3, a4)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object -> m a4
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m, MonadFail m) =>
Object -> m a
fromObject Object
a4
fromObject Object
_ = String -> m (a1, a2, a3, a4)
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"invalid encoding for tuple"
instance (MessagePack a1, MessagePack a2, MessagePack a3, MessagePack a4, MessagePack a5) => MessagePack (a1, a2, a3, a4, a5) where
toObject :: (a1, a2, a3, a4, a5) -> Object
toObject (a1
a1, a2
a2, a3
a3, a4
a4, a5
a5) = [Object] -> Object
ObjectArray [a1 -> Object
forall a. MessagePack a => a -> Object
toObject a1
a1, a2 -> Object
forall a. MessagePack a => a -> Object
toObject a2
a2, a3 -> Object
forall a. MessagePack a => a -> Object
toObject a3
a3, a4 -> Object
forall a. MessagePack a => a -> Object
toObject a4
a4, a5 -> Object
forall a. MessagePack a => a -> Object
toObject a5
a5]
fromObject :: Object -> m (a1, a2, a3, a4, a5)
fromObject (ObjectArray [Object
a1, Object
a2, Object
a3, Object
a4, Object
a5]) = (,,,,) (a1 -> a2 -> a3 -> a4 -> a5 -> (a1, a2, a3, a4, a5))
-> m a1 -> m (a2 -> a3 -> a4 -> a5 -> (a1, a2, a3, a4, a5))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object -> m a1
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m, MonadFail m) =>
Object -> m a
fromObject Object
a1 m (a2 -> a3 -> a4 -> a5 -> (a1, a2, a3, a4, a5))
-> m a2 -> m (a3 -> a4 -> a5 -> (a1, a2, a3, a4, a5))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object -> m a2
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m, MonadFail m) =>
Object -> m a
fromObject Object
a2 m (a3 -> a4 -> a5 -> (a1, a2, a3, a4, a5))
-> m a3 -> m (a4 -> a5 -> (a1, a2, a3, a4, a5))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object -> m a3
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m, MonadFail m) =>
Object -> m a
fromObject Object
a3 m (a4 -> a5 -> (a1, a2, a3, a4, a5))
-> m a4 -> m (a5 -> (a1, a2, a3, a4, a5))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object -> m a4
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m, MonadFail m) =>
Object -> m a
fromObject Object
a4 m (a5 -> (a1, a2, a3, a4, a5)) -> m a5 -> m (a1, a2, a3, a4, a5)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object -> m a5
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m, MonadFail m) =>
Object -> m a
fromObject Object
a5
fromObject Object
_ = String -> m (a1, a2, a3, a4, a5)
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"invalid encoding for tuple"
instance (MessagePack a1, MessagePack a2, MessagePack a3, MessagePack a4, MessagePack a5, MessagePack a6) => MessagePack (a1, a2, a3, a4, a5, a6) where
toObject :: (a1, a2, a3, a4, a5, a6) -> Object
toObject (a1
a1, a2
a2, a3
a3, a4
a4, a5
a5, a6
a6) = [Object] -> Object
ObjectArray [a1 -> Object
forall a. MessagePack a => a -> Object
toObject a1
a1, a2 -> Object
forall a. MessagePack a => a -> Object
toObject a2
a2, a3 -> Object
forall a. MessagePack a => a -> Object
toObject a3
a3, a4 -> Object
forall a. MessagePack a => a -> Object
toObject a4
a4, a5 -> Object
forall a. MessagePack a => a -> Object
toObject a5
a5, a6 -> Object
forall a. MessagePack a => a -> Object
toObject a6
a6]
fromObject :: Object -> m (a1, a2, a3, a4, a5, a6)
fromObject (ObjectArray [Object
a1, Object
a2, Object
a3, Object
a4, Object
a5, Object
a6]) = (,,,,,) (a1 -> a2 -> a3 -> a4 -> a5 -> a6 -> (a1, a2, a3, a4, a5, a6))
-> m a1
-> m (a2 -> a3 -> a4 -> a5 -> a6 -> (a1, a2, a3, a4, a5, a6))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object -> m a1
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m, MonadFail m) =>
Object -> m a
fromObject Object
a1 m (a2 -> a3 -> a4 -> a5 -> a6 -> (a1, a2, a3, a4, a5, a6))
-> m a2 -> m (a3 -> a4 -> a5 -> a6 -> (a1, a2, a3, a4, a5, a6))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object -> m a2
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m, MonadFail m) =>
Object -> m a
fromObject Object
a2 m (a3 -> a4 -> a5 -> a6 -> (a1, a2, a3, a4, a5, a6))
-> m a3 -> m (a4 -> a5 -> a6 -> (a1, a2, a3, a4, a5, a6))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object -> m a3
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m, MonadFail m) =>
Object -> m a
fromObject Object
a3 m (a4 -> a5 -> a6 -> (a1, a2, a3, a4, a5, a6))
-> m a4 -> m (a5 -> a6 -> (a1, a2, a3, a4, a5, a6))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object -> m a4
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m, MonadFail m) =>
Object -> m a
fromObject Object
a4 m (a5 -> a6 -> (a1, a2, a3, a4, a5, a6))
-> m a5 -> m (a6 -> (a1, a2, a3, a4, a5, a6))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object -> m a5
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m, MonadFail m) =>
Object -> m a
fromObject Object
a5 m (a6 -> (a1, a2, a3, a4, a5, a6))
-> m a6 -> m (a1, a2, a3, a4, a5, a6)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object -> m a6
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m, MonadFail m) =>
Object -> m a
fromObject Object
a6
fromObject Object
_ = String -> m (a1, a2, a3, a4, a5, a6)
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"invalid encoding for tuple"
instance (MessagePack a1, MessagePack a2, MessagePack a3, MessagePack a4, MessagePack a5, MessagePack a6, MessagePack a7) => MessagePack (a1, a2, a3, a4, a5, a6, a7) where
toObject :: (a1, a2, a3, a4, a5, a6, a7) -> Object
toObject (a1
a1, a2
a2, a3
a3, a4
a4, a5
a5, a6
a6, a7
a7) = [Object] -> Object
ObjectArray [a1 -> Object
forall a. MessagePack a => a -> Object
toObject a1
a1, a2 -> Object
forall a. MessagePack a => a -> Object
toObject a2
a2, a3 -> Object
forall a. MessagePack a => a -> Object
toObject a3
a3, a4 -> Object
forall a. MessagePack a => a -> Object
toObject a4
a4, a5 -> Object
forall a. MessagePack a => a -> Object
toObject a5
a5, a6 -> Object
forall a. MessagePack a => a -> Object
toObject a6
a6, a7 -> Object
forall a. MessagePack a => a -> Object
toObject a7
a7]
fromObject :: Object -> m (a1, a2, a3, a4, a5, a6, a7)
fromObject (ObjectArray [Object
a1, Object
a2, Object
a3, Object
a4, Object
a5, Object
a6, Object
a7]) = (,,,,,,) (a1
-> a2
-> a3
-> a4
-> a5
-> a6
-> a7
-> (a1, a2, a3, a4, a5, a6, a7))
-> m a1
-> m (a2
-> a3 -> a4 -> a5 -> a6 -> a7 -> (a1, a2, a3, a4, a5, a6, a7))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object -> m a1
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m, MonadFail m) =>
Object -> m a
fromObject Object
a1 m (a2
-> a3 -> a4 -> a5 -> a6 -> a7 -> (a1, a2, a3, a4, a5, a6, a7))
-> m a2
-> m (a3 -> a4 -> a5 -> a6 -> a7 -> (a1, a2, a3, a4, a5, a6, a7))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object -> m a2
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m, MonadFail m) =>
Object -> m a
fromObject Object
a2 m (a3 -> a4 -> a5 -> a6 -> a7 -> (a1, a2, a3, a4, a5, a6, a7))
-> m a3 -> m (a4 -> a5 -> a6 -> a7 -> (a1, a2, a3, a4, a5, a6, a7))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object -> m a3
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m, MonadFail m) =>
Object -> m a
fromObject Object
a3 m (a4 -> a5 -> a6 -> a7 -> (a1, a2, a3, a4, a5, a6, a7))
-> m a4 -> m (a5 -> a6 -> a7 -> (a1, a2, a3, a4, a5, a6, a7))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object -> m a4
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m, MonadFail m) =>
Object -> m a
fromObject Object
a4 m (a5 -> a6 -> a7 -> (a1, a2, a3, a4, a5, a6, a7))
-> m a5 -> m (a6 -> a7 -> (a1, a2, a3, a4, a5, a6, a7))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object -> m a5
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m, MonadFail m) =>
Object -> m a
fromObject Object
a5 m (a6 -> a7 -> (a1, a2, a3, a4, a5, a6, a7))
-> m a6 -> m (a7 -> (a1, a2, a3, a4, a5, a6, a7))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object -> m a6
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m, MonadFail m) =>
Object -> m a
fromObject Object
a6 m (a7 -> (a1, a2, a3, a4, a5, a6, a7))
-> m a7 -> m (a1, a2, a3, a4, a5, a6, a7)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object -> m a7
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m, MonadFail m) =>
Object -> m a
fromObject Object
a7
fromObject Object
_ = String -> m (a1, a2, a3, a4, a5, a6, a7)
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"invalid encoding for tuple"
instance (MessagePack a1, MessagePack a2, MessagePack a3, MessagePack a4, MessagePack a5, MessagePack a6, MessagePack a7, MessagePack a8) => MessagePack (a1, a2, a3, a4, a5, a6, a7, a8) where
toObject :: (a1, a2, a3, a4, a5, a6, a7, a8) -> Object
toObject (a1
a1, a2
a2, a3
a3, a4
a4, a5
a5, a6
a6, a7
a7, a8
a8) = [Object] -> Object
ObjectArray [a1 -> Object
forall a. MessagePack a => a -> Object
toObject a1
a1, a2 -> Object
forall a. MessagePack a => a -> Object
toObject a2
a2, a3 -> Object
forall a. MessagePack a => a -> Object
toObject a3
a3, a4 -> Object
forall a. MessagePack a => a -> Object
toObject a4
a4, a5 -> Object
forall a. MessagePack a => a -> Object
toObject a5
a5, a6 -> Object
forall a. MessagePack a => a -> Object
toObject a6
a6, a7 -> Object
forall a. MessagePack a => a -> Object
toObject a7
a7, a8 -> Object
forall a. MessagePack a => a -> Object
toObject a8
a8]
fromObject :: Object -> m (a1, a2, a3, a4, a5, a6, a7, a8)
fromObject (ObjectArray [Object
a1, Object
a2, Object
a3, Object
a4, Object
a5, Object
a6, Object
a7, Object
a8]) = (,,,,,,,) (a1
-> a2
-> a3
-> a4
-> a5
-> a6
-> a7
-> a8
-> (a1, a2, a3, a4, a5, a6, a7, a8))
-> m a1
-> m (a2
-> a3
-> a4
-> a5
-> a6
-> a7
-> a8
-> (a1, a2, a3, a4, a5, a6, a7, a8))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object -> m a1
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m, MonadFail m) =>
Object -> m a
fromObject Object
a1 m (a2
-> a3
-> a4
-> a5
-> a6
-> a7
-> a8
-> (a1, a2, a3, a4, a5, a6, a7, a8))
-> m a2
-> m (a3
-> a4 -> a5 -> a6 -> a7 -> a8 -> (a1, a2, a3, a4, a5, a6, a7, a8))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object -> m a2
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m, MonadFail m) =>
Object -> m a
fromObject Object
a2 m (a3
-> a4 -> a5 -> a6 -> a7 -> a8 -> (a1, a2, a3, a4, a5, a6, a7, a8))
-> m a3
-> m (a4
-> a5 -> a6 -> a7 -> a8 -> (a1, a2, a3, a4, a5, a6, a7, a8))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object -> m a3
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m, MonadFail m) =>
Object -> m a
fromObject Object
a3 m (a4 -> a5 -> a6 -> a7 -> a8 -> (a1, a2, a3, a4, a5, a6, a7, a8))
-> m a4
-> m (a5 -> a6 -> a7 -> a8 -> (a1, a2, a3, a4, a5, a6, a7, a8))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object -> m a4
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m, MonadFail m) =>
Object -> m a
fromObject Object
a4 m (a5 -> a6 -> a7 -> a8 -> (a1, a2, a3, a4, a5, a6, a7, a8))
-> m a5 -> m (a6 -> a7 -> a8 -> (a1, a2, a3, a4, a5, a6, a7, a8))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object -> m a5
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m, MonadFail m) =>
Object -> m a
fromObject Object
a5 m (a6 -> a7 -> a8 -> (a1, a2, a3, a4, a5, a6, a7, a8))
-> m a6 -> m (a7 -> a8 -> (a1, a2, a3, a4, a5, a6, a7, a8))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object -> m a6
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m, MonadFail m) =>
Object -> m a
fromObject Object
a6 m (a7 -> a8 -> (a1, a2, a3, a4, a5, a6, a7, a8))
-> m a7 -> m (a8 -> (a1, a2, a3, a4, a5, a6, a7, a8))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object -> m a7
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m, MonadFail m) =>
Object -> m a
fromObject Object
a7 m (a8 -> (a1, a2, a3, a4, a5, a6, a7, a8))
-> m a8 -> m (a1, a2, a3, a4, a5, a6, a7, a8)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object -> m a8
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m, MonadFail m) =>
Object -> m a
fromObject Object
a8
fromObject Object
_ = String -> m (a1, a2, a3, a4, a5, a6, a7, a8)
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"invalid encoding for tuple"
instance (MessagePack a1, MessagePack a2, MessagePack a3, MessagePack a4, MessagePack a5, MessagePack a6, MessagePack a7, MessagePack a8, MessagePack a9) => MessagePack (a1, a2, a3, a4, a5, a6, a7, a8, a9) where
toObject :: (a1, a2, a3, a4, a5, a6, a7, a8, a9) -> Object
toObject (a1
a1, a2
a2, a3
a3, a4
a4, a5
a5, a6
a6, a7
a7, a8
a8, a9
a9) = [Object] -> Object
ObjectArray [a1 -> Object
forall a. MessagePack a => a -> Object
toObject a1
a1, a2 -> Object
forall a. MessagePack a => a -> Object
toObject a2
a2, a3 -> Object
forall a. MessagePack a => a -> Object
toObject a3
a3, a4 -> Object
forall a. MessagePack a => a -> Object
toObject a4
a4, a5 -> Object
forall a. MessagePack a => a -> Object
toObject a5
a5, a6 -> Object
forall a. MessagePack a => a -> Object
toObject a6
a6, a7 -> Object
forall a. MessagePack a => a -> Object
toObject a7
a7, a8 -> Object
forall a. MessagePack a => a -> Object
toObject a8
a8, a9 -> Object
forall a. MessagePack a => a -> Object
toObject a9
a9]
fromObject :: Object -> m (a1, a2, a3, a4, a5, a6, a7, a8, a9)
fromObject (ObjectArray [Object
a1, Object
a2, Object
a3, Object
a4, Object
a5, Object
a6, Object
a7, Object
a8, Object
a9]) = (,,,,,,,,) (a1
-> a2
-> a3
-> a4
-> a5
-> a6
-> a7
-> a8
-> a9
-> (a1, a2, a3, a4, a5, a6, a7, a8, a9))
-> m a1
-> m (a2
-> a3
-> a4
-> a5
-> a6
-> a7
-> a8
-> a9
-> (a1, a2, a3, a4, a5, a6, a7, a8, a9))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object -> m a1
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m, MonadFail m) =>
Object -> m a
fromObject Object
a1 m (a2
-> a3
-> a4
-> a5
-> a6
-> a7
-> a8
-> a9
-> (a1, a2, a3, a4, a5, a6, a7, a8, a9))
-> m a2
-> m (a3
-> a4
-> a5
-> a6
-> a7
-> a8
-> a9
-> (a1, a2, a3, a4, a5, a6, a7, a8, a9))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object -> m a2
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m, MonadFail m) =>
Object -> m a
fromObject Object
a2 m (a3
-> a4
-> a5
-> a6
-> a7
-> a8
-> a9
-> (a1, a2, a3, a4, a5, a6, a7, a8, a9))
-> m a3
-> m (a4
-> a5
-> a6
-> a7
-> a8
-> a9
-> (a1, a2, a3, a4, a5, a6, a7, a8, a9))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object -> m a3
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m, MonadFail m) =>
Object -> m a
fromObject Object
a3 m (a4
-> a5
-> a6
-> a7
-> a8
-> a9
-> (a1, a2, a3, a4, a5, a6, a7, a8, a9))
-> m a4
-> m (a5
-> a6 -> a7 -> a8 -> a9 -> (a1, a2, a3, a4, a5, a6, a7, a8, a9))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object -> m a4
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m, MonadFail m) =>
Object -> m a
fromObject Object
a4 m (a5
-> a6 -> a7 -> a8 -> a9 -> (a1, a2, a3, a4, a5, a6, a7, a8, a9))
-> m a5
-> m (a6 -> a7 -> a8 -> a9 -> (a1, a2, a3, a4, a5, a6, a7, a8, a9))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object -> m a5
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m, MonadFail m) =>
Object -> m a
fromObject Object
a5 m (a6 -> a7 -> a8 -> a9 -> (a1, a2, a3, a4, a5, a6, a7, a8, a9))
-> m a6
-> m (a7 -> a8 -> a9 -> (a1, a2, a3, a4, a5, a6, a7, a8, a9))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object -> m a6
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m, MonadFail m) =>
Object -> m a
fromObject Object
a6 m (a7 -> a8 -> a9 -> (a1, a2, a3, a4, a5, a6, a7, a8, a9))
-> m a7 -> m (a8 -> a9 -> (a1, a2, a3, a4, a5, a6, a7, a8, a9))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object -> m a7
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m, MonadFail m) =>
Object -> m a
fromObject Object
a7 m (a8 -> a9 -> (a1, a2, a3, a4, a5, a6, a7, a8, a9))
-> m a8 -> m (a9 -> (a1, a2, a3, a4, a5, a6, a7, a8, a9))
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object -> m a8
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m, MonadFail m) =>
Object -> m a
fromObject Object
a8 m (a9 -> (a1, a2, a3, a4, a5, a6, a7, a8, a9))
-> m a9 -> m (a1, a2, a3, a4, a5, a6, a7, a8, a9)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Object -> m a9
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m, MonadFail m) =>
Object -> m a
fromObject Object
a9
fromObject Object
_ = String -> m (a1, a2, a3, a4, a5, a6, a7, a8, a9)
forall (m :: * -> *) a. MonadFail m => String -> m a
fail String
"invalid encoding for tuple"