Commit 8ab68e82 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Alecs King

IPAddressV6::kToFullyQualifiedSize.

Summary:
[Folly] IPAddressV6::kToFullyQualifiedSize.

The scenario: One has a string known to be a fully-qualified IPv4 or fully-qualified IPv6 address, but one does not know which of the two it is.

The dirty but fast solution: just check its size.

Test Plan: Build. Unit tests.

Reviewed By: mshneer@fb.com

Subscribers: folly-diffs@, dougw, yfeldblum, chalfant, brettp

FB internal diff: D2016634

Signature: t1:2016634:1429831808:08ecb28eab3060988f9613748ed8dabf3724bf13
parent b79405c6
...@@ -82,6 +82,10 @@ class IPAddressV6 : boost::totally_ordered<IPAddressV6> { ...@@ -82,6 +82,10 @@ class IPAddressV6 : boost::totally_ordered<IPAddressV6> {
// Binary prefix for 6to4 networks // Binary prefix for 6to4 networks
static const uint32_t PREFIX_6TO4; static const uint32_t PREFIX_6TO4;
// Size of std::string returned by toFullyQualified.
static constexpr size_t kToFullyQualifiedSize =
8 /*words*/ * 4 /*hex chars per word*/ + 7 /*separators*/;
/** /**
* Create a new IPAddress instance from the provided binary data. * Create a new IPAddress instance from the provided binary data.
* @throws IPAddressFormatException if the input length is not 16 bytes. * @throws IPAddressFormatException if the input length is not 16 bytes.
......
...@@ -409,6 +409,11 @@ TEST(IPAddress, ToFullyQualifiedLocal) { ...@@ -409,6 +409,11 @@ TEST(IPAddress, ToFullyQualifiedLocal) {
EXPECT_EQ("0000:0000:0000:0000:0000:0000:0000:0001", ip.toFullyQualified()) EXPECT_EQ("0000:0000:0000:0000:0000:0000:0000:0001", ip.toFullyQualified())
<< ip; << ip;
} }
TEST(IPAddress, ToFullyQualifiedSize) {
auto actual = IPAddressV6::kToFullyQualifiedSize;
auto expected = IPAddress("::").toFullyQualified().size();
EXPECT_EQ(expected, actual);
}
// test v4-v6 mapped addresses // test v4-v6 mapped addresses
TEST_P(IPAddressMappedTest, MappedEqual) { TEST_P(IPAddressMappedTest, MappedEqual) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment