{-# LANGUAGE CPP                 #-}
{-# LANGUAGE DefaultSignatures   #-}
{-# LANGUAGE FlexibleContexts    #-}
{-# LANGUAGE FlexibleInstances   #-}
{-# LANGUAGE IncoherentInstances #-}
{-# LANGUAGE LambdaCase          #-}
{-# LANGUAGE OverloadedStrings   #-}
{-# LANGUAGE StrictData          #-}
{-# LANGUAGE Trustworthy         #-}
{-# LANGUAGE ViewPatterns        #-}

--------------------------------------------------------------------
-- |
-- Module    : Data.MessagePack.Object
-- Copyright : (c) Hideyuki Tanaka, 2009-2015
-- License   : BSD3
--
-- Maintainer:  tanaka.hideyuki@gmail.com
-- Stability :  experimental
-- Portability: portable
--
-- MessagePack object definition
--
--------------------------------------------------------------------

module Data.MessagePack.Types.Class
    ( MessagePack (..)
    , GMessagePack (..)
    , Config
    , defaultConfig
    ) where

import           Control.Applicative                (Applicative, (<$>), (<*>))
import           Control.Arrow                      ((***))
import           Control.Monad.Validate             (MonadValidate (..))
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.DecodeError (DecodeError)
import           Data.MessagePack.Types.Object      (Object (..))


data Config = Config

defaultConfig :: Config
defaultConfig :: Config
defaultConfig = Config
Config


-- Generic serialisation.

class GMessagePack f where
    gToObject :: Config -> f a -> Object
    gFromObject
        :: ( Applicative m
           , Monad m
           , MonadValidate DecodeError m
           )
        => Config
        -> Object
        -> m (f a)


class MessagePack a where
    toObject :: Config -> a -> Object
    fromObjectWith
        :: ( Applicative m
           , Monad m
           , MonadValidate DecodeError m
           )
        => Config
        -> Object
        -> m a

    default toObject :: (Generic a, GMessagePack (Rep a)) => Config -> a -> Object
    toObject = Config -> a -> Object
forall a.
(Generic a, GMessagePack (Rep a)) =>
Config -> a -> Object
genericToObject
    default fromObjectWith
        :: ( Applicative m
           , Monad m
           , MonadValidate DecodeError m
           , Generic a, GMessagePack (Rep a))
        => Config
        -> Object
        -> m a
    fromObjectWith = Config -> Object -> m a
forall (m :: * -> *) a.
(Applicative m, Monad m, MonadValidate DecodeError m, Generic a,
 GMessagePack (Rep a)) =>
Config -> Object -> m a
genericFromObject


genericToObject :: (Generic a, GMessagePack (Rep a)) => Config -> a -> Object
genericToObject :: Config -> a -> Object
genericToObject Config
cfg = Config -> Rep a Any -> Object
forall (f :: * -> *) a. GMessagePack f => Config -> f a -> Object
gToObject Config
cfg (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
       , MonadValidate DecodeError m
       , Generic a
       , GMessagePack (Rep a)
       )
    => Config
    -> Object
    -> m a
genericFromObject :: Config -> Object -> m a
genericFromObject Config
cfg 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
<$> Config -> Object -> m (Rep a Any)
forall (f :: * -> *) (m :: * -> *) a.
(GMessagePack f, Applicative m, Monad m,
 MonadValidate DecodeError m) =>
Config -> Object -> m (f a)
gFromObject Config
cfg Object
x


-- Instances for integral types (Int etc.).

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 :: Config -> Int64 -> Object
toObject Config
_ 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
    fromObjectWith :: Config -> Object -> m Int64
fromObjectWith Config
_ = \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
_            -> DecodeError -> m Int64
forall e (m :: * -> *) a. MonadValidate e m => e -> m a
refute DecodeError
"invalid encoding for integer type"

instance MessagePack Word64 where
    toObject :: Config -> Word64 -> Object
toObject Config
_ = Word64 -> Object
ObjectWord
    fromObjectWith :: Config -> Object -> m Word64
fromObjectWith Config
_ = \case
        ObjectWord Word64
n -> Word64 -> m Word64
forall (m :: * -> *) a. Monad m => a -> m a
return Word64
n
        Object
_            -> DecodeError -> m Word64
forall e (m :: * -> *) a. MonadValidate e m => e -> m a
refute DecodeError
"invalid encoding for integer type"

instance MessagePack Int    where { toObject :: Config -> Int -> Object
toObject Config
cfg = Config -> Int64 -> Object
forall a. MessagePack a => Config -> a -> Object
toObject Config
cfg (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; fromObjectWith :: Config -> Object -> m Int
fromObjectWith Config
cfg 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
<$> Config -> Object -> m Int64
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m,
 MonadValidate DecodeError m) =>
Config -> Object -> m a
fromObjectWith Config
cfg Object
o }
instance MessagePack Int8   where { toObject :: Config -> Int8 -> Object
toObject Config
cfg = Config -> Int64 -> Object
forall a. MessagePack a => Config -> a -> Object
toObject Config
cfg (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; fromObjectWith :: Config -> Object -> m Int8
fromObjectWith Config
cfg 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
<$> Config -> Object -> m Int64
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m,
 MonadValidate DecodeError m) =>
Config -> Object -> m a
fromObjectWith Config
cfg Object
o }
instance MessagePack Int16  where { toObject :: Config -> Int16 -> Object
toObject Config
cfg = Config -> Int64 -> Object
forall a. MessagePack a => Config -> a -> Object
toObject Config
cfg (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; fromObjectWith :: Config -> Object -> m Int16
fromObjectWith Config
cfg 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
<$> Config -> Object -> m Int64
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m,
 MonadValidate DecodeError m) =>
Config -> Object -> m a
fromObjectWith Config
cfg Object
o }
instance MessagePack Int32  where { toObject :: Config -> Int32 -> Object
toObject Config
cfg = Config -> Int64 -> Object
forall a. MessagePack a => Config -> a -> Object
toObject Config
cfg (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; fromObjectWith :: Config -> Object -> m Int32
fromObjectWith Config
cfg 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
<$> Config -> Object -> m Int64
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m,
 MonadValidate DecodeError m) =>
Config -> Object -> m a
fromObjectWith Config
cfg Object
o }

instance MessagePack Word   where { toObject :: Config -> Word -> Object
toObject Config
cfg = Config -> Word64 -> Object
forall a. MessagePack a => Config -> a -> Object
toObject Config
cfg (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; fromObjectWith :: Config -> Object -> m Word
fromObjectWith Config
cfg 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
<$> Config -> Object -> m Word64
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m,
 MonadValidate DecodeError m) =>
Config -> Object -> m a
fromObjectWith Config
cfg Object
o }
instance MessagePack Word8  where { toObject :: Config -> Word8 -> Object
toObject Config
cfg = Config -> Word64 -> Object
forall a. MessagePack a => Config -> a -> Object
toObject Config
cfg (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; fromObjectWith :: Config -> Object -> m Word8
fromObjectWith Config
cfg 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
<$> Config -> Object -> m Word64
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m,
 MonadValidate DecodeError m) =>
Config -> Object -> m a
fromObjectWith Config
cfg Object
o }
instance MessagePack Word16 where { toObject :: Config -> Word16 -> Object
toObject Config
cfg = Config -> Word64 -> Object
forall a. MessagePack a => Config -> a -> Object
toObject Config
cfg (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; fromObjectWith :: Config -> Object -> m Word16
fromObjectWith Config
cfg 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
<$> Config -> Object -> m Word64
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m,
 MonadValidate DecodeError m) =>
Config -> Object -> m a
fromObjectWith Config
cfg Object
o }
instance MessagePack Word32 where { toObject :: Config -> Word32 -> Object
toObject Config
cfg = Config -> Word64 -> Object
forall a. MessagePack a => Config -> a -> Object
toObject Config
cfg (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; fromObjectWith :: Config -> Object -> m Word32
fromObjectWith Config
cfg 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
<$> Config -> Object -> m Word64
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m,
 MonadValidate DecodeError m) =>
Config -> Object -> m a
fromObjectWith Config
cfg Object
o }


-- Core instances.

instance MessagePack Object where
    toObject :: Config -> Object -> Object
toObject Config
_ = Object -> Object
forall a. a -> a
id
    fromObjectWith :: Config -> Object -> m Object
fromObjectWith Config
_ = Object -> m Object
forall (m :: * -> *) a. Monad m => a -> m a
return

instance MessagePack () where
    toObject :: Config -> () -> Object
toObject Config
_ ()
_ = Object
ObjectNil
    fromObjectWith :: Config -> Object -> m ()
fromObjectWith Config
_ = \case
        Object
ObjectNil                    -> () -> m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
        ObjectArray (Vector Object -> [Object]
forall a. Vector a -> [a]
V.toList -> []) -> () -> m ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
        Object
_                            -> DecodeError -> m ()
forall e (m :: * -> *) a. MonadValidate e m => e -> m a
refute DecodeError
"invalid encoding for ()"

instance MessagePack Bool where
    toObject :: Config -> Bool -> Object
toObject Config
_ = Bool -> Object
ObjectBool
    fromObjectWith :: Config -> Object -> m Bool
fromObjectWith Config
_ = \case
        ObjectBool Bool
b -> Bool -> m Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
b
        Object
_            -> DecodeError -> m Bool
forall e (m :: * -> *) a. MonadValidate e m => e -> m a
refute DecodeError
"invalid encoding for Bool"

instance MessagePack Float where
    toObject :: Config -> Float -> Object
toObject Config
_ = Float -> Object
ObjectFloat
    fromObjectWith :: Config -> Object -> m Float
fromObjectWith Config
_ = \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
_              -> DecodeError -> m Float
forall e (m :: * -> *) a. MonadValidate e m => e -> m a
refute DecodeError
"invalid encoding for Float"

instance MessagePack Double where
    toObject :: Config -> Double -> Object
toObject Config
_ = Double -> Object
ObjectDouble
    fromObjectWith :: Config -> Object -> m Double
fromObjectWith Config
_ = \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
_              -> DecodeError -> m Double
forall e (m :: * -> *) a. MonadValidate e m => e -> m a
refute DecodeError
"invalid encoding for Double"

-- Because of overlapping instance, this must be above [a].
-- IncoherentInstances and TypeSynonymInstances are required for this to work.
instance MessagePack String where
    toObject :: Config -> String -> Object
toObject Config
cfg = Config -> Text -> Object
forall a. MessagePack a => Config -> a -> Object
toObject Config
cfg (Text -> Object) -> (String -> Text) -> String -> Object
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> Text
T.pack
    fromObjectWith :: Config -> Object -> m String
fromObjectWith Config
cfg Object
obj = Text -> String
T.unpack (Text -> String) -> m Text -> m String
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Config -> Object -> m Text
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m,
 MonadValidate DecodeError m) =>
Config -> Object -> m a
fromObjectWith Config
cfg Object
obj


-- Instances for binary and UTF-8 encoded string.

instance MessagePack S.ByteString where
    toObject :: Config -> ByteString -> Object
toObject Config
_ = ByteString -> Object
ObjectBin
    fromObjectWith :: Config -> Object -> m ByteString
fromObjectWith Config
_ = \case
        ObjectBin ByteString
r -> ByteString -> m ByteString
forall (m :: * -> *) a. Monad m => a -> m a
return ByteString
r
        Object
_           -> DecodeError -> m ByteString
forall e (m :: * -> *) a. MonadValidate e m => e -> m a
refute DecodeError
"invalid encoding for ByteString"

instance MessagePack L.ByteString where
    toObject :: Config -> ByteString -> Object
toObject Config
_ = ByteString -> Object
ObjectBin (ByteString -> Object)
-> (ByteString -> ByteString) -> ByteString -> Object
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> ByteString
L.toStrict
    fromObjectWith :: Config -> Object -> m ByteString
fromObjectWith Config
cfg Object
obj = ByteString -> ByteString
L.fromStrict (ByteString -> ByteString) -> m ByteString -> m ByteString
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Config -> Object -> m ByteString
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m,
 MonadValidate DecodeError m) =>
Config -> Object -> m a
fromObjectWith Config
cfg Object
obj

instance MessagePack T.Text where
    toObject :: Config -> Text -> Object
toObject Config
_ = Text -> Object
ObjectStr
    fromObjectWith :: Config -> Object -> m Text
fromObjectWith Config
_ = \case
        ObjectStr Text
s -> Text -> m Text
forall (m :: * -> *) a. Monad m => a -> m a
return Text
s
        Object
_           -> DecodeError -> m Text
forall e (m :: * -> *) a. MonadValidate e m => e -> m a
refute DecodeError
"invalid encoding for Text"

instance MessagePack LT.Text where
    toObject :: Config -> Text -> Object
toObject Config
cfg = Config -> Text -> Object
forall a. MessagePack a => Config -> a -> Object
toObject Config
cfg (Text -> Object) -> (Text -> Text) -> Text -> Object
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> Text
LT.toStrict
    fromObjectWith :: Config -> Object -> m Text
fromObjectWith Config
cfg Object
obj = Text -> Text
LT.fromStrict (Text -> Text) -> m Text -> m Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Config -> Object -> m Text
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m,
 MonadValidate DecodeError m) =>
Config -> Object -> m a
fromObjectWith Config
cfg Object
obj


-- Instances for array-like data structures.

instance MessagePack a => MessagePack [a] where
    toObject :: Config -> [a] -> Object
toObject Config
cfg = Vector Object -> Object
ObjectArray (Vector Object -> Object)
-> ([a] -> Vector Object) -> [a] -> Object
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Object] -> Vector Object
forall a. [a] -> Vector a
V.fromList ([Object] -> Vector Object)
-> ([a] -> [Object]) -> [a] -> Vector Object
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Object) -> [a] -> [Object]
forall a b. (a -> b) -> [a] -> [b]
map (Config -> a -> Object
forall a. MessagePack a => Config -> a -> Object
toObject Config
cfg)
    fromObjectWith :: Config -> Object -> m [a]
fromObjectWith Config
cfg = \case
        ObjectArray Vector Object
o -> (Object -> m a) -> [Object] -> m [a]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (Config -> Object -> m a
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m,
 MonadValidate DecodeError m) =>
Config -> Object -> m a
fromObjectWith Config
cfg) (Vector Object -> [Object]
forall a. Vector a -> [a]
V.toList Vector Object
o)
        Object
_             -> DecodeError -> m [a]
forall e (m :: * -> *) a. MonadValidate e m => e -> m a
refute DecodeError
"invalid encoding for list"

instance MessagePack a => MessagePack (V.Vector a) where
    toObject :: Config -> Vector a -> Object
toObject Config
cfg = Vector Object -> Object
ObjectArray (Vector Object -> Object)
-> (Vector a -> Vector Object) -> Vector a -> Object
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Object) -> Vector a -> Vector Object
forall a b. (a -> b) -> Vector a -> Vector b
V.map (Config -> a -> Object
forall a. MessagePack a => Config -> a -> Object
toObject Config
cfg)
    fromObjectWith :: Config -> Object -> m (Vector a)
fromObjectWith Config
cfg = \case
        ObjectArray Vector 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 (Config -> Object -> m a
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m,
 MonadValidate DecodeError m) =>
Config -> Object -> m a
fromObjectWith Config
cfg) (Vector Object -> [Object]
forall a. Vector a -> [a]
V.toList Vector Object
o)
        Object
_             -> DecodeError -> m (Vector a)
forall e (m :: * -> *) a. MonadValidate e m => e -> m a
refute DecodeError
"invalid encoding for Vector"

instance (MessagePack a, VU.Unbox a) => MessagePack (VU.Vector a) where
    toObject :: Config -> Vector a -> Object
toObject Config
cfg = Vector Object -> Object
ObjectArray (Vector Object -> Object)
-> (Vector a -> Vector Object) -> Vector a -> Object
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Object) -> Vector a -> Vector Object
forall a b. (a -> b) -> Vector a -> Vector b
V.map (Config -> a -> Object
forall a. MessagePack a => Config -> a -> Object
toObject Config
cfg) (Vector a -> Vector Object)
-> (Vector a -> Vector a) -> Vector a -> Vector Object
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [a] -> Vector a
forall a. [a] -> Vector a
V.fromList ([a] -> Vector a) -> (Vector a -> [a]) -> Vector a -> Vector a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector a -> [a]
forall a. Unbox a => Vector a -> [a]
VU.toList
    fromObjectWith :: Config -> Object -> m (Vector a)
fromObjectWith Config
cfg = \case
        ObjectArray Vector Object
o -> [a] -> Vector a
forall a. Unbox a => [a] -> Vector a
VU.fromList ([a] -> Vector a) -> (Vector a -> [a]) -> Vector a -> Vector a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector a -> [a]
forall a. Vector a -> [a]
V.toList (Vector a -> Vector a) -> m (Vector a) -> m (Vector a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Object -> m a) -> Vector Object -> m (Vector a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Vector a -> m (Vector b)
V.mapM (Config -> Object -> m a
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m,
 MonadValidate DecodeError m) =>
Config -> Object -> m a
fromObjectWith Config
cfg) Vector Object
o
        Object
_             -> DecodeError -> m (Vector a)
forall e (m :: * -> *) a. MonadValidate e m => e -> m a
refute DecodeError
"invalid encoding for Unboxed Vector"

instance (MessagePack a, VS.Storable a) => MessagePack (VS.Vector a) where
    toObject :: Config -> Vector a -> Object
toObject Config
cfg = Vector Object -> Object
ObjectArray (Vector Object -> Object)
-> (Vector a -> Vector Object) -> Vector a -> Object
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Object) -> Vector a -> Vector Object
forall a b. (a -> b) -> Vector a -> Vector b
V.map (Config -> a -> Object
forall a. MessagePack a => Config -> a -> Object
toObject Config
cfg) (Vector a -> Vector Object)
-> (Vector a -> Vector a) -> Vector a -> Vector Object
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [a] -> Vector a
forall a. [a] -> Vector a
V.fromList ([a] -> Vector a) -> (Vector a -> [a]) -> Vector a -> Vector a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector a -> [a]
forall a. Storable a => Vector a -> [a]
VS.toList
    fromObjectWith :: Config -> Object -> m (Vector a)
fromObjectWith Config
cfg = \case
        ObjectArray Vector Object
o -> [a] -> Vector a
forall a. Storable a => [a] -> Vector a
VS.fromList ([a] -> Vector a) -> (Vector a -> [a]) -> Vector a -> Vector a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector a -> [a]
forall a. Vector a -> [a]
V.toList (Vector a -> Vector a) -> m (Vector a) -> m (Vector a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Object -> m a) -> Vector Object -> m (Vector a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Vector a -> m (Vector b)
V.mapM (Config -> Object -> m a
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m,
 MonadValidate DecodeError m) =>
Config -> Object -> m a
fromObjectWith Config
cfg) Vector Object
o
        Object
_             -> DecodeError -> m (Vector a)
forall e (m :: * -> *) a. MonadValidate e m => e -> m a
refute DecodeError
"invalid encoding for Storable Vector"

-- Instances for map-like data structures.

instance (MessagePack a, MessagePack b) => MessagePack (Assoc [(a, b)]) where
    toObject :: Config -> Assoc [(a, b)] -> Object
toObject Config
cfg (Assoc [(a, b)]
xs) = Vector (Object, Object) -> Object
ObjectMap (Vector (Object, Object) -> Object)
-> ([(Object, Object)] -> Vector (Object, Object))
-> [(Object, Object)]
-> Object
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(Object, Object)] -> Vector (Object, Object)
forall a. [a] -> Vector a
V.fromList ([(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 (Config -> a -> Object
forall a. MessagePack a => Config -> a -> Object
toObject Config
cfg (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')
*** Config -> b -> Object
forall a. MessagePack a => Config -> a -> Object
toObject Config
cfg) [(a, b)]
xs
    fromObjectWith :: Config -> Object -> m (Assoc [(a, b)])
fromObjectWith Config
cfg = \case
        ObjectMap Vector (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
<$> Config -> Object -> m a
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m,
 MonadValidate DecodeError m) =>
Config -> Object -> m a
fromObjectWith Config
cfg Object
k m (b -> (a, b)) -> m b -> m (a, b)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Config -> Object -> m b
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m,
 MonadValidate DecodeError m) =>
Config -> Object -> m a
fromObjectWith Config
cfg Object
v) (Vector (Object, Object) -> [(Object, Object)]
forall a. Vector a -> [a]
V.toList Vector (Object, Object)
xs)
        Object
_ -> DecodeError -> m (Assoc [(a, b)])
forall e (m :: * -> *) a. MonadValidate e m => e -> m a
refute DecodeError
"invalid encoding for Assoc"

instance (MessagePack k, MessagePack v, Ord k) => MessagePack (Map.Map k v) where
    toObject :: Config -> Map k v -> Object
toObject Config
cfg = Config -> Assoc [(k, v)] -> Object
forall a. MessagePack a => Config -> a -> Object
toObject Config
cfg (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
    fromObjectWith :: Config -> Object -> m (Map k v)
fromObjectWith Config
cfg 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
<$> Config -> Object -> m (Assoc [(k, v)])
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m,
 MonadValidate DecodeError m) =>
Config -> Object -> m a
fromObjectWith Config
cfg Object
obj

instance MessagePack v => MessagePack (IntMap.IntMap v) where
    toObject :: Config -> IntMap v -> Object
toObject Config
cfg = Config -> Assoc [(Int, v)] -> Object
forall a. MessagePack a => Config -> a -> Object
toObject Config
cfg (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
    fromObjectWith :: Config -> Object -> m (IntMap v)
fromObjectWith Config
cfg 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
<$> Config -> Object -> m (Assoc [(Int, v)])
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m,
 MonadValidate DecodeError m) =>
Config -> Object -> m a
fromObjectWith Config
cfg Object
obj

instance (MessagePack k, MessagePack v, Hashable k, Eq k) => MessagePack (HashMap.HashMap k v) where
    toObject :: Config -> HashMap k v -> Object
toObject Config
cfg = Config -> Assoc [(k, v)] -> Object
forall a. MessagePack a => Config -> a -> Object
toObject Config
cfg (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
    fromObjectWith :: Config -> Object -> m (HashMap k v)
fromObjectWith Config
cfg 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
<$> Config -> Object -> m (Assoc [(k, v)])
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m,
 MonadValidate DecodeError m) =>
Config -> Object -> m a
fromObjectWith Config
cfg Object
obj


-- Instances for various tuple arities.

instance (MessagePack a1, MessagePack a2) => MessagePack (a1, a2) where
    toObject :: Config -> (a1, a2) -> Object
toObject Config
cfg (a1
a1, a2
a2) = Vector Object -> Object
ObjectArray (Vector Object -> Object) -> Vector Object -> Object
forall a b. (a -> b) -> a -> b
$ [Object] -> Vector Object
forall a. [a] -> Vector a
V.fromList [Config -> a1 -> Object
forall a. MessagePack a => Config -> a -> Object
toObject Config
cfg a1
a1, Config -> a2 -> Object
forall a. MessagePack a => Config -> a -> Object
toObject Config
cfg a2
a2]
    fromObjectWith :: Config -> Object -> m (a1, a2)
fromObjectWith Config
cfg (ObjectArray (Vector Object -> [Object]
forall a. Vector a -> [a]
V.toList -> [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
<$> Config -> Object -> m a1
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m,
 MonadValidate DecodeError m) =>
Config -> Object -> m a
fromObjectWith Config
cfg Object
a1 m (a2 -> (a1, a2)) -> m a2 -> m (a1, a2)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Config -> Object -> m a2
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m,
 MonadValidate DecodeError m) =>
Config -> Object -> m a
fromObjectWith Config
cfg Object
a2
    fromObjectWith Config
_ Object
_                        = DecodeError -> m (a1, a2)
forall e (m :: * -> *) a. MonadValidate e m => e -> m a
refute DecodeError
"invalid encoding for tuple"

instance (MessagePack a1, MessagePack a2, MessagePack a3) => MessagePack (a1, a2, a3) where
    toObject :: Config -> (a1, a2, a3) -> Object
toObject Config
cfg (a1
a1, a2
a2, a3
a3) = Vector Object -> Object
ObjectArray (Vector Object -> Object) -> Vector Object -> Object
forall a b. (a -> b) -> a -> b
$ [Object] -> Vector Object
forall a. [a] -> Vector a
V.fromList [Config -> a1 -> Object
forall a. MessagePack a => Config -> a -> Object
toObject Config
cfg a1
a1, Config -> a2 -> Object
forall a. MessagePack a => Config -> a -> Object
toObject Config
cfg a2
a2, Config -> a3 -> Object
forall a. MessagePack a => Config -> a -> Object
toObject Config
cfg a3
a3]
    fromObjectWith :: Config -> Object -> m (a1, a2, a3)
fromObjectWith Config
cfg (ObjectArray (Vector Object -> [Object]
forall a. Vector a -> [a]
V.toList -> [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
<$> Config -> Object -> m a1
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m,
 MonadValidate DecodeError m) =>
Config -> Object -> m a
fromObjectWith Config
cfg 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
<*> Config -> Object -> m a2
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m,
 MonadValidate DecodeError m) =>
Config -> Object -> m a
fromObjectWith Config
cfg 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
<*> Config -> Object -> m a3
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m,
 MonadValidate DecodeError m) =>
Config -> Object -> m a
fromObjectWith Config
cfg Object
a3
    fromObjectWith Config
_ Object
_ = DecodeError -> m (a1, a2, a3)
forall e (m :: * -> *) a. MonadValidate e m => e -> m a
refute DecodeError
"invalid encoding for tuple"

instance (MessagePack a1, MessagePack a2, MessagePack a3, MessagePack a4) => MessagePack (a1, a2, a3, a4) where
    toObject :: Config -> (a1, a2, a3, a4) -> Object
toObject Config
cfg (a1
a1, a2
a2, a3
a3, a4
a4) = Vector Object -> Object
ObjectArray (Vector Object -> Object) -> Vector Object -> Object
forall a b. (a -> b) -> a -> b
$ [Object] -> Vector Object
forall a. [a] -> Vector a
V.fromList [Config -> a1 -> Object
forall a. MessagePack a => Config -> a -> Object
toObject Config
cfg a1
a1, Config -> a2 -> Object
forall a. MessagePack a => Config -> a -> Object
toObject Config
cfg a2
a2, Config -> a3 -> Object
forall a. MessagePack a => Config -> a -> Object
toObject Config
cfg a3
a3, Config -> a4 -> Object
forall a. MessagePack a => Config -> a -> Object
toObject Config
cfg a4
a4]
    fromObjectWith :: Config -> Object -> m (a1, a2, a3, a4)
fromObjectWith Config
cfg (ObjectArray (Vector Object -> [Object]
forall a. Vector a -> [a]
V.toList -> [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
<$> Config -> Object -> m a1
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m,
 MonadValidate DecodeError m) =>
Config -> Object -> m a
fromObjectWith Config
cfg 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
<*> Config -> Object -> m a2
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m,
 MonadValidate DecodeError m) =>
Config -> Object -> m a
fromObjectWith Config
cfg 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
<*> Config -> Object -> m a3
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m,
 MonadValidate DecodeError m) =>
Config -> Object -> m a
fromObjectWith Config
cfg 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
<*> Config -> Object -> m a4
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m,
 MonadValidate DecodeError m) =>
Config -> Object -> m a
fromObjectWith Config
cfg Object
a4
    fromObjectWith Config
_ Object
_ = DecodeError -> m (a1, a2, a3, a4)
forall e (m :: * -> *) a. MonadValidate e m => e -> m a
refute DecodeError
"invalid encoding for tuple"

instance (MessagePack a1, MessagePack a2, MessagePack a3, MessagePack a4, MessagePack a5) => MessagePack (a1, a2, a3, a4, a5) where
    toObject :: Config -> (a1, a2, a3, a4, a5) -> Object
toObject Config
cfg (a1
a1, a2
a2, a3
a3, a4
a4, a5
a5) = Vector Object -> Object
ObjectArray (Vector Object -> Object) -> Vector Object -> Object
forall a b. (a -> b) -> a -> b
$ [Object] -> Vector Object
forall a. [a] -> Vector a
V.fromList [Config -> a1 -> Object
forall a. MessagePack a => Config -> a -> Object
toObject Config
cfg a1
a1, Config -> a2 -> Object
forall a. MessagePack a => Config -> a -> Object
toObject Config
cfg a2
a2, Config -> a3 -> Object
forall a. MessagePack a => Config -> a -> Object
toObject Config
cfg a3
a3, Config -> a4 -> Object
forall a. MessagePack a => Config -> a -> Object
toObject Config
cfg a4
a4, Config -> a5 -> Object
forall a. MessagePack a => Config -> a -> Object
toObject Config
cfg a5
a5]
    fromObjectWith :: Config -> Object -> m (a1, a2, a3, a4, a5)
fromObjectWith Config
cfg (ObjectArray (Vector Object -> [Object]
forall a. Vector a -> [a]
V.toList -> [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
<$> Config -> Object -> m a1
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m,
 MonadValidate DecodeError m) =>
Config -> Object -> m a
fromObjectWith Config
cfg 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
<*> Config -> Object -> m a2
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m,
 MonadValidate DecodeError m) =>
Config -> Object -> m a
fromObjectWith Config
cfg 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
<*> Config -> Object -> m a3
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m,
 MonadValidate DecodeError m) =>
Config -> Object -> m a
fromObjectWith Config
cfg 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
<*> Config -> Object -> m a4
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m,
 MonadValidate DecodeError m) =>
Config -> Object -> m a
fromObjectWith Config
cfg 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
<*> Config -> Object -> m a5
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m,
 MonadValidate DecodeError m) =>
Config -> Object -> m a
fromObjectWith Config
cfg Object
a5
    fromObjectWith Config
_ Object
_ = DecodeError -> m (a1, a2, a3, a4, a5)
forall e (m :: * -> *) a. MonadValidate e m => e -> m a
refute DecodeError
"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 :: Config -> (a1, a2, a3, a4, a5, a6) -> Object
toObject Config
cfg (a1
a1, a2
a2, a3
a3, a4
a4, a5
a5, a6
a6) = Vector Object -> Object
ObjectArray (Vector Object -> Object) -> Vector Object -> Object
forall a b. (a -> b) -> a -> b
$ [Object] -> Vector Object
forall a. [a] -> Vector a
V.fromList [Config -> a1 -> Object
forall a. MessagePack a => Config -> a -> Object
toObject Config
cfg a1
a1, Config -> a2 -> Object
forall a. MessagePack a => Config -> a -> Object
toObject Config
cfg a2
a2, Config -> a3 -> Object
forall a. MessagePack a => Config -> a -> Object
toObject Config
cfg a3
a3, Config -> a4 -> Object
forall a. MessagePack a => Config -> a -> Object
toObject Config
cfg a4
a4, Config -> a5 -> Object
forall a. MessagePack a => Config -> a -> Object
toObject Config
cfg a5
a5, Config -> a6 -> Object
forall a. MessagePack a => Config -> a -> Object
toObject Config
cfg a6
a6]
    fromObjectWith :: Config -> Object -> m (a1, a2, a3, a4, a5, a6)
fromObjectWith Config
cfg (ObjectArray (Vector Object -> [Object]
forall a. Vector a -> [a]
V.toList -> [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
<$> Config -> Object -> m a1
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m,
 MonadValidate DecodeError m) =>
Config -> Object -> m a
fromObjectWith Config
cfg 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
<*> Config -> Object -> m a2
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m,
 MonadValidate DecodeError m) =>
Config -> Object -> m a
fromObjectWith Config
cfg 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
<*> Config -> Object -> m a3
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m,
 MonadValidate DecodeError m) =>
Config -> Object -> m a
fromObjectWith Config
cfg 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
<*> Config -> Object -> m a4
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m,
 MonadValidate DecodeError m) =>
Config -> Object -> m a
fromObjectWith Config
cfg 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
<*> Config -> Object -> m a5
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m,
 MonadValidate DecodeError m) =>
Config -> Object -> m a
fromObjectWith Config
cfg 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
<*> Config -> Object -> m a6
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m,
 MonadValidate DecodeError m) =>
Config -> Object -> m a
fromObjectWith Config
cfg Object
a6
    fromObjectWith Config
_ Object
_ = DecodeError -> m (a1, a2, a3, a4, a5, a6)
forall e (m :: * -> *) a. MonadValidate e m => e -> m a
refute DecodeError
"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 :: Config -> (a1, a2, a3, a4, a5, a6, a7) -> Object
toObject Config
cfg (a1
a1, a2
a2, a3
a3, a4
a4, a5
a5, a6
a6, a7
a7) = Vector Object -> Object
ObjectArray (Vector Object -> Object) -> Vector Object -> Object
forall a b. (a -> b) -> a -> b
$ [Object] -> Vector Object
forall a. [a] -> Vector a
V.fromList [Config -> a1 -> Object
forall a. MessagePack a => Config -> a -> Object
toObject Config
cfg a1
a1, Config -> a2 -> Object
forall a. MessagePack a => Config -> a -> Object
toObject Config
cfg a2
a2, Config -> a3 -> Object
forall a. MessagePack a => Config -> a -> Object
toObject Config
cfg a3
a3, Config -> a4 -> Object
forall a. MessagePack a => Config -> a -> Object
toObject Config
cfg a4
a4, Config -> a5 -> Object
forall a. MessagePack a => Config -> a -> Object
toObject Config
cfg a5
a5, Config -> a6 -> Object
forall a. MessagePack a => Config -> a -> Object
toObject Config
cfg a6
a6, Config -> a7 -> Object
forall a. MessagePack a => Config -> a -> Object
toObject Config
cfg a7
a7]
    fromObjectWith :: Config -> Object -> m (a1, a2, a3, a4, a5, a6, a7)
fromObjectWith Config
cfg (ObjectArray (Vector Object -> [Object]
forall a. Vector a -> [a]
V.toList -> [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
<$> Config -> Object -> m a1
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m,
 MonadValidate DecodeError m) =>
Config -> Object -> m a
fromObjectWith Config
cfg 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
<*> Config -> Object -> m a2
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m,
 MonadValidate DecodeError m) =>
Config -> Object -> m a
fromObjectWith Config
cfg 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
<*> Config -> Object -> m a3
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m,
 MonadValidate DecodeError m) =>
Config -> Object -> m a
fromObjectWith Config
cfg 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
<*> Config -> Object -> m a4
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m,
 MonadValidate DecodeError m) =>
Config -> Object -> m a
fromObjectWith Config
cfg 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
<*> Config -> Object -> m a5
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m,
 MonadValidate DecodeError m) =>
Config -> Object -> m a
fromObjectWith Config
cfg 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
<*> Config -> Object -> m a6
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m,
 MonadValidate DecodeError m) =>
Config -> Object -> m a
fromObjectWith Config
cfg 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
<*> Config -> Object -> m a7
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m,
 MonadValidate DecodeError m) =>
Config -> Object -> m a
fromObjectWith Config
cfg Object
a7
    fromObjectWith Config
_ Object
_ = DecodeError -> m (a1, a2, a3, a4, a5, a6, a7)
forall e (m :: * -> *) a. MonadValidate e m => e -> m a
refute DecodeError
"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 :: Config -> (a1, a2, a3, a4, a5, a6, a7, a8) -> Object
toObject Config
cfg (a1
a1, a2
a2, a3
a3, a4
a4, a5
a5, a6
a6, a7
a7, a8
a8) = Vector Object -> Object
ObjectArray (Vector Object -> Object) -> Vector Object -> Object
forall a b. (a -> b) -> a -> b
$ [Object] -> Vector Object
forall a. [a] -> Vector a
V.fromList [Config -> a1 -> Object
forall a. MessagePack a => Config -> a -> Object
toObject Config
cfg a1
a1, Config -> a2 -> Object
forall a. MessagePack a => Config -> a -> Object
toObject Config
cfg a2
a2, Config -> a3 -> Object
forall a. MessagePack a => Config -> a -> Object
toObject Config
cfg a3
a3, Config -> a4 -> Object
forall a. MessagePack a => Config -> a -> Object
toObject Config
cfg a4
a4, Config -> a5 -> Object
forall a. MessagePack a => Config -> a -> Object
toObject Config
cfg a5
a5, Config -> a6 -> Object
forall a. MessagePack a => Config -> a -> Object
toObject Config
cfg a6
a6, Config -> a7 -> Object
forall a. MessagePack a => Config -> a -> Object
toObject Config
cfg a7
a7, Config -> a8 -> Object
forall a. MessagePack a => Config -> a -> Object
toObject Config
cfg a8
a8]
    fromObjectWith :: Config -> Object -> m (a1, a2, a3, a4, a5, a6, a7, a8)
fromObjectWith Config
cfg (ObjectArray (Vector Object -> [Object]
forall a. Vector a -> [a]
V.toList -> [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
<$> Config -> Object -> m a1
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m,
 MonadValidate DecodeError m) =>
Config -> Object -> m a
fromObjectWith Config
cfg 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
<*> Config -> Object -> m a2
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m,
 MonadValidate DecodeError m) =>
Config -> Object -> m a
fromObjectWith Config
cfg 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
<*> Config -> Object -> m a3
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m,
 MonadValidate DecodeError m) =>
Config -> Object -> m a
fromObjectWith Config
cfg 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
<*> Config -> Object -> m a4
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m,
 MonadValidate DecodeError m) =>
Config -> Object -> m a
fromObjectWith Config
cfg 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
<*> Config -> Object -> m a5
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m,
 MonadValidate DecodeError m) =>
Config -> Object -> m a
fromObjectWith Config
cfg 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
<*> Config -> Object -> m a6
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m,
 MonadValidate DecodeError m) =>
Config -> Object -> m a
fromObjectWith Config
cfg 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
<*> Config -> Object -> m a7
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m,
 MonadValidate DecodeError m) =>
Config -> Object -> m a
fromObjectWith Config
cfg 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
<*> Config -> Object -> m a8
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m,
 MonadValidate DecodeError m) =>
Config -> Object -> m a
fromObjectWith Config
cfg Object
a8
    fromObjectWith Config
_ Object
_ = DecodeError -> m (a1, a2, a3, a4, a5, a6, a7, a8)
forall e (m :: * -> *) a. MonadValidate e m => e -> m a
refute DecodeError
"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 :: Config -> (a1, a2, a3, a4, a5, a6, a7, a8, a9) -> Object
toObject Config
cfg (a1
a1, a2
a2, a3
a3, a4
a4, a5
a5, a6
a6, a7
a7, a8
a8, a9
a9) = Vector Object -> Object
ObjectArray (Vector Object -> Object) -> Vector Object -> Object
forall a b. (a -> b) -> a -> b
$ [Object] -> Vector Object
forall a. [a] -> Vector a
V.fromList [Config -> a1 -> Object
forall a. MessagePack a => Config -> a -> Object
toObject Config
cfg a1
a1, Config -> a2 -> Object
forall a. MessagePack a => Config -> a -> Object
toObject Config
cfg a2
a2, Config -> a3 -> Object
forall a. MessagePack a => Config -> a -> Object
toObject Config
cfg a3
a3, Config -> a4 -> Object
forall a. MessagePack a => Config -> a -> Object
toObject Config
cfg a4
a4, Config -> a5 -> Object
forall a. MessagePack a => Config -> a -> Object
toObject Config
cfg a5
a5, Config -> a6 -> Object
forall a. MessagePack a => Config -> a -> Object
toObject Config
cfg a6
a6, Config -> a7 -> Object
forall a. MessagePack a => Config -> a -> Object
toObject Config
cfg a7
a7, Config -> a8 -> Object
forall a. MessagePack a => Config -> a -> Object
toObject Config
cfg a8
a8, Config -> a9 -> Object
forall a. MessagePack a => Config -> a -> Object
toObject Config
cfg a9
a9]
    fromObjectWith :: Config -> Object -> m (a1, a2, a3, a4, a5, a6, a7, a8, a9)
fromObjectWith Config
cfg (ObjectArray (Vector Object -> [Object]
forall a. Vector a -> [a]
V.toList -> [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
<$> Config -> Object -> m a1
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m,
 MonadValidate DecodeError m) =>
Config -> Object -> m a
fromObjectWith Config
cfg 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
<*> Config -> Object -> m a2
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m,
 MonadValidate DecodeError m) =>
Config -> Object -> m a
fromObjectWith Config
cfg 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
<*> Config -> Object -> m a3
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m,
 MonadValidate DecodeError m) =>
Config -> Object -> m a
fromObjectWith Config
cfg 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
<*> Config -> Object -> m a4
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m,
 MonadValidate DecodeError m) =>
Config -> Object -> m a
fromObjectWith Config
cfg 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
<*> Config -> Object -> m a5
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m,
 MonadValidate DecodeError m) =>
Config -> Object -> m a
fromObjectWith Config
cfg 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
<*> Config -> Object -> m a6
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m,
 MonadValidate DecodeError m) =>
Config -> Object -> m a
fromObjectWith Config
cfg 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
<*> Config -> Object -> m a7
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m,
 MonadValidate DecodeError m) =>
Config -> Object -> m a
fromObjectWith Config
cfg 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
<*> Config -> Object -> m a8
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m,
 MonadValidate DecodeError m) =>
Config -> Object -> m a
fromObjectWith Config
cfg 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
<*> Config -> Object -> m a9
forall a (m :: * -> *).
(MessagePack a, Applicative m, Monad m,
 MonadValidate DecodeError m) =>
Config -> Object -> m a
fromObjectWith Config
cfg Object
a9
    fromObjectWith Config
_ Object
_ = DecodeError -> m (a1, a2, a3, a4, a5, a6, a7, a8, a9)
forall e (m :: * -> *) a. MonadValidate e m => e -> m a
refute DecodeError
"invalid encoding for tuple"