在python中如何从flatbuffer的二进制字符串ubyte向量中输入数据?

2024-09-28 22:24:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我有下表中提到的字段:

table Blob {
name        : string;
size        : ulong;
data        : [ubyte];
}

并生成以下API

^{pr2}$

除此之外,我还有一个二进制stirng bin_data,现在我想把这个数据填充到Blob的data向量中。怎么做?在

我有以下代码:

blobName = builder.CreateString(blob_name)

Blob.BlobStartDataVector(builder, len(blob_data))
for i in reversed(range(0, len(blob_data))):
    builder.PrependByte(blob_data[i])   #Error here
blob_bin_data = builder.EndVector(len(blob_data))

Blob.BlobStart(builder)
Blob.BlobAddName(builder, blobName)
Blob.BlobAddSize(builder, 30) #for example size is 30
Blob.BlobAddData(builder, blob_bin_data)
binaryBlob = BlobEnd(builder)

通过上面的代码片段,我得到以下错误:

    builder.PrependByte(blob_data[i])
  File "build/bdist.linux-x86_64/egg/flatbuffers/builder.py", line 544, in PrependByte
  File "build/bdist.linux-x86_64/egg/flatbuffers/builder.py", line 472, in Prepend
  File "build/bdist.linux-x86_64/egg/flatbuffers/builder.py", line 627, in Place
  File "build/bdist.linux-x86_64/egg/flatbuffers/number_types.py", line 148, in enforce_number
TypeError: bad number  for type uint8

寻求帮助,如何向字节数组提供二进制数据?


Tags: inpybuilddatabinegglinuxbuilder