【发布时间】:2017-03-31 21:36:56
【问题描述】:
我有一个 3 级嵌套 Java POJO,它在架构文件中看起来像这样:
struct FPathSegment {
originIata:ushort;
destinationIata:ushort;
}
table FPathConnection {
segments:[FPathSegment];
}
table FPath {
connections:[FPathConnection];
}
当我尝试将 Java POJO 序列化为 Flatbuffer 等效项时,每次尝试使用通用 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: object serialization must not be nested”异常,不知道怎么做。
【问题讨论】:
标签: java flatbuffers