thift源码研究-客户端代码分析
来源:互联网 发布:淘宝上新提醒在哪里 编辑:程序博客网 时间:2024/05/17 20:30
这部分代码是用于客户端请求服务器,它由thrift compiler自动生成。
使用与前一篇一样的例子:thrift文件
/**
* gateway service definition.
*/
service GatewayService
{
i32 GetCompereCount( 1:i32 channel_id ),
list< i32 > GetCompereList( 1:i32 channel_id,
2:i32 from, 3:i32 range )
}
由thrift compiler自动生成的客户端代码:
class GatewayServiceClient : virtual public GatewayServiceIf {
public:
GatewayServiceClient(boost::shared_ptr< ::apache::thrift::protocol::TProtocol> prot) :
piprot_(prot),
poprot_(prot) {
iprot_ = prot.get();
oprot_ = prot.get();
}
GatewayServiceClient(boost::shared_ptr< ::apache::thrift::protocol::TProtocol> iprot, boost::shared_ptr< ::apache::thrift::protocol::TProtocol> oprot) :
piprot_(iprot),
poprot_(oprot) {
iprot_ = iprot.get();
oprot_ = oprot.get();
}
boost::shared_ptr< ::apache::thrift::protocol::TProtocol> getInputProtocol() {
return piprot_;
}
boost::shared_ptr< ::apache::thrift::protocol::TProtocol> getOutputProtocol() {
return poprot_;
}
int32_t GetCompereCount(const int32_t channel_id);
void send_GetCompereCount(const int32_t channel_id);
int32_t recv_GetCompereCount();
void GetCompereList(std::vector<int32_t> & _return, const int32_t channel_id, const int32_t from, const int32_t range);
void send_GetCompereList(const int32_t channel_id, const int32_t from, const int32_t range);
void recv_GetCompereList(std::vector<int32_t> & _return);
protected:
boost::shared_ptr< ::apache::thrift::protocol::TProtocol> piprot_;
boost::shared_ptr< ::apache::thrift::protocol::TProtocol> poprot_;
::apache::thrift::protocol::TProtocol* iprot_;
::apache::thrift::protocol::TProtocol* oprot_;
};
其中:
(1)int32_t GetCompereCount(const int32_t channel_id)和void GetCompereList(std::vector<int32_t> & _return, const int32_t channel_id, const int32_t from, const int32_t range)函数供用户调用;
(2)上述两个函数都会调用对应send和rec函数,如GetCompereCount函数调用send_GetCompereCount和recv_GetCompereCount函数;
代码如下:
int32_t GatewayServiceClient::GetCompereCount(const int32_t channel_id)
{
send_GetCompereCount(channel_id);
return recv_GetCompereCount();
}
(3)send函数,如send_GetCompereCount
代码如下:
void GatewayServiceClient::send_GetCompereCount(const int32_t channel_id)
{
int32_t cseqid = 0;
oprot_->writeMessageBegin("GetCompereCount", ::apache::thrift::protocol::T_CALL, cseqid);
GatewayService_GetCompereCount_pargs args;
args.channel_id = &channel_id;
args.write(oprot_);
oprot_->writeMessageEnd();
oprot_->getTransport()->writeEnd();
oprot_->getTransport()->flush();
}
(4)rec函数,如recv_GetCompereCount
代码如下:
int32_t GatewayServiceClient::recv_GetCompereCount()
{
int32_t rseqid = 0;
std::string fname;
::apache::thrift::protocol::TMessageType mtype;
iprot_->readMessageBegin(fname, mtype, rseqid);
if (mtype == ::apache::thrift::protocol::T_EXCEPTION) {
::apache::thrift::TApplicationException x;
x.read(iprot_);
iprot_->readMessageEnd();
iprot_->getTransport()->readEnd();
throw x;
}
if (mtype != ::apache::thrift::protocol::T_REPLY) {
iprot_->skip(::apache::thrift::protocol::T_STRUCT);
iprot_->readMessageEnd();
iprot_->getTransport()->readEnd();
}
if (fname.compare("GetCompereCount") != 0) {
iprot_->skip(::apache::thrift::protocol::T_STRUCT);
iprot_->readMessageEnd();
iprot_->getTransport()->readEnd();
}
int32_t _return;
GatewayService_GetCompereCount_presult result;
result.success = &_return;
result.read(iprot_);
iprot_->readMessageEnd();
iprot_->getTransport()->readEnd();
if (result.__isset.success) {
return _return;
}
if (result.__isset.err) {
throw result.err;
}
throw ::apache::thrift::TApplicationException(::apache::thrift::TApplicationException::MISSING_RESULT, "GetCompereCount failed: unknown result");
}
- thift源码研究-客户端代码分析
- thift源码研究-TProcessor类体系
- thrift源码研究-TBinaryProtocolT代码分析
- thrift源码研究-TCompactProtocolT代码分析
- thrift源码研究-TJSONProtocol代码分析
- caffe源码分析--math_functions.cu代码研究
- caffe源码分析--SyncedMemory类代码研究
- caffe源码分析--Blob类代码研究
- caffe源码分析--SyncedMemory类代码研究
- caffe源码分析--Blob类代码研究
- caffe源码分析--SyncedMemory类代码研究
- 仿陌陌客户端源码研究
- BT客户端源码分析
- BT客户端源码分析
- Zookeeper客户端源码分析
- xfire 客户端代码分析
- xfire 客户端代码分析
- Hadoop RPC源码研究----客户端部分
- 如何处理网络字节序之htonl和ntohl
- hibernate一对一单向外键关联_Annotation_联合主键
- iptables 基本命令
- linux 如何显示一个文件的某几行(中间几行)
- 如何抓DHCP包
- thift源码研究-客户端代码分析
- Linux 之Cut命令详解
- 【遇到SARS不要慌,让我们找到谁是可疑感染者!!】 并查集--poj1611
- Linux防火墙 配置文件 iptables详解
- Linux下删除非空目录
- AsyncTask介绍
- pinyin4j获取汉字正确的全拼和简拼
- java实现中文数字与阿拉伯数字互相转换
- Metamaterials perform image compression before light reaches the sensor(微波成像,拍摄与压缩同步进行)