【问题标题】:Using Data.Binary.decodeFile, encountered error "demandInput: not enough bytes"使用 Data.Binary.decodeFile,遇到错误“demandInput: not enough bytes”
【发布时间】:2013-08-29 22:59:59
【问题描述】:

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

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”):

Realtime: demandInput: not enough bytes

我无法确定这一点,并且搜索 Google 并没有发现任何关于此消息的实质性文档或讨论。任何见解将不胜感激!

【问题讨论】:

  • 在黑暗中刺伤,但究竟有多大?大于 4 GB?也许这是一个 32 位的东西?

标签: haskell io binary-data bytestring


【解决方案1】:

我参加聚会很晚,但在寻求类似问题的帮助时发现了这一点。我正在使用Data.Binary.Get 的增量接口。正如您在here 中看到的,该函数在Data.Binary.Get.Internal 中定义。现在我在猜测,但是您的 decodeFile 函数可能会进行某种解析并引发错误,因为文件没有完全解析(即解析器认为文件中必须有其他内容,但它已经达到 EOF)。

希望对遇到此/类似问题的人有所帮助!

【讨论】:

    猜你喜欢
    • 2012-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-24
    • 1970-01-01
    • 1970-01-01
    • 2022-01-08
    • 2017-05-08
    相关资源
    最近更新 更多