{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TypeFamilies #-}

module Capnp.GenHelpers.Rpc
  ( module Capnp.New.Rpc.Server,
    module Capnp.Repr.Methods,
    parseCap,
    encodeCap,
  )
where

import Capnp.Message (Mutability (..))
import qualified Capnp.Message as M
import Capnp.New.Rpc.Server
import qualified Capnp.Repr as R
import Capnp.Repr.Methods
import qualified Capnp.Untyped as U

parseCap :: (R.IsCap a, U.ReadCtx m 'Const) => R.Raw a 'Const -> m (Client a)
parseCap :: forall a (m :: * -> *).
(IsCap a, ReadCtx m 'Const) =>
Raw a 'Const -> m (Client a)
parseCap (R.Raw Unwrapped (Untyped (ReprFor a) 'Const)
cap) = forall a. Client -> Client a
Client forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) (mut :: Mutability).
ReadCtx m mut =>
Cap mut -> m Client
U.getClient Unwrapped (Untyped (ReprFor a) 'Const)
cap

encodeCap :: (R.IsCap a, U.RWCtx m s) => M.Message ('Mut s) -> Client a -> m (R.Raw a ('Mut s))
encodeCap :: forall a (m :: * -> *) s.
(IsCap a, RWCtx m s) =>
Message ('Mut s) -> Client a -> m (Raw a ('Mut s))
encodeCap Message ('Mut s)
msg (Client Client
c) = forall a (mut :: Mutability).
Unwrapped (Untyped (ReprFor a) mut) -> Raw a mut
R.Raw forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall (m :: * -> *) s.
WriteCtx m s =>
Message ('Mut s) -> Client -> m (Cap ('Mut s))
U.appendCap Message ('Mut s)
msg Client
c