{-# LANGUAGE UndecidableInstances #-}

module Binrep.Test where

import Binrep
import Binrep.Type.Magic
import Binrep.CBLen.Generic
import GHC.Generics ( Generic )
import Data.Word
import Binrep.Util.ByteOrder

data DMagic = DMagic
  { DMagic -> Magic '[255, 0, 1, 0, 1, 0, 1, 255]
dMagic1_8b :: Magic '[0xFF, 0, 1, 0, 1, 0, 1, 0xFF]
  } deriving stock (forall x. DMagic -> Rep DMagic x)
-> (forall x. Rep DMagic x -> DMagic) -> Generic DMagic
forall x. Rep DMagic x -> DMagic
forall x. DMagic -> Rep DMagic x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. DMagic -> Rep DMagic x
from :: forall x. DMagic -> Rep DMagic x
$cto :: forall x. Rep DMagic x -> DMagic
to :: forall x. Rep DMagic x -> DMagic
Generic

instance IsCBLen DMagic where type CBLen DMagic = CBLenGenericNonSum DMagic
instance PutC DMagic where putC :: DMagic -> PutterC
putC = DMagic -> PutterC
forall a.
(Generic a, GPoke PutC (Rep a), GAssertNotVoid a,
 GAssertNotSum a) =>
a -> PutterC
putGenericStruct

data DMagicSum = DMagicSum1 (Magic '[0]) | DMagicSum2 (Magic '[0xFF])
    deriving stock (forall x. DMagicSum -> Rep DMagicSum x)
-> (forall x. Rep DMagicSum x -> DMagicSum) -> Generic DMagicSum
forall x. Rep DMagicSum x -> DMagicSum
forall x. DMagicSum -> Rep DMagicSum x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. DMagicSum -> Rep DMagicSum x
from :: forall x. DMagicSum -> Rep DMagicSum x
$cto :: forall x. Rep DMagicSum x -> DMagicSum
to :: forall x. Rep DMagicSum x -> DMagicSum
Generic

instance IsCBLen DMagicSum where
    type CBLen DMagicSum = CBLenGenericNonSum DMagicSum

data DStruct = DStruct
  { DStruct -> Magic '[255, 0, 1, 255]
dStruct1 :: Magic '[0xFF, 0, 1, 0xFF]
  , DStruct -> ByteOrdered LE Word32
dStruct2 :: ByteOrdered LE Word32
  , DStruct -> ()
dStruct3 :: ()
  } deriving stock ((forall x. DStruct -> Rep DStruct x)
-> (forall x. Rep DStruct x -> DStruct) -> Generic DStruct
forall x. Rep DStruct x -> DStruct
forall x. DStruct -> Rep DStruct x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. DStruct -> Rep DStruct x
from :: forall x. DStruct -> Rep DStruct x
$cto :: forall x. Rep DStruct x -> DStruct
to :: forall x. Rep DStruct x -> DStruct
Generic, Int -> DStruct -> ShowS
[DStruct] -> ShowS
DStruct -> String
(Int -> DStruct -> ShowS)
-> (DStruct -> String) -> ([DStruct] -> ShowS) -> Show DStruct
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> DStruct -> ShowS
showsPrec :: Int -> DStruct -> ShowS
$cshow :: DStruct -> String
show :: DStruct -> String
$cshowList :: [DStruct] -> ShowS
showList :: [DStruct] -> ShowS
Show)

instance IsCBLen DStruct where type CBLen DStruct = CBLenGenericNonSum DStruct
instance GetC DStruct where getC :: GetterC DStruct
getC = GetterC DStruct
forall a.
(Generic a, GParse GetC (Rep a), GAssertNotVoid a,
 GAssertNotSum a) =>
GetterC a
getGenericStruct
deriving via ViaGetC DStruct instance Get DStruct