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

Use DynamicCastMessage instead of dynamic_cast to downcast protos in … #2446

Closed
wants to merge 3 commits into from
Closed

Conversation

shameekganguly
Copy link
Contributor

🦟 Bug fix

Summary

The UserCommands system uses built-in dynamic_cast to downcast proto messages. However the currently recommended cast method for protos is DynamicCastMessage: https://github.com/protocolbuffers/protobuf/blob/40ffd46cec1291e1320e46a134c47dd23a74ff43/src/google/protobuf/message_lite.h#L1018

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.

…UserCommands system

Signed-off-by: Shameek Ganguly <shameekarcanesphinx@gmail.com>
@github-actions github-actions bot added the 🎵 harmonic Gazebo Harmonic label Jun 16, 2024
Signed-off-by: Shameek Ganguly <shameekarcanesphinx@gmail.com>
Signed-off-by: Shameek Ganguly <shameekarcanesphinx@gmail.com>
@azeey
Copy link
Contributor

azeey commented Jun 17, 2024

The version of protobuf we use in Ubuntu Jammy and Noble doesn't have this function.

@scpeters
Copy link
Member

The version of protobuf we use in Ubuntu Jammy and Noble doesn't have this function.

This was pushed to protobuf's main branch 3 weeks ago in protocolbuffers/protobuf@18da465. It looks like that renamed the API from DynamicCastToGenerated to DynamicCastMessage, but it has not yet had a stable release. It was not included in v27.1, so I think we could assume it will be in v28.0. We could add an #ifdef based on the protobuf version to select between these APIs instead of dynamic_cast.

@shameekganguly
Copy link
Contributor Author

Yep, seems that way. Its ok, I'll add the methods to copybara when sync'ing to the internal repo for now and drop the PR. We can revisit it in a year. Adding an ifdef everywhere will really hamper code readability.

@scpeters
Copy link
Member

Adding an ifdef everywhere will really hamper code readability.

we could potentially define a type alias with using inside an ifdef in one place instead of using ifdefs all over, so it could still be readable

@scpeters
Copy link
Member

Adding an ifdef everywhere will really hamper code readability.

we could potentially define a type alias with using inside an ifdef in one place instead of using ifdefs all over, so it could still be readable

actually DynamicCastMessage isn't a class, so I don't think we could do a template type alias. I think we'd probably have to use a macro, which isn't ideal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🎵 harmonic Gazebo Harmonic
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants