我现在使用 Thrift 作为通信协议(protocol)。 我必须传递一个对象(树数据结构)来映射树数据结构。我想生成java代码。 如何通过 Thrift 传输树数据结构,我通过 Tree 定义了一个对象,但 thrift 不允许这种方式,来 self 的 thrift 文件的一部分:
struct MyObject {
1:i32 id,
2:i32 parentid,
3:string name,
4:list<MyObject> children
}
但是,我从 Thrift 收到此错误:类型“MyObject”尚未定义。 有没有解决这个问题的方法? 感谢您的任何建议!
最佳答案
你可以试试这个。
struct TreeNode {
1:i32 id,
2:i32 parentid,
3:string name,
4:list<i32> childrenIds
}
struct Tree {
1:i32 rootId,
2:map<i32,TreeNode> nodes,
}
使用这种方式,您可以将简单的数据结构解释为树
关于tree - 使用 Thrift 表达树结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11289484/