QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef QUICHE_QUIC_CORE_QUIC_SOCKET_ADDRESS_CODER_H_ |
| 6 | #define QUICHE_QUIC_CORE_QUIC_SOCKET_ADDRESS_CODER_H_ |
| 7 | |
| 8 | #include <cstdint> |
vasilvv | 872e7a3 | 2019-03-12 16:42:44 -0700 | [diff] [blame] | 9 | #include <string> |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10 | |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 11 | #include "net/third_party/quiche/src/quic/platform/api/quic_export.h" |
| 12 | #include "net/third_party/quiche/src/quic/platform/api/quic_socket_address.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 13 | |
| 14 | namespace quic { |
| 15 | |
| 16 | // Serializes and parses a socket address (IP address and port), to be used in |
| 17 | // the kCADR tag in the ServerHello handshake message and the Public Reset |
| 18 | // packet. |
| 19 | class QUIC_EXPORT_PRIVATE QuicSocketAddressCoder { |
| 20 | public: |
| 21 | QuicSocketAddressCoder(); |
| 22 | explicit QuicSocketAddressCoder(const QuicSocketAddress& address); |
| 23 | QuicSocketAddressCoder(const QuicSocketAddressCoder&) = delete; |
| 24 | QuicSocketAddressCoder& operator=(const QuicSocketAddressCoder&) = delete; |
| 25 | ~QuicSocketAddressCoder(); |
| 26 | |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 27 | std::string Encode() const; |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 28 | |
| 29 | bool Decode(const char* data, size_t length); |
| 30 | |
| 31 | QuicIpAddress ip() const { return address_.host(); } |
| 32 | |
| 33 | uint16_t port() const { return address_.port(); } |
| 34 | |
| 35 | private: |
| 36 | QuicSocketAddress address_; |
| 37 | }; |
| 38 | |
| 39 | } // namespace quic |
| 40 | |
| 41 | #endif // QUICHE_QUIC_CORE_QUIC_SOCKET_ADDRESS_CODER_H_ |