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

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

-- |Calculate the size (in bits) of the encoding of a value
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
showList :: [S] -> ShowS
$cshowList :: [S] -> ShowS
show :: S -> String
$cshow :: S -> String
showsPrec :: NumBits -> S -> ShowS
$cshowsPrec :: NumBits -> S -> ShowS
Show

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