Thrift采用自定义的.thrift
文件来定义Service
和结构体/消息
,参考.thrift
文件中可以使用的**Thrift Types**,.thrift
文档 Thrift IDL
namespace java org.smark.thrift.test
namespace go org.smark.thrift.test
const string Hello = 'Hello'
struct User{
1:string name,
2:int age = 20,
3:optional string faith
}
service HelloService{
string hello(1:User user)
}
Thrift 提供了二进制的代码生成工具,可以通过以下链接下载**https://thrift.apache.org/download**
thrift -r -out ../ --gen java hello.thrift
, 通过thrift
生产目标语言代码
Thrift没有纯粹的序列化对象到指定的格式,而是通过TProtocol
的不同实现,在传输的时候进行相应的处理, 可以利用继承TProtocolDecorator
来实现自己的数据处理:
Thrift使用Socket作为Transport
, 通过TProtocol
进行数据传输