使用Data.Binary.decodeFile,遇到错误“demandInput:not enough bytes” [英] Using Data.Binary.decodeFile, encountered error "demandInput: not enough bytes"

查看:199
本文介绍了使用Data.Binary.decodeFile,遇到错误“demandInput:not enough bytes”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Data.Binary中使用encodeFile和decodeFile函数来保存一个非常大的数据结构,这样我就不必每次运行这个程序时重新计算它。相关的编码和解码函数如下:

I'm attempting to use the encodeFile and decodeFile functions in Data.Binary to save a very large datastructure so that I don't have to recompute it every time I run this program. The relevant encoding- and decoding-functions are as follows:

writePlan :: IO ()
writePlan = do (d, _, bs) <- return subjectDomain
               outHandle <- openFile "outputfile" WriteMode
               ((ebsP, aP), cacheData) <- preplanDomain d bs
               putStrLn "Calculated."

               let toWrite = ((map pseudofyOverEBS ebsP, aP),
                              pseudofyOverMap cacheData) :: WrittenData
                 in do encodeFile preplanFilename $ encode toWrite
                    putStrLn "Done."


readPlan :: IO (([EvaluatedBeliefState], [Action]), MVar HeuCache)
readPlan = do (d, _, _) <- return subjectDomain
              inHandle <- openFile "outputfile" ReadMode

              ((ebsP, aP), cacheData) <-  decodeFile preplanFilename :: IO WrittenData

              fancyCache <- newMVar (M.empty, depseudofyOverMap cacheData)
              return $! ((map depseudofyOverEBS ebsP, aP), fancyCache)

计算和写入文件的程序(使用writePlan)无误地执行,输出一个巨大的二进制文件。但是,当我运行接收此文件的程序时,执行readPlan会导致错误(程序名称为Realtime):

The program to calculate and write the file (using writePlan) executes without error, outputting a gigantic binary file. However, when I run the program which takes in this file, executing readPlan results in the error (the program name is "Realtime"):

Realtime: demandInput: not enough bytes

我无法做到这一点,谷歌搜索谷歌没有提供关于此消息的实质性文档或讨论。任何洞察力将不胜感激!

I can't make head nor tail of this, and scouring Google has turned up no substantial documentation or discussion of this message. Any insight would be appreciated!

推荐答案

我很晚参加派对,但在寻找类似问题的帮助时发现了这一点。我正在使用 Data.Binary.Get 的增量接口。正如你可以在中看到的,函数在 Data.Binary.Get.Internal 中定义。现在我正在猜测,但decodeFile函数可能会进行某种解析并抛出错误,因为文件没有完全解析(即解析器认为文件中一定有其他东西,但它已经达到EOF)。

I am very late to the party, but found this while looking for help with a similar issue. I'm working with the incremental interface for Data.Binary.Get. As you can see in here, the function is defined in Data.Binary.Get.Internal. Now I am guessing, but your decodeFile function probably does some sort of parsing and the error is thrown because the file does not parse completely (i.e. the parser thinks that there must be something else in the file but it reaches EOF already).

希望能帮助任何有此类/类似问题的人!

Hope that helps anyone with this/similar issues!

这篇关于使用Data.Binary.decodeFile,遇到错误“demandInput:not enough bytes”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆