温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Thrift第三课 编写脚本

发布时间:2020-07-12 10:41:32 来源:网络 阅读:1199 作者:fengyuzaitu 栏目:编程语言

警告

    尽量使用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修饰的函数会直接返回。oneway方法必须是void,这个非常容易理解,因为返回值实际上就保存在反馈信息当中,既然没有监听反馈信息,当然没有返回值链接提供了oneway方法在网络不佳情况下,可能会丢包的说明,暂时没有发现该问题。oneway定义的双向通信,主要是避免反馈消息互相干扰


参考

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


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI