OLD | NEW |
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 Loading... |
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 |
OLD | NEW |