Search code examples
thriftthrift-protocol

How to create own thrift language-templates for custom language in thrift-compiler?


i'd like to use Thrift as RPC-Protocol to call Java-Server RPC-Endpoints from a custom, proprietary closed-source language. (some c-like vendor-specific scripting language)

No bindings for this exist.

How can i create my own thrift-compiler-plugins which generate language-specific code? Did not find anything on the documentation for that. Is there anything like a template-language?

Thanks


Solution

  • If there do not exist bindings for a desired target language, the roadmap is (roughly) as follows:

    • Search JIRA, and if you found nothing similar, create a new ticket, shortly describing what you are planning.

    • Do a fork of the Apache Thrift code base on GitHub. Although we accept patch files, expecially for larger change sets a GitHub branch is much easier to handle.

    • Implement the code generator, typically by picking one from the existing pool that is close to what you need. There are already plenty of languages supported, and you'll find oop, procedural and functional styles. If in doubt, which one to choose of the two or three candidates you found, head to the next point

    • Implement the Thrift library for that particular language, again by picking one of the existing libraries as a starting point. Because the libraries differ largely with regard to the "depth" of their implementations it is recommended to have a closer look on what is implemented, and what is not.

    • Implement the standardized Thrift cross platform test and make sure all tests succeed when run against at least one other language. This ensures interoperability and makes sure that the code does not only work when talking with yourself (= same language).

    • Implement the Tutorial code and test it against some other language. If you did everything well, this last step is comparingly easy.

    • Your done, now open a pull request!

    Note that the 4 implementation steps are not really a linear process, it is more kind of an iteratoin. Even if the code that comes out of the generator finally is compileable and does not spit out any warnings and seems to run, you still will run into problems as you move on with implementing library and tests. This is fully normal and expected.

    Besides that, it is a good idea to post your work on the mailing lists and to create the JIRA ticket early (that's why I put it on top of the list). This serves not only the purpose of announcing the work you are about to do, it is also a good starting point for other people who might be just looking for exactly that stuff. With some luck, you will be able not only to get early feedback (which is always a good thing), but also raise some support with implementation and/or testing.

    Remark

    If you want to implement a new flavour of an existing language, the preferred way is to add this to the existing code generators, library and so in. For a good model look at the nodejs implementation, or the various options that already exist for Python. thrift --help gives a great start.