6

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

Will Gorman
  • 839
  • 1
  • 6
  • 15

3 Answers3

1

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?

Community
  • 1
  • 1
captncraig
  • 19,430
  • 11
  • 95
  • 139
1

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;
}
Anderson Green
  • 25,996
  • 59
  • 164
  • 297
0

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

[2] https://github.com/jskeet/protobuf-csharp-port/blob/6ac38bf84452f1f9bd3df59a276708725be2ed49/src/ProtoGen/ProtocGenCs.cs

Igor Gatis
  • 3,870
  • 10
  • 36
  • 57