我有下表中提到的字段:
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
寻求帮助,如何向字节数组提供二进制数据?
似乎您的
blob_data
对象实际上不包含字节。您可以调试它以打印循环中的字节,并确保它符合[0255]相关问题 更多 >
编程相关推荐