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进行数据传输