Java 示例1:

在src下新建thrift目录,在此目录下新建MyData.thrift文件

namespace java thrift.generatedtypedef i16 short
typedef i32 int
typedef i64 long
typedef bool boolean
typedef string Stringstruct Person {1:optional String username,2:optional int age,3:optional boolean married
}exception DataException {1:optional String message,2:optional String callback,3:optional String date
}service PersonService {Person getPersonByUsername(1:required String username) throws (1:DataException dataException),void savePerson(1:required Person person) throws(1:DataException dataException)
}

然后在IDEA中新建Terminal

 thrift --gen java src/thrift/MyData.thrift


此时会在项目的根目录下生成代码,然后在src/main/java/com.retech下新建一个目录Thrift,然后将上面生成的代码复制到此路径下。
此时代码就已经生成好,
在此目录下新建PersonServiceImpl并实现生成的PersonService接口。

多语言示例2:

namespace c_glib TTest
namespace cpp thrift.test
namespace delphi Thrift.Test
namespace go thrifttest
namespace java thrift.test
namespace js ThriftTest
namespace lua ThriftTest
namespace netstd ThriftTest
namespace perl ThriftTest
namespace php ThriftTest
namespace py ThriftTest
namespace py.twisted ThriftTest
namespace rb Thrift.Test
namespace st ThriftTest
namespace xsd test (uri = 'http://thrift.apache.org/ns/ThriftTest')// Presence of namespaces and sub-namespaces for which there is
// no generator should compile with warnings only
namespace noexist ThriftTest
namespace cpp.noexist ThriftTestnamespace * thrift.test/*** Docstring!*/
enum Numberz
{ONE = 1,TWO,THREE,FIVE = 5,SIX,EIGHT = 8
}const Numberz myNumberz = Numberz.ONE;
// the following is expected to fail:
// const Numberz urNumberz = ONE;typedef i64 UserIdstruct Bonk
{1: string message,2: i32 type
}typedef map<string,Bonk> MapTypestruct Bools {1: bool im_true,2: bool im_false,
}struct Xtruct
{1:  string string_thing,4:  i8     byte_thing,9:  i32    i32_thing,11: i64    i64_thing
}struct Xtruct2
{1: i8     byte_thing,  // used to be byte, hence the name2: Xtruct struct_thing,3: i32    i32_thing
}struct Xtruct3
{1:  string string_thing,4:  i32    changed,9:  i32    i32_thing,11: i64    i64_thing
}struct Insanity
{1: map<Numberz, UserId> userMap,2: list<Xtruct> xtructs
} (python.immutable= "")struct CrazyNesting {1: string string_field,2: optional set<Insanity> set_field,// Do not insert line break as test/go/Makefile.am is removing this line with pattern match3: required list<map<set<i32> (python.immutable = ""), map<i32,set<list<map<Insanity,string>(python.immutable = "")> (python.immutable = "")>>>> list_field,4: binary binary_field
}union SomeUnion {1: map<Numberz, UserId> map_thing,2: string string_thing,3: i32 i32_thing,4: Xtruct3 xtruct_thing,5: Insanity insanity_thing
}exception Xception {1: i32 errorCode,2: string message
}exception Xception2 {1: i32 errorCode,2: Xtruct struct_thing
}struct EmptyStruct {}struct OneField {1: EmptyStruct field
}service ThriftTest
{/*** Prints "testVoid()" and returns nothing.*/void         testVoid(),/*** Prints 'testString("%s")' with thing as '%s'* @param string thing - the string to print* @return string - returns the string 'thing'*/string       testString(1: string thing),/*** Prints 'testBool("%s")' where '%s' with thing as 'true' or 'false'* @param bool  thing - the bool data to print* @return bool  - returns the bool 'thing'*/bool         testBool(1: bool thing),/*** Prints 'testByte("%d")' with thing as '%d'* The types i8 and byte are synonyms, use of i8 is encouraged, byte still exists for the sake of compatibility.* @param byte thing - the i8/byte to print* @return i8 - returns the i8/byte 'thing'*/i8           testByte(1: i8 thing),/*** Prints 'testI32("%d")' with thing as '%d'* @param i32 thing - the i32 to print* @return i32 - returns the i32 'thing'*/i32          testI32(1: i32 thing),/*** Prints 'testI64("%d")' with thing as '%d'* @param i64 thing - the i64 to print* @return i64 - returns the i64 'thing'*/i64          testI64(1: i64 thing),/*** Prints 'testDouble("%f")' with thing as '%f'* @param double thing - the double to print* @return double - returns the double 'thing'*/double       testDouble(1: double thing),/*** Prints 'testBinary("%s")' where '%s' is a hex-formatted string of thing's data* @param binary  thing - the binary data to print* @return binary  - returns the binary 'thing'*/binary       testBinary(1: binary thing),/*** Prints 'testStruct("{%s}")' where thing has been formatted into a string of comma separated values* @param Xtruct thing - the Xtruct to print* @return Xtruct - returns the Xtruct 'thing'*/Xtruct       testStruct(1: Xtruct thing),/*** Prints 'testNest("{%s}")' where thing has been formatted into a string of the nested struct* @param Xtruct2 thing - the Xtruct2 to print* @return Xtruct2 - returns the Xtruct2 'thing'*/Xtruct2      testNest(1: Xtruct2 thing),/*** Prints 'testMap("{%s")' where thing has been formatted into a string of 'key => value' pairs*  separated by commas and new lines* @param map<i32,i32> thing - the map<i32,i32> to print* @return map<i32,i32> - returns the map<i32,i32> 'thing'*/map<i32,i32> testMap(1: map<i32,i32> thing),/*** Prints 'testStringMap("{%s}")' where thing has been formatted into a string of 'key => value' pairs*  separated by commas and new lines* @param map<string,string> thing - the map<string,string> to print* @return map<string,string> - returns the map<string,string> 'thing'*/map<string,string> testStringMap(1: map<string,string> thing),/*** Prints 'testSet("{%s}")' where thing has been formatted into a string of values*  separated by commas and new lines* @param set<i32> thing - the set<i32> to print* @return set<i32> - returns the set<i32> 'thing'*/set<i32>     testSet(1: set<i32> thing),/*** Prints 'testList("{%s}")' where thing has been formatted into a string of values*  separated by commas and new lines* @param list<i32> thing - the list<i32> to print* @return list<i32> - returns the list<i32> 'thing'*/list<i32>    testList(1: list<i32> thing),/*** Prints 'testEnum("%d")' where thing has been formatted into its numeric value* @param Numberz thing - the Numberz to print* @return Numberz - returns the Numberz 'thing'*/Numberz      testEnum(1: Numberz thing),/*** Prints 'testTypedef("%d")' with thing as '%d'* @param UserId thing - the UserId to print* @return UserId - returns the UserId 'thing'*/UserId       testTypedef(1: UserId thing),/*** Prints 'testMapMap("%d")' with hello as '%d'* @param i32 hello - the i32 to print* @return map<i32,map<i32,i32>> - returns a dictionary with these values:*   {-4 => {-4 => -4, -3 => -3, -2 => -2, -1 => -1, }, 4 => {1 => 1, 2 => 2, 3 => 3, 4 => 4, }, }*/map<i32,map<i32,i32>> testMapMap(1: i32 hello),/*** So you think you've got this all worked out, eh?** Creates a map with these values and prints it out:*   { 1 => { 2 => argument,*            3 => argument,*          },*     2 => { 6 => <empty Insanity struct>, },*   }* @return map<UserId, map<Numberz,Insanity>> - a map with the above values*/map<UserId, map<Numberz,Insanity>> testInsanity(1: Insanity argument),/*** Prints 'testMulti()'* @param i8 arg0 -* @param i32 arg1 -* @param i64 arg2 -* @param map<i16, string> arg3 -* @param Numberz arg4 -* @param UserId arg5 -* @return Xtruct - returns an Xtruct with string_thing = "Hello2, byte_thing = arg0, i32_thing = arg1*    and i64_thing = arg2*/Xtruct testMulti(1: i8 arg0, 2: i32 arg1, 3: i64 arg2, 4: map<i16, string> arg3, 5: Numberz arg4, 6: UserId arg5),/*** Print 'testException(%s)' with arg as '%s'* @param string arg - a string indication what type of exception to throw* if arg == "Xception" throw Xception with errorCode = 1001 and message = arg* else if arg == "TException" throw TException* else do not throw anything*/void testException(1: string arg) throws(1: Xception err1),/*** Print 'testMultiException(%s, %s)' with arg0 as '%s' and arg1 as '%s'* @param string arg - a string indicating what type of exception to throw* if arg0 == "Xception" throw Xception with errorCode = 1001 and message = "This is an Xception"* else if arg0 == "Xception2" throw Xception2 with errorCode = 2002 and struct_thing.string_thing = "This is an Xception2"* else do not throw anything* @return Xtruct - an Xtruct with string_thing = arg1*/Xtruct testMultiException(1: string arg0, 2: string arg1) throws(1: Xception err1, 2: Xception2 err2)/*** Print 'testOneway(%d): Sleeping...' with secondsToSleep as '%d'* sleep 'secondsToSleep'* Print 'testOneway(%d): done sleeping!' with secondsToSleep as '%d'* @param i32 secondsToSleep - the number of seconds to sleep*/oneway void testOneway(1:i32 secondsToSleep)
}service SecondService
{/*** Prints 'testString("%s")' with thing as '%s'* @param string thing - the string to print* @return string - returns the string 'thing'*/string secondtestString(1: string thing)
}struct VersioningTestV1 {1: i32 begin_in_both,3: string old_string,12: i32 end_in_both
}struct VersioningTestV2 {1: i32 begin_in_both,2: i32 newint,3: i8 newbyte,4: i16 newshort,5: i64 newlong,6: double newdouble7: Bonk newstruct,8: list<i32> newlist,9: set<i32> newset,10: map<i32, i32> newmap,11: string newstring,12: i32 end_in_both
}struct ListTypeVersioningV1 {1: list<i32> myints;2: string hello;
}struct ListTypeVersioningV2 {1: list<string> strings;2: string hello;
}struct GuessProtocolStruct {7: map<string,string> map_field,
}struct LargeDeltas {1: Bools b1,10: Bools b10,100: Bools b100,500: bool check_true,1000: Bools b1000,1500: bool check_false,2000: VersioningTestV2 vertwo2000,2500: set<string> a_set2500,3000: VersioningTestV2 vertwo3000,4000: list<i32> big_numbers
}struct NestedListsI32x2 {1: list<list<i32>> integerlist
}
struct NestedListsI32x3 {1: list<list<list<i32>>> integerlist
}
struct NestedMixedx2 {1: list<set<i32>> int_set_list2: map<i32,set<string>> map_int_strset3: list<map<i32,set<string>>> map_int_strset_list
}
struct ListBonks {1: list<Bonk> bonk
}
struct NestedListsBonk {1: list<list<list<Bonk>>> bonk
}struct BoolTest {1: optional bool b = true;2: optional string s = "true";
}struct StructA {1: required string s;
}struct StructB {1: optional StructA aa;2: required StructA ab;
}struct OptionalSetDefaultTest {1: optional set<string> with_default = [ "test" ]
}

Thrift IDL示例文件相关推荐

  1. thrift IDL

    参考资料: [1] Thrift 入门 [2] Thrift入门及Java实例演示 [3] Thrift使用指南及语法介绍 [4] Thrift RPC 系列教程(1)--Thrift语言 [5] J ...

  2. Nginx配置示例文件

    Nginx配置示例文件 nginx.conf worker_processes 8;events {worker_connections 1024; }http {include mime.types ...

  3. power bi示例文件_Power BI桌面问答数据交互示例

    power bi示例文件 The Q&A feature in Power BI desktop provides a way to move towards Artificial Intel ...

  4. GitHub集成Circle CI(附 Circle CI 配置示例文件)

    文章目录 GitHub 集成Circle CI CI(持续集成) 简单解释 CI 工具 Circle的使用 将GitHub项目授权给 Circle CI 书写 config.yml文件 测试 Circ ...

  5. go语言学习笔记——godoc的使用(超详细,含示例文件)

    godoc使用教程 注释规范 注释符//后面要加空格, 例如: // xxx 在注释符要缩进的话,第二行注释符后面的空格要比上一行的空格多一个example:// 123// 123 注释要紧跟pac ...

  6. 锐浪报表 VFP9 全示例文件,示例所用锐浪版本号为 6.8.22.1201

    锐浪报表 VFP9 全示例文件,示例所用锐浪版本号为 6.8.22.1201 原文地址: https://mp.weixin.qq.com/s/jY0WiDlpi-sFfFJVuipUIQ 被人安利了 ...

  7. Thrift IDL基本语法

    简言:介绍Thrift的IDL基本语法,初次使用或多或少的会有很有"坑"要踩,但是我们要遇山挖山,遇海填海,在学习的道路上坚定的走下去,方可日后吹牛B! IDL Thrift 采用 ...

  8. HDFS的API调用,创建Maven工程,创建一个非Maven工程,HDFS客户端操作数据代码示例,文件方式操作和流式操作

    1. HDFS的java操作 hdfs在生产应用中主要是客户端的开发,其核心步骤是从hdfs提供的api中构造一个HDFS的访问客户端对象,然后通过该客户端对象操作(增删改查)HDFS上的文件 1.1 ...

  9. .vimrc示例文件

    转载:超神级.vimrc .vimrc文件示例 1 """"""""""""&q ...

最新文章

  1. 数据结构:平衡二叉树概念、旋转
  2. Java -- XStreamAlias 处理节点中的属性和值
  3. 深度学习之基于LeNet-5实现cifar10的识别
  4. 在Java中避免空检查
  5. 1112: 进制转换(函数专题)
  6. uploadify动态改变参数
  7. 孙鑫VC学习笔记:第十一讲 (四) 图形重绘方法三 利用兼容DC
  8. 常见分类算法优缺点比较
  9. python sql注入检测脚本_python 打造一个sql注入脚本 (一)
  10. 本科计算机专业考北大软微,2019北大软微计算机867高分经验分享
  11. 在线制作安卓手机主题
  12. 景深与光圈、拍摄距离和镜头焦距的关系
  13. 好奇那些进了大厂的程序员面试前都做了哪些准备?Android大厂面试官全套教程教你:这样准备面试顺利拿到offer
  14. Java OCR 图像智能字符识别技术,可识别中文
  15. censo7安装mysql_centos7环境下在线安装mysql
  16. linux启动mysql失败,Fatal error: Can‘t open and lock privilege tables: Table ‘mysql.host‘ doesn‘t exist
  17. 使用Python和OpenCV进行图像拼接和全景图构建
  18. python数学建模基础教程_Python 3破冰人工智能 从入门到实战 大学生数学建模竞赛数学建模算法与应用教程 机器学习深度学...
  19. gcc官网以及各个版本下载地址
  20. 漫谈WinCE的手写识别技术 一

热门文章

  1. 七天搞定Node.js微信公众号
  2. 重磅!Waymo首席执行官离职,自动驾驶商业化打上“问号”
  3. 1一10到时的英文单词_1英语(1到10的英语单词)
  4. PTCHECK查重好渣啊,还没有paperyy好用
  5. 已知圆外一点坐标,以及圆心坐标、半径,求圆的切线方程
  6. PUBG绿色玩家 看过来!
  7. 基于OpenCV的人脸识别考勤系统(三)
  8. access open 知乎_必备技能!国际汇款SCI Open Access费用
  9. 搭建Ubuntu 10.04系统(嵌入式开发) (重要)
  10. CAN总线错误分析方法