idl - How to specify non-default Thrift Protocols and Transports -


i have read official apache thrift docs. have read excellent thrift example docs. have read more excellent thrift: missing guide.

nowhere can figure out how specify, say, tcompactprotocol on default (tbinaryprotocol). or, say, tframedsocket on default (tsocket).

can elaborate here?

a protocol in thrift describes format how actual data bits written to/read underlying storage medium. typically 1 such thing needed, stacking them not necessary, since need 1 physical layout serialize data.

in contrast, designed stacked called "layered transports". transports operate on lower level of abstraction. typical examples tframedtransport , tbufferedtransport. layered transports add functionality byte stream, such adding frame size, buffering data or offering multiplexing capabilities. technically these located between protocol , underlying "endpoint transports" write/read bytes to/from storage medium (e.g. socket).

consequently, if need change conversion , bytes, write protocol. whenever additional storage medium required, write endpoint transport. if bytes should manipulated in between of serialization/deserialization process, want add new compression algorithm "schrippe" lets brotli , zopfli old bread (pun intended), write layered transport.

a example how stack can found in language-dependent implementation of thrift test suite (with few exceptions located under /test/yourlanguage). test suite designed test kinds of combinations. if done tutorial, recommend take code, explains lot of advanced features both client end , server end.

just example, relevant part from c++ test client selected components set up:

  boost::shared_ptr<ttransport> transport;   boost::shared_ptr<tprotocol> protocol;    boost::shared_ptr<tsocket> socket;   boost::shared_ptr<tsslsocketfactory> factory;    if (ssl) {     factory = boost::shared_ptr<tsslsocketfactory>(new tsslsocketfactory());     factory->ciphers("all:!adh:!low:!exp:!md5:@strength");     factory->loadtrustedcertificates((dir_path + "../keys/ca.pem").c_str());     factory->authenticate(true);     socket = factory->createsocket(host, port);   } else {     if (domain_socket != "") {       if (abstract_namespace) {         std::string abstract_socket("\0", 1);         abstract_socket += domain_socket;         socket = boost::shared_ptr<tsocket>(new tsocket(abstract_socket));       } else {         socket = boost::shared_ptr<tsocket>(new tsocket(domain_socket));       }       port = 0;     } else {       socket = boost::shared_ptr<tsocket>(new tsocket(host, port));     }   }    if (transport_type.compare("http") == 0) {     boost::shared_ptr<ttransport> httpsocket(new thttpclient(socket, host, "/service"));     transport = httpsocket;   } else if (transport_type.compare("framed") == 0) {     boost::shared_ptr<tframedtransport> framedsocket(new tframedtransport(socket));     transport = framedsocket;   } else {     boost::shared_ptr<tbufferedtransport> bufferedsocket(new tbufferedtransport(socket));     transport = bufferedsocket;   }    if (protocol_type.compare("json") == 0) {     boost::shared_ptr<tprotocol> jsonprotocol(new tjsonprotocol(transport));     protocol = jsonprotocol;   } else if (protocol_type.compare("compact") == 0) {     boost::shared_ptr<tprotocol> compactprotocol(new tcompactprotocol(transport));     protocol = compactprotocol;   } else if (protocol_type == "header") {     boost::shared_ptr<tprotocol> headerprotocol(new theaderprotocol(transport));     protocol = headerprotocol;   } else {     boost::shared_ptr<tbinaryprotocol> binaryprotocol(new tbinaryprotocol(transport));     protocol = binaryprotocol;   }    // connection info   cout << "connecting (" << transport_type << "/" << protocol_type << ") to: ";   if (abstract_namespace) {     cout << '@';   }   cout << domain_socket;   if (port != 0) {     cout << host << ":" << port;   }   cout << endl; 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -