Use Base64 to correctly handle binary ByteStrings

This commit is contained in:
Tissevert 2019-10-17 18:53:11 +02:00
parent 0c2974b055
commit 818c343e89
2 changed files with 5 additions and 3 deletions

View file

@ -23,6 +23,7 @@ library
-- other-extensions: -- other-extensions:
build-depends: aeson build-depends: aeson
, base >=4.9 && <4.13 , base >=4.9 && <4.13
, base64-bytestring
, bytestring , bytestring
, containers , containers
, hanafuda >= 0.3.3 , hanafuda >= 0.3.3

View file

@ -22,6 +22,7 @@ import Data.Aeson (
) )
import Data.Aeson.Types (toJSONKeyText) import Data.Aeson.Types (toJSONKeyText)
import Data.ByteString (ByteString) import Data.ByteString (ByteString)
import qualified Data.ByteString.Base64 as B64 (decode, encode)
import Data.Map (Map) import Data.Map (Map)
import Data.Monoid ((<>)) import Data.Monoid ((<>))
import Data.Text (Text) import Data.Text (Text)
@ -182,10 +183,10 @@ instance ToJSON PublicState where
toEncoding = genericToEncoding defaultOptions toEncoding = genericToEncoding defaultOptions
instance FromJSON ByteString where instance FromJSON ByteString where
parseJSON = withText "ByteString" (return . encodeUtf8) parseJSON = withText "ByteString" (either fail return . B64.decode . encodeUtf8)
instance ToJSON ByteString where instance ToJSON ByteString where
toJSON = String . decodeUtf8 toJSON = String . decodeUtf8 . B64.encode
toEncoding = toEncoding . decodeUtf8 toEncoding = toEncoding . decodeUtf8 . B64.encode
data PublicGame = PublicGame { data PublicGame = PublicGame {
nonce :: ByteString nonce :: ByteString