cereal icon indicating copy to clipboard operation
cereal copied to clipboard

lookAhead and bytesRead

Open td202 opened this issue 4 years ago • 2 comments

While lookAhead does not consume the input, it does update the bytesRead.

test = do
    x <- bytesRead
    _ <- lookAhead getInt64be
    y <- bytesRead
    return (x, y)

> runGet test (encode (2 :: Int)) -- result: Right (0, 8)

I suspect this is not the desired behaviour, and that the above example should return (0, 0), to reflect that no bytes of the input have been consumed. If this is the desired behaviour, it should probably be documented.

td202 avatar Aug 04 '20 16:08 td202

This seems like a bug to me, good find!

elliottt avatar Aug 04 '20 16:08 elliottt

Seems to me it's all the less likely to be the desired behavior that the same code does return (0,0) when run against binary.

jmazon avatar Sep 15 '21 17:09 jmazon