Skip to content

AnneYang720/thrift2proto

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

thrift2proto

This is a simple python script to convert thrift files to protobuf files. I made proper handling for some corner instances I met.

Requirements

This project is based on some great work:

Usage

$ python main.py -i your_file_path -o output_file_path

Features

  • Only thrift supports set type. It's converted to map because I'm using this tool to generate Golang code.
struct DemoStruct1 {
    1: set<i64> uid
}

message DemoStruct1 {
    map<int64, bool> uid = 1;
}
  • Except for basic type convertion, the nested list/set/map in thrift struct is supported.
struct DemoStruct2 {
    1: list<map<string,set<string>>> result
}

message DemoStruct2 {
    message result_map {
        message result_map_e_set {
            map<string, bool> result_map_e_set_e = 1;
        }
        map<string, result_map_e_set> result_map_e = 1;
    }
    repeated result_map result = 1;
}
  • Multiple request params are combined to a new message for proto.
service DemoService {
    DemoStruct2 GetStruct(1: i64 num, 2: DemoStruct1 struct1)
}

service DemoService {
    rpc GetStruct (GetStructReq) returns (DemoStruct2);
}
message GetStructReq {
    int64 num = 1;
    DemoStruct1 struct1 = 2;
}
  • The extend of thrift service is ignored because it's not supported in proto3.

  • void in thrift service is converted to google.protobuf.Empty in proto3.

Note

  • The generation of proto is proto3, so optional and required are not kept.
  • proto_schema_parser doesn't support the parser and generator of service type yet, but I already submitted a PR.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published