on master help sign in
Dissolve the Serialize module into ToBytes/FromBytes
commit672789a592c17b102804ce7e89d215ad096efd50 authorHarendra Kumar <harendra@composewell.com> dateSun 18 Dec 2022, 02:18 (4 years ago) parent03f14f0
4 files changed+20−30
core/src/Streamly/Internal/Serialize.hs−27 core/src/Streamly/Internal/Serialize/FromBytes.hs+10−1 core/src/Streamly/Internal/Serialize/ToBytes.hs+10−1 core/streamly-core.cabal−1
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 @@
99-- Parsers for binary encoded basic Haskell data types.
1010
1111module Streamly.Internal.Serialize.FromBytes
12− ( unit
12+ ( FromBytes (..)
13+ , unit
1314 , bool
1415 , ordering
1516 , eqWord8 -- XXX rename to word8Eq
@@ -278,3 +279,11 @@ word64le = PRD.toParserK word64leD
278279word64host :: MonadIO m => Parser Word8 m Word64
279280word64host =
280281 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 @@
99-- Converting Haskell data types to byte streams.
1010
1111module Streamly.Internal.Serialize.ToBytes
12− ( unit
12+ ( ToBytes (..)
13+ , unit
1314 , bool
1415 , ordering
1516 , word8
@@ -259,3 +260,11 @@ word64host =
259260#else
260261 word64le
261262#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
336336 -- streamly-serde
337337 , Streamly.Internal.Serialize.FromBytes
338338 , Streamly.Internal.Serialize.ToBytes
339− , Streamly.Internal.Serialize
340339
341340 -- streamly-unicode-core
342341 , Streamly.Internal.Unicode.Stream