diff options
author | Sam T <sta.cs.vsu@gmail.com> | 2013-04-24 07:04:10 +0400 |
---|---|---|
committer | Sam T <sta.cs.vsu@gmail.com> | 2013-04-24 07:04:10 +0400 |
commit | ea7947d3db0217f31dc507f930f3d9e6c6f437c0 (patch) | |
tree | 3f3a11f59db5e9d299e32f6825bd66048986d47b | |
parent | 71806baa0d07f2ea0a92698e26ce79c7c6647a50 (diff) |
~ One less orphan instance.
-rw-r--r-- | src/Data/Torrent.hs | 2 | ||||
-rw-r--r-- | src/Network/BitTorrent/PeerWire/Block.hs | 22 | ||||
-rw-r--r-- | src/Network/BitTorrent/PeerWire/Message.hs | 18 |
3 files changed, 24 insertions, 18 deletions
diff --git a/src/Data/Torrent.hs b/src/Data/Torrent.hs index 2185f702..35bed5f2 100644 --- a/src/Data/Torrent.hs +++ b/src/Data/Torrent.hs | |||
@@ -15,6 +15,8 @@ module Data.Torrent | |||
15 | , Layout, contentLayout | 15 | , Layout, contentLayout |
16 | , isSingleFile, isMultiFile | 16 | , isSingleFile, isMultiFile |
17 | , fromFile | 17 | , fromFile |
18 | |||
19 | , sizeInBase | ||
18 | ) where | 20 | ) where |
19 | 21 | ||
20 | import Control.Applicative | 22 | import Control.Applicative |
diff --git a/src/Network/BitTorrent/PeerWire/Block.hs b/src/Network/BitTorrent/PeerWire/Block.hs index a5bc4f32..8e4a1f24 100644 --- a/src/Network/BitTorrent/PeerWire/Block.hs +++ b/src/Network/BitTorrent/PeerWire/Block.hs | |||
@@ -4,12 +4,16 @@ module Network.BitTorrent.PeerWire.Block | |||
4 | , defaultBlockSize | 4 | , defaultBlockSize |
5 | , pieceIx, blockIx | 5 | , pieceIx, blockIx |
6 | , blockRange, ixRange, isPiece | 6 | , blockRange, ixRange, isPiece |
7 | |||
8 | , putInt, getInt | ||
7 | ) where | 9 | ) where |
8 | 10 | ||
9 | import Control.Applicative | 11 | import Control.Applicative |
10 | import Data.ByteString (ByteString) | 12 | import Data.ByteString (ByteString) |
11 | import qualified Data.ByteString as B | 13 | import qualified Data.ByteString as B |
12 | import Data.Int | 14 | import Data.Int |
15 | import Data.Serialize | ||
16 | |||
13 | 17 | ||
14 | type BlockLIx = Int | 18 | type BlockLIx = Int |
15 | type PieceLIx = Int | 19 | type PieceLIx = Int |
@@ -26,6 +30,24 @@ data BlockIx = BlockIx { | |||
26 | , ixLength :: {-# UNPACK #-} !Int | 30 | , ixLength :: {-# UNPACK #-} !Int |
27 | } deriving (Show, Eq) | 31 | } deriving (Show, Eq) |
28 | 32 | ||
33 | getInt :: Get Int | ||
34 | getInt = fromIntegral <$> getWord32be | ||
35 | {-# INLINE getInt #-} | ||
36 | |||
37 | putInt :: Putter Int | ||
38 | putInt = putWord32be . fromIntegral | ||
39 | {-# INLINE putInt #-} | ||
40 | |||
41 | instance Serialize BlockIx where | ||
42 | {-# SPECIALIZE instance Serialize BlockIx #-} | ||
43 | get = BlockIx <$> getInt <*> getInt <*> getInt | ||
44 | {-# INLINE get #-} | ||
45 | |||
46 | put ix = do putInt (ixPiece ix) | ||
47 | putInt (ixOffset ix) | ||
48 | putInt (ixLength ix) | ||
49 | {-# INLINE put #-} | ||
50 | |||
29 | 51 | ||
30 | data Block = Block { | 52 | data Block = Block { |
31 | -- ^ Zero-based piece index. | 53 | -- ^ Zero-based piece index. |
diff --git a/src/Network/BitTorrent/PeerWire/Message.hs b/src/Network/BitTorrent/PeerWire/Message.hs index 1bcb2ee5..66021487 100644 --- a/src/Network/BitTorrent/PeerWire/Message.hs +++ b/src/Network/BitTorrent/PeerWire/Message.hs | |||
@@ -25,15 +25,6 @@ data Message = KeepAlive | |||
25 | | Port Int | 25 | | Port Int |
26 | deriving (Show, Eq) | 26 | deriving (Show, Eq) |
27 | 27 | ||
28 | instance Serialize BlockIx where | ||
29 | {-# SPECIALIZE instance Serialize BlockIx #-} | ||
30 | get = BlockIx <$> getInt <*> getInt <*> getInt | ||
31 | {-# INLINE get #-} | ||
32 | |||
33 | put ix = do putInt (ixPiece ix) | ||
34 | putInt (ixOffset ix) | ||
35 | putInt (ixLength ix) | ||
36 | {-# INLINE put #-} | ||
37 | 28 | ||
38 | instance Serialize Message where | 29 | instance Serialize Message where |
39 | get = do | 30 | get = do |
@@ -80,12 +71,3 @@ instance Serialize Message where | |||
80 | 71 | ||
81 | put (Cancel blk) = putInt 13 >> putWord8 8 >> put blk | 72 | put (Cancel blk) = putInt 13 >> putWord8 8 >> put blk |
82 | put (Port p ) = putInt 3 >> putWord8 9 >> putWord16be (fromIntegral p) | 73 | put (Port p ) = putInt 3 >> putWord8 9 >> putWord16be (fromIntegral p) |
83 | |||
84 | |||
85 | getInt :: Get Int | ||
86 | getInt = fromIntegral <$> getWord32be | ||
87 | {-# INLINE getInt #-} | ||
88 | |||
89 | putInt :: Putter Int | ||
90 | putInt = putWord32be . fromIntegral | ||
91 | {-# INLINE putInt #-} | ||