summaryrefslogtreecommitdiff
path: root/src/Network/KRPC.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Network/KRPC.hs')
-rw-r--r--src/Network/KRPC.hs22
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
120import Control.Exception 120import Control.Exception
121import Control.Monad.Trans.Control 121import Control.Monad.Trans.Control
122import Control.Monad.IO.Class 122import Control.Monad.IO.Class
123import Data.BEncode 123import Data.BEncode as BE
124import Data.BEncode.BDict as BE
125import Data.BEncode.Types as BE
124import Data.ByteString.Char8 as BC 126import Data.ByteString.Char8 as BC
125import Data.List as L 127import Data.List as L
126import Data.Map as M 128import Data.Map as M
@@ -226,20 +228,24 @@ method = Method
226{-# INLINE method #-} 228{-# INLINE method #-}
227 229
228lookupKey :: ParamName -> BDict -> Result BValue 230lookupKey :: ParamName -> BDict -> Result BValue
229lookupKey x = maybe (Left ("not found key " ++ BC.unpack x)) Right . M.lookup x 231lookupKey x = maybe (Left ("not found key " ++ BC.unpack x)) Right . BE.lookup x
230 232
231extractArgs :: [ParamName] -> BDict -> Result BValue 233extractArgs :: [ParamName] -> BDict -> Result BValue
232extractArgs [] d = Right $ if M.null d then BList [] else BDict d 234extractArgs [] d = Right $ if BE.null d then BList [] else BDict d
233extractArgs [x] d = lookupKey x d 235extractArgs [x] d = lookupKey x d
234extractArgs xs d = BList <$> mapM (`lookupKey` d) xs 236extractArgs xs d = BList <$> mapM (`lookupKey` d) xs
235{-# INLINE extractArgs #-} 237{-# INLINE extractArgs #-}
236 238
237injectVals :: [ParamName] -> BValue -> [(ParamName, BValue)] 239zipBDict :: [BKey] -> [BValue] -> BDict
238injectVals [] (BList []) = [] 240zipBDict (k : ks) (v : vs) = Cons k v (zipBDict ks vs)
239injectVals [] (BDict d ) = M.toList d 241zipBDict _ _ = Nil
242
243injectVals :: [ParamName] -> BValue -> BDict
244injectVals [] (BList []) = BE.empty
245injectVals [] (BDict d ) = d
240injectVals [] be = invalidParamList [] be 246injectVals [] be = invalidParamList [] be
241injectVals [p] arg = [(p, arg)] 247injectVals [p] arg = BE.singleton p arg
242injectVals ps (BList as) = L.zip ps as 248injectVals ps (BList as) = zipBDict ps as
243injectVals ps be = invalidParamList ps be 249injectVals ps be = invalidParamList ps be
244{-# INLINE injectVals #-} 250{-# INLINE injectVals #-}
245 251