blob: e2a22ee5b51eca5dfc05a9f75a0a3025722716eb [file] [log] [blame]
<!DOCTYPE html>
<html xmlns="" xml:lang="en" lang="en">
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<meta content="en-us" http-equiv="Content-Language" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="/static/images/favicon.ico" rel="shortcut icon" />
<link href="/static/css/style.css" rel="stylesheet" type="text/css" />
<link href="/static/css/codehilite.css" rel="stylesheet" type="text/css" />
<link href="/static/css/bootstrap.css" media="screen, projection" rel="stylesheet" type="text/css" />
<link href="/static/css/thrift.css" media="screen, projection" rel="stylesheet" type="text/css" />
<script src="/static/js/jquery.min.js"></script>
<script src="/static/js/bootstrap-dropdown.js"></script>
<script src="/static/js/bootstrap-tab.js"></script>
<script src="/static/js/thrift.js"></script>
<title>Apache Thrift - Concepts</title>
<div class="navbar">
<div class="navbar-inner">
<div class="container">
<a class="brand" href="/">Apache Thrift &trade;</a>
<div class="nav-collapse">
<ul class="nav pull-right">
<li><a href="/download">Download</a></li>
<li><a href="/docs">Documentation</a></li>
<li><a href="/developers">Developers</a></li>
<li><a href="/lib">Libraries</a></li>
<li><a href="/tutorial">Tutorial</a></li>
<li><a href="/test">Test Suite</a></li>
<li><a href="/about">About</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Apache <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="" target="_blank">Apache Home</a></li>
<li><a href="" target="_blank">Apache License v2.0</a></li>
<li><a href="" target="_blank">Donate</a></li>
<li><a href="" target="_blank">Thanks</a></li>
<li><a href="" target="_blank">Security</a></li>
<div class="container">
<h2 id="thrift-network-stack">Thrift network stack</h2>
<p>Simple representation of the Apache Thrift networking stack</p>
| Server |
| (single-threaded, event-driven etc) |
| Processor |
| (compiler generated) |
| Protocol |
| (JSON, compact etc) |
| Transport |
| (raw TCP, HTTP etc) |
<h2 id="transport">Transport</h2>
<p>The Transport layer provides a simple abstraction for reading/writing from/to the network. This enables Thrift to decouple the underlying transport from the rest of the system (serialization/deserialization, for instance).</p>
<p>Here are some of the methods exposed by the <strong>Transport</strong> interface:</p>
<p>In addition to the <strong>Transport</strong> interface above, Thrift also uses a <strong>ServerTransport</strong> interface used to accept or create primitive transport objects. As the name suggest, <strong>ServerTransport</strong> is used mainly on the server side to create new Transport objects for incoming connections.</p>
<p>Here are some of the transports available for majority of the Thrift-supported languages:</p>
<li>file: read/write to/from a file on disk</li>
<li>http: as the name suggests</li>
<h2 id="protocol">Protocol</h2>
<p>The Protocol abstraction defines a mechanism to map in-memory data structures to a wire-format. In other words, a protocol specifies how datatypes use the
underlying Transport to encode/decode themselves. Thus the protocol implementation governs the encoding scheme and is responsible for (de)serialization. Some examples of protocols in this sense include JSON, XML, plain text, compact binary etc.</p>
<p>Here is the <strong>Protocol</strong> interface:</p>
<pre><code class="language-cpp">
writeMessageBegin(name, type, seq)
writeFieldBegin(name, type, id)
writeMapBegin(ktype, vtype, size)
writeListBegin(etype, size)
writeSetBegin(etype, size)
name, type, seq = readMessageBegin()
name = readStructBegin()
name, type, id = readFieldBegin()
k, v, size = readMapBegin()
etype, size = readListBegin()
etype, size = readSetBegin()
bool = readBool()
byte = readByte()
i16 = readI16()
i32 = readI32()
i64 = readI64()
double = readDouble()
string = readString()
<p>Thrift Protocols are stream oriented by design. There is no need for any explicit framing. For instance, it is not necessary to know the length of a
string or the number of items in a list before we start serializing them. Some of the protocols available for majority of the Thrift-supported
languages are:</p>
<li>binary: Fairly simple binary encoding – the length and type of a field are encoded as bytes followed by the actual value of the field.</li>
<li>compact: Described in <a href="">THRIFT-110</a></li>
<h2 id="processor">Processor</h2>
<p>A Processor encapsulates the ability to read data from input streams and write to output streams. The input and output streams are represented by Protocol
objects. The Processor interface is extremely simple</p>
<pre><code class="language-java">
interface TProcessor {
bool process(TProtocol in, TProtocol out) throws TException
<p>Service-specific processor implementations are generated by the compiler. The Processor essentially reads data from the wire (using the input protocol),
delegates processing to the handler (implemented by the user) and writes the response over the wire (using the output protocol).</p>
<h2 id="server">Server</h2>
<p>A Server pulls together all of the various features described above:</p>
<li>Create a transport</li>
<li>Create input/output protocols for the transport</li>
<li>Create a processor based on the input/output protocols</li>
<li>Wait for incoming connections and hand them off to the processor</li>
<div class="container">
<footer class="footer">
<div class="row">
<div class="span3">
<ul class="unstyled">
<li><a href="/download">Download</a></li>
<li><a href="/developers">Developers</a></li>
<li><a href="/tutorial">Tutorials</a></li>
<ul class="unstyled">
<li><a href="/sitemap">Sitemap</a></li>
<div class="span3">
<h3>Get Involved</h3>
<ul class="unstyled">
<li><a href="/mailing">Mailing Lists</a></li>
<li><a href="">Issue Tracking</a></li>
<li><a href="/docs/HowToContribute">How To Contribute</a></li>
<div class="span6">
<a href=""><img src="/static/images/feather.svg" onerror="this.src='/static/images/feather.png';this.onerror=null;" /></a>
Copyright &copy; 2023 <a href="">Apache Software Foundation</a>.
Licensed under the <a href="">Apache License v2.0</a>.
Apache, Apache Thrift, and the Apache feather logo are trademarks of The Apache Software Foundation.