mirror of
https://github.com/NorfairKing/autodocodec.git
synced 2024-11-27 02:02:59 +03:00
rename json encoding and decoding functions to mention json
This commit is contained in:
parent
68457161c6
commit
7e1f1ea5ff
@ -105,7 +105,7 @@ comparisonBench =
|
||||
bgroup
|
||||
"toByteString"
|
||||
[ bench "encode (Autodocodec)" $
|
||||
nf encodeViaCodec as,
|
||||
nf encodeJSONViaCodec as,
|
||||
bench "encode (Aeson)" $
|
||||
nf Aeson.encode as
|
||||
]
|
||||
@ -126,7 +126,7 @@ comparisonBench =
|
||||
bgroup
|
||||
"parseByteString"
|
||||
[ bench "decode (Autodocodec)" $
|
||||
nf (eitherDecodeViaCodec :: LB.ByteString -> Either String a) bs,
|
||||
nf (eitherDecodeJSONViaCodec :: LB.ByteString -> Either String a) bs,
|
||||
bench "decode (Aeson)" $
|
||||
nf (Aeson.eitherDecode :: LB.ByteString -> Either String a) bs
|
||||
]
|
||||
|
@ -147,8 +147,8 @@ codecSpec = do
|
||||
Right actual -> actual `shouldBe` a
|
||||
it "roundtrips through json bytes" $
|
||||
forAllValid $ \(a :: a) ->
|
||||
let encoded = encodeViaCodec a
|
||||
errOrDecoded = eitherDecodeViaCodec encoded
|
||||
let encoded = encodeJSONViaCodec a
|
||||
errOrDecoded = eitherDecodeJSONViaCodec encoded
|
||||
ctx =
|
||||
unlines
|
||||
[ "Encoded to this value:",
|
||||
@ -175,8 +175,8 @@ codecSpec = do
|
||||
Right actual -> JSON.toJSON (actual :: a) `shouldBe` toJSONViaCodec a
|
||||
it "roundtrips through json bytes and back" $
|
||||
forAllValid $ \(a :: a) ->
|
||||
let encoded = encodeViaCodec a
|
||||
errOrDecoded = eitherDecodeViaCodec encoded
|
||||
let encoded = encodeJSONViaCodec a
|
||||
errOrDecoded = eitherDecodeJSONViaCodec encoded
|
||||
ctx =
|
||||
unlines
|
||||
[ "Encoded to this value:",
|
||||
@ -186,4 +186,4 @@ codecSpec = do
|
||||
]
|
||||
in context ctx $ case errOrDecoded of
|
||||
Left err -> expectationFailure err
|
||||
Right actual -> encodeViaCodec (actual :: a) `shouldBe` encodeViaCodec a
|
||||
Right actual -> encodeJSONViaCodec (actual :: a) `shouldBe` encodeJSONViaCodec a
|
||||
|
@ -2,14 +2,14 @@
|
||||
|
||||
module Autodocodec
|
||||
( -- * Encoding
|
||||
encodeViaCodec,
|
||||
encodeJSONViaCodec,
|
||||
toJSONViaCodec,
|
||||
toJSONVia,
|
||||
toEncodingViaCodec,
|
||||
toEncodingVia,
|
||||
|
||||
-- * Decoding
|
||||
eitherDecodeViaCodec,
|
||||
eitherDecodeJSONViaCodec,
|
||||
parseJSONViaCodec,
|
||||
parseJSONVia,
|
||||
|
||||
|
@ -2,14 +2,14 @@
|
||||
|
||||
module Autodocodec.Aeson
|
||||
( -- * Encoding
|
||||
encodeViaCodec,
|
||||
encodeJSONViaCodec,
|
||||
toJSONViaCodec,
|
||||
toJSONVia,
|
||||
toEncodingViaCodec,
|
||||
toEncodingVia,
|
||||
|
||||
-- * Decoding
|
||||
eitherDecodeViaCodec,
|
||||
eitherDecodeJSONViaCodec,
|
||||
parseJSONViaCodec,
|
||||
parseJSONVia,
|
||||
|
||||
@ -27,9 +27,9 @@ import qualified Data.Aeson as Aeson (eitherDecode, encode)
|
||||
import qualified Data.ByteString.Lazy as LB
|
||||
|
||||
-- | Encode a value as a JSON 'LB.ByteString' via its type's 'codec'.
|
||||
encodeViaCodec :: HasCodec a => a -> LB.ByteString
|
||||
encodeViaCodec = Aeson.encode . Autodocodec
|
||||
encodeJSONViaCodec :: HasCodec a => a -> LB.ByteString
|
||||
encodeJSONViaCodec = Aeson.encode . Autodocodec
|
||||
|
||||
-- | Parse a JSON 'LB.ByteString' using a type's 'codec'.
|
||||
eitherDecodeViaCodec :: HasCodec a => LB.ByteString -> Either String a
|
||||
eitherDecodeViaCodec = fmap unAutodocodec . Aeson.eitherDecode
|
||||
eitherDecodeJSONViaCodec :: HasCodec a => LB.ByteString -> Either String a
|
||||
eitherDecodeJSONViaCodec = fmap unAutodocodec . Aeson.eitherDecode
|
||||
|
Loading…
Reference in New Issue
Block a user