David Reiss | 4e7530d | 2007-09-04 21:49:53 +0000 | [diff] [blame^] | 1 | /* |
| 2 | ../compiler/cpp/thrift -cpp -dense DebugProtoTest.thrift |
| 3 | g++ -Wall -g -I../lib/cpp/src -I/usr/local/include/boost-1_33_1 \ |
| 4 | DenseProtoTest.cpp gen-cpp/DebugProtoTest_types.cpp \ |
| 5 | ../lib/cpp/.libs/libthrift.a -o DenseProtoTest |
| 6 | ./DenseProtoTest |
| 7 | */ |
| 8 | |
| 9 | #include <iostream> |
| 10 | #include <cmath> |
| 11 | #include "gen-cpp/DebugProtoTest_types.h" |
| 12 | #include <protocol/TDenseProtocol.h> |
| 13 | #include <transport/TTransportUtils.h> |
| 14 | |
| 15 | int main() { |
| 16 | using std::cout; |
| 17 | using std::endl; |
| 18 | using boost::shared_ptr; |
| 19 | using namespace thrift::test; |
| 20 | using namespace facebook::thrift::transport; |
| 21 | using namespace facebook::thrift::protocol; |
| 22 | |
| 23 | |
| 24 | OneOfEach ooe; |
| 25 | ooe.im_true = true; |
| 26 | ooe.im_false = false; |
| 27 | ooe.a_bite = 0xd6; |
| 28 | ooe.integer16 = 27000; |
| 29 | ooe.integer32 = 1<<24; |
| 30 | ooe.integer64 = (uint64_t)6000 * 1000 * 1000; |
| 31 | ooe.double_precision = M_PI; |
| 32 | ooe.some_characters = "Debug THIS!"; |
| 33 | ooe.zomg_unicode = "\xd7\n\a\t"; |
| 34 | |
| 35 | //cout << facebook::thrift::ThriftDebugString(ooe) << endl << endl; |
| 36 | |
| 37 | |
| 38 | Nesting n; |
| 39 | n.my_ooe = ooe; |
| 40 | n.my_ooe.integer16 = 16; |
| 41 | n.my_ooe.integer32 = 32; |
| 42 | n.my_ooe.integer64 = 64; |
| 43 | n.my_ooe.double_precision = (std::sqrt(5)+1)/2; |
| 44 | n.my_ooe.some_characters = ":R (me going \"rrrr\")"; |
| 45 | n.my_ooe.zomg_unicode = "\xd3\x80\xe2\x85\xae\xce\x9d\x20" |
| 46 | "\xd0\x9d\xce\xbf\xe2\x85\xbf\xd0\xbe\xc9\xa1\xd0\xb3\xd0\xb0\xcf\x81\xe2\x84\x8e" |
| 47 | "\x20\xce\x91\x74\x74\xce\xb1\xe2\x85\xbd\xce\xba\xc7\x83\xe2\x80\xbc"; |
| 48 | n.my_bonk.type = 31337; |
| 49 | n.my_bonk.message = "I am a bonk... xor!"; |
| 50 | |
| 51 | //cout << facebook::thrift::ThriftDebugString(n) << endl << endl; |
| 52 | |
| 53 | |
| 54 | HolyMoley hm; |
| 55 | |
| 56 | hm.big.push_back(ooe); |
| 57 | hm.big.push_back(n.my_ooe); |
| 58 | hm.big[0].a_bite = 0x22; |
| 59 | hm.big[1].a_bite = 0x33; |
| 60 | |
| 61 | std::vector<std::string> stage1; |
| 62 | stage1.push_back("and a one"); |
| 63 | stage1.push_back("and a two"); |
| 64 | hm.contain.insert(stage1); |
| 65 | stage1.clear(); |
| 66 | stage1.push_back("then a one, two"); |
| 67 | stage1.push_back("three!"); |
| 68 | stage1.push_back("FOUR!!"); |
| 69 | hm.contain.insert(stage1); |
| 70 | stage1.clear(); |
| 71 | hm.contain.insert(stage1); |
| 72 | |
| 73 | std::vector<Bonk> stage2; |
| 74 | hm.bonks["nothing"] = stage2; |
| 75 | stage2.resize(stage2.size()+1); |
| 76 | stage2.back().type = 1; |
| 77 | stage2.back().message = "Wait."; |
| 78 | stage2.resize(stage2.size()+1); |
| 79 | stage2.back().type = 2; |
| 80 | stage2.back().message = "What?"; |
| 81 | hm.bonks["something"] = stage2; |
| 82 | stage2.clear(); |
| 83 | stage2.resize(stage2.size()+1); |
| 84 | stage2.back().type = 3; |
| 85 | stage2.back().message = "quoth"; |
| 86 | stage2.resize(stage2.size()+1); |
| 87 | stage2.back().type = 4; |
| 88 | stage2.back().message = "the raven"; |
| 89 | stage2.resize(stage2.size()+1); |
| 90 | stage2.back().type = 5; |
| 91 | stage2.back().message = "nevermore"; |
| 92 | hm.bonks["poe"] = stage2; |
| 93 | |
| 94 | //cout << facebook::thrift::ThriftDebugString(hm) << endl << endl; |
| 95 | |
| 96 | shared_ptr<TMemoryBuffer> buffer(new TMemoryBuffer()); |
| 97 | shared_ptr<TDenseProtocol> proto(new TDenseProtocol(buffer)); |
| 98 | proto->setTypeSpec(HolyMoley::local_reflection); |
| 99 | |
| 100 | hm.write(proto.get()); |
| 101 | HolyMoley hm2; |
| 102 | hm2.read(proto.get()); |
| 103 | |
| 104 | assert(hm == hm2); |
| 105 | |
| 106 | |
| 107 | return 0; |
| 108 | } |