Search code examples
thrift

How can I use our data types in apache thrift


How can I do something like this with apache thrift.

typedef i64 long
typedef i32 int
service MyService {
          long multiply(1:int num1, 2:int num2),
          MyService getMyservice()
}

here I have defined a MyService and it is used inside of the MyService as the return type of getMyService. Is there a way to do something like that.


Solution

  • You can't use language-specific types in an IDL-file. Keep in mind that the IDL-file needs to be usable on other languages also, that don't necessarily know what a long or an int are. The above code is syntactically legal, but will for instance generate C++ files that do not compile, as long and int are names of types that are already built into the language.

    Also, returning a service is not allowed, as it is basically just an interface. If you wanted to actually be able to return a service (including implementations of functions I presume), you would need some way to convert your code on one end, to some generic code that could run on all other platforms and all other languages. So while it would certainly be possible to do on two platforms that use the same language and environment, it gets very non-trivial as soon as any platform variety comes into the picture.