【发布时间】:2015-12-26 02:44:37
【问题描述】:
我正在尝试读取用 Java 编写的 Python 协议缓冲区文件,但在调用 ParseFromString() 时遇到此错误。
ParseFromString 中的文件“build/bdist.linux-x86_64/egg/google/protobuf/message.py”,第 182 行 MergeFromString 中的文件“build/bdist.linux-x86_64/egg/google/protobuf/internal/python_message.py”,第 795 行 InternalParse 中的文件“build/bdist.linux-x86_64/egg/google/protobuf/internal/python_message.py”,第 819 行 SkipField 中的文件“build/bdist.linux-x86_64/egg/google/protobuf/internal/decoder.py”,第 716 行 _RaiseInvalidWireType 中的文件“build/bdist.linux-x86_64/egg/google/protobuf/internal/decoder.py”,第 685 行 google.protobuf.message.DecodeError:标签的线路类型无效。我尝试谷歌并看到这个链接:http://comments.gmane.org/gmane.comp.lib.protocol-buffers.general/11996
我尝试编写一个简单的 protobuf 模式并用 Python 写出来,我也可以用 Python 读取它。只有当文件是用 Java 创建的(我没有尝试过 C++)时,我才能在 Python 中读取它。
我想知道这是不是真的?马哈洛!
【问题讨论】:
-
贴出用于消息序列化的代码。
-
这就是问题所在...我没有序列化代码,因为另一个团队使用 java 完成了它。但是,我有 .proto 文件,所以我使用
protoc生成 python 类,并在遇到此问题时尝试使用我的 python 脚本解析二进制文件。我确认我使用的是与它们相同版本的协议缓冲区(v2.5.0)