summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoriostat <>2017-03-20 22:29:00 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2017-03-20 22:29:00 (GMT)
commit8a9a99a8f5bc108df479464c49e5344af4227715 (patch)
tree48bf25da582c4d5c4bdb49ecea066549aa55ccd0
parentf4dfb216f7abeb11d9ef619e95ea03d32925b959 (diff)
version 0.2.0.00.2.0.0
-rw-r--r--relapse.cabal2
-rw-r--r--src/Data/RLP/Types.hs37
2 files changed, 14 insertions, 25 deletions
diff --git a/relapse.cabal b/relapse.cabal
index 3c24447..902c701 100644
--- a/relapse.cabal
+++ b/relapse.cabal
@@ -1,5 +1,5 @@
name: relapse
-version: 0.1.2.0
+version: 0.2.0.0
synopsis: Sensible RLP encoding
description: An implementation of RLP as specified in the Ethereum Wiki, using Attoparsec
homepage: https://github.com/iostat/relapse#readme
diff --git a/src/Data/RLP/Types.hs b/src/Data/RLP/Types.hs
index 4940a75..7299b29 100644
--- a/src/Data/RLP/Types.hs
+++ b/src/Data/RLP/Types.hs
@@ -1,6 +1,7 @@
-{-# LANGUAGE FlexibleInstances #-}
-{-# LANGUAGE LambdaCase #-}
-{-# OPTIONS -fno-warn-orphans #-}
+{-# LANGUAGE FlexibleInstances #-}
+{-# LANGUAGE LambdaCase #-}
+{-# LANGUAGE UndecidableInstances #-}
+{-# OPTIONS -fno-warn-orphans #-}
module Data.RLP.Types where
import qualified Data.ByteString as S
@@ -71,26 +72,12 @@ instance RLPEncodable S.ByteString where
String s -> Right s
x -> rlpDecodeFail "String" x
-instance {-# OVERLAPPING #-} RLPEncodable String where
- rlpEncode = String . S8.pack
- rlpDecode = \case
- String s -> Right (S8.unpack s)
- x -> rlpDecodeFail "String" x
-
-instance RLPEncodable Int where
+instance {-# OVERLAPPABLE #-} (Integral n, FiniteBits n) => RLPEncodable n where
rlpEncode = rlpEncodeFinite
rlpDecode = rlpDecodeIntegralBE
-instance RLPEncodable Word16 where
- rlpEncode = rlpEncodeFinite
- rlpDecode = rlpDecodeIntegralBE
-
-instance RLPEncodable Word32 where
- rlpEncode = rlpEncodeFinite
- rlpDecode = rlpDecodeIntegralBE
-
-instance RLPEncodable Word64 where
- rlpEncode = rlpEncodeFinite
+instance RLPEncodable Integer where
+ rlpEncode = rlpEncode . S.pack . packIntegerBE
rlpDecode = rlpDecodeIntegralBE
instance {-# OVERLAPPABLE #-} (RLPEncodable a) => RLPEncodable [a] where
@@ -99,6 +86,12 @@ instance {-# OVERLAPPABLE #-} (RLPEncodable a) => RLPEncodable [a] where
Array xs -> sequence $ rlpDecode <$> xs
x -> rlpDecodeFail "Array" x
+instance {-# OVERLAPPING #-} RLPEncodable String where
+ rlpEncode = String . S8.pack
+ rlpDecode = \case
+ String s -> Right (S8.unpack s)
+ x -> rlpDecodeFail "String" x
+
instance RLPEncodable () where
rlpEncode _ = rlp0
rlpDecode x = if x == rlp0 then return () else rlpDecodeFail "()" x
@@ -299,10 +292,6 @@ instance RLPEncodable RLPObject where -- ayy lmao
rlpEncode = id
rlpDecode = Right
-instance RLPEncodable Integer where
- rlpEncode = rlpEncode . S.pack . packIntegerBE
- rlpDecode = rlpDecodeIntegralBE
-
instance RLPEncodable Char where
rlpEncode = rlpEncodeFinite . ord
rlpDecode = \case