一个通过java的接口生成thrift文件的工具

?

很早之前写的一个工具,面向的用户主要有两种

1.没接触thrift,但是希望使用thrift的用户,可以便于新用户的理解

2.之前用的是rmi,之后想转成thrift的用户

example

public interface ICommonUserService {

    public User login(int id, String name);

    public User getUserById(long id);

    public boolean saveUser(User user);

    public List<User> getUserIds(long id); 

    public Map<Long, User> getUserByIds(List<User> ids);

    public Map<String, List<User>> getUsersByName(List<String> names);

    public Map<Long, List<Long>> getGroupUsers(List<String> names, List<User> userList, List<Long> lns, long ll);

    public List<String> testCase1(Map<Integer,String> num1, List<User> num2, List<String> num3, long num4, String num5);
}
public class ThriftStructBuilderTest {

    private ThriftFileBuilder fileBuilder = new ThriftFileBuilder();

    @Test
    public void toOutputstream() throws Exception {
        this.fileBuilder.buildToOutputStream(ICommonUserService.class, System.out);
    }

}

执行之后会在控制台输入如下:

    namespace java com.sohu.thrift.generator.test.thrift

    enum Status {
            NORMAL = 0,
            BLOCKED = 1
    }

    struct Account {
            1:i32 id,
            2:string name
    }
    struct User {
            1:i32 id,
            2:string name,
            3:bool sex,
            4:Status status,
            5:list<i64> ids,
            6:Account account
    }

    service ICommonUserService {
            User login(1:i32 arg0,2:string arg1),
            map<string, list<User>> getUsersByName(1:list<string> arg0),
            bool saveUser(1:User arg0),
            map<i64, User> getUserByIds(1:list<User> arg0),
            list<User> getUserIds(1:i64 arg0),
            map<i64, list<i64>> getGroupUsers(1:list<string> arg0,2:list<User> arg1,3:list<i64> arg2,4:i64 arg3),
            User getUserById(1:i64 arg0),
            list<string> testCase1(1:map<i32, string> arg0,2:list<User> arg1,3:list<string> arg2,4:i64 arg3,5:string arg4)
    }

?项目地址:?https://github.com/hongliuliao/thrift-generator

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。