tree - 使用 Thrift 表达树结构

标签 tree thrift

我现在使用 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/

相关文章:

c++ - 如何避免深树递归中的堆栈溢出

德语变音符号的 c# utf-8 转换问题

java - 序列化相对简单的 Java POJO 的最快方法?

c++ - Thrift - 每个套接字都有不同的 Handler 实例

C++ 和 Thrift : Reference needed to get started

ruby-on-rails - 集成 Thrift ruby​​ 服务器和 Ruby on Rails web 应用程序

使用2个队列的Java堆栈

c++ - C++遍历一般树

python - 使用networkx打印python图表时保留左右 child

c - 后序树遍历中的段错误