Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add compatibility with protobuf 28 #541

Merged
merged 2 commits into from
Nov 5, 2024

Conversation

ramir0-sultanov
Copy link
Contributor

🎉 New feature

Adds compatibility with the Google Protocol Buffers v28.

Summary

Basically, rules for message down casting have been changed in protobuf and this PR modifies the way protobuf is used for downcasting.

Protobuf does not allow to use google::protobuf::internal::DownCast function to downcast message types with concepts enabled in version 28 (see port.h file in this diff). When compiling custom packages which depend on the gz-transport with C++ concepts enabled, there will be compile-time errors, if RepHandler::RunLocalCallback or SubscriptionHandler::RunLocalCallback functions were used (not necessarily used directly, but via some other function, for example: Node::Request).

Alternatively. there are google::protobuf::DynamicCastMessage and google::protobuf::DownCastMessage functions. Because google::protobuf::DynamicCastMessage function has more sanity checks, it was used in this PR with some additional error logging.

Test it

To test the changes you may install the Google Protocol Buffers v28, write some code that uses RepHandler::RunLocalCallback or SubscriptionHandler::RunLocalCallback (not necessarily directly) with C++ concepts enabled, and try to compile the code.

Checklist

  • Signed all commits for DCO
  • Added tests
  • Added example and/or tutorial
  • Updated documentation (as needed)
  • Updated migration guide (as needed)
  • Consider updating Python bindings (if the library has them)
  • codecheck passed (See contributing)
  • All tests passed (See test coverage)
  • While waiting for a review on your PR, please help review another open pull request to support the maintainers

Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining Signed-off-by messages.

Signed-off-by: Ramir Sultanov <ramir0.sultanov@gmail.com>
@github-actions github-actions bot added the 🏛️ ionic Gazebo Ionic label Sep 19, 2024
auto msgRep =
google::protobuf::DynamicCastMessage<Rep>(&_msgRep);

// Verify the dynamically casted messages are valid
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to move this block of verifications after all the ifdefs? That way we could validate all versions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is me being extra cautious to not break parts of code that already work. After checking the source code of protobuf, I found that google::protobuf::Message::GetDescriptor() and google::protobuf::Descriptor::full_name() functions were in the initial commit. Assuming, they were not removed after that, I think, it is safe to validate messages using the specified block of code. The changes can be found in the corresponding commit.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@caguero any thoughts?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is safe.

Signed-off-by: Ramir Sultanov <ramir0.sultanov@gmail.com>
@oysstu
Copy link

oysstu commented Oct 29, 2024

Currently hitting this issue. Would be great if a backport to transport13 could be considered as well.

auto msgRep =
google::protobuf::DynamicCastMessage<Rep>(&_msgRep);

// Verify the dynamically casted messages are valid
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is safe.

@azeey
Copy link
Contributor

azeey commented Nov 5, 2024

The homebrew failures are due to osrf/homebrew-simulation#2834 related to Python tests, so I'll go ahead and merge this.

@azeey azeey merged commit 6256a56 into gazebosim:gz-transport14 Nov 5, 2024
9 of 10 checks passed
@azeey
Copy link
Contributor

azeey commented Nov 5, 2024

@Mergifyio backport gz-transport13

Copy link

mergify bot commented Nov 5, 2024

backport gz-transport13

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request Nov 5, 2024
* Add compatibility with protobuf 28

Signed-off-by: Ramir Sultanov <ramir0.sultanov@gmail.com>

* Add message verification after message down casts

Signed-off-by: Ramir Sultanov <ramir0.sultanov@gmail.com>

---------

Signed-off-by: Ramir Sultanov <ramir0.sultanov@gmail.com>
(cherry picked from commit 6256a56)
azeey pushed a commit that referenced this pull request Dec 16, 2024
* Add compatibility with protobuf 28

Signed-off-by: Ramir Sultanov <ramir0.sultanov@gmail.com>

* Add message verification after message down casts

Signed-off-by: Ramir Sultanov <ramir0.sultanov@gmail.com>

---------

Signed-off-by: Ramir Sultanov <ramir0.sultanov@gmail.com>
(cherry picked from commit 6256a56)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏛️ ionic Gazebo Ionic
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants