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

Side by Side Diff: net/quic/quic_utils.cc

Issue 15951002: QUIC - Added StringToHexASCIIDump to return a hex+ASCII dump in the (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixing windows build error Created 7 years, 7 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 | Annotate | Revision Log
« 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 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/port.h" 10 #include "base/port.h"
11 #include "base/stringprintf.h"
11 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
12 13
14 using base::StringPiece;
13 using std::string; 15 using std::string;
14 16
15 namespace net { 17 namespace net {
16 18
17 // static 19 // static
18 uint64 QuicUtils::FNV1a_64_Hash(const char* data, int len) { 20 uint64 QuicUtils::FNV1a_64_Hash(const char* data, int len) {
19 static const uint64 kOffset = GG_UINT64_C(14695981039346656037); 21 static const uint64 kOffset = GG_UINT64_C(14695981039346656037);
20 static const uint64 kPrime = GG_UINT64_C(1099511628211); 22 static const uint64 kPrime = GG_UINT64_C(1099511628211);
21 23
22 const uint8* octets = reinterpret_cast<const uint8*>(data); 24 const uint8* octets = reinterpret_cast<const uint8*>(data);
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 tag >>= 8; 228 tag >>= 8;
227 } 229 }
228 230
229 if (ascii) { 231 if (ascii) {
230 return string(chars, sizeof(chars)); 232 return string(chars, sizeof(chars));
231 } 233 }
232 234
233 return base::UintToString(orig_tag); 235 return base::UintToString(orig_tag);
234 } 236 }
235 237
238 // static
239 string QuicUtils::StringToHexASCIIDump(StringPiece in_buffer) {
240 int offset = 0;
241 const int kBytesPerLine = 16; // Max bytes dumped per line
242 const char* buf = in_buffer.data();
243 int bytes_remaining = in_buffer.size();
244 string s; // our output
245 const char* p = buf;
246 while (bytes_remaining > 0) {
247 const int line_bytes = std::min(bytes_remaining, kBytesPerLine);
248 base::StringAppendF(&s, "0x%04x: ", offset); // Do the line header
249 for (int i = 0; i < kBytesPerLine; ++i) {
250 if (i < line_bytes) {
251 base::StringAppendF(&s, "%02x", static_cast<unsigned char>(p[i]));
252 } else {
253 s += " "; // two-space filler instead of two-space hex digits
254 }
255 if (i % 2) s += ' ';
256 }
257 s += ' ';
258 for (int i = 0; i < line_bytes; ++i) { // Do the ASCII dump
259 s+= (p[i] > 32 && p[i] < 127) ? p[i] : '.';
260 }
261
262 bytes_remaining -= line_bytes;
263 offset += line_bytes;
264 p += line_bytes;
265 s += '\n';
266 }
267 return s;
268 }
269
236 } // namespace net 270 } // 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