summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSam T <sta.cs.vsu@gmail.com>2013-04-17 16:26:08 +0400
committerSam T <sta.cs.vsu@gmail.com>2013-04-17 16:26:08 +0400
commit08b92abe0cfc3a2075bcb73f970fa304bacfce73 (patch)
treef963b2414318d051c234aa95deae8076d2270563 /src
parent60f754161113324c94a6ed547c4e05bba598eedb (diff)
+ Add module documentation.
Diffstat (limited to 'src')
-rw-r--r--src/Data/BEncode.hs52
1 files changed, 46 insertions, 6 deletions
diff --git a/src/Data/BEncode.hs b/src/Data/BEncode.hs
index fb2fa0b..ac1dbaf 100644
--- a/src/Data/BEncode.hs
+++ b/src/Data/BEncode.hs
@@ -1,4 +1,45 @@
1-- | This module is intented to be imported qualified. 1-- |
2-- Copyright : (c) Sam T. 2013
3-- License : MIT
4-- Maintainer : pxqr.sta@gmail.com
5-- Stability : stable
6-- Portability : non-portable
7--
8-- This module provides convinient and fast way to serialize, deserealize
9-- and construct/destructure Bencoded values with optional fields.
10--
11-- It supports four different types of values:
12--
13-- * byte strings — represented as 'ByteString';
14--
15-- * integers — represented as 'Integer';
16--
17-- * lists - represented as ordinary lists;
18--
19-- * dictionaries — represented as 'Map';
20--
21-- To serialize any other types we need to make conversion.
22-- To make conversion more convenient there is type class for it: 'BEncodable'.
23-- Any textual strings are considered as UTF8 encoded 'Text'.
24--
25-- The complete Augmented BNF syntax for bencoding format is:
26--
27--
28-- > <BE> ::= <DICT> | <LIST> | <INT> | <STR>
29-- >
30-- > <DICT> ::= "d" 1 * (<STR> <BE>) "e"
31-- > <LIST> ::= "l" 1 * <BE> "e"
32-- > <INT> ::= "i" <SNUM> "e"
33-- > <STR> ::= <NUM> ":" n * <CHAR>; where n equals the <NUM>
34-- >
35-- > <SNUM> ::= "-" <NUM> / <NUM>
36-- > <NUM> ::= 1 * <DIGIT>
37-- > <CHAR> ::= %
38-- > <DIGIT> ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
39--
40--
41-- This module is considered to be imported qualified.
42--
2{-# LANGUAGE FlexibleInstances #-} 43{-# LANGUAGE FlexibleInstances #-}
3module Data.BEncode 44module Data.BEncode
4 ( -- * Datatype 45 ( -- * Datatype
@@ -18,11 +59,11 @@ module Data.BEncode
18 , encode, decode 59 , encode, decode
19 , encoded, decoded 60 , encoded, decoded
20 61
21 -- * Extra
22 , builder, parser, decodingError, printPretty
23
24 -- * Predicates 62 -- * Predicates
25 , isInteger, isString, isList, isDict 63 , isInteger, isString, isList, isDict
64
65 -- * Extra
66 , builder, parser, decodingError, printPretty
26 ) where 67 ) where
27 68
28 69
@@ -52,7 +93,7 @@ import qualified Text.PrettyPrint.ANSI.Leijen as PP
52 93
53type Dict = Map ByteString BEncode 94type Dict = Map ByteString BEncode
54 95
55-- | 'BEncode' is straightforward AST for b-encoded values. 96-- | 'BEncode' is straightforward ADT for b-encoded values.
56-- Please note that since dictionaries are sorted, in most cases we can 97-- Please note that since dictionaries are sorted, in most cases we can
57-- compare BEncoded values without serialization and vice versa. 98-- compare BEncoded values without serialization and vice versa.
58-- Lists is not required to be sorted through. 99-- Lists is not required to be sorted through.
@@ -131,7 +172,6 @@ instance BEncodable Text where
131 fromBEncode b = T.decodeUtf8 <$> fromBEncode b 172 fromBEncode b = T.decodeUtf8 <$> fromBEncode b
132 {-# INLINE fromBEncode #-} 173 {-# INLINE fromBEncode #-}
133 174
134
135{- 175{-
136instance BEncodable Stringwhere 176instance BEncodable Stringwhere
137 toBEncode = BString . BC.pack 177 toBEncode = BString . BC.pack