Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting Protobuf definitions to Thrift

Are there any tools that exist to generate a Thrift interface definition from a Protobuf definition?

like image 743
Will Gorman Avatar asked Mar 08 '12 20:03

Will Gorman


2 Answers

It appears the answer is "not yet". One problem you will face is that thrift defines a full RPC system with services and method calls, while protobuf really focuses on the datatypes and the serialization bits. Thrift's data model is a bit more restricted than protobuf's (no recursive structures, etc.), but that should not be a problem in the thrift -> protobuf direction.

Sure, you could quite easily convert all the thrift data types to protobuf definitions, while ignoring the service section entirely. You could even add something like that as a built in generator in the thrift compiler if you wanted to.

Thrift and Protobuf are not interchangeable though. Take a look at Biggest differences of Thrift vs Protocol Buffers? to see some key differences. What exactly are you trying to accomplish?

like image 176
captncraig Avatar answered Oct 02 '22 17:10

captncraig


I wrote a translator to convert a subset of Thrift into Protobuf and vice-versa.

This is some Thrift code:

enum Operation{
    ADD=1,SUBTRACT=2,MULTIPLY=3,DIVIDE=4
}
struct Work{1:i32 num1,2:i32 num2,4:string comment
}

which is automatically converted into this Protobuf code:

enum Operation{
    ADD=1,SUBTRACT=2,MULTIPLY=3,DIVIDE=4
}
message Work{int32 num1 = 1;int32 num2 = 2;string comment = 4;
}
like image 34
Anderson Green Avatar answered Oct 02 '22 19:10

Anderson Green