@@ -298,13 +298,6 @@ runDecoderWithLimit limit size Channel{recv} =
298298 -> DecodeStep bytes failure m (Identity a )
299299 -> m (Either (Maybe failure ) (a , Maybe bytes ))
300300
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-
308301 go ! sz trailing (DecodePartial k)
309302 | sz > limit = return (Left Nothing )
310303 | otherwise = case trailing of
@@ -314,6 +307,13 @@ runDecoderWithLimit limit size Channel{recv} =
314307 Just bs -> do let sz' = sz + size bs
315308 go sz' Nothing =<< k (Just bs)
316309
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+
317317
318318runAnnotatedDecoderWithLimit
319319 :: forall m bytes failure a .
@@ -350,16 +350,15 @@ runAnnotatedDecoderWithLimit limit size Channel{recv} =
350350 -> DecodeStep bytes failure m (bytes -> a )
351351 -> m (Either (Maybe failure ) (a , Maybe bytes ))
352352
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))
359353
360354 go ! _ ! sz ! _ DecodePartial {} | sz > limit =
361355 return (Left Nothing )
362356
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+
363362 go ! bytes ! sz Nothing (DecodePartial k) = do
364363 mbs <- recv
365364 let ! sz' = sz + maybe 0 size mbs
@@ -369,10 +368,12 @@ runAnnotatedDecoderWithLimit limit size Channel{recv} =
369368 Just bs -> bs : bytes)
370369 sz' Nothing step
371370
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))
376377
377378
378379-- | Run a peer with limits.
0 commit comments