Thrift now officially supports D!

Thrift is a cross-language serialization and RPC framework, originally developed for internal use at Facebook, and now an Apache Software Foundation project. I started working on support for the D programming language during Google Summer of Code 2011, and at the end of last week, the implementation was finally incorporated into the main project.

First, let me thank Jake Farrell and everybody else on the Thrift team who was involved in THRIFT-1500; reviewing a ~719 kB patch certainly isn’t an easy thing to do. But now that the work is in, what can you (as a Thrift user) expect from the implementation?

Feature-wise, the library should roughly be up to par with the other major implementations (i.e. C++ and Java):

  • Protocols: Binary, Compact and JSON. The Dense protocol has not been implemented yet – it is only supported by the C++ implementation and I am not sure about its relevance nowadays (but if you are at a certain well-known company and it turns out that you still need the feature for new projects, let me know; adding support for it should not be hard).

  • Transports: Socket, SSL, HTTP and log file reader/writer implementations (plus your familiar helpers, i.e. buffered/framed/memory-buffer/piped/zlib...)

  • Servers: several single- and multithreaded variants (including a libevent-based non-blocking implementation)

  • Clients: Both a synchronous and an asynchronous (future-based interface with one or more libevent-backed worker threads) implementation are provided. Additionally, several pooling implementations for redundancy as well as aggregation use cases are available.

The implementation makes heavy use of D’s metaprogramming capatibilties and is also able to work without code generated off-line from .thrift files, if so desired. There are also a few experimental gimmicks, such as the capatibility to generate Thrift IDL files from existing D types at compile time. Soon to come:

  • Unix domain sockets:  Currently, the D implementation only supports IPv4 and IPv6 TCP sockets, because that is what the D standard library does, but starting with the next release, it will also support Unix domain sockets (if really needed, the lack of support in `std.socket` could be worked around without much effort, though).

  • @safe-ty annotations:  The D language features built-in memory safety annotations. The majority of the methods in the D Thrift library should be memory safe (except for e.g. `TTransport.borrow`), so marking it as such allowed Thrift to be used in D programs where safety is enforced without requiring the user to mark the Thrift calls as `@trusted`.

So, how to get started? As said above, the source code has been mergerd from my personal GitHub repo to the trunk of the main ASF repo, and as soon as the currently ongoing rework of the official Thrift site is completed, the Getting Started with Thrift and D and Building Thrift/D on Windows pages will follow along. A recent build of the API docs is currently available here on my website. If you find any bugs, be sure to file them at the Thrift JIRA.