blob: 06950ea4ac2737fd204e8fa5ff2faad5cc4ede5e [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;
8using facebook::thrift::transport::TTransportException;
9using facebook::thrift::transport::TPipedTransport;
10using facebook::thrift::transport::TMemoryBuffer;
11
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}