diff options
author | Sam Truzjan <pxqr.sta@gmail.com> | 2013-09-28 02:12:54 +0400 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2013-09-28 02:12:54 +0400 |
commit | 1b089e7f550fc607546718a26388ea6faf2d91ae (patch) | |
tree | 397ca0ec3cc5f3392487704c24d12022899d4bc4 | |
parent | abd06172c9baa1a0a4013ea56de83a2d49d84c3a (diff) |
BInteger = Integer; to conform specification
-rw-r--r-- | TODO.org | 1 | ||||
-rw-r--r-- | src/Data/BEncode.hs | 11 |
2 files changed, 6 insertions, 6 deletions
@@ -8,6 +8,7 @@ | |||
8 | * TODO fix portability issues | 8 | * TODO fix portability issues |
9 | make int's instances platform independent so we can make library | 9 | make int's instances platform independent so we can make library |
10 | portable. | 10 | portable. |
11 | BInteger = Integer | ||
11 | * TODO rename BEncode to BValue | 12 | * TODO rename BEncode to BValue |
12 | * TODO use HashMap for dicts | 13 | * TODO use HashMap for dicts |
13 | * TODO CPS Result | 14 | * TODO CPS Result |
diff --git a/src/Data/BEncode.hs b/src/Data/BEncode.hs index 715393f..d7595a9 100644 --- a/src/Data/BEncode.hs +++ b/src/Data/BEncode.hs | |||
@@ -106,7 +106,6 @@ module Data.BEncode | |||
106 | import Control.Applicative | 106 | import Control.Applicative |
107 | import Control.DeepSeq | 107 | import Control.DeepSeq |
108 | import Control.Monad | 108 | import Control.Monad |
109 | import Data.Int | ||
110 | import Data.Maybe (mapMaybe) | 109 | import Data.Maybe (mapMaybe) |
111 | import Data.Monoid -- (mempty, (<>)) | 110 | import Data.Monoid -- (mempty, (<>)) |
112 | import Data.Foldable (foldMap) | 111 | import Data.Foldable (foldMap) |
@@ -136,7 +135,7 @@ import GHC.Generics | |||
136 | #endif | 135 | #endif |
137 | 136 | ||
138 | 137 | ||
139 | type BInteger = Int64 | 138 | type BInteger = Integer |
140 | type BString = ByteString | 139 | type BString = ByteString |
141 | type BList = [BEncode] | 140 | type BList = [BEncode] |
142 | type BDict = Map BKey BEncode | 141 | type BDict = Map BKey BEncode |
@@ -147,7 +146,7 @@ type BKey = ByteString | |||
147 | -- compare BEncoded values without serialization and vice versa. | 146 | -- compare BEncoded values without serialization and vice versa. |
148 | -- Lists is not required to be sorted through. | 147 | -- Lists is not required to be sorted through. |
149 | -- | 148 | -- |
150 | data BEncode = BInteger {-# UNPACK #-} !BInteger -- ^ bencode integers; | 149 | data BEncode = BInteger !BInteger -- ^ bencode integers; |
151 | | BString {-# UNPACK #-} !BString -- ^ bencode strings; | 150 | | BString {-# UNPACK #-} !BString -- ^ bencode strings; |
152 | | BList BList -- ^ list of bencode values; | 151 | | BList BList -- ^ list of bencode values; |
153 | | BDict BDict -- ^ bencode key-value dictionary. | 152 | | BDict BDict -- ^ bencode key-value dictionary. |
@@ -658,7 +657,7 @@ builder :: BEncode -> B.Builder | |||
658 | builder = go | 657 | builder = go |
659 | where | 658 | where |
660 | go (BInteger i) = B.word8 (c2w 'i') <> | 659 | go (BInteger i) = B.word8 (c2w 'i') <> |
661 | B.int64Dec i <> | 660 | B.integerDec i <> |
662 | B.word8 (c2w 'e') | 661 | B.word8 (c2w 'e') |
663 | go (BString s) = buildString s | 662 | go (BString s) = buildString s |
664 | go (BList l) = B.word8 (c2w 'l') <> | 663 | go (BList l) = B.word8 (c2w 'l') <> |
@@ -710,7 +709,7 @@ parser = valueP | |||
710 | P.take n | 709 | P.take n |
711 | {-# INLINE stringP #-} | 710 | {-# INLINE stringP #-} |
712 | 711 | ||
713 | integerP :: Parser Int64 | 712 | integerP :: Parser Integer |
714 | integerP = do | 713 | integerP = do |
715 | c <- P.peekChar | 714 | c <- P.peekChar |
716 | case c of | 715 | case c of |
@@ -770,7 +769,7 @@ instance BEncodable Word64 where | |||
770 | fromBEncode b = (fromIntegral :: Int -> Word64) <$> fromBEncode b | 769 | fromBEncode b = (fromIntegral :: Int -> Word64) <$> fromBEncode b |
771 | {-# INLINE fromBEncode #-} | 770 | {-# INLINE fromBEncode #-} |
772 | 771 | ||
773 | instance BEncodable Word where -- TODO: make platform independent | 772 | instance BEncodable Word where |
774 | {-# SPECIALIZE instance BEncodable Word #-} | 773 | {-# SPECIALIZE instance BEncodable Word #-} |
775 | toBEncode = toBEncode . (fromIntegral :: Word -> Int) | 774 | toBEncode = toBEncode . (fromIntegral :: Word -> Int) |
776 | {-# INLINE toBEncode #-} | 775 | {-# INLINE toBEncode #-} |