[Haskell-cafe] runGet exits prematurely

Quentin Liu quentin.liu.0415 at gmail.com
Fri Feb 23 15:59:51 UTC 2018


I am using Data.Binary to decode binary files and found that the `runGet` function would throw an exception “not enough bytes” even though it has not consumed all the input.

Specifically, in the loop I am repeatedly trying to parse the binary file until it has consumed all the input

 parsePPackets xs = do
  empty <- isEmpty
  if empty
   then return xs
   else do p <- parseB6034
        parsePPackets (p:xs)

When I try to run this function with `runGet`, the exception “Data.Binary.Get.runGet at position 3293603: not enough bytes” would be thrown, while the total length of input is 5864230, a number significantly larger. The function `parseB6034` consumes no more than 250 bytes in each round. In addition, the `parsePPackets` works well when fed with a small amount of data.

Is it the problem of my code or an error with the package binary? The ByteString fed into `runGet` is lazy ByteString, as required by `runGet` function.

Best Regards,
Qingbo Liu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20180223/651c128a/attachment.html>

More information about the Haskell-Cafe mailing list