【问题标题】:Is there any import statement like thing in apache thrift?apache thrift 中是否有类似的导入语句?
【发布时间】:2014-02-12 07:37:37
【问题描述】:

我想在 IDL 文件中定义几个结构。然后在服务中返回该结构类型的对象。为此,我必须导入该结构。如何在 IDL 中导入它们。

namespace java abc.xyz

struct struct_{
    1:string s
    2:bool b

}

service struct_test{
    struct_ getstruct_()
}

【问题讨论】:

    标签: thrift


    【解决方案1】:

    是的,正如@Vj- 正确指出的那样:

    include "path/to/file.thrift"
    

    顺便说一句,在调用编译器时,可以使用-r(用于递归)为所有 thrift IDL 生成代码,包括包含的文件。

    有两件重要的事情需要了解:

    (1) 包含文件中的定义在包含文件中使用前缀 进行引用,该前缀来自包含的 IDL 的文件名。本教程有一个很好的例子(注意shared 前缀):

    include "shared.thrift"
    
    service Calculator extends shared.SharedService {
        // more code
    }
    

    (2) 非常推荐在每个 IDL 文件中声明不同的命名空间。否则,某些目标语言(例如 PHP)可能会发生从外部 IDL 生成的代码会覆盖从内部 IDL 生成的代码,因为使用了相同的输出文件夹。

    例如:

    namespace * tutorial
    

    namespace * shared
    

    【讨论】:

      【解决方案2】:

      您只需将以下内容添加到 .thrift 文件的开头即可。

      include "path/to/file.thrift"
      

      注意文件名末尾的.thrift 扩展名。

      给出的路径是相对的,如果没有给出,则搜索当前目录。

      【讨论】:

        猜你喜欢
        • 2022-08-19
        • 1970-01-01
        • 2015-07-11
        • 2017-10-07
        • 1970-01-01
        • 2016-10-12
        • 2014-01-11
        • 2011-09-19
        • 2015-10-27
        相关资源
        最近更新 更多