From b0b31edf23730ff1458bdf5da9d5b5a37c20bc9b Mon Sep 17 00:00:00 2001 From: owent Date: Fri, 11 Oct 2024 16:54:02 +0800 Subject: [PATCH] Support protobuf v27+ --- atframework/atframe_utils | 2 +- atframework/cmake-toolset | 2 +- docs/experience/protocol_test.md | 4 ++++ src/atbus_connection.cpp | 4 ++++ src/atbus_msg_handler.cpp | 20 ++++++++++++++++++++ src/atbus_node.cpp | 16 ++++++++++++++++ 6 files changed, 46 insertions(+), 2 deletions(-) diff --git a/atframework/atframe_utils b/atframework/atframe_utils index e8a744d1b..505bba3e4 160000 --- a/atframework/atframe_utils +++ b/atframework/atframe_utils @@ -1 +1 @@ -Subproject commit e8a744d1b240fc095c0ea055957fe3a0ba5594ba +Subproject commit 505bba3e499f7c4fd5b579c63954b404e3149df4 diff --git a/atframework/cmake-toolset b/atframework/cmake-toolset index 944b6b33c..986f04c03 160000 --- a/atframework/cmake-toolset +++ b/atframework/cmake-toolset @@ -1 +1 @@ -Subproject commit 944b6b33c9293168dcb8e07316871cdee75e21bf +Subproject commit 986f04c032798992272d0fc52724bed4c5b14ba2 diff --git a/docs/experience/protocol_test.md b/docs/experience/protocol_test.md index cbfe72678..1857fa61a 100644 --- a/docs/experience/protocol_test.md +++ b/docs/experience/protocol_test.md @@ -247,7 +247,11 @@ message msg { ```cpp ::google::protobuf::Arena arena; +#if defined(PROTOBUF_VERSION) && PROTOBUF_VERSION >= 5027000 +atbus::protocol::msg * m_src = ::google::protobuf::Arena::Create(&arena); +#else atbus::protocol::msg * m_src = ::google::protobuf::Arena::CreateMessage(&arena); +#endif std::string packed_buffer; char test_buffer[] = "hello world!"; diff --git a/src/atbus_connection.cpp b/src/atbus_connection.cpp index e14479f19..b3553f630 100755 --- a/src/atbus_connection.cpp +++ b/src/atbus_connection.cpp @@ -937,7 +937,11 @@ ATBUS_MACRO_API int connection::ios_push_fn(connection &conn, const void *buffer ATBUS_MACRO_API bool connection::unpack(connection &conn, ::atbus::msg_t *&m, ::ATBUS_MACRO_PROTOBUF_NAMESPACE_ID::Arena &arena, std::vector &in) { +#if defined(PROTOBUF_VERSION) && PROTOBUF_VERSION >= 5027000 + m = ::ATBUS_MACRO_PROTOBUF_NAMESPACE_ID::Arena::Create(&arena); +#else m = ::ATBUS_MACRO_PROTOBUF_NAMESPACE_ID::Arena::CreateMessage(&arena); +#endif if (nullptr == m) { ATBUS_FUNC_NODE_ERROR(*conn.owner_, conn.binding_, &conn, EN_ATBUS_ERR_UNPACK, EN_ATBUS_ERR_MALLOC); return false; diff --git a/src/atbus_msg_handler.cpp b/src/atbus_msg_handler.cpp index 8e3b6c6be..72aba5b67 100755 --- a/src/atbus_msg_handler.cpp +++ b/src/atbus_msg_handler.cpp @@ -139,7 +139,11 @@ ATBUS_MACRO_API int msg_handler::send_ping(node &n, connection &conn, uint64_t m ::ATBUS_MACRO_PROTOBUF_NAMESPACE_ID::ArenaOptions arena_options; arena_options.initial_block_size = ATBUS_MACRO_RESERVED_SIZE; ::ATBUS_MACRO_PROTOBUF_NAMESPACE_ID::Arena arena(arena_options); +#if defined(PROTOBUF_VERSION) && PROTOBUF_VERSION >= 5027000 + atbus::protocol::msg *m = ::ATBUS_MACRO_PROTOBUF_NAMESPACE_ID::Arena::Create(&arena); +#else atbus::protocol::msg *m = ::ATBUS_MACRO_PROTOBUF_NAMESPACE_ID::Arena::CreateMessage(&arena); +#endif assert(m); ::atbus::protocol::msg_head *head = m->mutable_head(); @@ -169,7 +173,11 @@ ATBUS_MACRO_API int msg_handler::send_reg(int32_t msg_id, node &n, connection &c ::ATBUS_MACRO_PROTOBUF_NAMESPACE_ID::ArenaOptions arena_options; arena_options.initial_block_size = ATBUS_MACRO_RESERVED_SIZE; ::ATBUS_MACRO_PROTOBUF_NAMESPACE_ID::Arena arena(arena_options); +#if defined(PROTOBUF_VERSION) && PROTOBUF_VERSION >= 5027000 + atbus::protocol::msg *m = ::ATBUS_MACRO_PROTOBUF_NAMESPACE_ID::Arena::Create(&arena); +#else atbus::protocol::msg *m = ::ATBUS_MACRO_PROTOBUF_NAMESPACE_ID::Arena::CreateMessage(&arena); +#endif assert(m); ::atbus::protocol::msg_head *head = m->mutable_head(); @@ -294,7 +302,11 @@ ATBUS_MACRO_API int msg_handler::send_custom_cmd_rsp(node &n, connection *conn, ::ATBUS_MACRO_PROTOBUF_NAMESPACE_ID::ArenaOptions arena_options; arena_options.initial_block_size = ATBUS_MACRO_RESERVED_SIZE; ::ATBUS_MACRO_PROTOBUF_NAMESPACE_ID::Arena arena(arena_options); +#if defined(PROTOBUF_VERSION) && PROTOBUF_VERSION >= 5027000 + atbus::protocol::msg *m = ::ATBUS_MACRO_PROTOBUF_NAMESPACE_ID::Arena::Create(&arena); +#else atbus::protocol::msg *m = ::ATBUS_MACRO_PROTOBUF_NAMESPACE_ID::Arena::CreateMessage(&arena); +#endif assert(m); ::atbus::protocol::msg_head *head = m->mutable_head(); @@ -370,7 +382,11 @@ ATBUS_MACRO_API int msg_handler::send_node_connect_sync(node &n, uint64_t direct ::ATBUS_MACRO_PROTOBUF_NAMESPACE_ID::ArenaOptions arena_options; arena_options.initial_block_size = ATBUS_MACRO_RESERVED_SIZE; ::ATBUS_MACRO_PROTOBUF_NAMESPACE_ID::Arena arena(arena_options); +#if defined(PROTOBUF_VERSION) && PROTOBUF_VERSION >= 5027000 + atbus::protocol::msg *m = ::ATBUS_MACRO_PROTOBUF_NAMESPACE_ID::Arena::Create(&arena); +#else atbus::protocol::msg *m = ::ATBUS_MACRO_PROTOBUF_NAMESPACE_ID::Arena::CreateMessage(&arena); +#endif assert(m); ::atbus::protocol::msg_head *head = m->mutable_head(); @@ -1158,8 +1174,12 @@ ATBUS_MACRO_API int msg_handler::on_recv_node_ping(node &n, connection *conn, ::ATBUS_MACRO_PROTOBUF_NAMESPACE_ID::ArenaOptions arena_options; arena_options.initial_block_size = ATBUS_MACRO_RESERVED_SIZE; ::ATBUS_MACRO_PROTOBUF_NAMESPACE_ID::Arena arena(arena_options); +#if defined(PROTOBUF_VERSION) && PROTOBUF_VERSION >= 5027000 + atbus::protocol::msg *rsp_m = ::ATBUS_MACRO_PROTOBUF_NAMESPACE_ID::Arena::Create(&arena); +#else atbus::protocol::msg *rsp_m = ::ATBUS_MACRO_PROTOBUF_NAMESPACE_ID::Arena::CreateMessage(&arena); +#endif assert(rsp_m); ::atbus::protocol::msg_head *head = rsp_m->mutable_head(); diff --git a/src/atbus_node.cpp b/src/atbus_node.cpp index f5883f9de..7ba5a4f5b 100755 --- a/src/atbus_node.cpp +++ b/src/atbus_node.cpp @@ -882,7 +882,11 @@ ATBUS_MACRO_API int node::send_data(bus_id_t tid, int type, const void *buffer, ::ATBUS_MACRO_PROTOBUF_NAMESPACE_ID::ArenaOptions arena_options; arena_options.initial_block_size = ATBUS_MACRO_RESERVED_SIZE; ::ATBUS_MACRO_PROTOBUF_NAMESPACE_ID::Arena arena(arena_options); +#if defined(PROTOBUF_VERSION) && PROTOBUF_VERSION >= 5027000 + ::atbus::msg_t *m = ::ATBUS_MACRO_PROTOBUF_NAMESPACE_ID::Arena::Create(&arena); +#else ::atbus::msg_t *m = ::ATBUS_MACRO_PROTOBUF_NAMESPACE_ID::Arena::CreateMessage(&arena); +#endif if (nullptr == m) { ATBUS_FUNC_NODE_ERROR(*this, nullptr, nullptr, EN_ATBUS_ERR_UNPACK, EN_ATBUS_ERR_MALLOC); return EN_ATBUS_ERR_MALLOC; @@ -942,7 +946,11 @@ ATBUS_MACRO_API int node::send_custom_cmd(bus_id_t tid, const void *arr_buf[], s ::ATBUS_MACRO_PROTOBUF_NAMESPACE_ID::ArenaOptions arena_options; arena_options.initial_block_size = ATBUS_MACRO_RESERVED_SIZE; ::ATBUS_MACRO_PROTOBUF_NAMESPACE_ID::Arena arena(arena_options); +#if defined(PROTOBUF_VERSION) && PROTOBUF_VERSION >= 5027000 + ::atbus::msg_t *m = ::ATBUS_MACRO_PROTOBUF_NAMESPACE_ID::Arena::Create(&arena); +#else ::atbus::msg_t *m = ::ATBUS_MACRO_PROTOBUF_NAMESPACE_ID::Arena::CreateMessage(&arena); +#endif if (nullptr == m) { ATBUS_FUNC_NODE_ERROR(*this, nullptr, nullptr, EN_ATBUS_ERR_UNPACK, EN_ATBUS_ERR_MALLOC); return EN_ATBUS_ERR_MALLOC; @@ -1735,7 +1743,11 @@ ATBUS_MACRO_API int node::dispatch_all_self_msgs() { ::ATBUS_MACRO_PROTOBUF_NAMESPACE_ID::ArenaOptions arena_options; arena_options.initial_block_size = ATBUS_MACRO_RESERVED_SIZE; ::ATBUS_MACRO_PROTOBUF_NAMESPACE_ID::Arena arena(arena_options); +#if defined(PROTOBUF_VERSION) && PROTOBUF_VERSION >= 5027000 + ::atbus::msg_t *m = ::ATBUS_MACRO_PROTOBUF_NAMESPACE_ID::Arena::Create(&arena); +#else ::atbus::msg_t *m = ::ATBUS_MACRO_PROTOBUF_NAMESPACE_ID::Arena::CreateMessage(&arena); +#endif if (nullptr == m) { ATBUS_FUNC_NODE_ERROR(*this, get_self_endpoint(), nullptr, EN_ATBUS_ERR_UNPACK, EN_ATBUS_ERR_MALLOC); break; @@ -1782,7 +1794,11 @@ ATBUS_MACRO_API int node::dispatch_all_self_msgs() { ::ATBUS_MACRO_PROTOBUF_NAMESPACE_ID::ArenaOptions arena_options; arena_options.initial_block_size = ATBUS_MACRO_RESERVED_SIZE; ::ATBUS_MACRO_PROTOBUF_NAMESPACE_ID::Arena arena(arena_options); +#if defined(PROTOBUF_VERSION) && PROTOBUF_VERSION >= 5027000 + ::atbus::msg_t *m = ::ATBUS_MACRO_PROTOBUF_NAMESPACE_ID::Arena::Create(&arena); +#else ::atbus::msg_t *m = ::ATBUS_MACRO_PROTOBUF_NAMESPACE_ID::Arena::CreateMessage(&arena); +#endif if (nullptr == m) { ATBUS_FUNC_NODE_ERROR(*this, get_self_endpoint(), nullptr, EN_ATBUS_ERR_UNPACK, EN_ATBUS_ERR_MALLOC); break;