thrift使用傳輸協議TCompactProtocol

如何使用其他傳輸協議?

默認使用TBinaryProtocol,如何使用TCompactProtocol?

解決方法:
首先確認系統支持算術位移(負數的位移)
在支持的情況下#include <config.h>
因爲在文件TCompactProtocol.tcc開頭會有:
#if !defined(SIGNED_RIGHT_SHIFT_IS) || !defined(ARITHMETIC_RIGHT_SHIFT)
# error "Unable to determine the behavior of a signed right shift"
#endif
#if SIGNED_RIGHT_SHIFT_IS != ARITHMETIC_RIGHT_SHIFT
# error "TCompactProtocol currently only works if a signed right shift is arithmetic"
#endif

如果沒有config.h的話,程序編譯到此爲止。

接着,

服務端和客戶端均#include <protocol/TCompactProtocol.h>
將shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());
替換成shared_ptr<TProtocolFactory> protocolFactory(new TCompactProtocolFactory());即可

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章