@@ -28,7 +28,11 @@ import Streamly.Internal.Data.Unbox (Unbox(..), sizeOfMutableByteArray)
28import Control.Monad (void)
28import Control.Monad (void)
29import Data.List (foldl')
29import Data.List (foldl')
30import Data.Proxy (Proxy (..))
30import Data.Proxy (Proxy (..))
31−import Streamly.Internal.Data.Unbox (MutableByteArray(..), PinnedState(..))
31+import Streamly.Internal.Data.Unbox
32+ ( MutableByteArray(..)
32import Streamly.Internal.Data.Array.Type (Array(..))
36import Streamly.Internal.Data.Array.Type (Array(..))
33import Streamly.Internal.System.IO (unsafeInlineIO)
37import Streamly.Internal.System.IO (unsafeInlineIO)
34import GHC.Int (Int16(..), Int32(..), Int64(..), Int8(..))
38import GHC.Int (Int16(..), Int32(..), Int64(..), Int8(..))
@@ -126,25 +130,32 @@ checkBounds _label _off _arr = do
126 return ()
130 return ()
133+{-# INLINE deserializeUnsafe #-}
134+deserializeUnsafe :: forall a. Unbox a => Int -> MutableByteArray -> IO (Int, a)
135+deserializeUnsafe off arr =
136+ let next = off + Unbox.sizeOf (Proxy :: Proxy a)
138+ checkBounds "deserialize" next arr
139+ Unbox.peekByteIndex off arr >>= \val -> pure (next, val)
141+{-# INLINE serializeUnsafe #-}
142+serializeUnsafe :: forall a. Unbox a => Int -> MutableByteArray -> a -> IO Int
143+serializeUnsafe off arr val =
144+ let next = off + Unbox.sizeOf (Proxy :: Proxy a)
146+ checkBounds "serialize" next arr
147+ Unbox.pokeByteIndex off arr val
129#define DERIVE_SERIALIZE_FROM_UNBOX(_type) \
150#define DERIVE_SERIALIZE_FROM_UNBOX(_type) \
130instance Serialize _type where \
151instance Serialize _type where \
131; {-# INLINE size #-} \
152; {-# INLINE size #-} \
132; size = Size (\acc _ -> acc + Unbox.sizeOf (Proxy :: Proxy _type)) \
153; size = Size (\acc _ -> acc + Unbox.sizeOf (Proxy :: Proxy _type)) \
133; {-# INLINE deserialize #-} \
154; {-# INLINE deserialize #-} \
134−; deserialize off arr = \
155+; deserialize off arr = deserializeUnsafe off arr :: IO (Int, _type) \
135− let next = off + Unbox.sizeOf (Proxy :: Proxy _type) \
137− checkBounds "deserialize" next arr; \
138− Unbox.peekByteIndex off arr >>= \val -> pure (next, val); \
140; {-# INLINE serialize #-} \
156; {-# INLINE serialize #-} \
141−; serialize off arr val = \
157+; serialize = \
142− let next = off + Unbox.sizeOf (Proxy :: Proxy _type) \
158+ serializeUnsafe :: Int -> MutableByteArray -> _type -> IO Int
144− checkBounds "serialize" next arr; \
145− Unbox.pokeByteIndex off arr val; \
149DERIVE_SERIALIZE_FROM_UNBOX(Bool)
160DERIVE_SERIALIZE_FROM_UNBOX(Bool)
150DERIVE_SERIALIZE_FROM_UNBOX(Char)
161DERIVE_SERIALIZE_FROM_UNBOX(Char)