cpp-msgpack-rpc 0.2.0
An RPC library implementing MessagePack RPC.
Loading...
Searching...
No Matches
tcp_address.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 <ostream>
24#include <string>
25#include <string_view>
26
27#include <asio/ip/tcp.hpp>
28#include <fmt/base.h>
29
32#include "msgpack_rpc/impl/msgpack_rpc_export.h"
33
34namespace msgpack_rpc::addresses {
35
39using AsioTCPAddress = asio::ip::tcp::endpoint;
40
44class MSGPACK_RPC_EXPORT TCPAddress final : public IAddress {
45public:
52 TCPAddress(std::string_view ip_address, std::uint16_t port_number);
53
59 explicit TCPAddress(AsioTCPAddress address);
60
66 [[nodiscard]] std::string ip_address() const;
67
73 [[nodiscard]] std::uint16_t port_number() const;
74
76 [[nodiscard]] URI to_uri() const override;
77
79 [[nodiscard]] std::string to_string() const override;
80
86 [[nodiscard]] const AsioTCPAddress& asio_address() const;
87
95 bool operator==(const TCPAddress& right) const;
96
104 bool operator!=(const TCPAddress& right) const;
105
106private:
109};
110
111} // namespace msgpack_rpc::addresses
112
113namespace fmt {
114
119template <>
120class formatter<msgpack_rpc::addresses::TCPAddress> {
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
142 format_context& context) const;
143};
144
145} // namespace fmt
146
154MSGPACK_RPC_EXPORT std::ostream& operator<<(
155 std::ostream& stream, const msgpack_rpc::addresses::TCPAddress& address);
constexpr format_parse_context::iterator parse(format_parse_context &context)
Parse format.
Class of addresses of TCP.
Definition tcp_address.h:44
std::uint16_t port_number() const
Get the port number.
bool operator!=(const TCPAddress &right) const
Compare with an address.
AsioTCPAddress address_
Address in asio library.
bool operator==(const TCPAddress &right) const
Compare with an address.
std::string ip_address() const
Get the IP address.
URI to_uri() const override
Convert to a URI.
std::string to_string() const override
Convert to a string specifying URI.
TCPAddress(std::string_view ip_address, std::uint16_t port_number)
Constructor.
const AsioTCPAddress & asio_address() const
Get the address in asio library.
Class of URIs (Uniform Resource Identifiers) to specify endpoints in this library.
Definition uri.h:38
Definition of IAddress.
Namespace of fmt library.
Definition uri.h:113
Namespace of addresses.
Definition i_address.h:26
asio::ip::tcp::endpoint AsioTCPAddress
Type of addresses of TCP in asio library.
Definition tcp_address.h:39
Namespace of cpp-msgpack-rpc library.
Definition i_address.h:26
std::ostream & operator<<(std::ostream &stream, const msgpack_rpc::addresses::TCPAddress &address)
Format an address.
Definition of URI class.