X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2FIPAddressV6.h;h=161a2404b620868adf4c1406d526846f8f6453c6;hb=cc9ce0e1e7d84db3ccb553cc8c75e179459ef42f;hp=f641bdcd85e988fa8562a0f986cb0aa467597f2a;hpb=dce47b8a0cc0e90f93844e66651d68340ed2f940;p=folly.git diff --git a/folly/IPAddressV6.h b/folly/IPAddressV6.h index f641bdcd..161a2404 100644 --- a/folly/IPAddressV6.h +++ b/folly/IPAddressV6.h @@ -24,11 +24,13 @@ #include #include +#include #include -#include +#include #include #include #include +#include namespace folly { @@ -92,17 +94,27 @@ class IPAddressV6 { 8 /*words*/ * 4 /*hex chars per word*/ + 7 /*separators*/; // returns true iff the input string can be parsed as an ipv6-address - static bool validate(StringPiece ip); + static bool validate(StringPiece ip) noexcept; /** * Create a new IPAddress instance from the provided binary data. * @throws IPAddressFormatException if the input length is not 16 bytes. */ - static IPAddressV6 fromBinary(ByteRange bytes) { - IPAddressV6 addr; - addr.setFromBinary(bytes); - return addr; - } + static IPAddressV6 fromBinary(ByteRange bytes); + + /** + * Non-throwing version of fromBinary(). + * On failure returns IPAddressFormatError. + */ + static Expected tryFromBinary( + ByteRange bytes) noexcept; + + /** + * Tries to create a new IPAddressV6 instance from provided string and + * returns it on success. Returns IPAddressFormatError on failure. + */ + static Expected tryFromString( + StringPiece str) noexcept; /** * Create a new IPAddress instance from the ip6.arpa representation. @@ -131,13 +143,13 @@ class IPAddressV6 { explicit IPAddressV6(StringPiece ip); // ByteArray16 constructor - explicit IPAddressV6(const ByteArray16& src); + explicit IPAddressV6(const ByteArray16& src) noexcept; // in6_addr constructor - explicit IPAddressV6(const in6_addr& src); + explicit IPAddressV6(const in6_addr& src) noexcept; // sockaddr_in6 constructor - explicit IPAddressV6(const sockaddr_in6& src); + explicit IPAddressV6(const sockaddr_in6& src) noexcept; /** * Create a link-local IPAddressV6 from the specified ethernet MAC address. @@ -406,9 +418,10 @@ class IPAddressV6 { /** * Set the current IPAddressV6 object to have the address specified by bytes. - * @throws IPAddressFormatException if bytes.size() is not 16. + * Returns IPAddressFormatError if bytes.size() is not 16. */ - void setFromBinary(ByteRange bytes); + Expected trySetFromBinary( + ByteRange bytes) noexcept; }; // boost::hash uses hash_value() so this allows boost::hash to work