Chinaunix首页 | 论坛 | 博客
  • 博客访问: 441475
  • 博文数量: 97
  • 博客积分: 1552
  • 博客等级: 上尉
  • 技术积分: 1091
  • 用 户 组: 普通用户
  • 注册时间: 2012-05-17 17:05
个人简介

专注于大规模运维场景运维工具解决方案。欢迎有这方面兴趣的朋友跟我联系。

文章分类

全部博文(97)

文章存档

2014年(12)

2013年(25)

2012年(60)

我的朋友

分类: LINUX

2012-08-21 21:21:58

工程目录如下:
project 
    idl/
gen.bat
thrift.exe
main.thrift
    res/
a.jpg
    lib/
a.py
其中idl里面存放的是thrift相关的配置文件内容。gen.bat的内容如下:

点击(此处)折叠或打开

  1. @ECHO OFF
  2. set THRIFT_CODEDEFINE=main.thrift
  3. if "%1"=="" goto genDefault

  4. :genDefault
  5. call thrift-0.7.0.exe --gen py main.thrift
  6. goto end

  7. :genByArg
  8. call thrift-0.7.0.exe --gen java:hashcode %1
  9. call thrift-0.7.0.exe --gen php %1
  10. call thrift-0.7.0.exe --gen py %1
  11. goto end

  12. :exit
  13. exit /b 1

  14. :end
  15. exit /b 0
可以给它传递一个thrift配置文件然后编译输出相应的代码.
ps:如果是py的话中文是个问题的.需要手工置#coding:utf-8

main.thrift的内容如下

点击(此处)折叠或打开

  1. namespace py thriftlib.adspub.thrift
  2. exception ThrfitException {
  3. 1: i32 errCode,
  4. 2: string msg
  5. }
  6. struct ResultInfo{
  7. 1: i32 err,
  8. 2: string value,
  9. 3: string msg
  10. }
  11. struct A {
  12. 1: string type,
  13. 2: i32 age
  14. }
  15. struct B {
  16. 1: i32 id,
  17. 2: list a
  18. }

  19. service InfoService {
  20. ResultInfo deployTemplateCreate(1:B deployObject,2:string username);
  21. list deployPlanList(1:string planName);
  22. }
简单介绍一下如何编写thrift配置文件



阅读(11187) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~