-- | Encoder Types
module PlutusCore.Flat.Encoder.Types
  ( Size
  , NumBits
  , Prim
  , S (..)
  ) where

import GHC.Ptr (Ptr (..))
import PlutusCore.Flat.Types

-- | Add the maximum size in bits of the encoding of value a to a NumBits
type Size a = a -> NumBits -> NumBits

-- | Strict encoder state
data S
  = S
  { S -> Ptr Word8
nextPtr :: {-# UNPACK #-} !(Ptr Word8)
  , S -> Word8
currByte :: {-# UNPACK #-} !Word8
  , S -> NumBits
usedBits :: {-# UNPACK #-} !NumBits
  }
  deriving (NumBits -> S -> ShowS
[S] -> ShowS
S -> String
(NumBits -> S -> ShowS)
-> (S -> String) -> ([S] -> ShowS) -> Show S
forall a.
(NumBits -> a -> ShowS)
-> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: NumBits -> S -> ShowS
showsPrec :: NumBits -> S -> ShowS
$cshow :: S -> String
show :: S -> String
$cshowList :: [S] -> ShowS
showList :: [S] -> ShowS
Show)

-- | A basic encoder
type Prim = S -> IO S