Thrift 编写节俭模式:非平坦结构常量,使我重复
我试图使用thrift的Thrift 编写节俭模式:非平坦结构常量,使我重复,thrift,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
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
}
结构书{
1:i32 id
}
结构作者{
1:书
}
const Book bookEx1={//Book的示例实例
“id”:1
}
const Author AuthorEx1={///Author的示例实例
//'book':{'id':1}//这是上面的副本,但效果很好
“book”:BookEx1//这不起作用,请参见下文
}
上面的示例在编译时抛出一个错误:
$ 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
$thrift-v-gen js:ts model.thrift
扫描model.thrift for includes
分析类型的model.thrift
[失败:model.thrift:17]类型错误:const“AuthorEx1.book”已声明为struct/exception
问题:我想通过以前已定义的结构(例如bookEx1)引用其他已定义的常量结构,而不是平展值。我该怎么做
我使用Thrift 0.9.2。交叉发布到他们的问题跟踪器:你最终是如何解决这个问题的?很难维护这些固定装置,所以我把它们处理掉了。相反,我公开了我的服务的一个无依赖性的小型实现,以便在单元测试中使用。