mirror of
https://github.com/composewell/streamly.git
synced 2024-08-16 23:10:36 +03:00
Add Serialize instance for tuple
This commit is contained in:
parent
763460b1b6
commit
8e04e4b988
@ -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
|
||||
--------------------------------------------------------------------------------
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user