Using Data.Binary.decodeFile, encountered error “demandInput: not enough bytes”

元气小坏坏 提交于 2019-12-11 02:10:08

问题


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)

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!


回答1:


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!



来源:https://stackoverflow.com/questions/18522278/using-data-binary-decodefile-encountered-error-demandinput-not-enough-bytes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!