@@ -13,7 +13,6 @@ import Data.Aeson
13
13
import Control.Monad.IO.Class
14
14
import Control.Monad.STM
15
15
import Control.Monad.State.Strict
16
- import qualified Data.Aeson as A
17
16
import qualified Data.Attoparsec.ByteString as AB
18
17
import qualified Data.Attoparsec.ByteString.Char8 as AB
19
18
import qualified Data.ByteString.Char8 as B
@@ -63,10 +62,10 @@ parseToJsonPipe oneShot cin cout cid =
63
62
cout
64
63
(cid + 1 )
65
64
66
- jsonConsumer :: P. Consumer A. Value IO ()
65
+ jsonConsumer :: P. Consumer Value IO ()
67
66
jsonConsumer =
68
67
do val <- P. await
69
- liftIO $ BL. putStr (A. encode val)
68
+ liftIO $ BL. putStr (encode val)
70
69
liftIO $ BL. putStr (BL. singleton $ fromIntegral (ord ' \STX ' ))
71
70
jsonConsumer
72
71
@@ -76,8 +75,8 @@ tchanProducer oneShot chan = do
76
75
P. yield val
77
76
unless oneShot $ tchanProducer False chan
78
77
79
- encodePipe :: P. Pipe ChannelResponse A. Value IO ()
80
- encodePipe = P. map (A. toJSON . channelToWire)
78
+ encodePipe :: P. Pipe ChannelResponse Value IO ()
79
+ encodePipe = P. map (toJSON . channelToWire)
81
80
82
81
parseFrames
83
82
:: forall m .
@@ -90,8 +89,8 @@ parseFrames prod0 = do
90
89
if isEmpty then return () else go prod1
91
90
where
92
91
-- ignore inputs consisting only of space
93
- terminatedJSON :: AB. Parser (Maybe A. Value )
94
- terminatedJSON = (fmap Just $ A. json' <* AB. many' AB. space <* AB. endOfInput)
92
+ terminatedJSON :: AB. Parser (Maybe Value )
93
+ terminatedJSON = (fmap Just $ json' <* AB. many' AB. space <* AB. endOfInput)
95
94
<|> (AB. many' AB. space *> pure Nothing )
96
95
-- endOfInput: we want to be sure that the given
97
96
-- parser consumes the entirety of the given input
@@ -107,9 +106,9 @@ parseFrames prod0 = do
107
106
let maybeWrappedRet :: Maybe (Either PAe. DecodingError WireRequest )
108
107
maybeWrappedRet = case ret of
109
108
Left parseErr -> pure $ Left $ PAe. AttoparsecError parseErr
110
- Right (Just a) -> case A. fromJSON a of
111
- A. Error err -> pure $ Left $ PAe. FromJSONError err
112
- A. Success wireReq -> pure $ Right wireReq
109
+ Right (Just a) -> case fromJSON a of
110
+ Error err -> pure $ Left $ PAe. FromJSONError err
111
+ Success wireReq -> pure $ Right wireReq
113
112
Right Nothing -> Nothing
114
113
case maybeWrappedRet of
115
114
Just wrappedRet -> P. yield wrappedRet
@@ -143,7 +142,7 @@ wireToChannel cout ri wr =
143
142
-- ---------------------------------------------------------------------
144
143
145
144
channelToWire :: ChannelResponse -> WireResponse
146
- channelToWire cr = WireResp $ A. toJSON $ coutResp cr
145
+ channelToWire cr = WireResp $ toJSON $ coutResp cr
147
146
148
147
-- ---------------------------------------------------------------------
149
148
@@ -152,28 +151,27 @@ data WireRequest = WireReq
152
151
, params :: ParamMap
153
152
} deriving (Show ,Eq )
154
153
155
- instance A. ToJSON WireRequest where
156
- toJSON wr = A. object
157
- [ " cmd" A. .= cmd wr
158
- , " params" A. .= params wr
154
+ instance ToJSON WireRequest where
155
+ toJSON wr = object
156
+ [ " cmd" .= cmd wr
157
+ , " params" .= params wr
159
158
]
160
159
161
160
162
- instance A. FromJSON WireRequest where
163
- parseJSON (A. Object v) = WireReq <$>
164
- v A. .: " cmd" <*>
165
- v A. .:? " params" A. .!= Map. empty
166
- -- A non-Object value is of the wrong type, so fail.
167
- parseJSON _ = mzero
161
+ instance FromJSON WireRequest where
162
+ parseJSON = withObject " WireRequest" $ \ v ->
163
+ WireReq <$>
164
+ v .: " cmd" <*>
165
+ v .:? " params" .!= Map. empty
168
166
169
167
-- ---------------------------------------------------------------------
170
168
171
- data WireResponse = WireResp A. Value
169
+ data WireResponse = WireResp Value
172
170
deriving (Show ,Eq )
173
171
174
- instance A. ToJSON WireResponse where
172
+ instance ToJSON WireResponse where
175
173
toJSON (WireResp val) = val
176
174
177
175
178
- instance A. FromJSON WireResponse where
176
+ instance FromJSON WireResponse where
179
177
parseJSON p = return $ WireResp p
0 commit comments