binary-conduit 1.2.4.1 → 1.2.5
raw patch · 3 files changed
+25/−28 lines, 3 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Data.Conduit.Serialization.Binary: conduitMsgEncode :: (Binary b, MonadThrow m) => Conduit b m ByteString
+ Data.Conduit.Serialization.Binary: conduitMsgEncode :: Monad m => (Binary b) => Conduit b m ByteString
- Data.Conduit.Serialization.Binary: conduitPut :: MonadThrow m => Conduit Put m ByteString
+ Data.Conduit.Serialization.Binary: conduitPut :: Monad m => Conduit Put m ByteString
- Data.Conduit.Serialization.Binary: conduitPutLBS :: MonadThrow m => Conduit Put m ByteString
+ Data.Conduit.Serialization.Binary: conduitPutLBS :: Monad m => Conduit Put m ByteString
- Data.Conduit.Serialization.Binary: conduitPutList :: MonadThrow m => Conduit Put m [ByteString]
+ Data.Conduit.Serialization.Binary: conduitPutList :: Monad m => Conduit Put m [ByteString]
- Data.Conduit.Serialization.Binary: conduitPutMany :: MonadThrow m => Conduit Put m (Vector ByteString)
+ Data.Conduit.Serialization.Binary: conduitPutMany :: Monad m => Conduit Put m (Vector ByteString)
- Data.Conduit.Serialization.Binary: sourcePut :: MonadThrow m => Put -> Producer m ByteString
+ Data.Conduit.Serialization.Binary: sourcePut :: Monad m => Put -> Producer m ByteString
Files
- Data/Conduit/Serialization/Binary.hs +10/−10
- binary-conduit.cabal +4/−4
- test/Main.hs +11/−14
Data/Conduit/Serialization/Binary.hs view
@@ -27,7 +27,7 @@ import qualified Data.Conduit.List as CL import Data.Typeable import qualified Data.Vector as V-import Control.Monad.Trans.Resource +import Control.Monad.Trans.Resource (MonadThrow , monadThrow) @@ -52,7 +52,7 @@ -- -- This function produces a stream of bytes where for each input -- value you will have a number of 'ByteString's, and no boundary--- between different values. +-- between different values. conduitEncode :: (Binary b, MonadThrow m) => Conduit b m ByteString conduitEncode = CL.map put =$= conduitPut @@ -70,7 +70,7 @@ -- you interested in iterative packet serialization -- concider using 'conduitPutList' or 'conduitPutMany' ---conduitMsgEncode :: (Binary b, MonadThrow m) => Conduit b m ByteString+conduitMsgEncode :: Monad m => (Binary b) => Conduit b m ByteString conduitMsgEncode = CL.map put =$= conduitMsg -- | Runs getter repeatedly on a input stream.@@ -98,31 +98,31 @@ Just x -> do { yi ; conduit}} -- | Runs putter repeatedly on a input stream, returns an output stream.-conduitPut :: MonadThrow m => Conduit Put m ByteString+conduitPut :: Monad m => Conduit Put m ByteString conduitPutGeneric(conduitPut, (sourcePut x $$ CL.mapM_ yield)) -- | Runs a putter repeatedly on a input stream, returns a packets.-conduitMsg :: MonadThrow m => Conduit Put m ByteString+conduitMsg :: Monad m => Conduit Put m ByteString conduitPutGeneric(conduitMsg, (yield (LBS.toStrict $ runPut x))) -- | Runs putter repeatedly on a input stream. -- Returns a lazy butestring so it's possible to use vectorized--- IO on the result either by calling' LBS.toChunks' or by +-- IO on the result either by calling' LBS.toChunks' or by -- calling 'Network.Socket.ByteString.Lazy.send'.-conduitPutLBS :: MonadThrow m => Conduit Put m LBS.ByteString+conduitPutLBS :: Monad m => Conduit Put m LBS.ByteString conduitPutGeneric(conduitPutLBS, yield (runPut x)) -- | Vectorized variant of 'conduitPut' returning list contains -- all chunks from one element representation-conduitPutList :: MonadThrow m => Conduit Put m [ByteString]+conduitPutList :: Monad m => Conduit Put m [ByteString] conduitPutGeneric(conduitPutList, yield (LBS.toChunks (runPut x))) -- | Vectorized variant of 'conduitPut'.-conduitPutMany :: MonadThrow m => Conduit Put m (V.Vector ByteString)+conduitPutMany :: Monad m => Conduit Put m (V.Vector ByteString) conduitPutGeneric(conduitPutMany, yield (V.fromList (LBS.toChunks (runPut x)))) -- | Create stream of strict bytestrings from 'Put' value.-sourcePut :: MonadThrow m => Put -> Producer m ByteString+sourcePut :: Monad m => Put -> Producer m ByteString sourcePut = CL.sourceList . LBS.toChunks . runPut -- | Decode message from input stream.
binary-conduit.cabal view
@@ -1,5 +1,5 @@ name: binary-conduit-version: 1.2.4.1+version: 1.2.5 synopsis: data serialization/deserialization conduit library description: The binary-conduit package. Allow binary serialization using iterative conduit interface.@@ -7,16 +7,16 @@ license-file: LICENSE author: Alexander Vershilov maintainer: alexander.vershilov@gmail.com-copyright: 2013-2016 Alexander Vershilov+copyright: 2013 Alexander Vershilov category: Conduit stability: Experimental homepage: http://github.com/qnikst/binary-conduit/ bug-reports: http://github.com/qnikst/binary-conduit/issues build-type: Simple cabal-version: >=1.8-+tested-with: GHC == 7.8.4, GHC == 7.10.3, GHC == 8.2.1 library- exposed-modules:+ exposed-modules: Data.Conduit.Serialization.Binary build-depends: base >=4 && <5, conduit >= 1.1 && < 1.3,
test/Main.hs view
@@ -14,13 +14,13 @@ import Test.QuickCheck.Property import Test.QuickCheck.Monadic import Test.QuickCheck-import Control.Monad.Trans.Resource +import Control.Monad.Trans.Resource import GHC.Generics -- | check conduitEncode =$= conduitDecode == id prop_eq :: (Binary a,Eq a) => [a] -> Property-prop_eq xs = monadicIO $ do - xs' <- runExceptionT $ CL.sourceList xs +prop_eq xs = monadicIO $ do+ xs' <- runExceptionT $ CL.sourceList xs $= enc xs =$= dec xs $$ CL.consume@@ -28,7 +28,7 @@ Left e -> fail "exception" Right x -> assert $ x == xs where enc :: (Binary a, MonadThrow m) => [a] -> Conduit a m ByteString- enc _ = conduitEncode + enc _ = conduitEncode dec :: (Binary a, MonadThrow m) => [a] -> Conduit ByteString m a dec _ = conduitDecode @@ -43,7 +43,7 @@ assert $ a == a' assert $ runPut (put b) == LBS.fromChunks b' where enc :: (Binary a, MonadThrow m) => a -> Conduit a m ByteString- enc _ = conduitEncode + enc _ = conduitEncode dec :: (Binary a, MonadThrow m) => a -> Conduit ByteString m a dec _ = conduitDecode @@ -84,14 +84,11 @@ arbitrary = A <$> fmap BS.pack arbitrary <*> fmap BS.pack arbitrary - prop_eq_plus :: (Binary a, Eq a) => [a] -> Property prop_eq_plus xs = monadicIO $ do- x <- runExceptionT $ CL.sourceList xs $= CL.map encode =$= CL.map LBS.toStrict $$ CL.consume- y <- runExceptionT $ CL.sourceList xs $= conduitMsgEncode $$ CL.consume- case liftA2 (?==) x y of- Left _ -> fail "exception in conduit"- Right a -> stop a+ x <- CL.sourceList xs $= CL.map encode =$= CL.map LBS.toStrict $$ CL.consume :: PropertyM IO [BS.ByteString]+ y <- CL.sourceList xs $= conduitMsgEncode $$ CL.consume :: PropertyM IO [BS.ByteString]+ stop $ x ?== y :: PropertyM IO () main = hspec $ do describe "QC properties: conduitEncode =$= conduitDecode == id" $ do@@ -101,7 +98,7 @@ prop "either int string" $ (prop_eq :: [Either Int String] -> Property) prop "(Int,Int)" $ (prop_sink :: (Int,Int) -> Property) prop "(String,String)" $ (prop_sink :: (String,String) -> Property)- prop "A" $ (prop_eq :: [A] -> Property)+ prop "A" $ (prop_eq :: [A] -> Property) describe "QC properties partial lists" $ do prop "break data in 2 parts" $ (prop_part2) prop "break data in 3 parts" $ (prop_part3)@@ -121,10 +118,10 @@ x `shouldBe` [i] it "decodes message with list of values inside" $ do let is = [-32,45::Int]- ls = BS.concat . Prelude.concatMap (LBS.toChunks .runPut . put) $ is + ls = BS.concat . Prelude.concatMap (LBS.toChunks .runPut . put) $ is (ls1,ls2) = BS.splitAt ((BS.length ls `div` 2) +1) ls x <- CL.sourceList [ls,ls] $= conduitDecode $$ CL.consume x' <- CL.sourceList [ls1,ls2] $= conduitDecode $$ CL.consume x `shouldBe` is++is x' `shouldBe` is- +