David Reiss | 1ffb61b | 2008-04-08 05:07:26 +0000 | [diff] [blame] | 1 | #include <cstdlib> |
| 2 | #include <stdexcept> |
| 3 | #include <Thrift.h> |
| 4 | #include <transport/TTransportUtils.h> |
| 5 | using namespace std; |
| 6 | using boost::shared_ptr; |
| 7 | using facebook::thrift::transport::TTransportException; |
| 8 | using facebook::thrift::transport::TPipedTransport; |
| 9 | using facebook::thrift::transport::TMemoryBuffer; |
| 10 | |
| 11 | int main() { |
| 12 | shared_ptr<TMemoryBuffer> underlying(new TMemoryBuffer); |
| 13 | shared_ptr<TMemoryBuffer> pipe(new TMemoryBuffer); |
| 14 | shared_ptr<TPipedTransport> trans(new TPipedTransport(underlying, pipe)); |
| 15 | |
| 16 | uint8_t buffer[4]; |
| 17 | |
| 18 | underlying->write((uint8_t*)"abcd", 4); |
| 19 | trans->readAll(buffer, 2); |
| 20 | assert( string((char*)buffer, 2) == "ab" ); |
| 21 | trans->readEnd(); |
| 22 | assert( pipe->getBufferAsString() == "ab" ); |
| 23 | pipe->resetBuffer(); |
| 24 | underlying->write((uint8_t*)"ef", 2); |
| 25 | trans->readAll(buffer, 2); |
| 26 | assert( string((char*)buffer, 2) == "cd" ); |
| 27 | trans->readAll(buffer, 2); |
| 28 | assert( string((char*)buffer, 2) == "ef" ); |
| 29 | trans->readEnd(); |
| 30 | assert( pipe->getBufferAsString() == "cdef" ); |
| 31 | |
| 32 | return 0; |
| 33 | |
| 34 | } |