【问题标题】:Express tree structure using Thrift使用 Thrift 表达树结构
【发布时间】:2013-08-27 16:44:52
【问题描述】:

我现在使用 Thrift 作为通信协议。 我必须传递一个对象(树数据结构)来映射树数据结构。我想生成java代码。 如何通过 Thrift 传输树数据结构,我通过 Tree 定义了一个对象,但 thrift 不允许这种方式,我的 thrift 文件中的一个片段:

struct MyObject {
1:i32 id,
2:i32 parentid,
3:string name,
4:list<MyObject> children
}

但是,我从 Thrift 收到此错误:尚未定义类型“MyObject”。 有什么解决方法吗? 感谢您的任何建议!

【问题讨论】:

    标签: tree thrift


    【解决方案1】:

    你可以试试这个。

    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,
    }
    

    使用这种方式,您可以获得可以解释为树的简单数据结构

    【讨论】:

      【解决方案2】:

      Thrift 不允许递归: http://grokbase.com/t/thrift/user/0984cqwxen/recursive-datatypes 可能的解决方法由 user537862 编写

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多