cpp-msgpack-rpc 0.2.0
An RPC library implementing MessagePack RPC.
Loading...
Searching...
No Matches
uri.h
Go to the documentation of this file.
1/*
2 * Copyright 2023 MusicScience37 (Kenta Kabashima)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
20#pragma once
21
22#include <cstdint>
23#include <optional>
24#include <ostream>
25#include <string>
26#include <string_view>
27
28#include <fmt/base.h>
29
30#include "msgpack_rpc/impl/msgpack_rpc_export.h"
31
32namespace msgpack_rpc::addresses {
33
38class MSGPACK_RPC_EXPORT URI {
39public:
49 URI(std::string_view scheme, std::string_view host_or_path,
50 std::optional<std::uint16_t> port_number =
51 std::optional<std::uint16_t>());
52
58 [[nodiscard]] std::string_view scheme() const noexcept;
59
65 [[nodiscard]] std::string_view host_or_path() const noexcept;
66
72 [[nodiscard]] std::optional<std::uint16_t> port_number() const noexcept;
73
81 bool operator==(const URI& right) const;
82
90 bool operator!=(const URI& right) const;
91
98 [[nodiscard]] static URI parse(std::string_view uri_string);
99
100private:
102 std::string scheme_;
103
105 std::string host_or_path_;
106
108 std::optional<std::uint16_t> port_number_;
109};
110
111} // namespace msgpack_rpc::addresses
112
113namespace fmt {
114
119template <>
120class formatter<msgpack_rpc::addresses::URI> {
121public:
128 constexpr format_parse_context::iterator parse( // NOLINT
129 format_parse_context& context) {
130 return context.end();
131 }
132
140 MSGPACK_RPC_EXPORT format_context::iterator format( // NOLINT
141 const msgpack_rpc::addresses::URI& val, format_context& context) const;
142};
143
144} // namespace fmt
145
153MSGPACK_RPC_EXPORT std::ostream& operator<<(
154 std::ostream& stream, const msgpack_rpc::addresses::URI& uri);
constexpr format_parse_context::iterator parse(format_parse_context &context)
Parse format.
Definition uri.h:128
Class of URIs (Uniform Resource Identifiers) to specify endpoints in this library.
Definition uri.h:38
std::string_view scheme() const noexcept
Get the scheme.
Definition uri.cpp:38
std::string scheme_
Scheme.
Definition uri.h:102
std::optional< std::uint16_t > port_number() const noexcept
Get the port number.
Definition uri.cpp:42
std::string host_or_path_
Host name or file path.
Definition uri.h:105
std::optional< std::uint16_t > port_number_
Port.
Definition uri.h:108
std::string_view host_or_path() const noexcept
Get the host name or file path.
Definition uri.cpp:40
static URI parse(std::string_view uri_string)
Parse a string to create a URI.
Definition uri.cpp:54
bool operator==(const URI &right) const
Compare with a URI.
Definition uri.cpp:46
bool operator!=(const URI &right) const
Compare with a URI.
Definition uri.cpp:52
URI(std::string_view scheme, std::string_view host_or_path, std::optional< std::uint16_t > port_number=std::optional< std::uint16_t >())
Constructor.
Definition uri.cpp:34
Namespace of fmt library.
Definition uri.h:113
Namespace of addresses.
Definition i_address.h:26
Namespace of cpp-msgpack-rpc library.
Definition i_address.h:26
std::ostream & operator<<(std::ostream &stream, const msgpack_rpc::addresses::URI &uri)
Format a URI.
Definition uri.cpp:110