#ifndef NET_BASE_HOST_PORT_PAIR_H_
#define NET_BASE_HOST_PORT_PAIR_H_
#include <stdint.h>
#include <string>
#include <tuple>
#include "base/strings/string_piece.h"
#include "base/values.h"
#include "net/base/net_export.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
class GURL;
namespace url {
class SchemeHostPort;
}
namespace net {
class IPEndPoint;
class NET_EXPORT HostPortPair {
public:
HostPortPair();
HostPortPair(base::StringPiece in_host, uint16_t in_port);
static HostPortPair FromURL(const GURL& url);
static HostPortPair FromSchemeHostPort(
const url::SchemeHostPort& scheme_host_port);
static HostPortPair FromIPEndPoint(const IPEndPoint& ipe);
static HostPortPair FromString(base::StringPiece str);
static absl::optional<HostPortPair> FromValue(const base::Value& value);
bool operator<(const HostPortPair& other) const {
return std::tie(port_, host_) < std::tie(other.port_, other.host_);
}
bool operator==(const HostPortPair& other) const { return Equals(other); }
bool Equals(const HostPortPair& other) const {
return host_ == other.host_ && port_ == other.port_;
}
bool IsEmpty() const {
return host_.empty() && port_ == 0;
}
const std::string& host() const {
return host_;
}
uint16_t port() const { return port_; }
void set_host(const std::string& in_host) {
host_ = in_host;
}
void set_port(uint16_t in_port) { port_ = in_port; }
std::string ToString() const;
std::string HostForURL() const;
base::Value ToValue() const;
private:
std::string host_;
uint16_t port_;
};
}
#endif