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> 9 #include <string> 10 11 #include "quiche/quic/platform/api/quic_export.h" 12 #include "quiche/quic/platform/api/quic_ip_address.h" 13 #include "quiche/quic/platform/api/quic_socket_address.h" 14 15 namespace quic { 16 17 // Serializes and parses a socket address (IP address and port), to be used in 18 // the kCADR tag in the ServerHello handshake message and the Public Reset 19 // packet. 20 class QUICHE_EXPORT QuicSocketAddressCoder { 21 public: 22 QuicSocketAddressCoder(); 23 explicit QuicSocketAddressCoder(const QuicSocketAddress& address); 24 QuicSocketAddressCoder(const QuicSocketAddressCoder&) = delete; 25 QuicSocketAddressCoder& operator=(const QuicSocketAddressCoder&) = delete; 26 ~QuicSocketAddressCoder(); 27 28 std::string Encode() const; 29 30 bool Decode(const char* data, size_t length); 31 ip()32 QuicIpAddress ip() const { return address_.host(); } 33 port()34 uint16_t port() const { return address_.port(); } 35 36 private: 37 QuicSocketAddress address_; 38 }; 39 40 } // namespace quic 41 42 #endif // QUICHE_QUIC_CORE_QUIC_SOCKET_ADDRESS_CODER_H_ 43