@@ -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,15 +350,10 @@ 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))
359-
360- go ! _ ! sz ! _ DecodePartial {} | sz > limit =
361- return (Left Nothing )
353+ go ! bytes ! sz (Just trailing) (DecodePartial k) = do
354+ let sz' = sz + size trailing
355+ step <- k (Just trailing)
356+ go (trailing : bytes) sz' Nothing step
362357
363358 go ! bytes ! sz Nothing (DecodePartial k) = do
364359 mbs <- recv
@@ -369,10 +364,15 @@ runAnnotatedDecoderWithLimit limit size Channel{recv} =
369364 Just bs -> bs : bytes)
370365 sz' Nothing step
371366
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
367+ go ! bytes ! sz ! _ (DecodeDone f trailing)
368+ | let sz' = sz - maybe 0 size trailing
369+ , sz' > limit = return (Left Nothing )
370+ | otherwise = return (Right (f (mconcat $ reverse bytes), trailing))
371+
372+ go ! _ ! _ ! _ (DecodeFail failure) = return (Left (Just failure))
373+
374+ go ! _ ! sz ! _ DecodePartial {} | sz > limit =
375+ return (Left Nothing )
376376
377377
378378-- | Run a peer with limits.
0 commit comments