packages feed

tools-yj 0.1.0.30 → 0.1.0.31

raw patch · 3 files changed

+57/−3 lines, 3 filesPVP: minor bump suggested

API additions: PVP suggests at least a minor version bump

API changes (from Hackage documentation)

+ Data.ByteString.Lazy.ToolsYj: fromBits :: Bits b => b -> ByteString
+ Data.ByteString.Lazy.ToolsYj: fromBits' :: FiniteBits b => b -> ByteString
+ Data.ByteString.Lazy.ToolsYj: fromBitsBE' :: FiniteBits b => b -> ByteString
+ Data.ByteString.Lazy.ToolsYj: toBits :: Bits b => ByteString -> b
+ Data.ByteString.Lazy.ToolsYj: toBits' :: FiniteBits b => ByteString -> Maybe b
+ Data.ByteString.Lazy.ToolsYj: toBitsBE :: Bits b => ByteString -> b

Files

src/Data/ByteString/Lazy/ToolsYj.hs view
@@ -1,11 +1,57 @@ {-# LANGUAGE ImportQualifiedPost #-}+{-# LANGUAGE BlockArguments, OverloadedStrings #-}+{-# LANGUAGE ScopedTypeVariables, TypeApplications #-} {-# OPTIONS_GHC -Wall -fno-warn-tabs #-}  module Data.ByteString.Lazy.ToolsYj (-	splitAt' ) where +	-- * FROM/TO BITS++	fromBits, fromBits', toBits, toBits',++	-- * FROM/TO BITS -- BIG ENDIEN++	fromBitsBE', toBitsBE,++	-- * SPLIT AT++	splitAt'++	) where++import Data.Bits+import Data.Bits.ToolsYj+import Data.Bool import Data.Int import Data.ByteString.Lazy qualified as LBS++fromBits :: Bits b => b -> LBS.ByteString+fromBits = LBS.unfoldr \b ->+	bool Nothing (Just (bitsToBits 8 b, b `shiftR` 8)) (b /= zeroBits)++fromBits' :: FiniteBits b => b -> LBS.ByteString+fromBits' b0 = go (finiteBitSize b0 `div` 8) b0+	where+	go 0 _ = ""+	go n b = bitsToBits 8 b `LBS.cons` go (n - 1) (b `shiftR` 8)++toBits :: Bits b => LBS.ByteString -> b+toBits = LBS.foldr (\b s -> bitsToBits 8 b .|. s `shiftL` 8) zeroBits++toBits' :: forall b . FiniteBits b => LBS.ByteString -> Maybe b+toBits' bs = bool+	Nothing+	(Just $ LBS.foldr (\b s -> bitsToBits 8 b .|. s `shiftL` 8) zeroBits bs)+	(8 * LBS.length bs <= fromIntegral (finiteBitSize @b undefined))++toBitsBE :: Bits b => LBS.ByteString -> b+toBitsBE = LBS.foldl (\s b -> bitsToBits 8 b .|. s `shiftL` 8) zeroBits++fromBitsBE' :: FiniteBits b => b -> LBS.ByteString+fromBitsBE' b0 = go (finiteBitSize b0 `div` 8) b0+	where+	go 0 _ = ""+	go n b = go (n - 1) (b `shiftR` 8) `LBS.snoc` bitsToBits 8 b  splitAt' :: Int64 -> LBS.ByteString -> Maybe (LBS.ByteString, LBS.ByteString) splitAt' n bs
src/Data/ByteString/ToolsYj.hs view
@@ -5,9 +5,17 @@  module Data.ByteString.ToolsYj ( +	-- * FROM/TO BITS+ 	fromBits, fromBits', toBits, toBits', -	fromBitsBE', toBitsBE, splitAt'+	-- * FROM/TO BITS -- BIG ENDIEN++	fromBitsBE', toBitsBE,++	-- * SPLIT AT++	splitAt'  	) where 
tools-yj.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack  name:           tools-yj-version:        0.1.0.30+version:        0.1.0.31 synopsis:       Tribial tools description:    Please see the README on GitHub at <https://github.com/YoshikuniJujo/tools-yj#readme> category:       Tools