blob: d8401c62f8d7bd05de6524c5c786cd3ba02caaac [file] [log] [blame]
QUICHE teama6ef0a62019-03-07 20:34:33 -05001// 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>
vasilvv872e7a32019-03-12 16:42:44 -07009#include <string>
QUICHE teama6ef0a62019-03-07 20:34:33 -050010
QUICHE teama6ef0a62019-03-07 20:34:33 -050011#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 teama6ef0a62019-03-07 20:34:33 -050013
14namespace 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.
19class 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
vasilvvc48c8712019-03-11 13:38:16 -070027 std::string Encode() const;
QUICHE teama6ef0a62019-03-07 20:34:33 -050028
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_