美文网首页
序列化工具 - Thrift安装配置与使用

序列化工具 - Thrift安装配置与使用

作者: 垃圾简书_吃枣药丸 | 来源:发表于2021-06-17 17:10 被阅读0次

    一、 windows下安装Thrift

    二、 编写平台/语言无关.thrift文件

    • common.thrift
    // 命名空间
    namespace java com.futao.thrift.model.gen
    
    // 定义常量
    const i32 MIN_AGE=0;
    
    // 定义枚举
    enum Gender{
     MALE=1,
     FAMALE=2;
    }
    
    • person.thrift
    // 命名空间
    namespace java com.futao.thrift.model.gen
    
    // 包含文件
    include "common.thrift"
    
    // 结构体
    struct EducationInfo{
      1: string name;
      2: i16 age;
      3: double height;
      4: common.Gender gender;
      5: list<EducationInfo> educationList;
      6: map<string,string> friendInfoMap;
    }
    

    三、 生成语言相关的文件

    thrift -r --gen <language> <Thrift filename>

    • -r 表示递归生成include包含的.thrift文件


      image.png
      image.png
      image.png

    相关文章

      网友评论

          本文标题:序列化工具 - Thrift安装配置与使用

          本文链接:https://www.haomeiwen.com/subject/ihvcyltx.html