summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2013-09-28 02:12:54 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2013-09-28 02:12:54 +0400
commit1b089e7f550fc607546718a26388ea6faf2d91ae (patch)
tree397ca0ec3cc5f3392487704c24d12022899d4bc4
parentabd06172c9baa1a0a4013ea56de83a2d49d84c3a (diff)
BInteger = Integer; to conform specification
-rw-r--r--TODO.org1
-rw-r--r--src/Data/BEncode.hs11
2 files changed, 6 insertions, 6 deletions
diff --git a/TODO.org b/TODO.org
index 47beccc..0e9cd35 100644
--- a/TODO.org
+++ b/TODO.org
@@ -8,6 +8,7 @@
8* TODO fix portability issues 8* TODO fix portability issues
9make int's instances platform independent so we can make library 9make int's instances platform independent so we can make library
10portable. 10portable.
11BInteger = 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
106import Control.Applicative 106import Control.Applicative
107import Control.DeepSeq 107import Control.DeepSeq
108import Control.Monad 108import Control.Monad
109import Data.Int
110import Data.Maybe (mapMaybe) 109import Data.Maybe (mapMaybe)
111import Data.Monoid -- (mempty, (<>)) 110import Data.Monoid -- (mempty, (<>))
112import Data.Foldable (foldMap) 111import Data.Foldable (foldMap)
@@ -136,7 +135,7 @@ import GHC.Generics
136#endif 135#endif
137 136
138 137
139type BInteger = Int64 138type BInteger = Integer
140type BString = ByteString 139type BString = ByteString
141type BList = [BEncode] 140type BList = [BEncode]
142type BDict = Map BKey BEncode 141type 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--
150data BEncode = BInteger {-# UNPACK #-} !BInteger -- ^ bencode integers; 149data 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
658builder = go 657builder = 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
773instance BEncodable Word where -- TODO: make platform independent 772instance 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 #-}