packages feed

cborg-json 0.2.5.0 → 0.2.6.0

raw patch · 4 files changed

+82/−11 lines, 4 filesdep +QuickCheckdep +base-orphansdep +base16-bytestringdep ~basedep ~cborgdep ~zlibPVP ok

version bump matches the API change (PVP)

Dependencies added: QuickCheck, base-orphans, base16-bytestring, base64-bytestring, fail, tasty, tasty-hunit

Dependency ranges changed: base, cborg, zlib

API changes (from Hackage documentation)

Files

ChangeLog.md view
@@ -1,5 +1,11 @@ # Revision history for cborg-json +## 0.2.6.0++* Use `Base62Url` encoding for bytes++* Support GHC 9.8+ ## 0.2.5.0  -- 2022-09-24  * Support GHC 9.4
cborg-json.cabal view
@@ -1,5 +1,5 @@ name:                cborg-json-version:             0.2.5.0+version:             0.2.6.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.@@ -23,19 +23,21 @@   GHC == 8.10.7,   GHC == 9.0.1,   GHC == 9.2.2,-  GHC == 9.4.2+  GHC == 9.4.2,+  GHC == 9.6.1  library   exposed-modules:     Codec.CBOR.JSON   ghc-options:         -Wall   build-depends:-    base                 >=4.11 && < 4.18,-    aeson                >=0.7  && <2.2,+    base                 >=4.11 && < 4.20,+    aeson                >=0.7  && <2.3,     aeson-pretty         >=0.8  && <0.9,+    base64-bytestring    >=1.0  && <1.3,     unordered-containers >=0.2  && <0.3,     scientific           >=0.3  && <0.4,-    text                 >=1.1  && <2.1,-    vector               >=0.10 && <0.13,+    text                 >=1.1  && <2.2,+    vector               >=0.10 && <0.14,      cborg ==0.2.* @@ -59,10 +61,10 @@   other-modules:    build-depends:-    base       >= 4.11    && < 4.18,-    bytestring >= 0.10.4  && < 0.12,-    criterion  >= 1.0     && < 1.6,-    deepseq    >= 1.0     && < 1.5,+    base       >= 4.11    && < 4.20,+    bytestring >= 0.10.4  && < 0.13,+    criterion  >= 1.0     && < 1.7,+    deepseq    >= 1.0     && < 1.6,     zlib       >= 0.5     && < 0.7,     directory,     process,@@ -70,3 +72,32 @@      cborg,     cborg-json+++test-suite tests+  type:              exitcode-stdio-1.0+  hs-source-dirs:    tests+  main-is:           Main.hs++  default-language:  Haskell2010+  ghc-options:+    -Wall -fno-warn-orphans+    -threaded -rtsopts "-with-rtsopts=-N2"++  other-modules:++  build-depends:+    base                    >= 4.7     && < 4.20,+    base-orphans,+    base16-bytestring       >= 1.0     && < 1.1,+    bytestring              >= 0.10.4  && < 0.13,+    cborg,+    cborg-json,+    aeson                   >= 0.7     && < 2.3,+    QuickCheck              >= 2.9     && < 2.15,+    tasty                   >= 0.11    && < 1.6,+    tasty-hunit             >= 0.9     && < 0.11,+    text                    >= 1.1     && < 2.2+  if !impl(ghc >= 8.0)+    build-depends:+      fail                    >= 4.9.0.0 && < 4.10
src/Codec/CBOR/JSON.hs view
@@ -14,8 +14,10 @@ import           Codec.CBOR.Decoding import           Data.Aeson                          ( Value(..) ) import qualified Data.Aeson                          as Aeson+import qualified Data.ByteString.Base64.URL          as Base64url import           Data.Scientific                     as Scientific import qualified Data.Text                           as T+import qualified Data.Text.Encoding                  as TE import qualified Data.Vector                         as V  #if MIN_VERSION_aeson(2,0,0)@@ -77,9 +79,14 @@       TypeListLenIndef -> decodeListLenIndef >> decodeListIndef lenient []       TypeMapLen       -> decodeMapLen >>= flip (decodeMapN lenient) mempty +      TypeBytes   -> bytesToBase64Text <$> decodeBytes+       _           -> fail $ "unexpected CBOR token type for a JSON value: "                          ++ show tkty+    where+      bytesToBase64Text = String . TE.decodeLatin1 . Base64url.encode + decodeNumberIntegral :: Decoder s Value decodeNumberIntegral = Number . fromInteger <$> decodeInteger @@ -95,7 +102,7 @@  decodeListN :: Bool -> Int -> Decoder s Value decodeListN !lenient !n = do-  vec <- V.replicateM n (decodeValue lenient) +  vec <- V.replicateM n (decodeValue lenient)   return $! Array vec  decodeListIndef :: Bool -> [Value] -> Decoder s Value
+ tests/Main.hs view
@@ -0,0 +1,27 @@+{-# LANGUAGE OverloadedStrings #-}++module Main (main) where++import           Codec.CBOR.JSON+import           Codec.CBOR.Read+import           Data.Aeson (Value (String))+import qualified Data.ByteString.Base16 as HEX+import           Data.ByteString.Lazy (fromStrict)+import           Test.Tasty (TestTree, defaultMain, testGroup)+import           Test.Tasty.HUnit (testCase, (@=?))+++main :: IO ()+main = do+  defaultMain tests+++tests :: TestTree+tests =+  testGroup "CBOR-JSON"+    [ testGroup "unit tests"+        [ testCase "decode variable ByteString as Base62Url String" $+            Right ("", String "MDEy") @=? deserialiseFromBytes (decodeValue True)+                                              (fromStrict . either error id $ HEX.decode "5803303132")+        ]+    ]