summaryrefslogtreecommitdiff
path: root/src/Network/BitTorrent/PeerWire/Bitfield.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Network/BitTorrent/PeerWire/Bitfield.hs')
-rw-r--r--src/Network/BitTorrent/PeerWire/Bitfield.hs39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/Network/BitTorrent/PeerWire/Bitfield.hs b/src/Network/BitTorrent/PeerWire/Bitfield.hs
new file mode 100644
index 00000000..c9357a25
--- /dev/null
+++ b/src/Network/BitTorrent/PeerWire/Bitfield.hs
@@ -0,0 +1,39 @@
1-- |
2-- Copyright : (c) Sam T. 2013
3-- License : MIT
4-- Maintainer : pxqr.sta@gmail.com
5-- Stability : experimental
6-- Portability : portable
7--
8--
9-- This module provides Bitfield datatype used to represent sets of
10-- piece indexes any peer have. All associated operations should be
11-- defined here as well.
12--
13module Network.BitTorrent.PeerWire.Bitfield
14 ( Bitfield(..)
15 , getBitfield, putBitfield, bitfieldByteCount
16 ) where
17
18import Control.Applicative
19import Data.ByteString (ByteString)
20import qualified Data.ByteString as B
21
22import Data.Serialize
23
24
25newtype Bitfield = MkBitfield {
26 bfBits :: ByteString
27 } deriving (Show, Eq, Ord)
28
29bitfieldByteCount :: Bitfield -> Int
30bitfieldByteCount = B.length . bfBits
31{-# INLINE bitfieldByteCount #-}
32
33getBitfield :: Int -> Get Bitfield
34getBitfield n = MkBitfield <$> getBytes n
35{-# INLINE getBitfield #-}
36
37putBitfield :: Bitfield -> Put
38putBitfield = putByteString . bfBits
39{-# INLINE putBitfield #-} \ No newline at end of file