summaryrefslogtreecommitdiff
path: root/src/Data/BEncode
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2013-09-29 08:03:07 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2013-09-29 08:03:07 +0400
commite7a93379de8af8567d052e71c6f728a4665bc102 (patch)
treee4d193336a7f6be9bc765ff39229b374a770d3f9 /src/Data/BEncode
parente1810a1318da49db2e25cdcc478b41dbe938928f (diff)
Move types to separate module
Diffstat (limited to 'src/Data/BEncode')
-rw-r--r--src/Data/BEncode/Types.hs45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/Data/BEncode/Types.hs b/src/Data/BEncode/Types.hs
new file mode 100644
index 0000000..e505249
--- /dev/null
+++ b/src/Data/BEncode/Types.hs
@@ -0,0 +1,45 @@
1-- |
2-- Copyright : (c) Sam Truzjan 2013
3-- License : BSD3
4-- Maintainer : pxqr.sta@gmail.com
5-- Stability : stable
6-- Portability : portable
7--
8-- Types for working with bencode data.
9--
10module Data.BEncode.Types
11 ( BInteger
12 , BString
13 , BList
14 , BDict
15 , BValue (..)
16 ) where
17
18import Control.DeepSeq
19import Data.ByteString
20
21import Data.BEncode.BDict
22
23
24type BInteger = Integer
25type BString = ByteString
26type BList = [BValue]
27type BDict = BDictMap BValue
28
29-- | 'BEncode' is straightforward ADT for b-encoded values. Please
30-- note that since dictionaries are sorted, in most cases we can
31-- compare BEncoded values without serialization and vice versa.
32-- Lists is not required to be sorted through.
33--
34data BValue
35 = BInteger !BInteger -- ^ bencode integers;
36 | BString !BString -- ^ bencode strings;
37 | BList BList -- ^ list of bencode values;
38 | BDict BDict -- ^ bencode key-value dictionary.
39 deriving (Show, Read, Eq, Ord)
40
41instance NFData BValue where
42 rnf (BInteger i) = rnf i
43 rnf (BString s) = rnf s
44 rnf (BList l) = rnf l
45 rnf (BDict d) = rnf d