本文只介绍thrift接口描述文件的编写,至于客户端与服务端代码的编写和代码的生成请参考文章:点击打开链接
在使用apache的thrift时,第一步是需要编写thrift的接口描述文件(.thrift)。thrift文件的格式语法如下:
include "share.thrift" //引入其他的thrift文件
/**
* 命名空间,也就是生成代码之后的package
* namespace 语言名 空间名
**/
namespace java com.study.netty.thrift //根据自己的需要可以自定义
/**
* thrift支持的数据类型:
*
* bool 布尔类型
* i8 (byte) 整型8位
* i16 整型16位
* i32 整型32位
* i64 整型64位
* double 64位的浮点数
* string 字符串
* binary 字节
* map<t1,t2> Map集合
* list<t1> List集合
* set<t1> Set集合
*/
/**
* 为数据类型定义别名,定义好之后,文档中可以直接使用别名
**/
typedef i32 integer
typedef bool boolean
typedef i64 long
/**
* 定义常量
**/
const integer INTCONSTANT= 9853
const map<string,