diff --git a/hanafuda-APILanguage.cabal b/hanafuda-APILanguage.cabal index 9cded08..3530d35 100644 --- a/hanafuda-APILanguage.cabal +++ b/hanafuda-APILanguage.cabal @@ -23,6 +23,7 @@ library -- other-extensions: build-depends: aeson , base >=4.9 && <4.13 + , base64-bytestring , bytestring , containers , hanafuda >= 0.3.3 diff --git a/src/Hanafuda/Message.hs b/src/Hanafuda/Message.hs index c95114a..08f561c 100644 --- a/src/Hanafuda/Message.hs +++ b/src/Hanafuda/Message.hs @@ -22,6 +22,7 @@ import Data.Aeson ( ) import Data.Aeson.Types (toJSONKeyText) import Data.ByteString (ByteString) +import qualified Data.ByteString.Base64 as B64 (decode, encode) import Data.Map (Map) import Data.Monoid ((<>)) import Data.Text (Text) @@ -182,10 +183,10 @@ instance ToJSON PublicState where toEncoding = genericToEncoding defaultOptions instance FromJSON ByteString where - parseJSON = withText "ByteString" (return . encodeUtf8) + parseJSON = withText "ByteString" (either fail return . B64.decode . encodeUtf8) instance ToJSON ByteString where - toJSON = String . decodeUtf8 - toEncoding = toEncoding . decodeUtf8 + toJSON = String . decodeUtf8 . B64.encode + toEncoding = toEncoding . decodeUtf8 . B64.encode data PublicGame = PublicGame { nonce :: ByteString