{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
module Capnp.Repr.Parsed (Parsed) where
import qualified Capnp.Basics as B
import qualified Capnp.Classes as C
import Capnp.Repr (List, PtrRepr (..), Repr (..), ReprFor)
import Capnp.Rpc.Common (Client)
import qualified Data.ByteString as BS
import Data.Kind (Type)
import qualified Data.Text as T
import qualified Data.Vector as V
type Parsed a = ParsedByRepr (ReprFor a) a
type family ParsedByRepr (r :: Repr) (a :: Type) where
ParsedByRepr ('Data _) a = a
ParsedByRepr ('Ptr ('Just 'Cap)) a = Client a
ParsedByRepr _ B.Data = BS.ByteString
ParsedByRepr _ B.Text = T.Text
ParsedByRepr _ (List a) = V.Vector (Parsed a)
ParsedByRepr _ (Maybe B.AnyPointer) = Maybe (C.Parsed B.AnyPointer)
ParsedByRepr _ a = C.Parsed a