{-# LANGUAGE TypeFamilies #-}
module Data.Solidity.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 Data.Solidity.Abi (AbiGet (..), AbiPut (..),
GenericAbiGet (..),
GenericAbiPut (..))
import Data.Solidity.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