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> |
11 #include <stdint.h> | 11 #include <stdint.h> |
12 | 12 |
13 #include <string> | 13 #include <string> |
14 | 14 |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "base/strings/string_piece.h" | 16 #include "base/strings/string_piece.h" |
17 #include "net/base/int128.h" | 17 #include "net/base/int128.h" |
18 #include "net/base/net_export.h" | 18 #include "net/base/net_export.h" |
19 #include "net/quic/core/quic_iovector.h" | |
20 #include "net/quic/core/quic_protocol.h" | 19 #include "net/quic/core/quic_protocol.h" |
21 | 20 |
22 #ifdef _MSC_VER | 21 #ifdef _MSC_VER |
23 // MSVC 2013 and prior don't have alignof or aligned(); they have __alignof and | 22 // MSVC 2013 and prior don't have alignof or aligned(); they have __alignof and |
24 // a __declspec instead. | 23 // a __declspec instead. |
25 #define QUIC_ALIGN_OF __alignof | 24 #define QUIC_ALIGN_OF __alignof |
26 #define QUIC_ALIGNED(X) __declspec(align(X)) | 25 #define QUIC_ALIGNED(X) __declspec(align(X)) |
27 #else | 26 #else |
28 #define QUIC_ALIGN_OF alignof | 27 #define QUIC_ALIGN_OF alignof |
29 #define QUIC_ALIGNED(X) __attribute__((aligned(X))) | 28 #define QUIC_ALIGNED(X) __attribute__((aligned(X))) |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 // Returns a std::string containing hex and ASCII representations of |binary|, | 113 // Returns a std::string containing hex and ASCII representations of |binary|, |
115 // side-by-side in the style of hexdump. Non-printable characters will be | 114 // side-by-side in the style of hexdump. Non-printable characters will be |
116 // printed as '.' in the ASCII output. | 115 // printed as '.' in the ASCII output. |
117 // "0x0000: 4865 6c6c 6f2c 2051 5549 4321 0102 0304 Hello,.QUIC!...." | 116 // "0x0000: 4865 6c6c 6f2c 2051 5549 4321 0102 0304 Hello,.QUIC!...." |
118 static std::string HexDump(base::StringPiece binary_data); | 117 static std::string HexDump(base::StringPiece binary_data); |
119 | 118 |
120 private: | 119 private: |
121 DISALLOW_COPY_AND_ASSIGN(QuicUtils); | 120 DISALLOW_COPY_AND_ASSIGN(QuicUtils); |
122 }; | 121 }; |
123 | 122 |
124 // Utility function that returns an QuicIOVector object wrapped around |str|. | |
125 // |str|'s data is stored in |iov|. | |
126 inline QuicIOVector MakeIOVector(base::StringPiece str, struct iovec* iov) { | |
127 iov->iov_base = const_cast<char*>(str.data()); | |
128 iov->iov_len = static_cast<size_t>(str.size()); | |
129 QuicIOVector quic_iov(iov, 1, str.size()); | |
130 return quic_iov; | |
131 } | |
132 | |
133 } // namespace net | 123 } // namespace net |
134 | 124 |
135 #endif // NET_QUIC_CORE_QUIC_UTILS_H_ | 125 #endif // NET_QUIC_CORE_QUIC_UTILS_H_ |
OLD | NEW |