packages feed

relapse 0.1.2.0 → 0.2.0.0

raw patch · 2 files changed

+14/−25 lines, 2 files

Files

relapse.cabal view
@@ -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
src/Data/RLP/Types.hs view
@@ -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 @@         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-    rlpEncode = rlpEncodeFinite-    rlpDecode = rlpDecodeIntegralBE--instance RLPEncodable Word16 where-    rlpEncode = rlpEncodeFinite-    rlpDecode = rlpDecodeIntegralBE--instance RLPEncodable Word32 where+instance {-# OVERLAPPABLE #-} (Integral n, FiniteBits n) => RLPEncodable n 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 @@         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@@ -298,10 +291,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