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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/quic/quic_utils.h" 5 #include "net/quic/quic_utils.h"
6 6
7 #include <ctype.h> 7 #include <ctype.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 return ""; 562 return "";
563 std::vector<uint8_t> v; 563 std::vector<uint8_t> v;
564 if (!base::HexStringToBytes(data.as_string(), &v)) 564 if (!base::HexStringToBytes(data.as_string(), &v))
565 return ""; 565 return "";
566 string out; 566 string out;
567 if (!v.empty()) 567 if (!v.empty())
568 out.assign(reinterpret_cast<const char*>(&v[0]), v.size()); 568 out.assign(reinterpret_cast<const char*>(&v[0]), v.size());
569 return out; 569 return out;
570 } 570 }
571 571
572 string QuicUtils::BinaryToAscii(StringPiece binary) { 572 string QuicUtils::HexDump(StringPiece binary_input) {
573 string out = ""; 573 string out = "";
574 for (const unsigned char c : binary) { 574 const int kBytesPerRow = 16;
575 // Leading space. 575 const int size = binary_input.size();
576 out += " "; 576 for (int i = 0; i < size;) {
577 if (isprint(c)) { 577 // Print one row of hex.
578 out += c; 578 for (int j = i; j < i + kBytesPerRow; ++j) {
579 } else { 579 if (j < size) {
580 out += '.'; 580 out += HexEncode(string(1, binary_input[j]));
581 } else {
582 out += " ";
583 }
584 out += " ";
581 } 585 }
586 out += " |";
587
588 // Print one row of ascii.
589 for (int j = i; j < i + kBytesPerRow; ++j) {
590 if (j < size) {
591 char c = binary_input[j];
592 bool is_printable = (c >= 32 && c < 127);
593 if (!is_printable) {
594 // Non-printable characters are replaced with '.'.
595 c = '.';
596 }
597 out += string(1, c);
598 } else {
599 out += " ";
600 }
601 }
602
603 out += "|\n";
604 i += kBytesPerRow;
582 } 605 }
583 return out; 606 return out;
584 } 607 }
585 608
586 } // namespace net 609 } // namespace net
OLDNEW
« 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