1 // RequestDumper.cpp 2 3 #include "RequestDumper.h" 4 5 #include <string.h> 6 7 #include <typeinfo> 8 9 #include <ByteOrder.h> 10 11 #include "DebugSupport.h" 12 13 static const char* kIndentation = " "; 14 static const int kMaxIndentation = 32; 15 16 // constructor 17 RequestDumper::RequestDumper() 18 : RequestMemberVisitor(), 19 fIndentationLevel(0) 20 { 21 } 22 23 // DumpRequest 24 void 25 RequestDumper::DumpRequest(Request* request) 26 { 27 PRINT("request: %s\n", typeid(*request).name()); 28 fIndentationLevel++; 29 request->ShowAround(this); 30 fIndentationLevel--; 31 } 32 33 // Visit 34 void 35 RequestDumper::Visit(RequestMember* member, bool& data) 36 { 37 PRINT("%sbool: %s\n", _Indentation(), (data ? "true" : "false")); 38 } 39 40 // Visit 41 void 42 RequestDumper::Visit(RequestMember* member, int8& data) 43 { 44 PRINT("%sint8: %d\n", _Indentation(), (int)data); 45 } 46 47 // Visit 48 void 49 RequestDumper::Visit(RequestMember* member, uint8& data) 50 { 51 PRINT("%suint8: %d\n", _Indentation(), (int)data); 52 } 53 54 // Visit 55 void 56 RequestDumper::Visit(RequestMember* member, int16& data) 57 { 58 PRINT("%sint16: %d\n", _Indentation(), (int)data); 59 } 60 61 // Visit 62 void 63 RequestDumper::Visit(RequestMember* member, uint16& data) 64 { 65 PRINT("%suint16: %d\n", _Indentation(), (int)data); 66 } 67 68 // Visit 69 void 70 RequestDumper::Visit(RequestMember* member, int32& data) 71 { 72 PRINT("%sint32: %ld\n", _Indentation(), data); 73 } 74 75 // Visit 76 void 77 RequestDumper::Visit(RequestMember* member, uint32& data) 78 { 79 PRINT("%suint32: %lu\n", _Indentation(), data); 80 } 81 82 // Visit 83 void 84 RequestDumper::Visit(RequestMember* member, int64& data) 85 { 86 PRINT("%sint64: %lld\n", _Indentation(), data); 87 } 88 89 // Visit 90 void 91 RequestDumper::Visit(RequestMember* member, uint64& data) 92 { 93 PRINT("%suint64: %llu\n", _Indentation(), data); 94 } 95 96 // Visit 97 void 98 RequestDumper::Visit(RequestMember* member, Data& data) 99 { 100 PRINT("%sdata: %p (%ld bytes)\n", _Indentation(), data.GetData(), 101 data.GetSize()); 102 } 103 104 // Visit 105 void 106 RequestDumper::Visit(RequestMember* member, StringData& data) 107 { 108 PRINT("%sstring: \"%s\" (%p, %ld bytes)\n", _Indentation(), 109 data.GetString(), data.GetString(), data.GetSize()); 110 } 111 112 // Visit 113 void 114 RequestDumper::Visit(RequestMember* member, RequestMember& subMember) 115 { 116 PRINT("%ssubmember:\n", _Indentation()); 117 118 fIndentationLevel++; 119 subMember.ShowAround(this); 120 fIndentationLevel--; 121 } 122 123 // Visit 124 void 125 RequestDumper::Visit(RequestMember* member, 126 FlattenableRequestMember& subMember) 127 { 128 PRINT("%sflattenable: %s\n", _Indentation(), typeid(subMember).name()); 129 } 130 131 // _Indentation 132 const char* 133 RequestDumper::_Indentation() const 134 { 135 int indentation = fIndentationLevel * 2; 136 if (indentation >= kMaxIndentation) 137 return kIndentation; 138 return kIndentation + kMaxIndentation - indentation; 139 } 140