blob: 991032ab1b6a012165f2ab1092e31baa5277963f [file] [log] [blame]
David Reiss1ffb61b2008-04-08 05:07:26 +00001#include <cstdlib>
2#include <stdexcept>
3#include <Thrift.h>
4#include <transport/TTransportUtils.h>
David Reiss28f298d2008-05-01 06:17:36 +00005#include <transport/TBufferTransports.h>
David Reiss1ffb61b2008-04-08 05:07:26 +00006using namespace std;
7using boost::shared_ptr;
T Jake Lucianib5e62212009-01-31 22:36:20 +00008using apache::thrift::transport::TTransportException;
9using apache::thrift::transport::TPipedTransport;
10using apache::thrift::transport::TMemoryBuffer;
David Reiss1ffb61b2008-04-08 05:07:26 +000011
12int main() {
13 shared_ptr<TMemoryBuffer> underlying(new TMemoryBuffer);
14 shared_ptr<TMemoryBuffer> pipe(new TMemoryBuffer);
15 shared_ptr<TPipedTransport> trans(new TPipedTransport(underlying, pipe));
16
17 uint8_t buffer[4];
18
19 underlying->write((uint8_t*)"abcd", 4);
20 trans->readAll(buffer, 2);
21 assert( string((char*)buffer, 2) == "ab" );
22 trans->readEnd();
23 assert( pipe->getBufferAsString() == "ab" );
24 pipe->resetBuffer();
25 underlying->write((uint8_t*)"ef", 2);
26 trans->readAll(buffer, 2);
27 assert( string((char*)buffer, 2) == "cd" );
28 trans->readAll(buffer, 2);
29 assert( string((char*)buffer, 2) == "ef" );
30 trans->readEnd();
31 assert( pipe->getBufferAsString() == "cdef" );
32
33 return 0;
34
35}