Skip to content

Commit 0c01e74

Browse files
authored
Cleanup: use proto DynamicCastMessage if available (#596) (#598)
(cherry picked from commit c47393f) Signed-off-by: Clayton Knittel <cknit1999@gmail.com>
1 parent 0e2f10a commit 0c01e74

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

core/include/gz/msgs/detail/dynamic_message_cast.hh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,12 @@ template<typename MsgT>
3737
std::unique_ptr<MsgT>
3838
dynamic_message_cast(std::unique_ptr<google::protobuf::Message> &&_baseMsg)
3939
{
40+
#if GOOGLE_PROTOBUF_VERSION >= 5028000
41+
auto converted = std::unique_ptr<MsgT>{
42+
google::protobuf::DynamicCastMessage<MsgT>(_baseMsg.get())};
43+
#else
4044
auto converted = std::unique_ptr<MsgT>{dynamic_cast<MsgT*>(_baseMsg.get())};
45+
#endif
4146
if (converted) {
4247
// transfer ownership to a new unique_ptr object by releasing from old one
4348
(void) _baseMsg.release();

0 commit comments

Comments
 (0)