module Remote.KRPC.Scheme
( KMessage(..)
, KQueryScheme(..), methodQueryScheme
, KResponseScheme(..), methodRespScheme
) where
import Control.Applicative
import Data.Map as M
import Data.Set as S
import Remote.KRPC.Protocol
import Remote.KRPC
class KMessage message scheme | message -> scheme where
scheme :: message -> scheme
validate :: message -> scheme -> Bool
default validate :: Eq scheme => message -> scheme -> Bool
validate = (==) . scheme
instance KMessage KError ErrorCode where
scheme = errorCode
data KQueryScheme = KQueryScheme {
qscMethod :: MethodName
, qscParams :: Set ParamName
} deriving (Show, Read, Eq, Ord)
instance KMessage KQuery KQueryScheme where
scheme q = KQueryScheme (queryMethod q) (M.keysSet (queryArgs q))
methodQueryScheme :: Method a b -> KQueryScheme
methodQueryScheme = KQueryScheme <$> methodName
<*> S.fromList . methodParams
newtype KResponseScheme = KResponseScheme {
rscVals :: Set ValName
} deriving (Show, Read, Eq, Ord)
instance KMessage KResponse KResponseScheme where
scheme = KResponseScheme . keysSet . respVals
methodRespScheme :: Method a b -> KResponseScheme
methodRespScheme = KResponseScheme . S.fromList . methodVals