Skip to content

Commit

Permalink
Support protobuf v27+
Browse files Browse the repository at this point in the history
  • Loading branch information
owent committed Oct 11, 2024
1 parent ddbdd4e commit b0b31ed
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 2 deletions.
2 changes: 1 addition & 1 deletion atframework/atframe_utils
2 changes: 1 addition & 1 deletion atframework/cmake-toolset
4 changes: 4 additions & 0 deletions docs/experience/protocol_test.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<atbus::protocol::msg>(&arena);
#else
atbus::protocol::msg * m_src = ::google::protobuf::Arena::CreateMessage<atbus::protocol::msg>(&arena);
#endif
std::string packed_buffer;
char test_buffer[] = "hello world!";

Expand Down
4 changes: 4 additions & 0 deletions src/atbus_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<unsigned char> &in) {
#if defined(PROTOBUF_VERSION) && PROTOBUF_VERSION >= 5027000
m = ::ATBUS_MACRO_PROTOBUF_NAMESPACE_ID::Arena::Create<atbus::protocol::msg>(&arena);
#else
m = ::ATBUS_MACRO_PROTOBUF_NAMESPACE_ID::Arena::CreateMessage<atbus::protocol::msg>(&arena);
#endif
if (nullptr == m) {
ATBUS_FUNC_NODE_ERROR(*conn.owner_, conn.binding_, &conn, EN_ATBUS_ERR_UNPACK, EN_ATBUS_ERR_MALLOC);
return false;
Expand Down
20 changes: 20 additions & 0 deletions src/atbus_msg_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<atbus::protocol::msg>(&arena);
#else
atbus::protocol::msg *m = ::ATBUS_MACRO_PROTOBUF_NAMESPACE_ID::Arena::CreateMessage<atbus::protocol::msg>(&arena);
#endif
assert(m);

::atbus::protocol::msg_head *head = m->mutable_head();
Expand Down Expand Up @@ -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<atbus::protocol::msg>(&arena);
#else
atbus::protocol::msg *m = ::ATBUS_MACRO_PROTOBUF_NAMESPACE_ID::Arena::CreateMessage<atbus::protocol::msg>(&arena);
#endif
assert(m);

::atbus::protocol::msg_head *head = m->mutable_head();
Expand Down Expand Up @@ -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<atbus::protocol::msg>(&arena);
#else
atbus::protocol::msg *m = ::ATBUS_MACRO_PROTOBUF_NAMESPACE_ID::Arena::CreateMessage<atbus::protocol::msg>(&arena);
#endif
assert(m);

::atbus::protocol::msg_head *head = m->mutable_head();
Expand Down Expand Up @@ -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<atbus::protocol::msg>(&arena);
#else
atbus::protocol::msg *m = ::ATBUS_MACRO_PROTOBUF_NAMESPACE_ID::Arena::CreateMessage<atbus::protocol::msg>(&arena);
#endif
assert(m);

::atbus::protocol::msg_head *head = m->mutable_head();
Expand Down Expand Up @@ -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<atbus::protocol::msg>(&arena);
#else
atbus::protocol::msg *rsp_m =
::ATBUS_MACRO_PROTOBUF_NAMESPACE_ID::Arena::CreateMessage<atbus::protocol::msg>(&arena);
#endif
assert(rsp_m);

::atbus::protocol::msg_head *head = rsp_m->mutable_head();
Expand Down
16 changes: 16 additions & 0 deletions src/atbus_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<atbus::protocol::msg>(&arena);
#else
::atbus::msg_t *m = ::ATBUS_MACRO_PROTOBUF_NAMESPACE_ID::Arena::CreateMessage<atbus::protocol::msg>(&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;
Expand Down Expand Up @@ -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<atbus::protocol::msg>(&arena);
#else
::atbus::msg_t *m = ::ATBUS_MACRO_PROTOBUF_NAMESPACE_ID::Arena::CreateMessage<atbus::protocol::msg>(&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;
Expand Down Expand Up @@ -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<atbus::protocol::msg>(&arena);
#else
::atbus::msg_t *m = ::ATBUS_MACRO_PROTOBUF_NAMESPACE_ID::Arena::CreateMessage<atbus::protocol::msg>(&arena);
#endif
if (nullptr == m) {
ATBUS_FUNC_NODE_ERROR(*this, get_self_endpoint(), nullptr, EN_ATBUS_ERR_UNPACK, EN_ATBUS_ERR_MALLOC);
break;
Expand Down Expand Up @@ -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<atbus::protocol::msg>(&arena);
#else
::atbus::msg_t *m = ::ATBUS_MACRO_PROTOBUF_NAMESPACE_ID::Arena::CreateMessage<atbus::protocol::msg>(&arena);
#endif
if (nullptr == m) {
ATBUS_FUNC_NODE_ERROR(*this, get_self_endpoint(), nullptr, EN_ATBUS_ERR_UNPACK, EN_ATBUS_ERR_MALLOC);
break;
Expand Down

0 comments on commit b0b31ed

Please sign in to comment.