summaryrefslogtreecommitdiff
path: root/src/Remote/KRPC/Protocol.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Remote/KRPC/Protocol.hs')
-rw-r--r--src/Remote/KRPC/Protocol.hs24
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
77instance BEncodable KError where 77instance 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--
126data KQuery = KQuery { 126data 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
131instance BEncodable KQuery where 131instance 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
148kquery :: MethodName -> [(ParamName, BEncode)] -> KQuery 148kquery :: MethodName -> [(ParamName, BValue)] -> KQuery
149kquery name args = KQuery name (M.fromList args) 149kquery 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--
166newtype KResponse = KResponse { 166newtype KResponse = KResponse { respVals :: BDict }
167 respVals :: Map ValName BEncode 167 deriving (Show, Read, Eq, Ord)
168 } deriving (Show, Read, Eq, Ord)
169 168
170instance BEncodable KResponse where 169instance 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
186kresponse :: [(ValName, BEncode)] -> KResponse 184kresponse :: [(ValName, BValue)] -> KResponse
187kresponse = KResponse . M.fromList 185kresponse = 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
211sendMessage :: BEncodable msg => msg -> KRemoteAddr -> KRemote -> IO () 209sendMessage :: BEncode msg => msg -> KRemoteAddr -> KRemote -> IO ()
212sendMessage msg (host, port) sock = 210sendMessage 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 #-}