binary 0.8.6.0 → 0.8.7.0
raw patch · 9 files changed
+96/−61 lines, 9 filesdep +base-orphansdep ~basePVP ok
version bump matches the API change (PVP)
Dependencies added: base-orphans
Dependency ranges changed: base
API changes (from Hackage documentation)
Files
- binary.cabal +3/−2
- changelog.md +15/−8
- src/Data/Binary.hs +3/−3
- src/Data/Binary/Class.hs +48/−30
- src/Data/Binary/FloatCast.hs +1/−1
- src/Data/Binary/Generic.hs +2/−0
- src/Data/Binary/Get.hs +3/−3
- src/Data/Binary/Get/Internal.hs +18/−10
- tests/QC.hs +3/−4
binary.cabal view
@@ -1,5 +1,5 @@ name: binary-version: 0.8.6.0+version: 0.8.7.0 license: BSD3 license-file: LICENSE author: Lennart Kolmodin <kolmodin@gmail.com>@@ -18,7 +18,7 @@ stability: provisional build-type: Simple cabal-version: >= 1.8-tested-with: GHC == 7.4.2, GHC == 7.6.3, GHC == 7.8.4, GHC == 7.10.3, GHC == 8.0.2+tested-with: GHC == 7.6.3, GHC == 7.8.4, GHC == 7.10.3, GHC == 8.0.2, GHC ==8.2.2, GHC == 8.4.4, GHC == 8.6.5 extra-source-files: README.md changelog.md docs/hcar/binary-Lb.tex tools/derive/*.hs @@ -76,6 +76,7 @@ Data.Binary.Put build-depends: base >= 4.5.0.0 && < 5,+ base-orphans >=0.8.1 && <0.9, bytestring >= 0.10.4, random>=1.0.1.0, test-framework,
changelog.md view
@@ -1,19 +1,26 @@ binary ====== -binary-0.10.0.0----------------+binary-0.8.7.0+-------------- -- Add binary instance for Data.Functor.Identity from base, #146.-- Don't use * when we have TypeOperators, #148.+- MonadFail compatibility in base-4.13 (`fail` is not method of `Monad).+- `Binary NonEmpty` `fail`s non empty lists, not `error`s -binary-0.9.0.0---------------+binary-0.9.0.0 & binary-0.10.0.0+-------------------------------- - `0.8.5.0` was first released as version `0.9.0.0`. It didn't have any breaking changes though, so it was again released as version `0.8.5.0`- according to PVP. Next breaking release of `binary` will be version- `0.10.0.0`.+ according to PVP.+- `0.8.6.0` was first released as version `0.10.0.0`.++binary-0.8.6.0+---------------++- Add binary instance for Data.Functor.Identity from base, #146.+- Don't use * when we have TypeOperators, #148.+ binary-0.8.5.0 --------------
src/Data/Binary.hs view
@@ -132,7 +132,7 @@ -- > > let e = OpE "*" (IntE 7) (OpE "/" (IntE 4) (IntE 2)) -- > > let v = encode e ----- Where 'v' is a binary encoded data structure. To reconstruct the+-- Where @v@ is a binary encoded data structure. To reconstruct the -- original data, we use 'decode' -- -- > > decode v :: Exp@@ -177,7 +177,7 @@ -- consumed bytes is returned. In case of failure, a human-readable error -- message will be returned as well. ----- /Since: 0.7.0.0/+-- @since 0.7.0.0 decodeOrFail :: Binary a => L.ByteString -> Either (L.ByteString, ByteOffset, String) (L.ByteString, ByteOffset, a)@@ -203,7 +203,7 @@ -- | Decode a value from a file. In case of errors, 'error' will -- be called with the error message. ----- /Since: 0.7.0.0/+-- @since 0.7.0.0 decodeFile :: Binary a => FilePath -> IO a decodeFile f = do result <- decodeFileOrFail f
src/Data/Binary/Class.hs view
@@ -59,7 +59,9 @@ import Data.Monoid (mempty) #endif import qualified Data.Monoid as Monoid+#if !MIN_VERSION_base(4,11,0) import Data.Monoid ((<>))+#endif #if MIN_VERSION_base(4,8,0) import Data.Functor.Identity (Identity (..)) #endif@@ -172,7 +174,7 @@ -- Void never gets written nor reconstructed since it's impossible to have a -- value of that type --- | /Since: 0.8.0.0/+-- | @since 0.8.0.0 instance Binary Void where put = absurd get = mzero@@ -337,7 +339,7 @@ let v = roll bytes return $! if sign == (1 :: Word8) then v else - v --- | /Since: 0.8.0.0/+-- | @since 0.8.0.0 #ifdef HAS_FIXED_CONSTRUCTOR instance Binary (Fixed.Fixed a) where put (Fixed.MkFixed a) = put a@@ -367,7 +369,7 @@ -- Fixed-size type for a subset of Natural type NaturalWord = Word64 --- | /Since: 0.7.3.0/+-- | @since 0.7.3.0 instance Binary Natural where {-# INLINE put #-} put n | n <= hi =@@ -580,7 +582,7 @@ get = do n <- get :: Get Int getMany n --- | 'getMany n' get 'n' elements in order, without blowing the stack.+-- | @'getMany' n@ get @n@ elements in order, without blowing the stack. getMany :: Binary a => Int -> Get [a] getMany n = go [] n where@@ -725,7 +727,7 @@ ------------------------------------------------------------------------ -- Fingerprints --- | /Since: 0.7.6.0/+-- | @since 0.7.6.0 instance Binary Fingerprint where put (Fingerprint x1 x2) = put x1 <> put x2 get = do@@ -736,7 +738,7 @@ ------------------------------------------------------------------------ -- Version --- | /Since: 0.8.0.0/+-- | @since 0.8.0.0 instance Binary Version where put (Version br tags) = put br <> put tags get = Version <$> get <*> get@@ -744,43 +746,43 @@ ------------------------------------------------------------------------ -- Data.Monoid datatypes --- | /Since: 0.8.4.0/+-- | @since 0.8.4.0 instance Binary a => Binary (Monoid.Dual a) where get = fmap Monoid.Dual get put = put . Monoid.getDual --- | /Since: 0.8.4.0/+-- | @since 0.8.4.0 instance Binary Monoid.All where get = fmap Monoid.All get put = put . Monoid.getAll --- | /Since: 0.8.4.0/+-- | @since 0.8.4.0 instance Binary Monoid.Any where get = fmap Monoid.Any get put = put . Monoid.getAny --- | /Since: 0.8.4.0/+-- | @since 0.8.4.0 instance Binary a => Binary (Monoid.Sum a) where get = fmap Monoid.Sum get put = put . Monoid.getSum --- | /Since: 0.8.4.0/+-- | @since 0.8.4.0 instance Binary a => Binary (Monoid.Product a) where get = fmap Monoid.Product get put = put . Monoid.getProduct --- | /Since: 0.8.4.0/+-- | @since 0.8.4.0 instance Binary a => Binary (Monoid.First a) where get = fmap Monoid.First get put = put . Monoid.getFirst --- | /Since: 0.8.4.0/+-- | @since 0.8.4.0 instance Binary a => Binary (Monoid.Last a) where get = fmap Monoid.Last get put = put . Monoid.getLast #if MIN_VERSION_base(4,8,0)--- | /Since: 0.8.4.0/+-- | @since 0.8.4.0 instance Binary (f a) => Binary (Monoid.Alt f a) where get = fmap Monoid.Alt get put = put . Monoid.getAlt@@ -790,37 +792,37 @@ ------------------------------------------------------------------------ -- Data.Semigroup datatypes --- | /Since: 0.8.4.0/+-- | @since 0.8.4.0 instance Binary a => Binary (Semigroup.Min a) where get = fmap Semigroup.Min get put = put . Semigroup.getMin --- | /Since: 0.8.4.0/+-- | @since 0.8.4.0 instance Binary a => Binary (Semigroup.Max a) where get = fmap Semigroup.Max get put = put . Semigroup.getMax --- | /Since: 0.8.4.0/+-- | @since 0.8.4.0 instance Binary a => Binary (Semigroup.First a) where get = fmap Semigroup.First get put = put . Semigroup.getFirst --- | /Since: 0.8.4.0/+-- | @since 0.8.4.0 instance Binary a => Binary (Semigroup.Last a) where get = fmap Semigroup.Last get put = put . Semigroup.getLast --- | /Since: 0.8.4.0/+-- | @since 0.8.4.0 instance Binary a => Binary (Semigroup.Option a) where get = fmap Semigroup.Option get put = put . Semigroup.getOption --- | /Since: 0.8.4.0/+-- | @since 0.8.4.0 instance Binary m => Binary (Semigroup.WrappedMonoid m) where get = fmap Semigroup.WrapMonoid get put = put . Semigroup.unwrapMonoid --- | /Since: 0.8.4.0/+-- | @since 0.8.4.0 instance (Binary a, Binary b) => Binary (Semigroup.Arg a b) where get = liftM2 Semigroup.Arg get get put (Semigroup.Arg a b) = put a <> put b@@ -828,9 +830,13 @@ ------------------------------------------------------------------------ -- Non-empty lists --- | /Since: 0.8.4.0/+-- | @since 0.8.4.0 instance Binary a => Binary (NE.NonEmpty a) where- get = fmap NE.fromList get+ get = do+ list <- get+ case list of+ [] -> fail "NonEmpty is empty!"+ x:xs -> pure (x NE.:| xs) put = put . NE.toList #endif @@ -858,17 +864,17 @@ -- * 'SomeTypeRep' (also known as 'Data.Typeable.TypeRep') -- --- | @since 0.8.5.0. See #typeable-instances#+-- | @since 0.8.5.0 instance Binary VecCount where put = putWord8 . fromIntegral . fromEnum get = toEnum . fromIntegral <$> getWord8 --- | @since 0.8.5.0. See #typeable-instances#+-- | @since 0.8.5.0 instance Binary VecElem where put = putWord8 . fromIntegral . fromEnum get = toEnum . fromIntegral <$> getWord8 --- | @since 0.8.5.0. See #typeable-instances#+-- | @since 0.8.5.0 instance Binary RuntimeRep where put (VecRep a b) = putWord8 0 >> put a >> put b put (TupleRep reps) = putWord8 1 >> put reps@@ -882,6 +888,12 @@ put AddrRep = putWord8 9 put FloatRep = putWord8 10 put DoubleRep = putWord8 11+#if __GLASGOW_HASKELL__ >= 807+ put Int8Rep = putWord8 12+ put Word8Rep = putWord8 13+ put Int16Rep = putWord8 14+ put Word16Rep = putWord8 15+#endif get = do tag <- getWord8@@ -898,9 +910,15 @@ 9 -> pure AddrRep 10 -> pure FloatRep 11 -> pure DoubleRep+#if __GLASGOW_HASKELL__ >= 807+ 12 -> pure Int8Rep+ 13 -> pure Word8Rep+ 14 -> pure Int16Rep+ 15 -> pure Word16Rep+#endif _ -> fail "GHCi.TH.Binary.putRuntimeRep: invalid tag" --- | @since 0.8.5.0. See #typeable-instances#+-- | @since 0.8.5.0 instance Binary TyCon where put tc = do put (tyConPackage tc)@@ -910,7 +928,7 @@ put (tyConKindRep tc) get = mkTyCon <$> get <*> get <*> get <*> get <*> get --- | @since 0.8.5.0. See #typeable-instances#+-- | @since 0.8.5.0 instance Binary KindRep where put (KindRepTyConApp tc k) = putWord8 0 >> put tc >> put k put (KindRepVar bndr) = putWord8 1 >> put bndr@@ -930,7 +948,7 @@ 5 -> KindRepTypeLit <$> get <*> get _ -> fail "GHCi.TH.Binary.putKindRep: invalid tag" --- | @since 0.8.5.0. See #typeable-instances#+-- | @since 0.8.5.0 instance Binary TypeLitSort where put TypeLitSymbol = putWord8 0 put TypeLitNat = putWord8 1@@ -960,7 +978,7 @@ put (3 :: Word8) putTypeRep arg putTypeRep res-putTypeRep _ = fail "GHCi.TH.Binary.putTypeRep: Impossible"+putTypeRep _ = error "GHCi.TH.Binary.putTypeRep: Impossible" getSomeTypeRep :: Get SomeTypeRep getSomeTypeRep = do
src/Data/Binary/FloatCast.hs view
@@ -5,7 +5,7 @@ -- | This module was written based on -- <http://hackage.haskell.org/package/reinterpret-cast-0.1.0/docs/src/Data-ReinterpretCast-Internal-ImplArray.html>. ----- Implements casting via a 1-elemnt STUArray, as described in+-- Implements casting via a 1-element STUArray, as described in -- <http://stackoverflow.com/a/7002812/263061>. module Data.Binary.FloatCast ( floatToWord
src/Data/Binary/Generic.hs view
@@ -30,7 +30,9 @@ import Data.Binary.Put import Data.Bits import Data.Word+#if !MIN_VERSION_base(4,11,0) import Data.Monoid ((<>))+#endif #ifdef HAS_DATA_KIND import Data.Kind #endif
src/Data/Binary/Get.hs view
@@ -126,7 +126,7 @@ -- from a socket which has higher likelihood to fail. To address these needs, -- use the incremental input method like in @incrementalExample@. -- For an example of how to read incrementally from a Handle,--- see the implementation of 'decodeFileOrFail' in "Data.Binary".+-- see the implementation of 'Data.Binary.decodeFileOrFail'. ----------------------------------------------------------------------------- @@ -328,7 +328,7 @@ -- consumed is returned. In the case of failure, a human-readable -- error message is included as well. ----- /Since: 0.6.4.0/+-- @since 0.6.4.0 runGetOrFail :: Get a -> L.ByteString -> Either (L.ByteString, ByteOffset, String) (L.ByteString, ByteOffset, a) runGetOrFail g lbs0 = feedAll (runGetIncremental g) lbs0@@ -366,7 +366,7 @@ -- | Feed a 'Decoder' with more input. If the 'Decoder' is 'Done' or 'Fail' it--- will add the input to 'ByteString' of unconsumed input.+-- will add the input to 'L.ByteString' of unconsumed input. -- -- @ -- 'runGetIncremental' myParser \`pushChunks\` myLazyByteString
src/Data/Binary/Get/Internal.hs view
@@ -91,12 +91,20 @@ instance Monad Get where return = pure (>>=) = bindG-#if MIN_VERSION_base(4,9,0)- fail = Fail.fail+#if !(MIN_VERSION_base(4,9,0))+ fail = failG -- base < 4.9+#elif !(MIN_VERSION_base(4,13,0))+ fail = Fail.fail -- base < 4.13+#endif+-- NB: Starting with base-4.13, the `fail` method+-- has been removed from the `Monad`-class+-- according to the MonadFail proposal (MFP) schedule+-- which completes the process that started with base-4.9. +#if MIN_VERSION_base(4,9,0) instance Fail.MonadFail Get where-#endif fail = failG+#endif bindG :: Get a -> (a -> Get b) -> Get b bindG (C c) f = C $ \i ks -> c i (\i' a -> (runCont (f a)) i' ks)@@ -122,7 +130,7 @@ (<*>) = apG {-# INLINE (<*>) #-} --- | /Since: 0.7.1.0/+-- | @since 0.7.1.0 instance MonadPlus Get where mzero = empty mplus = (<|>)@@ -193,7 +201,7 @@ -- Offset from 'bytesRead' will be relative to the start of 'isolate', not the -- absolute of the input. ----- /Since: 0.7.2.0/+-- @since 0.7.2.0 isolate :: Int -- ^ The number of bytes that must be consumed -> Get a -- ^ The decoder to isolate -> Get a@@ -256,7 +264,7 @@ getBytes = getByteString {-# INLINE getBytes #-} --- | /Since: 0.7.0.0/+-- | @since 0.7.0.0 instance Alternative Get where empty = C $ \inp _ks -> Fail inp "Data.Binary.Get(Alternative).empty" {-# INLINE empty #-}@@ -304,7 +312,7 @@ -- | Run the given decoder, but without consuming its input. If the given -- decoder fails, then so will this function. ----- /Since: 0.7.0.0/+-- @since 0.7.0.0 lookAhead :: Get a -> Get a lookAhead g = do (decoder, bs) <- runAndKeepTrack g@@ -317,7 +325,7 @@ -- If 'Nothing' is returned, the input will be unconsumed. -- If the given decoder fails, then so will this function. ----- /Since: 0.7.0.0/+-- @since 0.7.0.0 lookAheadM :: Get (Maybe a) -> Get (Maybe a) lookAheadM g = do let g' = maybe (Left ()) Right <$> g@@ -327,7 +335,7 @@ -- If 'Left' is returned, the input will be unconsumed. -- If the given decoder fails, then so will this function. ----- /Since: 0.7.1.0/+-- @since 0.7.1.0 lookAheadE :: Get (Either a b) -> Get (Either a b) lookAheadE g = do (decoder, bs) <- runAndKeepTrack g@@ -340,7 +348,7 @@ -- | Label a decoder. If the decoder fails, the label will be appended on -- a new line to the error message string. ----- /Since: 0.7.2.0/+-- @since 0.7.2.0 label :: String -> Get a -> Get a label msg decoder = C $ \inp ks -> let r0 = runCont decoder inp (\inp' a -> Done inp' a)
tests/QC.hs view
@@ -24,6 +24,8 @@ import Data.Typeable import System.IO.Unsafe +import Data.Orphans ()+ #ifdef HAS_NATURAL import Numeric.Natural #endif@@ -43,6 +45,7 @@ import Data.Binary.Put import qualified Data.Binary.Class as Class + ------------------------------------------------------------------------ roundTrip :: (Eq a, Binary a) => a -> (L.ByteString -> L.ByteString) -> Bool@@ -499,10 +502,6 @@ genFingerprint :: Gen Fingerprint genFingerprint = liftM2 Fingerprint arbitrary arbitrary-#if !MIN_VERSION_base(4,7,0)-instance Show Fingerprint where- show (Fingerprint x1 x2) = show (x1,x2)-#endif ------------------------------------------------------------------------