diff options
author | Sam Truzjan <pxqr.sta@gmail.com> | 2013-10-17 09:49:42 +0400 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2013-10-17 09:49:42 +0400 |
commit | 2f5450c06b70b5d9b319d651af5934aa4e5f97c4 (patch) | |
tree | be1e87fb94445a8ac1c4b6ce231c31e000a5d2ee /src/Network/KRPC.hs | |
parent | 3d61d2d9b12bc41853aa388048da96460b34605d (diff) |
Update library to use bencoding == 0.4.*
Diffstat (limited to 'src/Network/KRPC.hs')
-rw-r--r-- | src/Network/KRPC.hs | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/src/Network/KRPC.hs b/src/Network/KRPC.hs index 0428669b..27363515 100644 --- a/src/Network/KRPC.hs +++ b/src/Network/KRPC.hs | |||
@@ -120,7 +120,9 @@ import Control.Applicative | |||
120 | import Control.Exception | 120 | import Control.Exception |
121 | import Control.Monad.Trans.Control | 121 | import Control.Monad.Trans.Control |
122 | import Control.Monad.IO.Class | 122 | import Control.Monad.IO.Class |
123 | import Data.BEncode | 123 | import Data.BEncode as BE |
124 | import Data.BEncode.BDict as BE | ||
125 | import Data.BEncode.Types as BE | ||
124 | import Data.ByteString.Char8 as BC | 126 | import Data.ByteString.Char8 as BC |
125 | import Data.List as L | 127 | import Data.List as L |
126 | import Data.Map as M | 128 | import Data.Map as M |
@@ -226,20 +228,24 @@ method = Method | |||
226 | {-# INLINE method #-} | 228 | {-# INLINE method #-} |
227 | 229 | ||
228 | lookupKey :: ParamName -> BDict -> Result BValue | 230 | lookupKey :: ParamName -> BDict -> Result BValue |
229 | lookupKey x = maybe (Left ("not found key " ++ BC.unpack x)) Right . M.lookup x | 231 | lookupKey x = maybe (Left ("not found key " ++ BC.unpack x)) Right . BE.lookup x |
230 | 232 | ||
231 | extractArgs :: [ParamName] -> BDict -> Result BValue | 233 | extractArgs :: [ParamName] -> BDict -> Result BValue |
232 | extractArgs [] d = Right $ if M.null d then BList [] else BDict d | 234 | extractArgs [] d = Right $ if BE.null d then BList [] else BDict d |
233 | extractArgs [x] d = lookupKey x d | 235 | extractArgs [x] d = lookupKey x d |
234 | extractArgs xs d = BList <$> mapM (`lookupKey` d) xs | 236 | extractArgs xs d = BList <$> mapM (`lookupKey` d) xs |
235 | {-# INLINE extractArgs #-} | 237 | {-# INLINE extractArgs #-} |
236 | 238 | ||
237 | injectVals :: [ParamName] -> BValue -> [(ParamName, BValue)] | 239 | zipBDict :: [BKey] -> [BValue] -> BDict |
238 | injectVals [] (BList []) = [] | 240 | zipBDict (k : ks) (v : vs) = Cons k v (zipBDict ks vs) |
239 | injectVals [] (BDict d ) = M.toList d | 241 | zipBDict _ _ = Nil |
242 | |||
243 | injectVals :: [ParamName] -> BValue -> BDict | ||
244 | injectVals [] (BList []) = BE.empty | ||
245 | injectVals [] (BDict d ) = d | ||
240 | injectVals [] be = invalidParamList [] be | 246 | injectVals [] be = invalidParamList [] be |
241 | injectVals [p] arg = [(p, arg)] | 247 | injectVals [p] arg = BE.singleton p arg |
242 | injectVals ps (BList as) = L.zip ps as | 248 | injectVals ps (BList as) = zipBDict ps as |
243 | injectVals ps be = invalidParamList ps be | 249 | injectVals ps be = invalidParamList ps be |
244 | {-# INLINE injectVals #-} | 250 | {-# INLINE injectVals #-} |
245 | 251 | ||