I've seen several sources declare that Thrift is a binary communication protocol (the first line of its Wikipedia article, for instance).
But, Thrift can make calls over http, which I believed was a text-based protocol and not a binary one.
Maybe the sources are just saying that Thrift has binary protocol options available, but also has options like http?
I realize I may be misunderstanding something about what "protocol" means in the context of Thrift. With the TJsonProtocol option for JSON encoding of data, for example, could data be sent over http as well as over a binary protocol?
Apologies if I've misused any terms, which I think might be contributing to my confusion. I'm sadly not an expert on the OSI model.
First, Wikipedia is not an authoritative resource, so don't bet your whatever on it.
No, Thrift is not a binary communication protocol. Thrift is not a protocol at all.
Thrift is a framework that offers the ability to serialize into and communicate over various protocols and transports, which include HTTP and binary, but are by no means limited to that.
In fact, the whole idea about the Thrift library is to offer a rich pool of options, from which a particular solution can be built as freely as possible. You want JSON over HTTP? Sure, here you go. You want binary but need something more compact than binary? Sure, use TCompactProtocol
or GZIP. You want to add TLS? No problem, just add it to your stack. Named Pipes? SASL? Messaging? You name it.
And if that's not enough (or if a particular item has not yet been implemented for your language of choice) then one can always write an own transport or protocol implementation. It's not hard, and the /contrib
folder already holds a few examples.
I realize I may be misunderstanding something about what "protocol" means in the context of Thrift.
Indeed, protocol is an overloaded term. In the Thrift context, a protocol is some implementation that derives from TProtocol
.
void WriteMessageBegin(TMessage message);
void WriteMessageEnd();
void WriteStructBegin(TStruct struc);
void WriteStructEnd();
void WriteFieldBegin(TField field);
void WriteFieldEnd();
void WriteFieldStop();
void WriteMapBegin(TMap map);
void WriteMapEnd();
void WriteListBegin(TList list);
void WriteListEnd();
void WriteSetBegin(TSet set);
void WriteSetEnd();
void WriteBool(bool b);
void WriteByte(sbyte b);
void WriteI16(short i16);
void WriteI32(int i32);
void WriteI64(long i64);
void WriteDouble(double d);
void WriteString(string s);
void WriteBinary(byte[] b);
TMessage ReadMessageBegin();
void ReadMessageEnd();
TStruct ReadStructBegin();
void ReadStructEnd();
TField ReadFieldBegin();
void ReadFieldEnd();
TMap ReadMapBegin();
void ReadMapEnd();
TList ReadListBegin();
void ReadListEnd();
TSet ReadSetBegin();
void ReadSetEnd();
bool ReadBool();
sbyte ReadByte();
short ReadI16();
int ReadI32();
long ReadI64();
double ReadDouble();
string ReadString();
byte[] ReadBinary();
Thrift protocols offer a high-level way to write into and read from the underlying transport layer. A Thrift protocol is responsible for translating between the data used in the program and the raw bytes that go into the native transport. For example, the TJSONProtocol
takes care of rendering and parsing data into and from JSON bytes.
In contrast, the Thrift TTransport
derivate that lies below the protocol layer determiones, where the data are stored physically. That aspect is entirely abstracted away, the protocol layer does not have a clue about the physical medium (and shouldn't). Vice versa, the transport layer does not know what the data mean that flow through it, it only sees bytes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With