diff options
Diffstat (limited to 'src/Network/KRPC/Scheme.hs')
-rw-r--r-- | src/Network/KRPC/Scheme.hs | 22 |
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 | ||
23 | import Control.Applicative | 23 | import Control.Applicative |
24 | import Data.BEncode as BE | ||
25 | import Data.BEncode.BDict as BS | ||
26 | import Data.BEncode.Types as BS | ||
24 | import Data.Map as M | 27 | import Data.Map as M |
25 | import Data.Set as S | 28 | import Data.Set as S |
26 | 29 | ||
@@ -45,19 +48,23 @@ class KMessage message scheme | message -> scheme where | |||
45 | 48 | ||
46 | 49 | ||
47 | instance KMessage KError ErrorCode where | 50 | instance 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 | |||
53 | data KQueryScheme = KQueryScheme { | 54 | data 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 | ||
59 | bdictKeys :: BDict -> [BKey] | ||
60 | bdictKeys (Cons k _ xs) = k : bdictKeys xs | ||
61 | bdictKeys Nil = [] | ||
62 | |||
58 | instance KMessage KQuery KQueryScheme where | 63 | instance 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 | ||
63 | methodQueryScheme :: Method a b -> KQueryScheme | 70 | methodQueryScheme :: 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 | 75 | newtype KResponseScheme = KResponseScheme | |
69 | newtype KResponseScheme = KResponseScheme { | 76 | { rscVals :: Set ValName |
70 | rscVals :: Set ValName | ||
71 | } deriving (Show, Read, Eq, Ord) | 77 | } deriving (Show, Read, Eq, Ord) |
72 | 78 | ||
73 | instance KMessage KResponse KResponseScheme where | 79 | instance 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 | ||
78 | methodRespScheme :: Method a b -> KResponseScheme | 84 | methodRespScheme :: Method a b -> KResponseScheme |