首页 > 其他 > 详细

Thrift第三课 编写脚本

时间:2018-02-17 14:47:56      阅读:265      评论:0      收藏:0      [点我收藏+]
警告

    尽量使用tutorial下面的模板,注意脚本的格式,否则生成错误

使用thrift-0.9.0生成C++/csharp代码

使用的指令如下:

thrift-0.9.0.exe --gen cpp thriftcom.thrift

thrift-0.9.0.exe --gen csharp thriftcom.thrift


1 注释

有如下的三种方式

1)// 

2)/**/

支持C语言的注释方法

3)#


2 命名空间

namespace cpp tutorial


namespace d tutorial


namespace java tutorial


namespace php tutorial


namespace perl tutorial


3 脚本嵌套

include "shared.thrift"


4 基本类型

*  bool        Boolean, one byte

 *  byte        Signed byte

 

*  i16         Signed 16-bit integer

 

*  i32         Signed 32-bit integer

 

*  i64         Signed 64-bit integer

 

*  double      64-bit floating point value

 

*  string      String

 *  binary      Blob (byte array)

 

*  map<t1,t2>  Map from one type to another

 

*  list<t1>    Ordered list of one type

 

*  set<t1>     Set of unique elements of one type


4 定义结构体


struct SharedStruct 

{

 

 1: i32 key;

  

 2: string value;


}




5 例子


service SharedService 

 SharedStruct getStruct(1: i32 key);

}


6 双向通信使用oneway关键字修饰

oneway修饰一个方法的时候,意味着客户端仅仅是发送请求,而没有监听反馈信息,

并且oneway方法必须是void,这个非常容易理解,因为返回值实际上就保存在

反馈信息当中,既然没有监听反馈信息,当然没有返回值

链接提供了oneway方法在网络不佳情况下,可能会丢包的说明

oneway定义的双向通信,主要是避免反馈消息互相干扰


参考

http://blog.csdn.net/lovemdx/article/details/9829457


Thrift第三课 编写脚本

原文:http://blog.51cto.com/fengyuzaitu/2071769

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!