on master help sign in
Dissolve the Serialize module into ToBytes/FromBytes
672789aHarendra Kumar
core/src/Streamly/Internal/Serialize.hsdeleted−27
@@ -1,27 +0,0 @@
1−-- |
2−-- Module : Streamly.Internal.Serialize
3−-- Copyright : (c) 2022 Composewell Technologies
4−-- License : BSD-3-Clause
5−-- Maintainer : streamly@composewell.com
6−-- Stability : pre-release
7−-- Portability : GHC
8−--
9−-- Convert Haskell data types to byte streams and vice-versa.
10−
11−module Streamly.Internal.Serialize
12− ( ToBytes (..)
13− , FromBytes (..)
14− )
15−where
16−
17−import Data.Word (Word8)
18−import Streamly.Internal.Data.Stream (Stream)
19−import Streamly.Internal.Data.Parser (Parser)
20−
21−class ToBytes a where
22− -- | Convert a Haskell type to a byte stream.
23− toBytes :: a -> Stream m Word8
24−
25−class FromBytes a where
26− -- | Decode a byte stream to a Haskell type.
27− fromBytes :: Parser Word8 m a
core/src/Streamly/Internal/Serialize/FromBytes.hs+10−1
@@ -9,7 +9,8 @@
9-- Parsers for binary encoded basic Haskell data types.
9-- Parsers for binary encoded basic Haskell data types.
10
10
11module Streamly.Internal.Serialize.FromBytes
11module Streamly.Internal.Serialize.FromBytes
12+ ( FromBytes (..)
12− ( unit
13+ , unit
13 , bool
14 , bool
14 , ordering
15 , ordering
15 , eqWord8 -- XXX rename to word8Eq
16 , eqWord8 -- XXX rename to word8Eq
@@ -278,3 +279,11 @@ word64le = PRD.toParserK word64leD
278word64host :: MonadIO m => Parser Word8 m Word64
279word64host :: MonadIO m => Parser Word8 m Word64
279word64host =
280word64host =
280 fmap (A.unsafeIndex 0 . A.castUnsafe) $ PR.takeEQ 8 (A.writeN 8)
281 fmap (A.unsafeIndex 0 . A.castUnsafe) $ PR.takeEQ 8 (A.writeN 8)
282+
283+-------------------------------------------------------------------------------
284+-- Type class
285+-------------------------------------------------------------------------------
286+
287+class FromBytes a where
288+ -- | Decode a byte stream to a Haskell type.
289+ fromBytes :: Parser Word8 m a
core/src/Streamly/Internal/Serialize/ToBytes.hs+10−1
@@ -9,7 +9,8 @@
9-- Converting Haskell data types to byte streams.
9-- Converting Haskell data types to byte streams.
10
10
11module Streamly.Internal.Serialize.ToBytes
11module Streamly.Internal.Serialize.ToBytes
12+ ( ToBytes (..)
12− ( unit
13+ , unit
13 , bool
14 , bool
14 , ordering
15 , ordering
15 , word8
16 , word8
@@ -259,3 +260,11 @@ word64host =
259#else
260#else
260 word64le
261 word64le
261#endif
262#endif
263+
264+-------------------------------------------------------------------------------
265+-- Type class
266+-------------------------------------------------------------------------------
267+
268+class ToBytes a where
269+ -- | Convert a Haskell type to a byte stream.
270+ toBytes :: a -> Stream m Word8
core/streamly-core.cabal−1
@@ -336,7 +336,6 @@ library
336 -- streamly-serde
336 -- streamly-serde
337 , Streamly.Internal.Serialize.FromBytes
337 , Streamly.Internal.Serialize.FromBytes
338 , Streamly.Internal.Serialize.ToBytes
338 , Streamly.Internal.Serialize.ToBytes
339− , Streamly.Internal.Serialize
340
339
341 -- streamly-unicode-core
340 -- streamly-unicode-core
342 , Streamly.Internal.Unicode.Stream
341 , Streamly.Internal.Unicode.Stream