diff options
author | antervis <antervis@yandex-team.ru> | 2022-02-10 16:49:48 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:48 +0300 |
commit | b3eef5b52437f05851a3e8fb489a68db0132657b (patch) | |
tree | 5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp/ipv6_address/ipv6_address.h | |
parent | 0942f9eeaefcfc84db83fa240d8ed52b99345e7d (diff) | |
download | ydb-b3eef5b52437f05851a3e8fb489a68db0132657b.tar.gz |
Restoring authorship annotation for <antervis@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/ipv6_address/ipv6_address.h')
-rw-r--r-- | library/cpp/ipv6_address/ipv6_address.h | 106 |
1 files changed, 53 insertions, 53 deletions
diff --git a/library/cpp/ipv6_address/ipv6_address.h b/library/cpp/ipv6_address/ipv6_address.h index 3c9db90d15..1d7eb0b65f 100644 --- a/library/cpp/ipv6_address/ipv6_address.h +++ b/library/cpp/ipv6_address/ipv6_address.h @@ -32,26 +32,26 @@ public: Ipv4, LAST }; - constexpr TIpv6Address() noexcept = default; - constexpr TIpv6Address(const TIpv6Address&) noexcept = default; - constexpr TIpv6Address& operator=(const TIpv6Address&) noexcept = default; - - constexpr TIpv6Address(const ui128& ip, TIpType Type) noexcept - : Ip(ip), Type_(Type) - {} - - constexpr TIpv6Address(ui8 a, ui8 b, ui8 c, ui8 d) noexcept - : Ip((ui32(a) << 24) | (ui32(b) << 16) | (ui32(c) << 8) | ui32(d)) - , Type_(TIpv6Address::Ipv4) - {} - - constexpr TIpv6Address(ui16 a, ui16 b, ui16 c, ui16 d, ui16 e, ui16 f, ui16 g, ui16 h, ui32 scope = 0) noexcept - : Type_(TIpv6Address::Ipv6) - , ScopeId_(scope) - { - auto hi = (ui64(a) << 48) | (ui64(b) << 32) | (ui64(c) << 16) | ui64(d); - auto lo = (ui64(e) << 48) | (ui64(f) << 32) | (ui64(g) << 16) | ui64(h); - Ip = {hi, lo}; + constexpr TIpv6Address() noexcept = default; + constexpr TIpv6Address(const TIpv6Address&) noexcept = default; + constexpr TIpv6Address& operator=(const TIpv6Address&) noexcept = default; + + constexpr TIpv6Address(const ui128& ip, TIpType Type) noexcept + : Ip(ip), Type_(Type) + {} + + constexpr TIpv6Address(ui8 a, ui8 b, ui8 c, ui8 d) noexcept + : Ip((ui32(a) << 24) | (ui32(b) << 16) | (ui32(c) << 8) | ui32(d)) + , Type_(TIpv6Address::Ipv4) + {} + + constexpr TIpv6Address(ui16 a, ui16 b, ui16 c, ui16 d, ui16 e, ui16 f, ui16 g, ui16 h, ui32 scope = 0) noexcept + : Type_(TIpv6Address::Ipv6) + , ScopeId_(scope) + { + auto hi = (ui64(a) << 48) | (ui64(b) << 32) | (ui64(c) << 16) | ui64(d); + auto lo = (ui64(e) << 48) | (ui64(f) << 32) | (ui64(g) << 16) | ui64(h); + Ip = {hi, lo}; } explicit TIpv6Address(const NAddr::IRemoteAddr& addr); @@ -60,24 +60,24 @@ public: explicit TIpv6Address(const in6_addr& addr, ui32 Scope); explicit TIpv6Address(const in_addr& addr); - static TIpv6Address FromString(TStringBuf srcStr, bool& ok) noexcept; + static TIpv6Address FromString(TStringBuf srcStr, bool& ok) noexcept; - constexpr bool IsNull() const noexcept { + constexpr bool IsNull() const noexcept { return Ip == 0; } - constexpr bool IsValid() const noexcept { - return Ip != 0 && (Type_ == Ipv6 || Type_ == Ipv4); - } + constexpr bool IsValid() const noexcept { + return Ip != 0 && (Type_ == Ipv6 || Type_ == Ipv4); + } - explicit constexpr operator bool() const noexcept { - return IsValid(); + explicit constexpr operator bool() const noexcept { + return IsValid(); + } + + constexpr bool operator ! () const noexcept { + return !IsValid(); } - constexpr bool operator ! () const noexcept { - return !IsValid(); - } - bool Isv4MappedTov6() const noexcept; TIpv6Address TryToExtractIpv4From6() const noexcept; TIpv6Address Normalized() const noexcept; @@ -95,45 +95,45 @@ public: void ToIn6Addr(in6_addr& Addr6) const; // int SocketFamily() const; - constexpr bool operator<(const TIpv6Address& other) const noexcept { + constexpr bool operator<(const TIpv6Address& other) const noexcept { if (Type_ != other.Type_) return Type_ > other.Type_; else return Ip < other.Ip; } - constexpr bool operator>(const TIpv6Address& other) const noexcept { + constexpr bool operator>(const TIpv6Address& other) const noexcept { if (Type_ != other.Type_) return Type_ < other.Type_; else return Ip > other.Ip; } - constexpr bool operator==(const TIpv6Address& other) const noexcept { + constexpr bool operator==(const TIpv6Address& other) const noexcept { return Type_ == other.Type_ && Ip == other.Ip; } - constexpr bool operator!=(const TIpv6Address& other) const noexcept { + constexpr bool operator!=(const TIpv6Address& other) const noexcept { return Type_ != other.Type_ || Ip != other.Ip; } - constexpr bool operator<=(const TIpv6Address& other) const noexcept { + constexpr bool operator<=(const TIpv6Address& other) const noexcept { return !(*this > other); } - constexpr bool operator>=(const TIpv6Address& other) const noexcept { + constexpr bool operator>=(const TIpv6Address& other) const noexcept { return !(*this < other); } - constexpr operator ui128() const noexcept { + constexpr operator ui128() const noexcept { return Ip; } - constexpr TIpType Type() const noexcept { + constexpr TIpType Type() const noexcept { return Type_; } - void SetScopeId(ui32 New) noexcept { + void SetScopeId(ui32 New) noexcept { ScopeId_ = New; } - constexpr ui32 ScopeId() const noexcept { + constexpr ui32 ScopeId() const noexcept { return ScopeId_; } @@ -154,35 +154,35 @@ private: IOutputStream& operator<<(IOutputStream& Out, const TIpv6Address::TIpType Type) noexcept; IOutputStream& operator<<(IOutputStream& Out, const TIpv6Address& ipv6Address) noexcept; -constexpr TIpv6Address Get127001() noexcept { - return {127, 0, 0, 1}; +constexpr TIpv6Address Get127001() noexcept { + return {127, 0, 0, 1}; } - -constexpr TIpv6Address Get1() noexcept { - return {1, TIpv6Address::Ipv6}; + +constexpr TIpv6Address Get1() noexcept { + return {1, TIpv6Address::Ipv6}; } struct THostAddressAndPort { - constexpr THostAddressAndPort() noexcept = default; - constexpr THostAddressAndPort(const TIpv6Address& i, TIpPort p) noexcept { + constexpr THostAddressAndPort() noexcept = default; + constexpr THostAddressAndPort(const TIpv6Address& i, TIpPort p) noexcept { Ip = i; Port = p; } - constexpr bool operator==(const THostAddressAndPort& Other) const noexcept { + constexpr bool operator==(const THostAddressAndPort& Other) const noexcept { return Ip == Other.Ip && Port == Other.Port; } - constexpr bool operator!=(const THostAddressAndPort& Other) const noexcept { + constexpr bool operator!=(const THostAddressAndPort& Other) const noexcept { return !(*this == Other); } - constexpr bool IsValid() const noexcept { + constexpr bool IsValid() const noexcept { return Ip.IsValid() && Port != 0; } TString ToString() const noexcept; - TIpv6Address Ip {}; - TIpPort Port {0}; + TIpv6Address Ip {}; + TIpPort Port {0}; }; IOutputStream& operator<<(IOutputStream& Out, const THostAddressAndPort& HostAddressAndPort) noexcept; |