Prints the bytes in the given value to the given ostream.
| 9089 | |
| 9090 | // Prints the bytes in the given value to the given ostream. |
| 9091 | void PrintBytesInObjectToImpl(const unsigned char* obj_bytes, size_t count, |
| 9092 | ostream* os) { |
| 9093 | // Tells the user how big the object is. |
| 9094 | *os << count << "-byte object <"; |
| 9095 | |
| 9096 | const size_t kThreshold = 132; |
| 9097 | const size_t kChunkSize = 64; |
| 9098 | // If the object size is bigger than kThreshold, we'll have to omit |
| 9099 | // some details by printing only the first and the last kChunkSize |
| 9100 | // bytes. |
| 9101 | // TODO(wan): let the user control the threshold using a flag. |
| 9102 | if (count < kThreshold) { |
| 9103 | PrintByteSegmentInObjectTo(obj_bytes, 0, count, os); |
| 9104 | } else { |
| 9105 | PrintByteSegmentInObjectTo(obj_bytes, 0, kChunkSize, os); |
| 9106 | *os << " ... "; |
| 9107 | // Rounds up to 2-byte boundary. |
| 9108 | const size_t resume_pos = (count - kChunkSize + 1)/2*2; |
| 9109 | PrintByteSegmentInObjectTo(obj_bytes, resume_pos, count - resume_pos, os); |
| 9110 | } |
| 9111 | *os << ">"; |
| 9112 | } |
| 9113 | |
| 9114 | } // namespace |
| 9115 |
no test coverage detected