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

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

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 | « no previous file | net/quic/quic_utils.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 // Some helpers for quic. 5 // Some helpers for quic.
6 6
7 #ifndef NET_QUIC_QUIC_UTILS_H_ 7 #ifndef NET_QUIC_QUIC_UTILS_H_
8 #define NET_QUIC_QUIC_UTILS_H_ 8 #define NET_QUIC_QUIC_UTILS_H_
9 9
10 #include <stddef.h> 10 #include <stddef.h>
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 // This converts 'num' bytes of binary to a 2*'num'-character hexadecimal 136 // This converts 'num' bytes of binary to a 2*'num'-character hexadecimal
137 // representation. Return value: 2*'num' characters of ascii std::string. 137 // representation. Return value: 2*'num' characters of ascii std::string.
138 static std::string HexEncode(const char* data, size_t length); 138 static std::string HexEncode(const char* data, size_t length);
139 static std::string HexEncode(base::StringPiece data); 139 static std::string HexEncode(base::StringPiece data);
140 140
141 // This converts 2*'num' hexadecimal characters to 'num' binary data. 141 // This converts 2*'num' hexadecimal characters to 'num' binary data.
142 // Return value: 'num' bytes of binary data (via the 'to' argument). 142 // Return value: 'num' bytes of binary data (via the 'to' argument).
143 static std::string HexDecode(const char* data, size_t length); 143 static std::string HexDecode(const char* data, size_t length);
144 static std::string HexDecode(base::StringPiece data); 144 static std::string HexDecode(base::StringPiece data);
145 145
146 // Converts binary data into an ASCII string. Each character in the resulting 146 // Returns a std::string containing hex and ASCII representations of |binary|,
147 // string is preceeded by a space, and replaced with a '.' if not printable. 147 // side-by-side in the style of hexdump. Non-printable characters will be
148 static std::string BinaryToAscii(base::StringPiece binary); 148 // printed as '.' in the ASCII output.
149 // For example:
150 // "48 65 6c 6c 6f 2c 20 51 55 49 43 21 01 02 03 04 |Hello, QUIC!....|"
151 static std::string HexDump(base::StringPiece binary_data);
149 152
150 private: 153 private:
151 DISALLOW_COPY_AND_ASSIGN(QuicUtils); 154 DISALLOW_COPY_AND_ASSIGN(QuicUtils);
152 }; 155 };
153 156
154 // Utility function that returns an QuicIOVector object wrapped around |str|. 157 // Utility function that returns an QuicIOVector object wrapped around |str|.
155 // |str|'s data is stored in |iov|. 158 // |str|'s data is stored in |iov|.
156 inline QuicIOVector MakeIOVector(base::StringPiece str, struct iovec* iov) { 159 inline QuicIOVector MakeIOVector(base::StringPiece str, struct iovec* iov) {
157 iov->iov_base = const_cast<char*>(str.data()); 160 iov->iov_base = const_cast<char*>(str.data());
158 iov->iov_len = static_cast<size_t>(str.size()); 161 iov->iov_len = static_cast<size_t>(str.size());
159 QuicIOVector quic_iov(iov, 1, str.size()); 162 QuicIOVector quic_iov(iov, 1, str.size());
160 return quic_iov; 163 return quic_iov;
161 } 164 }
162 165
163 } // namespace net 166 } // namespace net
164 167
165 #endif // NET_QUIC_QUIC_UTILS_H_ 168 #endif // NET_QUIC_QUIC_UTILS_H_
OLDNEW
« no previous file with comments | « no previous file | net/quic/quic_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698