diff --git a/folly/IPAddressV6.h b/folly/IPAddressV6.h index ed64a75..d4876af 100644 --- a/folly/IPAddressV6.h +++ b/folly/IPAddressV6.h @@ -82,6 +82,10 @@ class IPAddressV6 : boost::totally_ordered { // Binary prefix for 6to4 networks 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. * @throws IPAddressFormatException if the input length is not 16 bytes. diff --git a/folly/test/IPAddressTest.cpp b/folly/test/IPAddressTest.cpp index 9f39b5a..2e62f5d 100644 --- a/folly/test/IPAddressTest.cpp +++ b/folly/test/IPAddressTest.cpp @@ -409,6 +409,11 @@ TEST(IPAddress, ToFullyQualifiedLocal) { EXPECT_EQ("0000:0000:0000:0000:0000:0000:0000:0001", ip.toFullyQualified()) << ip; } +TEST(IPAddress, ToFullyQualifiedSize) { + auto actual = IPAddressV6::kToFullyQualifiedSize; + auto expected = IPAddress("::").toFullyQualified().size(); + EXPECT_EQ(expected, actual); +} // test v4-v6 mapped addresses TEST_P(IPAddressMappedTest, MappedEqual) {