@@ -298,13 +298,6 @@ runDecoderWithLimit limit size Channel{recv} =
298
298
-> DecodeStep bytes failure m (Identity a )
299
299
-> m (Either (Maybe failure ) (a , Maybe bytes ))
300
300
301
- go ! sz ! _ (DecodeDone (Identity x) trailing)
302
- | let sz' = sz - maybe 0 size trailing
303
- , sz' > limit = return (Left Nothing )
304
- | otherwise = return (Right (x, trailing))
305
-
306
- go ! _ ! _ (DecodeFail failure) = return (Left (Just failure))
307
-
308
301
go ! sz trailing (DecodePartial k)
309
302
| sz > limit = return (Left Nothing )
310
303
| otherwise = case trailing of
@@ -314,6 +307,13 @@ runDecoderWithLimit limit size Channel{recv} =
314
307
Just bs -> do let sz' = sz + size bs
315
308
go sz' Nothing =<< k (Just bs)
316
309
310
+ go ! sz ! _ (DecodeDone (Identity x) trailing)
311
+ | let sz' = sz - maybe 0 size trailing
312
+ , sz' > limit = return (Left Nothing )
313
+ | otherwise = return (Right (x, trailing))
314
+
315
+ go ! _ ! _ (DecodeFail failure) = return (Left (Just failure))
316
+
317
317
318
318
runAnnotatedDecoderWithLimit
319
319
:: forall m bytes failure a .
@@ -350,16 +350,15 @@ runAnnotatedDecoderWithLimit limit size Channel{recv} =
350
350
-> DecodeStep bytes failure m (bytes -> a )
351
351
-> m (Either (Maybe failure ) (a , Maybe bytes ))
352
352
353
- go ! bytes ! sz ! _ (DecodeDone f trailing)
354
- | let sz' = sz - maybe 0 size trailing
355
- , sz' > limit = return (Left Nothing )
356
- | otherwise = return (Right (f (mconcat $ reverse bytes), trailing))
357
-
358
- go ! _ ! _ ! _ (DecodeFail failure) = return (Left (Just failure))
359
353
360
354
go ! _ ! sz ! _ DecodePartial {} | sz > limit =
361
355
return (Left Nothing )
362
356
357
+ go ! bytes ! sz (Just trailing) (DecodePartial k) = do
358
+ let sz' = sz + size trailing
359
+ step <- k (Just trailing)
360
+ go (trailing : bytes) sz' Nothing step
361
+
363
362
go ! bytes ! sz Nothing (DecodePartial k) = do
364
363
mbs <- recv
365
364
let ! sz' = sz + maybe 0 size mbs
@@ -369,10 +368,12 @@ runAnnotatedDecoderWithLimit limit size Channel{recv} =
369
368
Just bs -> bs : bytes)
370
369
sz' Nothing step
371
370
372
- go ! bytes ! sz (Just trailing) (DecodePartial k) = do
373
- let sz' = sz + size trailing
374
- step <- k (Just trailing)
375
- go (trailing : bytes) sz' Nothing step
371
+ go ! bytes ! sz ! _ (DecodeDone f trailing)
372
+ | let sz' = sz - maybe 0 size trailing
373
+ , sz' > limit = return (Left Nothing )
374
+ | otherwise = return (Right (f (mconcat $ reverse bytes), trailing))
375
+
376
+ go ! _ ! _ ! _ (DecodeFail failure) = return (Left (Just failure))
376
377
377
378
378
379
-- | Run a peer with limits.
0 commit comments