一个通过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 ids,
            6:Account account
    }

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

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

你可能感兴趣的:(java,thrift)