on master help sign in
Add word64host
commit6b856286fa30f0b248d1a6c87badb3937df2e6fc authorHarendra Kumar <harendra@composewell.com> dateWed 12 Aug 2020, 00:48 (6 years ago) parenta98d897
1 file changed+16
src/Streamly/Internal/Data/Binary/Decode.hs+16
src/Streamly/Internal/Data/Binary/Decode.hs+16
@@ -20,15 +20,18 @@ module Streamly.Internal.Data.Binary.Decode
2020 , word32le
2121 , word64be
2222 , word64le
23+ , word64host
2324 )
2425where
2526
2627import Control.Monad.Catch (MonadCatch, throwM)
28+import Control.Monad.IO.Class (MonadIO)
2729import Data.Bits ((.|.), unsafeShiftL)
2830import Data.Word (Word8, Word16, Word32, Word64)
2931import Streamly.Internal.Data.Parser (Parser)
3032import Streamly.Internal.Data.Strict (Maybe'(..), Tuple' (..))
3133
34+import qualified Streamly.Internal.Memory.Array as A
3235import qualified Streamly.Internal.Data.Parser as PR
3336import qualified Streamly.Internal.Data.Parser.ParserD as PRD
3437import qualified Streamly.Internal.Data.Parser.ParserK.Types as PRK
@@ -259,3 +262,16 @@ word64leD = PRD.Parser step initial extract
259262{-# INLINE word64le #-}
260263word64le :: MonadCatch m => Parser m Word8 Word64
261264word64le = PRK.toParserK word64leD
265+
266+-------------------------------------------------------------------------------
267+-- Host byte order
268+-------------------------------------------------------------------------------
269+
270+-- | Parse eight bytes as a 'Word64' in the host byte order.
271+--
272+-- /Internal/
273+--
274+{-# INLINE word64host #-}
275+word64host :: (MonadIO m, MonadCatch m) => Parser m Word8 Word64
276+word64host =
277+ fmap (flip A.unsafeIndex 0 . A.unsafeCast) $ PR.take 8 (A.writeN 8)