{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeFamilies #-}
module Data.Capnp.GenHelpers.Pure where
import Control.Monad.Catch.Pure (runCatchT)
import Data.Either (fromRight)
import Data.Functor.Identity (runIdentity)
import Data.Capnp.TraversalLimit (evalLimitT)
import qualified Data.Capnp.Classes as C
import qualified Data.Capnp.Message as M
import qualified Data.Capnp.Untyped as U
defaultStruct :: (C.Decerialize a, C.FromStruct M.ConstMsg (C.Cerial M.ConstMsg a)) => a
defaultStruct =
fromRight (error "impossible") $
runIdentity $
runCatchT $
evalLimitT maxBound $
U.rootPtr M.empty >>= C.fromStruct >>= C.decerialize