Are there any tools that exist to generate a Thrift interface definition from a Protobuf definition?
3 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?
![](../../users/profiles/-1.webp)
- 1
- 1
![](../../users/profiles/121660.webp)
- 19,430
- 11
- 95
- 139
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;
}
![](../../users/profiles/975097.webp)
- 25,996
- 59
- 164
- 297
I don't think there is. If you're up to write code for that, you can write a language generator that produces .thrift files for you.
You can write the tool in any language (I wrote in C++ in protobuf-j2me [1], and adapted protobuf-csharp-port code in [2]).
You can have protoc.exe to call it like:
protoc.exe --plugin=protoc-gen-thrift.exe --thrift_out=. file.proto
You need to name it as protoc-gen-thrift.exe
to make --thrift_out
option available.
![](../../users/profiles/298622.webp)
- 3,870
- 10
- 36
- 57