【发布时间】:2019-10-18 10:24:57
【问题描述】:
我想设置一个带有字节值的 flatbuffers 表字段。
到目前为止我所管理的,没有成功,是以下。
平面缓冲区架构:
namespace sint.bl;
table Response {
id:short;
body:[byte];
}
python示例代码:
import flatbuffers
import pickle
import sint.bl.Request
import sint.bl.Response
my_dict = {
'a': 1
}
my_bytes = pickle.dumps(my_dict)
builder = flatbuffers.Builder(1024)
sint.bl.Response.ResponseStart(builder)
sint.bl.Response.ResponseAddId(builder, 100)
# this line throws the exception:
# ValueError: invalid literal for int()
# with base 10: b'\x80\x03}q\x00X\x01\x00\x00\x00aq\x01K\x01s.'
sint.bl.Response.ResponseAddBody(builder, my_bytes)
response = sint.bl.Response.ResponseEnd(builder)
builder.Finish(response)
response_pdu = builder.Output()
使用 flatbuffers 管理字节编码字段的正确方法是什么?
【问题讨论】:
标签: python flatbuffers