From 1ae7d4877a2a30131babbee54bc0c24651eaba90 Mon Sep 17 00:00:00 2001 From: Sam Truzjan Date: Sat, 7 Dec 2013 23:10:27 +0400 Subject: Move JSON options to separate module --- src/Network/BitTorrent/Core/PeerAddr.hs | 3 ++- src/Network/BitTorrent/Exchange/Block.hs | 3 ++- src/Network/BitTorrent/Exchange/Status.hs | 7 ++++--- src/Network/BitTorrent/Tracker/Message.hs | 12 ++++++++---- 4 files changed, 16 insertions(+), 9 deletions(-) (limited to 'src/Network') diff --git a/src/Network/BitTorrent/Core/PeerAddr.hs b/src/Network/BitTorrent/Core/PeerAddr.hs index 846a14f9..e7a4ea61 100644 --- a/src/Network/BitTorrent/Core/PeerAddr.hs +++ b/src/Network/BitTorrent/Core/PeerAddr.hs @@ -41,6 +41,7 @@ import Text.PrettyPrint.Class import Text.Read (readMaybe) import System.IO.Unsafe +import Data.Torrent.JSON import Network.BitTorrent.Core.PeerId @@ -68,7 +69,7 @@ data PeerAddr = PeerAddr , peerPort :: {-# UNPACK #-} !PortNumber } deriving (Show, Eq, Ord, Typeable) -$(deriveJSON defaultOptions { fieldLabelModifier = (L.map toLower . L.dropWhile isLower) } ''PeerAddr) +$(deriveJSON omitRecordPrefix ''PeerAddr) peer_id_key, peer_ip_key, peer_port_key :: BKey peer_id_key = "peer id" diff --git a/src/Network/BitTorrent/Exchange/Block.hs b/src/Network/BitTorrent/Exchange/Block.hs index 5ab73b65..d06fe727 100644 --- a/src/Network/BitTorrent/Exchange/Block.hs +++ b/src/Network/BitTorrent/Exchange/Block.hs @@ -41,6 +41,7 @@ import Data.Typeable import Text.PrettyPrint import Text.PrettyPrint.Class +import Data.Torrent.JSON import Data.Torrent.Piece {----------------------------------------------------------------------- @@ -84,7 +85,7 @@ data BlockIx = BlockIx { , ixLength :: {-# UNPACK #-} !BlockSize } deriving (Show, Eq, Typeable) -$(deriveJSON defaultOptions { fieldLabelModifier = (L.map toLower . L.dropWhile isLower) } ''BlockIx) +$(deriveJSON omitRecordPrefix ''BlockIx) getInt :: S.Get Int getInt = fromIntegral <$> S.getWord32be diff --git a/src/Network/BitTorrent/Exchange/Status.hs b/src/Network/BitTorrent/Exchange/Status.hs index 42766428..8472e575 100644 --- a/src/Network/BitTorrent/Exchange/Status.hs +++ b/src/Network/BitTorrent/Exchange/Status.hs @@ -36,14 +36,15 @@ module Network.BitTorrent.Exchange.Status import Control.Lens import Data.Aeson.TH import Data.Default -import Data.List as L import Data.Maybe import Data.Monoid import Text.PrettyPrint as PP hiding ((<>)) import Text.PrettyPrint.Class +import Data.Torrent.JSON import Network.BitTorrent.Exchange.Message + {----------------------------------------------------------------------- -- Peer status -----------------------------------------------------------------------} @@ -60,7 +61,7 @@ data PeerStatus = PeerStatus } deriving (Show, Eq, Ord) $(makeLenses ''PeerStatus) -$(deriveJSON defaultOptions { fieldLabelModifier = L.tail } ''PeerStatus) +$(deriveJSON omitLensPrefix ''PeerStatus) instance Pretty PeerStatus where pretty PeerStatus {..} = @@ -103,7 +104,7 @@ data SessionStatus = SessionStatus } deriving (Show, Eq) $(makeLenses ''SessionStatus) -$(deriveJSON defaultOptions { fieldLabelModifier = L.tail } ''SessionStatus) +$(deriveJSON omitRecordPrefix ''SessionStatus) instance Pretty SessionStatus where pretty SessionStatus {..} = diff --git a/src/Network/BitTorrent/Tracker/Message.hs b/src/Network/BitTorrent/Tracker/Message.hs index 212181b9..943c3af5 100644 --- a/src/Network/BitTorrent/Tracker/Message.hs +++ b/src/Network/BitTorrent/Tracker/Message.hs @@ -34,6 +34,9 @@ module Network.BitTorrent.Tracker.Message -- ** Request , AnnounceQueryExt (..) + , renderAnnounceQueryExt + , parseAnnounceQueryExt + , AnnounceRequest (..) , parseAnnounceRequest , renderAnnounceRequest @@ -87,6 +90,7 @@ import Network.Socket import Text.Read (readMaybe) import Data.Torrent.InfoHash +import Data.Torrent.JSON import Data.Torrent.Progress import Network.BitTorrent.Core @@ -104,7 +108,7 @@ data Event = Started -- ^ To be sent when the peer completes a download. deriving (Show, Read, Eq, Ord, Enum, Bounded, Typeable) -$(deriveJSON defaultOptions { fieldLabelModifier = (L.map toLower . L.dropWhile isLower) } ''Event) +$(deriveJSON omitRecordPrefix ''Event) -- | HTTP tracker protocol compatible encoding. instance QueryValueLike Event where @@ -174,7 +178,7 @@ data AnnounceQuery = AnnounceQuery , reqEvent :: Maybe Event } deriving (Show, Eq, Typeable) -$(deriveJSON defaultOptions { fieldLabelModifier = (L.map toLower . L.dropWhile isLower) } ''AnnounceQuery) +$(deriveJSON omitRecordPrefix ''AnnounceQuery) -- | UDP tracker protocol compatible encoding. instance Serialize AnnounceQuery where @@ -480,7 +484,7 @@ data AnnounceInfo = , respWarning :: !(Maybe Text) } deriving (Show, Typeable) -$(deriveJSON defaultOptions { fieldLabelModifier = (L.map toLower . L.dropWhile isLower) } ''AnnounceInfo) +$(deriveJSON omitRecordPrefix ''AnnounceInfo) -- | HTTP tracker protocol compatible encoding. instance BEncode AnnounceInfo where @@ -630,7 +634,7 @@ data ScrapeEntry = ScrapeEntry { , siName :: !(Maybe Text) } deriving (Show, Eq, Typeable) -$(deriveJSON defaultOptions { fieldLabelModifier = (L.map toLower . L.dropWhile isLower) } ''ScrapeEntry) +$(deriveJSON omitRecordPrefix ''ScrapeEntry) -- | HTTP tracker protocol compatible encoding. instance BEncode ScrapeEntry where -- cgit v1.2.3