我有以下课程:
命名空间消息;
struct BBox {
xmin:float;
xmax:float;
ymin:float;
ymax:float;
}
table msg {
key:string;
boxes: [BBox];
}
root_type Message;
要创建对象,我会做一些事情,例如
b = flatbuffers.Builder(0)
msg.msgStart(b)
msg.msgAddKey(b, b.CreateString(key))
v = flatbuffers.Builder(0)
size = len(boxes)
msg.msgBoxesVector(v, size)
for elem in boxes:
xmin, ymin, xmax, ymax = elem
BBox.CreateBBox(v, xmin, xmax, ymin, ymax)
boxes = v.EndVector(size)
msg.msgAddBoxes(b, boxes)
obj = msg.msgEnd(b)
b.Finish(obj)
并且没有抛出错误
但是,当我尝试显示结果时,关键是好的,但是向量的大小和内容是错误的
rep = msg.msg.GetRootAsmsg(bytearray(b.Output()), 0)
print rep.BoxesLength() # give me 4 instead of 1
for i in range(rep.BoxesLength()):
print rep.Boxes(i).Xmin(), rep.Boxes(i).Ymin()
print rep.Boxes(i).Xmax(), rep.Boxes(i).Ymax()