serialise 0.2.3.0 → 0.2.4.0
raw patch · 4 files changed
+114/−22 lines, 4 filesdep +strictdep +thesedep ~aesondep ~basedep ~ghc-prim
Dependencies added: strict, these
Dependency ranges changed: aeson, base, ghc-prim, text, time
Files
- ChangeLog.md +6/−0
- serialise.cabal +30/−22
- src/Codec/Serialise/Class.hs +76/−0
- tests/Tests/Serialise.hs +2/−0
ChangeLog.md view
@@ -1,5 +1,11 @@ # Revision history for serialise +## 0.2.4.0 -- 2021-10-31++* Add instances for `Data.Void`, `strict`, and `these`.++* Compatibility with GHC 9.0 and 9.2+ ## 0.2.3.0 -- 2020-05-10 * Bounds bumps and GHC 8.10 compatibility
serialise.cabal view
@@ -1,5 +1,5 @@ name: serialise-version: 0.2.3.0+version: 0.2.4.0 synopsis: A binary serialisation library for Haskell values. description: This package (formerly @binary-serialise-cbor@) provides pure, efficient@@ -30,7 +30,13 @@ category: Codec build-type: Simple tested-with:- GHC == 7.8.4, GHC == 7.10.3, GHC == 8.0.2, GHC == 8.2.2, GHC == 8.4.4, GHC == 8.6.5, GHC == 8.8.3, GHC == 8.10.1+ GHC == 8.0.2,+ GHC == 8.2.2,+ GHC == 8.4.4,+ GHC == 8.6.5,+ GHC == 8.8.3,+ GHC == 8.10.1,+ GHC == 9.0.1 extra-source-files: ChangeLog.md@@ -64,21 +70,23 @@ build-depends: array >= 0.4 && < 0.6,- base >= 4.7 && < 4.15,- bytestring >= 0.10.4 && < 0.11,+ base >= 4.7 && < 4.17,+ bytestring >= 0.10.4 && < 0.12, cborg == 0.2.*, containers >= 0.5 && < 0.7,- ghc-prim >= 0.3.1.0 && < 0.7,+ ghc-prim >= 0.3.1.0 && < 0.9, half >= 0.2.2.3 && < 0.4, hashable >= 1.2 && < 2.0, primitive >= 0.5 && < 0.8,+ strict >= 0.4 && < 0.5, text >= 1.1 && < 1.3,+ these >= 1.1 && < 1.2, unordered-containers >= 0.2 && < 0.3, vector >= 0.10 && < 0.13 if flag(newtime15) build-depends:- time >= 1.5 && < 1.11+ time >= 1.5 && < 1.14 else build-depends: time >= 1.4 && < 1.5,@@ -116,19 +124,19 @@ Tests.GeneralisedUTF8 build-depends:- base >= 4.7 && < 4.15,- bytestring >= 0.10.4 && < 0.11,+ base >= 4.7 && < 4.17,+ bytestring >= 0.10.4 && < 0.12, directory >= 1.0 && < 1.4, filepath >= 1.0 && < 1.5, text >= 1.1 && < 1.3,- time >= 1.4 && < 1.11,+ time >= 1.4 && < 1.14, containers >= 0.5 && < 0.7, unordered-containers >= 0.2 && < 0.3, primitive >= 0.5 && < 0.8, cborg, serialise, QuickCheck >= 2.9 && < 2.15,- tasty >= 0.11 && < 1.4,+ tasty >= 0.11 && < 1.5, tasty-hunit >= 0.9 && < 0.11, tasty-quickcheck >= 0.8 && < 0.11, quickcheck-instances >= 0.3.12 && < 0.4,@@ -153,9 +161,9 @@ Instances.Time build-depends:- base >= 4.7 && < 4.15,+ base >= 4.7 && < 4.17, binary >= 0.7 && < 0.11,- bytestring >= 0.10.4 && < 0.11,+ bytestring >= 0.10.4 && < 0.12, vector >= 0.10 && < 0.13, cborg, serialise,@@ -165,7 +173,7 @@ if flag(newtime15) build-depends:- time >= 1.5 && < 1.11+ time >= 1.5 && < 1.14 else build-depends: time >= 1.4 && < 1.5,@@ -197,15 +205,15 @@ SimpleVersus build-depends:- base >= 4.7 && < 4.15,+ base >= 4.7 && < 4.17, binary >= 0.7 && < 0.11,- bytestring >= 0.10.4 && < 0.11,- ghc-prim >= 0.3.1.0 && < 0.7,+ bytestring >= 0.10.4 && < 0.12,+ ghc-prim >= 0.3.1.0 && < 0.9, vector >= 0.10 && < 0.13, cborg, serialise, - aeson >= 0.7 && < 1.5,+ aeson >= 0.7 && < 2.1, deepseq >= 1.0 && < 1.5, criterion >= 1.0 && < 1.6, cereal >= 0.5.2.0 && < 0.6,@@ -244,11 +252,11 @@ build-depends: array >= 0.4 && < 0.6,- base >= 4.7 && < 4.15,+ base >= 4.7 && < 4.17, binary >= 0.7 && < 0.11,- bytestring >= 0.10.4 && < 0.11,+ bytestring >= 0.10.4 && < 0.12, directory >= 1.0 && < 1.4,- ghc-prim >= 0.3.1.0 && < 0.7,+ ghc-prim >= 0.3.1.0 && < 0.9, fail >= 4.9.0.0 && < 4.10, text >= 1.1 && < 1.3, vector >= 0.10 && < 0.13,@@ -258,7 +266,7 @@ filepath >= 1.0 && < 1.5, containers >= 0.5 && < 0.7, deepseq >= 1.0 && < 1.5,- aeson >= 0.7 && < 1.5,+ aeson >= 0.7 && < 2.1, cereal >= 0.5.2.0 && < 0.6, half >= 0.2.2.3 && < 0.4, tar >= 0.4 && < 0.6,@@ -270,7 +278,7 @@ if flag(newtime15) build-depends:- time >= 1.5 && < 1.11+ time >= 1.5 && < 1.14 else build-depends: time >= 1.4 && < 1.5,
src/Codec/Serialise/Class.hs view
@@ -51,6 +51,7 @@ #if MIN_VERSION_base(4,8,0) import Numeric.Natural import Data.Functor.Identity+import Data.Void (Void, absurd) #endif #if MIN_VERSION_base(4,9,0)@@ -70,10 +71,12 @@ import qualified Data.Map as Map import qualified Data.Sequence as Sequence import qualified Data.Set as Set+import qualified Data.Strict as Strict import qualified Data.IntSet as IntSet import qualified Data.IntMap as IntMap import qualified Data.HashSet as HashSet import qualified Data.HashMap.Strict as HashMap+import qualified Data.These as These import qualified Data.Tree as Tree import qualified Data.Primitive.ByteArray as Prim import qualified Data.Vector as Vector@@ -99,6 +102,9 @@ import Prelude hiding (decodeFloat, encodeFloat, foldr) import qualified Prelude+#if MIN_VERSION_base(4,16,0)+import GHC.Exts (Levity(..))+#endif #if MIN_VERSION_base(4,10,0) import Type.Reflection import Type.Reflection.Unsafe@@ -204,6 +210,13 @@ -------------------------------------------------------------------------------- -- Primitive and integral instances +#if MIN_VERSION_base(4,8,0)+-- | @since 0.2.4.0+instance Serialise Void where+ encode = absurd+ decode = fail "tried to decode void"+#endif+ -- | @since 0.2.0.0 instance Serialise () where encode = const encodeNull@@ -530,10 +543,12 @@ encode = encode . Semigroup.getLast decode = fmap Semigroup.Last decode +#if !MIN_VERSION_base(4,16,0) -- | @since 0.2.0.0 instance Serialise a => Serialise (Semigroup.Option a) where encode = encode . Semigroup.getOption decode = fmap Semigroup.Option decode+#endif instance Serialise a => Serialise (Semigroup.WrappedMonoid a) where encode = encode . Semigroup.unwrapMonoid@@ -850,7 +865,45 @@ return (Right x) _ -> fail "unknown tag" +-- | @since 0.2.4.0+instance (Serialise a, Serialise b) => Serialise (These.These a b) where+ encode (These.This x) = encodeListLen 2 <> encodeWord 0 <> encode x+ encode (These.That x) = encodeListLen 2 <> encodeWord 1 <> encode x+ encode (These.These x y) = encodeListLen 3 <> encodeWord 2 <> encode x <> encode y + decode = do n <- decodeListLen+ t <- decodeWord+ case (t, n) of+ (0, 2) -> do !x <- decode+ return (These.This x)+ (1, 2) -> do !x <- decode+ return (These.That x)+ (2, 3) -> do !x <- decode+ !y <- decode+ return (These.These x y)+ _ -> fail "unknown tag"++-- | @since 0.2.4.0+instance (Serialise a, Serialise b) => Serialise (Strict.Pair a b) where+ encode = encode . Strict.toLazy+ decode = Strict.toStrict <$> decode++-- | @since 0.2.4.0+instance Serialise a => Serialise (Strict.Maybe a) where+ encode = encode . Strict.toLazy+ decode = Strict.toStrict <$> decode++-- | @since 0.2.4.0+instance (Serialise a, Serialise b) => Serialise (Strict.Either a b) where+ encode = encode . Strict.toLazy+ decode = Strict.toStrict <$> decode++-- | @since 0.2.4.0+instance (Serialise a, Serialise b) => Serialise (Strict.These a b) where+ encode = encode . Strict.toLazy+ decode = Strict.toStrict <$> decode++ -------------------------------------------------------------------------------- -- Container instances @@ -1136,6 +1189,15 @@ decodeListLenOf 1 toEnum . fromIntegral <$> decodeWord +#if MIN_VERSION_base(4,16,0)+-- | @since 0.2.6.0+instance Serialise Levity where+ encode lev = encodeListLen 1 <> encodeWord (fromIntegral $ fromEnum lev)+ decode = do+ decodeListLenOf 1+ toEnum . fromIntegral <$> decodeWord+#endif+ -- | @since 0.2.0.0 instance Serialise RuntimeRep where encode rr =@@ -1143,8 +1205,12 @@ VecRep a b -> encodeListLen 3 <> encodeWord 0 <> encode a <> encode b TupleRep reps -> encodeListLen 2 <> encodeWord 1 <> encode reps SumRep reps -> encodeListLen 2 <> encodeWord 2 <> encode reps+#if MIN_VERSION_base(4,16,0)+ BoxedRep lev -> encodeListLen 2 <> encodeWord 3 <> encode lev+#else LiftedRep -> encodeListLen 1 <> encodeWord 3 UnliftedRep -> encodeListLen 1 <> encodeWord 4+#endif IntRep -> encodeListLen 1 <> encodeWord 5 WordRep -> encodeListLen 1 <> encodeWord 6 Int64Rep -> encodeListLen 1 <> encodeWord 7@@ -1170,8 +1236,12 @@ 0 | len == 3 -> VecRep <$> decode <*> decode 1 | len == 2 -> TupleRep <$> decode 2 | len == 2 -> SumRep <$> decode+#if MIN_VERSION_base(4,16,0)+ 3 | len == 2 -> BoxedRep <$> decode+#else 3 | len == 1 -> pure LiftedRep 4 | len == 1 -> pure UnliftedRep+#endif 5 | len == 1 -> pure IntRep 6 | len == 1 -> pure WordRep 7 | len == 1 -> pure Int64Rep@@ -1221,12 +1291,18 @@ <> case n of TypeLitSymbol -> encodeWord 0 TypeLitNat -> encodeWord 1+#if MIN_VERSION_base(4,16,0)+ TypeLitChar -> encodeWord 2+#endif decode = do decodeListLenOf 1 tag <- decodeWord case tag of 0 -> pure TypeLitSymbol 1 -> pure TypeLitNat+#if MIN_VERSION_base(4,16,0)+ 2 -> pure TypeLitChar+#endif _ -> fail "Data.Serialise.Binary.CBOR.putTypeLitSort: invalid tag" decodeSomeTypeRep :: Decoder s SomeTypeRep
tests/Tests/Serialise.hs view
@@ -190,7 +190,9 @@ , mkTest (T :: T (Semigroup.Max ())) , mkTest (T :: T (Semigroup.First ())) , mkTest (T :: T (Semigroup.Last ()))+#if !MIN_VERSION_base(4,16,0) , mkTest (T :: T (Semigroup.Option ()))+#endif , mkTest (T :: T (Semigroup.WrappedMonoid ())) #endif #if MIN_VERSION_base(4,7,0)