我有嵌套的Java POJO 3級,看起來像這樣的模式文件:Flatbuffers:你如何構建嵌套表?
struct FPathSegment {
originIata:ushort;
destinationIata:ushort;
}
table FPathConnection {
segments:[FPathSegment];
}
table FPath {
connections:[FPathConnection];
}
當我嘗試序列化的Java POJO的Flatbuffer相當於我幾乎得到「嵌套serialzation不允許」每次嘗試使用普通的FlatBufferBuilder來構建整個對象圖時都會出錯。
在文檔中沒有線索可以說明我是否擁有整個圖形的單個構建器?每個表/結構單獨一個?如果分開,你如何將子對象導入父對象?
有所有這些方法,如創建/開始/添加各種載體,但沒有解釋什麼建設者去那裏。痛苦複雜。
這裏是我的Java代碼,我試圖將我的Java POJO序列化爲Flatbuffers相當於:
private FPath convert(Path path) {
FlatBufferBuilder bld = new FlatBufferBuilder(1024);
// build the Flatbuffer object
FPath.startFPath(bld);
FPath.startConnectionsVector(bld, path.getConnections().size());
for(Path.PathConnection connection : path.getConnections()) {
FPathConnection.startFPathConnection(bld);
for(Path.PathSegment segment : connection.getSegments()) {
FPathSegment.createFPathSegment(bld,
stringCache.getPointer(segment.getOriginIata()),
stringCache.getPointer(segment.getDestinationIata()));
}
FPathConnection.endFPathConnection(bld);
}
FPath.endFPath(bld);
return FPath.getRootAsFPath(bld.dataBuffer());
}
每start()方法拋出一個「FlatBuffers:對象序列化不能嵌套」異常,不能弄清楚如何做到這一點。