{-# LANGUAGE TypeFamilies #-}
module Codec.Scale
( encode
, decode
, encode'
, decode'
, Encode
, Decode
, module Core
) where
import Data.ByteArray (ByteArray, ByteArrayAccess, convert)
import Data.Serialize (runGet, runPut)
import Generics.SOP (Generic, Rep, from, to)
import Codec.Scale.Class (Decode (..), Encode (..), GDecode (..),
GEncode (..))
import Codec.Scale.Core as Core
encode :: (Encode a, ByteArray ba)
=> a
-> ba
{-# INLINE encode #-}
encode = convert . runPut . put
encode' :: (Generic a,
Rep a ~ rep,
GEncode rep,
ByteArray ba)
=> a
-> ba
{-# INLINE encode' #-}
encode' = convert . runPut . gPut . from
decode :: (ByteArrayAccess ba, Decode a)
=> ba
-> Either String a
{-# INLINE decode #-}
decode = runGet get . convert
decode' :: (Generic a,
Rep a ~ rep,
GDecode rep,
ByteArrayAccess ba)
=> ba
-> Either String a
{-# INLINE decode' #-}
decode' = runGet (to <$> gGet) . convert