From fc67511356b876a7da702265738fa935a699fea8 Mon Sep 17 00:00:00 2001 From: qicosmos Date: Mon, 6 Oct 2025 13:01:10 +0800 Subject: [PATCH] add for mac --- include/rest_rpc/rest_rpc_protocol.hpp | 17 ++++++++++------- tests/test_rest_rpc.cpp | 8 ++++---- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/include/rest_rpc/rest_rpc_protocol.hpp b/include/rest_rpc/rest_rpc_protocol.hpp index 4bf64fe..c178c7f 100644 --- a/include/rest_rpc/rest_rpc_protocol.hpp +++ b/include/rest_rpc/rest_rpc_protocol.hpp @@ -7,6 +7,7 @@ #endif namespace rest_rpc::detail { +#ifndef htonll inline uint64_t htonll(uint64_t value) { return ((uint64_t)htonl(value & 0xFFFFFFFF) << 32) | htonl(value >> 32); } @@ -14,9 +15,9 @@ inline uint64_t htonll(uint64_t value) { inline uint64_t ntohll(uint64_t value) { return ((uint64_t)ntohl(value & 0xFFFFFFFF) << 32) | ntohl(value >> 32); } +#endif } // namespace rest_rpc::detail - namespace rest_rpc { inline constexpr uint8_t REST_MAGIC_NUM = 39; struct rest_rpc_header { @@ -31,16 +32,18 @@ struct rest_rpc_header { }; inline void prepare_for_send(rest_rpc_header &header) { + using namespace detail; header.function_id = htonl(header.function_id); - header.seq_num = detail::htonll(header.seq_num); - header.body_len = detail::htonll(header.body_len); - header.attach_length = detail::htonll(header.attach_length); + header.seq_num = htonll(header.seq_num); + header.body_len = htonll(header.body_len); + header.attach_length = htonll(header.attach_length); } inline void parse_recieved(rest_rpc_header &header) { + using namespace detail; header.function_id = ntohl(header.function_id); - header.seq_num = detail::ntohll(header.seq_num); - header.body_len = detail::ntohll(header.body_len); - header.attach_length = detail::ntohll(header.attach_length); + header.seq_num = ntohll(header.seq_num); + header.body_len = ntohll(header.body_len); + header.attach_length = ntohll(header.attach_length); } } // namespace rest_rpc \ No newline at end of file diff --git a/tests/test_rest_rpc.cpp b/tests/test_rest_rpc.cpp index 15d990d..781eb5c 100644 --- a/tests/test_rest_rpc.cpp +++ b/tests/test_rest_rpc.cpp @@ -298,10 +298,10 @@ TEST_CASE("test pub sub") { std::promise promise; auto sub = [&]() -> asio::awaitable { for (int i = 0; i < 5; i++) { - auto [ec, result] = co_await client.subscribe("topic1"); - REST_LOG_INFO << result; - CHECK(ec == rpc_errc::ok); - CHECK(result == "publish message"); + auto result = co_await client.subscribe("topic1"); + REST_LOG_INFO << result.value; + CHECK(result.ec == rpc_errc::ok); + CHECK(result.value == "publish message"); } promise.set_value(); };