cpp-msgpack-rpc 0.2.0
An RPC library implementing MessagePack RPC.
Loading...
Searching...
No Matches
unix_socket_address.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2024 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 */
21
22#if MSGPACK_RPC_HAS_UNIX_SOCKETS
23
24#include <utility>
25
26#include <asio/local/basic_endpoint.hpp>
27#include <fmt/format.h>
28
30
31namespace msgpack_rpc::addresses {
32
33UnixSocketAddress::UnixSocketAddress(AsioUnixSocketAddress address)
34 : address_(std::move(address)) {}
35
36std::string UnixSocketAddress::file_path() const { return address_.path(); }
37
38URI UnixSocketAddress::to_uri() const {
39 return URI(UNIX_SOCKET_SCHEME, address_.path());
40}
41
42std::string UnixSocketAddress::to_string() const {
43 return fmt::format("unix://{}", address_.path());
44}
45
46const AsioUnixSocketAddress& UnixSocketAddress::asio_address() const {
47 return address_;
48}
49
50bool UnixSocketAddress::operator==(const UnixSocketAddress& right) const {
51 return address_ == right.address_;
52}
53
54bool UnixSocketAddress::operator!=(const UnixSocketAddress& right) const {
55 return !operator==(right);
56}
57
58} // namespace msgpack_rpc::addresses
59
60namespace fmt {
61
62format_context::iterator
63formatter<msgpack_rpc::addresses::UnixSocketAddress>::format( // NOLINT
64 const msgpack_rpc::addresses::UnixSocketAddress& val,
65 format_context& context) const {
66 return fmt::format_to(context.out(), "unix://{}", val.file_path());
67}
68
69} // namespace fmt
70
71std::ostream& operator<<(std::ostream& stream,
72 const msgpack_rpc::addresses::UnixSocketAddress& address) {
73 stream << "unix://" << address.file_path();
74 return stream;
75}
76
77#endif
Namespace of fmt library.
Definition uri.h:113
Namespace of addresses.
Definition i_address.h:26
bool operator==(const MethodName &left, const MethodName &right) noexcept
Compare two method names.
Definition of constants of schemes.
Definition of UnixSocketAddress class.
std::ostream & operator<<(std::ostream &stream, const msgpack_rpc::addresses::URI &uri)
Format a URI.
Definition uri.cpp:110