24#include <absl/strings/string_view.h>
25#include <fmt/format.h>
55 static re2::RE2 ip_regex{R
"((tcp)://([a-zA-Z0-9+-.]+):(\d+))"};
56 static re2::RE2 ipv6_regex{R
"((tcp)://\[([a-zA-Z0-9+-.:]+)\]:(\d+))"};
57 static re2::RE2 file_path_regex{R
"((unix)://(.+))"};
61 auto port =
static_cast<std::uint16_t
>(0);
63 const auto absl_uri_string =
64 absl::string_view(uri_string.data(), uri_string.size());
65 if (!re2::RE2::FullMatch(
66 absl_uri_string, ip_regex, &
scheme, &host, &port) &&
68 absl_uri_string, ipv6_regex, &
scheme, &host, &port) &&
70 absl_uri_string, file_path_regex, &
scheme, &host)) {
72 fmt::format(
"Invalid URI string: \"{}\".", uri_string));
81 StatusCode::UNEXPECTED_ERROR,
"Unexpected line is executed.");
88format_context::iterator
89formatter<msgpack_rpc::addresses::URI>::format(
91 auto out = context.out();
92 out = fmt::format_to(out,
"{}://", val.
scheme());
94 if (val.
host_or_path().find(
':') == std::string_view::npos) {
103 out = fmt::format_to(out,
":{}", *(val.
port_number()));
112 stream << fmt::format(
"{}", uri);
Class of URIs (Uniform Resource Identifiers) to specify endpoints in this library.
std::string_view scheme() const noexcept
Get the scheme.
std::string scheme_
Scheme.
std::optional< std::uint16_t > port_number() const noexcept
Get the port number.
std::string host_or_path_
Host name or file path.
std::optional< std::uint16_t > port_number_
Port.
std::string_view host_or_path() const noexcept
Get the host name or file path.
static URI parse(std::string_view uri_string)
Parse a string to create a URI.
bool operator==(const URI &right) const
Compare with a URI.
bool operator!=(const URI &right) const
Compare with a URI.
URI(std::string_view scheme, std::string_view host_or_path, std::optional< std::uint16_t > port_number=std::optional< std::uint16_t >())
Constructor.
Class of exceptions in cpp-msgpack-rpc library.
Definition of MsgpackRPCException class.
Namespace of fmt library.
constexpr std::string_view UNIX_SOCKET_SCHEME
Scheme of unix sockets (streaming protocol).
constexpr std::string_view TCP_SCHEME
Scheme of TCP.
Definition of constants of schemes.
Definition of StatusCode enumeration.
std::ostream & operator<<(std::ostream &stream, const msgpack_rpc::addresses::URI &uri)
Format a URI.