cborg-json 0.2.2.0 → 0.2.3.0
raw patch · 3 files changed
+44/−11 lines, 3 filesdep ~aesondep ~basePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: aeson, base
API changes (from Hackage documentation)
Files
- ChangeLog.md +4/−0
- cborg-json.cabal +12/−6
- src/Codec/CBOR/JSON.hs +28/−5
ChangeLog.md view
@@ -1,5 +1,9 @@ # Revision history for cborg-json +## 0.2.3.0 -- 2021-10-31++* Support for `aeson-2.0`, GHC 9.0, GHC 9.2, and `bytestring-0.11`.+ ## 0.2.2.0 -- 2019-12-29 * Use `replicateM` to significantly speed up decoding. Now faster than Aeson!
cborg-json.cabal view
@@ -1,5 +1,5 @@ name: cborg-json-version: 0.2.2.0+version: 0.2.3.0 synopsis: A library for encoding JSON as CBOR description: This package implements the bijection between JSON and CBOR defined in the CBOR specification, RFC 7049.@@ -17,14 +17,20 @@ extra-source-files: ChangeLog.md cabal-version: >=1.10 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.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 library exposed-modules: Codec.CBOR.JSON ghc-options: -Wall build-depends:- base >=4.7 && < 4.14,- aeson >=0.7 && <1.5,+ base >=4.7 && < 4.17,+ aeson >=0.7 && <2.1, aeson-pretty >=0.8 && <0.9, unordered-containers >=0.2 && <0.3, scientific >=0.3 && <0.4,@@ -51,11 +57,11 @@ other-modules: build-depends:- base >= 4.6 && < 5.0,+ base >= 4.6 && < 4.17, cborg , cborg-json , aeson ,- bytestring >= 0.10.4 && < 0.11,+ bytestring >= 0.10.4 && < 0.12, criterion >= 1.0 && < 1.6, deepseq >= 1.0 && < 1.5, directory,
src/Codec/CBOR/JSON.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE BangPatterns #-}+{-# LANGUAGE CPP #-} module Codec.CBOR.JSON ( encodeValue@@ -13,11 +14,17 @@ import Codec.CBOR.Decoding import Data.Aeson ( Value(..) ) import qualified Data.Aeson as Aeson-import qualified Data.HashMap.Lazy as HM import Data.Scientific as Scientific import qualified Data.Text as T import qualified Data.Vector as V +#if MIN_VERSION_aeson(2,0,0)+import qualified Data.Aeson.Key as K+import qualified Data.Aeson.KeyMap as KM+#else+import qualified Data.HashMap.Lazy as HM+#endif+ -- | Encode a JSON value into CBOR. encodeValue :: Value -> Encoding encodeValue (Object vs) = encodeObject vs@@ -31,8 +38,18 @@ encodeObject :: Aeson.Object -> Encoding encodeObject vs =- encodeMapLen (fromIntegral (HM.size vs))- <> HM.foldrWithKey (\k v r -> encodeString k <> encodeValue v <> r) mempty vs+ encodeMapLen (fromIntegral size)+ <> foldrWithKey (\k v r -> encodeString' k <> encodeValue v <> r) mempty vs+ where+#if MIN_VERSION_aeson(2,0,0)+ size = KM.size vs+ foldrWithKey = KM.foldrWithKey+ encodeString' = encodeString . K.toText+#else+ size = HM.size vs+ foldrWithKey = HM.foldrWithKey+ encodeString' = encodeString+#endif encodeArray :: Aeson.Array -> Encoding encodeArray vs =@@ -58,7 +75,7 @@ TypeListLen -> decodeListLen >>= decodeListN lenient TypeListLenIndef -> decodeListLenIndef >> decodeListIndef lenient []- TypeMapLen -> decodeMapLen >>= flip (decodeMapN lenient) HM.empty+ TypeMapLen -> decodeMapLen >>= flip (decodeMapN lenient) mempty _ -> fail $ "unexpected CBOR token type for a JSON value: " ++ show tkty@@ -101,4 +118,10 @@ Bool b | lenient -> return $ T.pack (show b) _ -> fail "Could not decode map key type" !tv <- decodeValue lenient- decodeMapN lenient (n-1) (HM.insert tk tv acc)+ decodeMapN lenient (n-1) (insert tk tv acc)+ where+#if MIN_VERSION_aeson(2,0,0)+ insert k v m = KM.insert (K.fromText k) v m+#else+ insert k v m = HM.insert k v m+#endif