diff options
Diffstat (limited to 'src/Remote/KRPC/Protocol.hs')
-rw-r--r-- | src/Remote/KRPC/Protocol.hs | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/src/Remote/KRPC/Protocol.hs b/src/Remote/KRPC/Protocol.hs index 06e54f78..d28fdbeb 100644 --- a/src/Remote/KRPC/Protocol.hs +++ b/src/Remote/KRPC/Protocol.hs | |||
@@ -74,8 +74,8 @@ data KError | |||
74 | | MethodUnknown { errorMessage :: ByteString } | 74 | | MethodUnknown { errorMessage :: ByteString } |
75 | deriving (Show, Read, Eq, Ord) | 75 | deriving (Show, Read, Eq, Ord) |
76 | 76 | ||
77 | instance BEncodable KError where | 77 | instance BEncode KError where |
78 | {-# SPECIALIZE instance BEncodable KError #-} | 78 | {-# SPECIALIZE instance BEncode KError #-} |
79 | {-# INLINE toBEncode #-} | 79 | {-# INLINE toBEncode #-} |
80 | toBEncode e = fromAscAssocs -- WARN: keep keys sorted | 80 | toBEncode e = fromAscAssocs -- WARN: keep keys sorted |
81 | [ "e" --> (errorCode e, errorMessage e) | 81 | [ "e" --> (errorCode e, errorMessage e) |
@@ -125,11 +125,11 @@ type ParamName = ByteString | |||
125 | -- | 125 | -- |
126 | data KQuery = KQuery { | 126 | data KQuery = KQuery { |
127 | queryMethod :: MethodName | 127 | queryMethod :: MethodName |
128 | , queryArgs :: Map ParamName BEncode | 128 | , queryArgs :: Map ParamName BValue |
129 | } deriving (Show, Read, Eq, Ord) | 129 | } deriving (Show, Read, Eq, Ord) |
130 | 130 | ||
131 | instance BEncodable KQuery where | 131 | instance BEncode KQuery where |
132 | {-# SPECIALIZE instance BEncodable KQuery #-} | 132 | {-# SPECIALIZE instance BEncode KQuery #-} |
133 | {-# INLINE toBEncode #-} | 133 | {-# INLINE toBEncode #-} |
134 | toBEncode (KQuery m args) = fromAscAssocs -- WARN: keep keys sorted | 134 | toBEncode (KQuery m args) = fromAscAssocs -- WARN: keep keys sorted |
135 | [ "a" --> BDict args | 135 | [ "a" --> BDict args |
@@ -145,7 +145,7 @@ instance BEncodable KQuery where | |||
145 | 145 | ||
146 | fromBEncode _ = decodingError "KQuery" | 146 | fromBEncode _ = decodingError "KQuery" |
147 | 147 | ||
148 | kquery :: MethodName -> [(ParamName, BEncode)] -> KQuery | 148 | kquery :: MethodName -> [(ParamName, BValue)] -> KQuery |
149 | kquery name args = KQuery name (M.fromList args) | 149 | kquery name args = KQuery name (M.fromList args) |
150 | {-# INLINE kquery #-} | 150 | {-# INLINE kquery #-} |
151 | 151 | ||
@@ -163,12 +163,10 @@ type ValName = ByteString | |||
163 | -- | 163 | -- |
164 | -- > { "y" : "r", "r" : [<val1>, <val2>, ...] } | 164 | -- > { "y" : "r", "r" : [<val1>, <val2>, ...] } |
165 | -- | 165 | -- |
166 | newtype KResponse = KResponse { | 166 | newtype KResponse = KResponse { respVals :: BDict } |
167 | respVals :: Map ValName BEncode | 167 | deriving (Show, Read, Eq, Ord) |
168 | } deriving (Show, Read, Eq, Ord) | ||
169 | 168 | ||
170 | instance BEncodable KResponse where | 169 | instance BEncode KResponse where |
171 | {-# SPECIALIZE instance BEncodable KResponse #-} | ||
172 | {-# INLINE toBEncode #-} | 170 | {-# INLINE toBEncode #-} |
173 | toBEncode (KResponse vals) = fromAscAssocs -- WARN: keep keys sorted | 171 | toBEncode (KResponse vals) = fromAscAssocs -- WARN: keep keys sorted |
174 | [ "r" --> vals | 172 | [ "r" --> vals |
@@ -183,7 +181,7 @@ instance BEncodable KResponse where | |||
183 | fromBEncode _ = decodingError "KDict" | 181 | fromBEncode _ = decodingError "KDict" |
184 | 182 | ||
185 | 183 | ||
186 | kresponse :: [(ValName, BEncode)] -> KResponse | 184 | kresponse :: [(ValName, BValue)] -> KResponse |
187 | kresponse = KResponse . M.fromList | 185 | kresponse = KResponse . M.fromList |
188 | {-# INLINE kresponse #-} | 186 | {-# INLINE kresponse #-} |
189 | 187 | ||
@@ -208,7 +206,7 @@ maxMsgSize = 64 * 1024 -- max udp size | |||
208 | 206 | ||
209 | 207 | ||
210 | -- TODO eliminate toStrict | 208 | -- TODO eliminate toStrict |
211 | sendMessage :: BEncodable msg => msg -> KRemoteAddr -> KRemote -> IO () | 209 | sendMessage :: BEncode msg => msg -> KRemoteAddr -> KRemote -> IO () |
212 | sendMessage msg (host, port) sock = | 210 | sendMessage msg (host, port) sock = |
213 | sendAllTo sock (LB.toStrict (encoded msg)) (SockAddrInet port host) | 211 | sendAllTo sock (LB.toStrict (encoded msg)) (SockAddrInet port host) |
214 | {-# INLINE sendMessage #-} | 212 | {-# INLINE sendMessage #-} |