编写Thrift模式:非扁平化的结构常量,使我重复

时间:2015-09-06 14:57:07

标签: thrift

我正在尝试使用thrift的Const功能为我的模型创建存根数据。例如:

struct Book {
    1: i32 id
}

struct Author {
    1: Book book
}

const Book bookEx1 = { // example instance of Book
    'id': 1
}

const Author AuthorEx1 = { /// example instance of Author
    //'book': { 'id': 1 }  // This is a copy from above, but works well
    'book': BookEx1  // this doesn't work, see below
}

以上示例在编译时会抛出错误:

$ thrift -v -gen js:ts model.thrift
Scanning model.thrift for includes
Parsing model.thrift for types
[FAILURE:model.thrift:17] type error: const "AuthorEx1.book" was declared as struct/xception

问题:我想通过之前定义的结构(例如bookEx1)引用其他定义的const结构,而不是展平值。我怎么能这样做?

我使用Thrift 0.9.2。

0 个答案:

没有答案