Reputation: 879
Are there any tools that exist to generate a Thrift interface definition from a Protobuf definition?
Upvotes: 6
Views: 3154
Reputation: 1
I believe there is.
Check out the non-destructive transformer I wrote protobuf-thrift, which can transform protobuf to thrift and vice-versa. What's more, it will preserve the declaration order and comments, which gives you maximum retention of source code format.
You can also try out the web interface here.
BTW, I also agreed with captncraig's answer. It's true that thrift and protobuf have many differences, such as nested type in protobuf and union type in thrift. But you can't deny that they have a lot of syntaxes in common, such as enum => enum, struct => message, service => service, which are our most used syntaxes.
So, protobuf-thrift is the tool that helps you reduce repeating work, with knowing the truth that "they are not 100% convertible".
Upvotes: 0
Reputation: 31810
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;
}
Upvotes: 1
Reputation: 4898
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.
[1] https://github.com/igorgatis/protobuf-j2me
Upvotes: 0
Reputation: 23098
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?
Upvotes: 1