summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSam T <pxqr.sta@gmail.com>2013-05-19 09:37:51 +0400
committerSam T <pxqr.sta@gmail.com>2013-05-19 09:37:51 +0400
commitb77691e022600e7eef6f933c1d52831f732ec606 (patch)
tree6a10074d98cc517bc8aeffcca8e6864146d4358b /src
parent8a18d0d510bef4284688dfc6c9b7209983d1d193 (diff)
~ Make use fromAscAssocs.
Diffstat (limited to 'src')
-rw-r--r--src/Remote/KRPC/Protocol.hs27
1 files changed, 18 insertions, 9 deletions
diff --git a/src/Remote/KRPC/Protocol.hs b/src/Remote/KRPC/Protocol.hs
index 45ce2bb0..462f72eb 100644
--- a/src/Remote/KRPC/Protocol.hs
+++ b/src/Remote/KRPC/Protocol.hs
@@ -76,11 +76,14 @@ data KError
76 deriving (Show, Read, Eq, Ord) 76 deriving (Show, Read, Eq, Ord)
77 77
78instance BEncodable KError where 78instance BEncodable KError where
79 toBEncode e = fromAssocs 79 {-# SPECIALIZE instance BEncodable KError #-}
80 [ "y" --> ("e" :: ByteString) 80 {-# INLINE toBEncode #-}
81 , "e" --> (errorCode e, errorMessage e) 81 toBEncode e = fromAscAssocs -- WARN: keep keys sorted
82 [ "e" --> (errorCode e, errorMessage e)
83 , "y" --> ("e" :: ByteString)
82 ] 84 ]
83 85
86 {-# INLINE fromBEncode #-}
84 fromBEncode (BDict d) 87 fromBEncode (BDict d)
85 | M.lookup "y" d == Just (BString "e") 88 | M.lookup "y" d == Just (BString "e")
86 = uncurry mkKError <$> d >-- "e" 89 = uncurry mkKError <$> d >-- "e"
@@ -127,12 +130,15 @@ data KQuery = KQuery {
127 } deriving (Show, Read, Eq, Ord) 130 } deriving (Show, Read, Eq, Ord)
128 131
129instance BEncodable KQuery where 132instance BEncodable KQuery where
130 toBEncode (KQuery m args) = fromAssocs 133 {-# SPECIALIZE instance BEncodable KQuery #-}
131 [ "y" --> ("q" :: ByteString) 134 {-# INLINE toBEncode #-}
135 toBEncode (KQuery m args) = fromAscAssocs -- WARN: keep keys sorted
136 [ "a" --> BDict args
132 , "q" --> m 137 , "q" --> m
133 , "a" --> BDict args 138 , "y" --> ("q" :: ByteString)
134 ] 139 ]
135 140
141 {-# INLINE fromBEncode #-}
136 fromBEncode (BDict d) 142 fromBEncode (BDict d)
137 | M.lookup "y" d == Just (BString "q") = 143 | M.lookup "y" d == Just (BString "q") =
138 KQuery <$> d >-- "q" 144 KQuery <$> d >-- "q"
@@ -163,11 +169,14 @@ newtype KResponse = KResponse {
163 } deriving (Show, Read, Eq, Ord) 169 } deriving (Show, Read, Eq, Ord)
164 170
165instance BEncodable KResponse where 171instance BEncodable KResponse where
166 toBEncode (KResponse vals) = fromAssocs 172 {-# SPECIALIZE instance BEncodable KResponse #-}
167 [ "y" --> ("r" :: ByteString) 173 {-# INLINE toBEncode #-}
168 , "r" --> vals 174 toBEncode (KResponse vals) = fromAscAssocs -- WARN: keep keys sorted
175 [ "r" --> vals
176 , "y" --> ("r" :: ByteString)
169 ] 177 ]
170 178
179 {-# INLINE fromBEncode #-}
171 fromBEncode (BDict d) 180 fromBEncode (BDict d)
172 | M.lookup "y" d == Just (BString "r") = 181 | M.lookup "y" d == Just (BString "r") =
173 KResponse <$> d >-- "r" 182 KResponse <$> d >-- "r"