【发布时间】:2020-05-14 22:05:05
【问题描述】:
我已经写了以下fbs文件
命名空间测试;
table polygon {
x : double;
y : double;
}
table layer {
layer_name : string;
polygons : [polygon];
}
root_type layer;
我的计划是序列化大约 500 万个坐标并将其转储到一个文件中。问题是我看到的字节数与我预期的相比有所增加。我期望它应该是 aounf (5M* 16) 字节。但我得到的大小是 140000032 字节
这是我用来将序列化数据转储到文件中的 java 代码。
FlatBufferBuilder fbb = new FlatBufferBuilder(0);
String s = "Product1";
int str = fbb.createString("layer1");
int size = 1 * 5 * 1000000;
int[] offset = new int[size];
int cur = 0;
for (double i = 0; i < size; i++) {
fbb.startTable(2);
polygon.addX(fbb, i);
polygon.addY(fbb, i);
offset[cur++] = polygon.endpolygon(fbb);
}
int arrayoffset = layer.createPolygonsVector(fbb, offset);
layer.startlayer(fbb);
layer.addLayerName(fbb, str);
layer.addPolygons(fbb, arrayoffset);
int bla = layer.endlayer(fbb);
fbb.finish(bla);
ByteBuffer bf = fbb.dataBuffer().duplicate();
File myfile = new File("/tmp/test.dat");
try {
FileChannel channel = new FileOutputStream(myfile).getChannel();
channel.write(bf);
channel.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
如果我在这里做错了,请告诉我
【问题讨论】: