AttoBencode-0.3.1.0: Fast Bencode encoding and parsing library

PortabilityGHC
Stabilityexperimental
MaintainerFlorian Hartwig <florian.j.hartwig@gmail.com>
Safe HaskellNone

Data.AttoBencode

Contents

Description

 

Synopsis

BEncode Types

data BValue Source

The Haskell data type for Bencode values

type Dict = Map ByteString BValueSource

A Bencode dictionary. Dictionaries have ByteString keys and BValue values.

Encoding and Decoding

decode :: FromBencode a => ByteString -> Maybe aSource

Deserialise a bencoded ByteString. If parsing or conversion fails, Nothing is returned.

encode :: ToBencode a => a -> ByteStringSource

Serialise a Bencode value to a (strict) ByteString

class FromBencode a whereSource

A type that can be converted from a BValue. The conversion can fail.

class ToBencode a whereSource

A type that can be converted to a BValue.

Methods

toBencode :: a -> BValueSource

Convencience Functions

(.:) :: FromBencode a => Dict -> ByteString -> Maybe aSource

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.

dict :: [(ByteString, BValue)] -> BValueSource

Make a BDict from a list of (key, value) tuples.

(.=) :: ToBencode a => ByteString -> a -> (ByteString, BValue)Source

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.