博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
thrift 实战总结
阅读量:4036 次
发布时间:2019-05-24

本文共 1071 字,大约阅读时间需要 3 分钟。

Return 实践

enum ReturnCode {Success,Failed,}struct ValueGetResult { required ReturnCode code, optional  string value, } service Find_SomeThing {  ValueGetResult  GetValue(1: required string key)  }

在实践的时候,我发现它给ValueGetResult 多生成了一个变量 bool __isset.value ,所以thrift 并不是直接帮我们把查找到的Value返回,它需要我们自己判断什么时候返回,那么我们就可以根据得到的ReturnCode 来进行判断如果Success ,我们需要手动去置 __isset.value 为True。这个时候Thrift 的逻辑对于Server端来说,当它给Client返回数据的时候会进行判断,如果为True就把这个value返回了回去

Thrift Debug String

有的时候我们想把thrift结构的内容输出到日志上,那么可以使用下面这个函数,这个函数是官方头文件推荐的做法。

// TODO(dreiss): Move (part of) ThriftDebugString into a .cpp file and remove this.#include 
namespace apache {namespace thrift {template
std::string ThriftDebugString(const ThriftStruct& ts) { using namespace apache::thrift::transport; using namespace apache::thrift::protocol; TMemoryBuffer* buffer = new TMemoryBuffer; boost::shared_ptr
trans(buffer); TDebugProtocol protocol(trans); ts.write(&protocol); uint8_t* buf; uint32_t size; buffer->getBuffer(&buf, &size); return std::string((char*)buf, (unsigned int)size);}

转载地址:http://vmjdi.baihongyu.com/

你可能感兴趣的文章
mint/ubuntu安装搜狗输入法
查看>>
C++动态申请数组和参数传递问题
查看>>
opencv学习——在MFC中读取和显示图像
查看>>
retext出现Could not parse file contents, check if you have the necessary module installed解决方案
查看>>
Matlab与CUDA C的混合编程配置出现的问题及解决方案
查看>>
python一句话之利用文件对话框获取文件路径
查看>>
PaperDownloader——文献命名6起来
查看>>
如何将PaperDownloader下载的文献存放到任意位置
查看>>
C/C++中关于动态生成一维数组和二维数组的学习
查看>>
JVM最简生存指南
查看>>
Java的对象驻留
查看>>
logback高级特性使用(二) 自定义Pattern模板
查看>>
JVM并发机制探讨—内存模型、内存可见性和指令重排序
查看>>
可扩展、高可用服务网络设计方案
查看>>
如何构建高扩展性网站
查看>>
微服务架构的设计模式
查看>>
持续可用与CAP理论 – 一个系统开发者的观点
查看>>
nginx+tomcat+memcached (msm)实现 session同步复制
查看>>
c++字符数组和字符指针区别以及str***函数
查看>>
c++类的操作符重载注意事项
查看>>