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 // Some helpers for quic. | 5 // Some helpers for quic. |
6 | 6 |
7 #ifndef NET_QUIC_CORE_QUIC_UTILS_H_ | 7 #ifndef NET_QUIC_CORE_QUIC_UTILS_H_ |
8 #define NET_QUIC_CORE_QUIC_UTILS_H_ | 8 #define NET_QUIC_CORE_QUIC_UTILS_H_ |
9 | 9 |
10 #include <stddef.h> | 10 #include <stddef.h> |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 // Allocates a new char[] of size |packet.encrypted_length| and copies in | 89 // Allocates a new char[] of size |packet.encrypted_length| and copies in |
90 // |packet.encrypted_buffer|. | 90 // |packet.encrypted_buffer|. |
91 static char* CopyBuffer(const SerializedPacket& packet); | 91 static char* CopyBuffer(const SerializedPacket& packet); |
92 | 92 |
93 // Determines and returns change type of address change from |old_address| to | 93 // Determines and returns change type of address change from |old_address| to |
94 // |new_address|. | 94 // |new_address|. |
95 static PeerAddressChangeType DetermineAddressChangeType( | 95 static PeerAddressChangeType DetermineAddressChangeType( |
96 const IPEndPoint& old_address, | 96 const IPEndPoint& old_address, |
97 const IPEndPoint& new_address); | 97 const IPEndPoint& new_address); |
98 | 98 |
99 // This converts 'num' bytes of binary to a 2*'num'-character hexadecimal | 99 // This converts |length| bytes of binary to a 2*|length|-character |
100 // representation. Return value: 2*'num' characters of ascii std::string. | 100 // hexadecimal representation. |
| 101 // Return value: 2*|length| characters of ASCII std::string. |
101 static std::string HexEncode(const char* data, size_t length); | 102 static std::string HexEncode(const char* data, size_t length); |
102 static std::string HexEncode(base::StringPiece data); | 103 static std::string HexEncode(base::StringPiece data); |
103 | 104 |
104 // This converts 2*'num' hexadecimal characters to 'num' binary data. | 105 // Converts |data| from a hexadecimal ASCII std::string to binary. |
105 // Return value: 'num' bytes of binary data (via the 'to' argument). | |
106 static std::string HexDecode(const char* data, size_t length); | |
107 static std::string HexDecode(base::StringPiece data); | 106 static std::string HexDecode(base::StringPiece data); |
108 | 107 |
109 // Returns a std::string containing hex and ASCII representations of |binary|, | 108 // Returns a std::string containing hex and ASCII representations of |binary|, |
110 // side-by-side in the style of hexdump. Non-printable characters will be | 109 // side-by-side in the style of hexdump. Non-printable characters will be |
111 // printed as '.' in the ASCII output. | 110 // printed as '.' in the ASCII output. |
112 // "0x0000: 4865 6c6c 6f2c 2051 5549 4321 0102 0304 Hello,.QUIC!...." | 111 // "0x0000: 4865 6c6c 6f2c 2051 5549 4321 0102 0304 Hello,.QUIC!...." |
113 static std::string HexDump(base::StringPiece binary_data); | 112 static std::string HexDump(base::StringPiece binary_data); |
114 | 113 |
115 private: | 114 private: |
116 DISALLOW_COPY_AND_ASSIGN(QuicUtils); | 115 DISALLOW_COPY_AND_ASSIGN(QuicUtils); |
117 }; | 116 }; |
118 | 117 |
119 } // namespace net | 118 } // namespace net |
120 | 119 |
121 #endif // NET_QUIC_CORE_QUIC_UTILS_H_ | 120 #endif // NET_QUIC_CORE_QUIC_UTILS_H_ |
OLD | NEW |