on master help sign in
Add Serialize instance for tuple
8e04e4bAdithya Kumar
core/src/Streamly/Internal/Data/Serialize/Type.hs+16
@@ -267,6 +267,22 @@ instance Serialize (Array a) where
267 Unbox.putSliceUnsafe arrContents arrStart arr off1 arrLen
267 Unbox.putSliceUnsafe arrContents arrStart arr off1 arrLen
268 pure (off1 + arrLen)
268 pure (off1 + arrLen)
269
269
270+instance (Serialize a, Serialize b) => Serialize (a, b) where
271+
272+ {-# INLINE size #-}
273+ size acc (a, b) = size (size acc a) b
274+
275+ {-# INLINE serialize #-}
276+ serialize off arr (a, b) = do
277+ off1 <- serialize off arr a
278+ serialize off1 arr b
279+
280+ {-# INLINE deserialize #-}
281+ deserialize off arr end = do
282+ (off1, a) <- deserialize off arr end
283+ (off2, b) <- deserialize off1 arr end
284+ pure (off2, (a, b))
285+
270--------------------------------------------------------------------------------
286--------------------------------------------------------------------------------
271-- High level functions
287-- High level functions
272--------------------------------------------------------------------------------
288--------------------------------------------------------------------------------
test/Streamly/Test/Data/Serialize.hs+3
@@ -239,6 +239,9 @@ testCases = do
239 prop "Integer"
239 prop "Integer"
240 $ \(x :: Integer) -> roundtrip x
240 $ \(x :: Integer) -> roundtrip x
241
241
242+ prop "([Integer], [Int])"
243+ $ \(x :: ([Integer], [Int])) -> roundtrip x
244+
242 prop "Array Int"
245 prop "Array Int"
243 $ \(x :: [Int]) -> roundtrip (Array.fromList x)
246 $ \(x :: [Int]) -> roundtrip (Array.fromList x)
244
247