{-# LANGUAGE TypeFamilies #-}
module Network.Ethereum.ABI.Codec (
encode
, decode
, encode'
, decode'
) where
import Data.ByteArray (ByteArray, ByteArrayAccess,
convert)
import Data.Serialize (runGet, runPut)
import Generics.SOP (Generic, Rep, from, to)
import Network.Ethereum.ABI.Class (ABIGet (..), ABIPut (..),
GenericABIGet (..),
GenericABIPut (..))
import Network.Ethereum.ABI.Generic ()
encode :: (ABIPut a, ByteArray ba)
=> a
-> ba
{-# INLINE encode #-}
encode = convert . runPut . abiPut
encode' :: (Generic a,
Rep a ~ rep,
GenericABIPut rep,
ByteArray ba)
=> a
-> ba
{-# INLINE encode' #-}
encode' = convert . runPut . gAbiPut . from
decode :: (ByteArrayAccess ba, ABIGet a)
=> ba
-> Either String a
{-# INLINE decode #-}
decode = runGet abiGet . convert
decode' :: (Generic a,
Rep a ~ rep,
GenericABIGet rep,
ByteArrayAccess ba)
=> ba
-> Either String a
decode' = runGet (to <$> gAbiGet) . convert