summaryrefslogtreecommitdiff
path: root/src/Network/KRPC/Scheme.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Network/KRPC/Scheme.hs')
-rw-r--r--src/Network/KRPC/Scheme.hs22
1 files changed, 14 insertions, 8 deletions
diff --git a/src/Network/KRPC/Scheme.hs b/src/Network/KRPC/Scheme.hs
index 15f0b677..59d2c627 100644
--- a/src/Network/KRPC/Scheme.hs
+++ b/src/Network/KRPC/Scheme.hs
@@ -21,6 +21,9 @@ module Network.KRPC.Scheme
21 ) where 21 ) where
22 22
23import Control.Applicative 23import Control.Applicative
24import Data.BEncode as BE
25import Data.BEncode.BDict as BS
26import Data.BEncode.Types as BS
24import Data.Map as M 27import Data.Map as M
25import Data.Set as S 28import Data.Set as S
26 29
@@ -45,19 +48,23 @@ class KMessage message scheme | message -> scheme where
45 48
46 49
47instance KMessage KError ErrorCode where 50instance KMessage KError ErrorCode where
48 {-# SPECIALIZE instance KMessage KError ErrorCode #-}
49 scheme = errorCode 51 scheme = errorCode
50 {-# INLINE scheme #-} 52 {-# INLINE scheme #-}
51 53
52
53data KQueryScheme = KQueryScheme { 54data KQueryScheme = KQueryScheme {
54 qscMethod :: MethodName 55 qscMethod :: MethodName
55 , qscParams :: Set ParamName 56 , qscParams :: Set ParamName
56 } deriving (Show, Read, Eq, Ord) 57 } deriving (Show, Read, Eq, Ord)
57 58
59bdictKeys :: BDict -> [BKey]
60bdictKeys (Cons k _ xs) = k : bdictKeys xs
61bdictKeys Nil = []
62
58instance KMessage KQuery KQueryScheme where 63instance KMessage KQuery KQueryScheme where
59 {-# SPECIALIZE instance KMessage KQuery KQueryScheme #-} 64 scheme q = KQueryScheme
60 scheme q = KQueryScheme (queryMethod q) (M.keysSet (queryArgs q)) 65 { qscMethod = queryMethod q
66 , qscParams = S.fromAscList $ bdictKeys $ queryArgs q
67 }
61 {-# INLINE scheme #-} 68 {-# INLINE scheme #-}
62 69
63methodQueryScheme :: Method a b -> KQueryScheme 70methodQueryScheme :: Method a b -> KQueryScheme
@@ -65,14 +72,13 @@ methodQueryScheme = KQueryScheme <$> methodName
65 <*> S.fromList . methodParams 72 <*> S.fromList . methodParams
66{-# INLINE methodQueryScheme #-} 73{-# INLINE methodQueryScheme #-}
67 74
68 75newtype KResponseScheme = KResponseScheme
69newtype KResponseScheme = KResponseScheme { 76 { rscVals :: Set ValName
70 rscVals :: Set ValName
71 } deriving (Show, Read, Eq, Ord) 77 } deriving (Show, Read, Eq, Ord)
72 78
73instance KMessage KResponse KResponseScheme where 79instance KMessage KResponse KResponseScheme where
74 {-# SPECIALIZE instance KMessage KResponse KResponseScheme #-} 80 {-# SPECIALIZE instance KMessage KResponse KResponseScheme #-}
75 scheme = KResponseScheme . keysSet . respVals 81 scheme = KResponseScheme . S.fromAscList . bdictKeys . respVals
76 {-# INLINE scheme #-} 82 {-# INLINE scheme #-}
77 83
78methodRespScheme :: Method a b -> KResponseScheme 84methodRespScheme :: Method a b -> KResponseScheme