packages feed

hexstring 0.11.0 → 0.11.1

raw patch · 2 files changed

+13/−3 lines, 2 filesdep +aesonPVP ok

version bump matches the API change (PVP)

Dependencies added: aeson

API changes (from Hackage documentation)

+ Data.HexString: instance FromJSON HexString
+ Data.HexString: instance ToJSON HexString

Files

hexstring.cabal view
@@ -1,6 +1,6 @@ name: hexstring
 category: Data
-version: 0.11.0
+version: 0.11.1
 license: MIT
 license-file: LICENSE
 copyright: (c) 2015 Leon Mergen
@@ -31,6 +31,7 @@                      , text
                      , bytestring
                      , base16-bytestring
+                     , aeson
 
 test-suite test-suite
   type:                exitcode-stdio-1.0
src/Data/HexString.hs view
@@ -6,10 +6,13 @@                       , toBytes
                       , toText ) where
 
-import           Data.Word                   (Word8)
+import           Control.Applicative    (pure)
 
-import qualified Data.ByteString.Base16 as BS16 (decode, encode)
+import           Data.Aeson
+import           Data.Word              (Word8)
+
 import qualified Data.ByteString        as BS
+import qualified Data.ByteString.Base16 as BS16 (decode, encode)
 import qualified Data.ByteString.Lazy   as BSL
 
 import qualified Data.Text              as T
@@ -22,6 +25,12 @@ data HexString =
   HexString BS.ByteString
   deriving ( Show, Eq, Ord )
+
+instance FromJSON HexString where
+  parseJSON = withText "HexString" $ pure . hexString . TE.encodeUtf8
+
+instance ToJSON HexString where
+  toJSON = String . toText
 
 -- | Smart constructor which validates that all the text are actually
 --   hexadecimal characters.