thrift 使用笔记

来源:互联网 发布:oracle是什么软件 编辑:程序博客网 时间:2024/06/07 03:07

1. 生成代码

-r 什么意思?
-o 输出文件目录

thrift.exe -o [directory] -gen cpp [source.thrift]

2. optional、required
required是必须的数据,optional标记的数据若为空则不序列化,若有默认值,则optional未赋值时为默认值。

struct Person{    1:require string name;    2:optional string photo}

3. 常量、枚举类型、默认值

const i32 INT_CONST = 1234;const map<string,string> MAP_CONST = {"hello": "world", "goodnight": "moon"}
enum TweetType {TWEET,RETWEET = 2,DM = 0xa,REPLY}struct Tweet {1: required i32 userId;2: required string userName;3: required string text;4: optional Location loc;5: optional TweetType tweetType = TweetType.TWEET;16: optional string language = "english"}

4. 命名空间

namespace csharp thrift_test

5. 服务可以被继承、结构体不能被继承

原创粉丝点击