Add Serialize instance for tuple

This commit is contained in:
Adithya Kumar 2023-09-30 12:39:47 +05:30
parent 763460b1b6
commit 8e04e4b988
2 changed files with 19 additions and 0 deletions

View File

@ -267,6 +267,22 @@ instance Serialize (Array a) where
Unbox.putSliceUnsafe arrContents arrStart arr off1 arrLen
pure (off1 + arrLen)
instance (Serialize a, Serialize b) => Serialize (a, b) where
{-# INLINE size #-}
size acc (a, b) = size (size acc a) b
{-# INLINE serialize #-}
serialize off arr (a, b) = do
off1 <- serialize off arr a
serialize off1 arr b
{-# INLINE deserialize #-}
deserialize off arr end = do
(off1, a) <- deserialize off arr end
(off2, b) <- deserialize off1 arr end
pure (off2, (a, b))
--------------------------------------------------------------------------------
-- High level functions
--------------------------------------------------------------------------------

View File

@ -239,6 +239,9 @@ testCases = do
prop "Integer"
$ \(x :: Integer) -> roundtrip x
prop "([Integer], [Int])"
$ \(x :: ([Integer], [Int])) -> roundtrip x
prop "Array Int"
$ \(x :: [Int]) -> roundtrip (Array.fromList x)