2013-03-26 57 views
6

我想代表阿帕奇節儉標準樹結構,但我遇到 以下問題:阿帕奇節儉失敗產生遞歸結構

[ERROR:/path_to_project/thrift/service.thrift:31] (last token was 'TCategoryTree') 
Type "TCategoryTree" has not been defined. 

這些都是我的節儉結構:

struct TCategory { 
    1: required string name 
} 

struct TCategoryTree { 
    1: required TCategory element, 
    2: optional list<TCategoryTree> children 
} 

線31是2: optional list<TCategoryTree> children,我定義了一個字段 ,它與我現在定義的類型相同。

難道是apache節儉不支持遞歸結構,或者我在這裏犯了 某種錯誤嗎?

編輯:我使用的是0.9.0版本

回答

7

是,unfortuantely節儉不允許遞歸結構呢。有這種限制的解決方法,例如在傳輸數據結構時將其扁平化。在大多數情況下,這是可行的,儘管它在雙方都需要額外的代碼。

這裏是一個很好的例子,如何做到這一點: http://grokbase.com/t/thrift/user/0984cqwxen/recursive-datatypes


更新

當前的節儉開發主幹現在支持這一段時間。要小心,因爲它允許無盡的參考循環(A引用B引用A ...),當嘗試序列化時導致堆棧溢出。