Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(256)

Unified Diff: net/quic/quic_utils.cc

Issue 2121293003: Adds a QuicUtil::HexDump method that provides better debug output of binary data. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@126089643
Patch Set: Use uppercase hex characters Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/quic/quic_utils.h ('k') | net/quic/quic_utils_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/quic/quic_utils.cc
diff --git a/net/quic/quic_utils.cc b/net/quic/quic_utils.cc
index 1af16db853c3494f46db32cbdbc056c8eab9c0ac..0fddb623584407db94a983d14ce6527579c34ca8 100644
--- a/net/quic/quic_utils.cc
+++ b/net/quic/quic_utils.cc
@@ -569,16 +569,39 @@ string QuicUtils::HexDecode(StringPiece data) {
return out;
}
-string QuicUtils::BinaryToAscii(StringPiece binary) {
+string QuicUtils::HexDump(StringPiece binary_input) {
string out = "";
- for (const unsigned char c : binary) {
- // Leading space.
- out += " ";
- if (isprint(c)) {
- out += c;
- } else {
- out += '.';
+ const int kBytesPerRow = 16;
+ const int size = binary_input.size();
+ for (int i = 0; i < size;) {
+ // Print one row of hex.
+ for (int j = i; j < i + kBytesPerRow; ++j) {
+ if (j < size) {
+ out += HexEncode(string(1, binary_input[j]));
+ } else {
+ out += " ";
+ }
+ out += " ";
}
+ out += " |";
+
+ // Print one row of ascii.
+ for (int j = i; j < i + kBytesPerRow; ++j) {
+ if (j < size) {
+ char c = binary_input[j];
+ bool is_printable = (c >= 32 && c < 127);
+ if (!is_printable) {
+ // Non-printable characters are replaced with '.'.
+ c = '.';
+ }
+ out += string(1, c);
+ } else {
+ out += " ";
+ }
+ }
+
+ out += "|\n";
+ i += kBytesPerRow;
}
return out;
}
« no previous file with comments | « net/quic/quic_utils.h ('k') | net/quic/quic_utils_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698