diff options
author | Sam Truzjan <pxqr.sta@gmail.com> | 2014-03-20 03:19:14 +0400 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2014-03-20 03:19:14 +0400 |
commit | 95f519df298c98d966c6408cac33cdd57b8e8a03 (patch) | |
tree | e6b0fb3ba6dafd6771cfc5084fcb3f7b1a7e26da /src/Data/Torrent | |
parent | 17949276fbd32ab75bcb18016210b6947df54ed1 (diff) |
Add instance ToJSON TrackerEntry
Diffstat (limited to 'src/Data/Torrent')
-rw-r--r-- | src/Data/Torrent/JSON.hs | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/Data/Torrent/JSON.hs b/src/Data/Torrent/JSON.hs index 6a0aa510..71db3039 100644 --- a/src/Data/Torrent/JSON.hs +++ b/src/Data/Torrent/JSON.hs | |||
@@ -1,3 +1,4 @@ | |||
1 | {-# OPTIONS_GHC -fno-warn-orphans #-} | ||
1 | module Data.Torrent.JSON | 2 | module Data.Torrent.JSON |
2 | ( omitLensPrefix | 3 | ( omitLensPrefix |
3 | , omitRecordPrefix | 4 | , omitRecordPrefix |
@@ -9,6 +10,7 @@ import Data.Aeson.Types | |||
9 | import Data.ByteString as BS | 10 | import Data.ByteString as BS |
10 | import Data.ByteString.Base16 as Base16 | 11 | import Data.ByteString.Base16 as Base16 |
11 | import Data.Char | 12 | import Data.Char |
13 | import Data.IP | ||
12 | import Data.List as L | 14 | import Data.List as L |
13 | import Data.Text.Encoding as T | 15 | import Data.Text.Encoding as T |
14 | 16 | ||
@@ -44,3 +46,11 @@ instance FromJSON ByteString where | |||
44 | if BS.null bad | 46 | if BS.null bad |
45 | then return ok | 47 | then return ok |
46 | else fail "parseJSON: unable to decode ByteString" | 48 | else fail "parseJSON: unable to decode ByteString" |
49 | |||
50 | instance ToJSON IP where | ||
51 | toJSON = toJSON . show | ||
52 | |||
53 | instance FromJSON IP where | ||
54 | parseJSON v = do | ||
55 | str <- parseJSON v | ||
56 | return $ read str | ||