diff options
author | Sam Truzjan <pxqr.sta@gmail.com> | 2014-02-26 08:57:03 +0400 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2014-02-26 08:57:03 +0400 |
commit | 918bb023aec3a49298003ec87da341d744190320 (patch) | |
tree | 71faf477230b1df25eae1e286a439530dd947770 /src | |
parent | c1b4289459faa1fd0c982472d3eeaa2d772fbfdf (diff) |
Bump aeson dependency
Diffstat (limited to 'src')
-rw-r--r-- | src/Data/Torrent/JSON.hs | 17 | ||||
-rw-r--r-- | src/Network/BitTorrent/Core/PeerId.hs | 1 |
2 files changed, 17 insertions, 1 deletions
diff --git a/src/Data/Torrent/JSON.hs b/src/Data/Torrent/JSON.hs index 3fa8973d..6a0aa510 100644 --- a/src/Data/Torrent/JSON.hs +++ b/src/Data/Torrent/JSON.hs | |||
@@ -3,9 +3,14 @@ module Data.Torrent.JSON | |||
3 | , omitRecordPrefix | 3 | , omitRecordPrefix |
4 | ) where | 4 | ) where |
5 | 5 | ||
6 | import Control.Applicative | ||
6 | import Data.Aeson.TH | 7 | import Data.Aeson.TH |
8 | import Data.Aeson.Types | ||
9 | import Data.ByteString as BS | ||
10 | import Data.ByteString.Base16 as Base16 | ||
7 | import Data.Char | 11 | import Data.Char |
8 | import Data.List as L | 12 | import Data.List as L |
13 | import Data.Text.Encoding as T | ||
9 | 14 | ||
10 | 15 | ||
11 | -- | Ignore '_' prefix. | 16 | -- | Ignore '_' prefix. |
@@ -28,4 +33,14 @@ mapWhile p f = go | |||
28 | omitRecordPrefix :: Options | 33 | omitRecordPrefix :: Options |
29 | omitRecordPrefix = omitLensPrefix | 34 | omitRecordPrefix = omitLensPrefix |
30 | { fieldLabelModifier = mapWhile isUpper toLower . L.dropWhile isLower | 35 | { fieldLabelModifier = mapWhile isUpper toLower . L.dropWhile isLower |
31 | } \ No newline at end of file | 36 | } |
37 | |||
38 | instance ToJSON ByteString where | ||
39 | toJSON = String . T.decodeUtf8 . Base16.encode | ||
40 | |||
41 | instance FromJSON ByteString where | ||
42 | parseJSON v = do | ||
43 | (ok, bad) <- (Base16.decode . T.encodeUtf8) <$> parseJSON v | ||
44 | if BS.null bad | ||
45 | then return ok | ||
46 | else fail "parseJSON: unable to decode ByteString" | ||
diff --git a/src/Network/BitTorrent/Core/PeerId.hs b/src/Network/BitTorrent/Core/PeerId.hs index c860d9d4..f8d69e8b 100644 --- a/src/Network/BitTorrent/Core/PeerId.hs +++ b/src/Network/BitTorrent/Core/PeerId.hs | |||
@@ -62,6 +62,7 @@ import Text.PrettyPrint hiding ((<>)) | |||
62 | import Text.PrettyPrint.Class | 62 | import Text.PrettyPrint.Class |
63 | import Text.Read (readMaybe) | 63 | import Text.Read (readMaybe) |
64 | 64 | ||
65 | import Data.Torrent.JSON () | ||
65 | import Network.BitTorrent.Core.Fingerprint | 66 | import Network.BitTorrent.Core.Fingerprint |
66 | 67 | ||
67 | -- TODO use unpacked Word160 form (length is known statically) | 68 | -- TODO use unpacked Word160 form (length is known statically) |