我有一个^ {CD1>},我将它转换成C++字符串^ {CD2>},因为我想把它传递给Python。在
C++可以与:
protoObj.ParseFromArray(buffer, sbuffer.size());
我通过以下方式将buffer
传递给python:
python文件看起来像这样:
import proto.protobuf_pb2
class Calculation:
def funcName(self, sbuffer, sbuffer_size):
protoObj = ProtoBuffClass()
protoObj.ParseFromString(sbuffer.encode('utf-8'))
如果我运行代码,会收到以下错误消息:
terminate called after throwing an instance of 'pybind11::error_already_set'
what(): DecodeError: Truncated message.
At:
/usr/local/lib/python3.6/dist-packages/google/protobuf/internal/decoder.py(721): DecodeField
/usr/local/lib/python3.6/dist-packages/google/protobuf/internal/python_message.py(1189): InternalParse
/usr/local/lib/python3.6/dist-packages/google/protobuf/internal/python_message.py(1132): MergeFromString
/usr/local/lib/python3.6/dist-packages/google/protobuf/message.py(187): ParseFromString
./Calculation.py(31): funcName
Aborted (core dumped)
我是否犯了一些根本性的错误或如何解决这个问题?是sbuffer的编码吗(当我不编码时,我得到错误:TypeError: memoryview: a bytes-like object is required, not 'str'
)?提前谢谢。在
我想您应该将缓冲区作为
bytes
传递。所以不是你需要
^{pr2}$同时更改python接口以接受一个参数。在
Source of ^{}
相关问题 更多 >
编程相关推荐