如何在 Python 中没有 Premature 的 EOF 的情况下读取船长 proto 消息.bin 文件?

问题描述

我正在尝试读取 captian proto .bin 消息(以打包方式编写):

while

但它产生以下错误

timestep = []
with open('example.txt','r') as f:
    lines = f.readlines()
i = 0
while i < len(lines):
    if line[i].startswith("ITEM: timestep"):
       i += 1
       while not line[i].startswith("ITEM: "):
           timestep.append(next(line))     
           i += 1
    else:
       i += 1

为什么会出现这个错误?我假设我没有正确阅读打包的消息(或类似的东西)。如何在captain proto for python中正确打开这个文件内容

我阅读了以下链接,但没有帮助:

  1. Reading/writing Cap’n Proto messages partially
  2. How to set the Cap'n Proto RPC message traversal limit?
  3. https://github.com/capnproto/capnproto/issues/545
  4. https://jparyani.github.io/pycapnp/capnp.html#capnp._StructModule.read_packed

但他们并没有多大帮助。似乎很难在网上找到任何带有确切错误消息的内容dag_file = dag_api_capnp.Dag.read_packed(dependency_file,traversal_limit_in_words=2 ** 64 - 1) ,除了链接 4 似乎不太有用(并且没有提到 Python 一词)。

顺便说一句,这三个都会出错:

Traceback (most recent call last):
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/_pydevd_bundle/pydevd_exec2.py",line 1,in Exec
    def Exec(exp,global_vars,local_vars=None):
  File "<input>",in <module>
  File "capnp/lib/capnp.pyx",line 3013,in capnp.lib.capnp._StructModule.read_packed
  File "capnp/lib/capnp.pyx",line 3600,in capnp.lib.capnp._PackedFdMessageReader.__init__
capnp.lib.capnp.KjException: kj/io.c++:53: Failed: expected n >= minBytes; Premature EOF
stack: 122b411e3 122b43536 122a48a97 108ca7d40 1229aa340 122a5a3d7 108c0fcf0 108c15396 108d64cf4 108d62abe 10a9f7f4c 108d5520a 108d4f728 108c6ef33 108d64cf4 108d62a04 10a9f7f4c 108d5520a 108c1117d 108d64cf4 108d62a04 10a9f7f4c 108c110c1 108d64cf4 108d616f9 10a9f7f4c 108c110c1 108d64cf4 108d61662 10a9f7f4c 108c110c1

交叉发布:https://github.com/capnproto/pycapnp/issues/257

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)