Thrift includes a complete stack for creating clients and servers.[9] The top part is generated code from the Thrift definition. From this file, the services generate client and processor codes. In contrast to built-in types, createddata structures are sent as a result of generated code. The protocol andtransport layer are part of theruntime library. With Thrift, it is possible to define a service and change the protocol and transport without recompiling the code. Besides the client part, Thrift includes server infrastructure such as blocking, non-blocking, andmulti-threaded servers. The underlying I/O part of the stack is implemented differently for different programming languages.[9]
TBinaryProtocol – A binary format not optimized forspace efficiency. Faster to process than the text protocol.
TCompactProtocol – More compact binary format.
TJSONProtocol – UsesJSON for the encoding of data.
TSimpleJSONProtocol – A write-only protocol that cannot be parsed by Thrift because it drops metadata using JSON. Suitable for parsing by scripting languages.[10]
The supportedtransports are:
TSimpleFileTransport – This transport writes to a file.
TFramedTransport – This transport is required when using a non-blocking server. It sends data in frames, each preceded by length information.
TZlibTransport – Performs compression usingzlib. Used in conjunction with another transport.
Thrift also provides a number of servers, which are:
TNonblockingServer – A multi-threaded server usingnon-blocking I/O (Java implementation usesNIO channels). TFramedTransport must be used with this server.
TSimpleServer – A single-threaded server using standard blocking I/O.
TThreadedServer – A multi-threaded server using a thread per connection model and standard blocking I/O.
TThreadPoolServer – A multi-threaded server using a thread pool and standard blocking I/O.
Thrift is written in C++, but can create code for some other programming languages. To create a Thrift service, one has to write Thrift files that describe it, generate the code in the destination language, write some code to start the server, and call it from the client. An example of such a description file:
^Prunicki, Andrew."Apache Thrift: Introduction".Object Computing. Archived fromthe original on July 23, 2011. RetrievedApril 11, 2011.Using code generation, Thrift creates a set of files which can then be used for creating clients and/or servers.
^"ThriftRequirements".Apache Software Foundation. Archived from the original on February 26, 2024. RetrievedJune 22, 2024.