FlorianHartwig avatar FlorianHartwig committed e64c893 Draft

Add some haddock documentation and a package description.

Comments (0)

Files changed (5)

AttoBencode.cabal

 Category:            Data
 Build-type:          Simple
 Cabal-version:       >=1.8
+Description:
+    A library for encoding and decoding the Bencode data serialisation format
+    used by BitTorrent. The focus of this library are good performance (good
+    enough to be used in a BitTorrent client) and ease of
+    use.
+
 Library
   Exposed-modules:
     Data.AttoBencode,

src/Data/AttoBencode.hs

-module Data.AttoBencode 
-    ( BValue(..)
+-- |
+-- Module: Data.AttoBencode
+-- Copyright: Florian Hartwig
+-- License: BSD3
+-- Maintainer: Florian Hartwig <florian.j.hartwig@gmail.com>
+-- Stability: experimental
+-- Portability: GHC
+--
+module Data.AttoBencode
+    ( 
+    -- * BEncode Types
+      BValue(..)
     , Dict
+    -- * Encoding and Decoding
     , decode
     , encode
     , FromBencode(..)
     , ToBencode(..)
+    -- * Convencience Functions
     , (.:)
     ) where
 

src/Data/AttoBencode/Encode.hs

+-- |
+-- Module: Data.AttoBencode.Encode
+-- Copyright: Florian Hartwig
+-- License: BSD3
+-- Maintainer: Florian Hartwig <florian.j.hartwig@gmail.com>
+-- Stability: experimental
+-- Portability: GHC
+
 module Data.AttoBencode.Encode (encode) where
 
 import Data.AttoBencode.Types
 iWord = 105
 colon = 58
 
--- TODO: check out associativity of <>
 fromBValue :: BValue -> Builder
 fromBValue (BString s) = fromString s
 fromBValue (BList l)   = fromWord8 lWord <> (mconcat . map fromBValue) l <> fromWord8 eWord

src/Data/AttoBencode/Parser.hs

+-- |
+-- Module: Data.AttoBencode.Parser
+-- Copyright: Florian Hartwig
+-- License: BSD3
+-- Maintainer: Florian Hartwig <florian.j.hartwig@gmail.com>
+-- Stability: experimental
+-- Portability: GHC
+
 {-# LANGUAGE BangPatterns #-}
 module Data.AttoBencode.Parser 
     ( decode

src/Data/AttoBencode/Types.hs

+-- |
+-- Module: Data.AttoBencode.Types
+-- Copyright: Florian Hartwig
+-- License: BSD3
+-- Maintainer: Florian Hartwig <florian.j.hartwig@gmail.com>
+-- Stability: experimental
+-- Portability: GHC
+
 {-# LANGUAGE FlexibleInstances #-}
 
 module Data.AttoBencode.Types
             | BDict !Dict
     deriving (Show, Eq)
 
--- | A Bencode dictionary is a map from ByteStrings to Bencode values
+-- | A Bencode dictionary. Dictionaries have 'ByteString' keys and 'BValue'
+--   values.
 type Dict = M.Map ByteString BValue
 
--- | A type that can be converted to a BValue
+-- TODO: example
+-- | A type that can be converted to a 'BValue'.
 class ToBencode a where
     toBencode :: a -> BValue
 
--- | A type that can be converted from a BValue. The conversion can fail.
+-- TODO: example
+-- | A type that can be converted from a 'BValue'. The conversion can fail.
 class FromBencode a where
     fromBencode :: BValue -> Maybe a
 
     fromBencode (BList l) = sequence $ map fromBencode l
     fromBencode _         = Nothing
 
+-- | Look up the value corresponding to a (ByteString) key from a dictionary.
+--   Returns 'Nothing' if the key is not in the dictionary or if the 'BValue'
+--   cannot be converted to the expected type.
 (.:) :: (FromBencode a) => Dict -> ByteString -> Maybe a
 d .: s = M.lookup s d >>= fromBencode
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.