-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/
-- | Fast Bencode encoding and parsing library
--
-- 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.
@package AttoBencode
@version 0.2
module Data.AttoBencode.Parser
-- | Deserialise a bencoded ByteString. If parsing or conversion fails,
-- Nothing is returned.
decode :: FromBencode a => ByteString -> Maybe a
-- | Parser for Bencode values
bValue :: Parser BValue
module Data.AttoBencode
-- | The Haskell data type for Bencode values
data BValue
BString :: !ByteString -> BValue
BInt :: !Integer -> BValue
BList :: ![BValue] -> BValue
BDict :: !Dict -> BValue
-- | A Bencode dictionary. Dictionaries have ByteString keys and
-- BValue values.
type Dict = Map ByteString BValue
-- | Deserialise a bencoded ByteString. If parsing or conversion fails,
-- Nothing is returned.
decode :: FromBencode a => ByteString -> Maybe a
-- | Serialise a Bencode value to a (strict) ByteString
encode :: ToBencode a => a -> ByteString
-- | A type that can be converted from a BValue. The conversion can
-- fail.
class FromBencode a
fromBencode :: FromBencode a => BValue -> Maybe a
-- | A type that can be converted to a BValue.
class ToBencode a
toBencode :: ToBencode a => a -> BValue
-- | 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
-- | Make a BDict from a list of (key, value) tuples.
dict :: [(ByteString, BValue)] -> BValue
-- | Create a (key, value) tuple from a ByteString key and some
-- bencode-able value. Can be used with the dict function as a
-- convenient way to create BDicts.
(.=) :: ToBencode a => ByteString -> a -> (ByteString, BValue)