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 C++ conversion APIs to proto2ros #118

Merged
merged 8 commits into from
Sep 17, 2024
Merged

Conversation

mhidalgo-bdai
Copy link
Contributor

Precisely what the title says. We are almost there, I'm just missing the C++ test suite but conversion code compiles and looks correct on visual inspection. We can start the review.

{{ destination }}->Add(static_cast<{{ type_spec.annotations["proto-type"] | as_pb2_cpp_type }}>(item.value));
}
{%- else -%}
{{ destination | rreplace("mutable", "set", 1) | rreplace("()", "", 1) }}(
Copy link
Contributor Author

@mhidalgo-bdai mhidalgo-bdai Sep 13, 2024

Choose a reason for hiding this comment

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

I'm not super proud of this but the C++ API for Protobuf messages is so inconsistent across types that it hurts.

{%- set output_item = itemize_cpp_identifier(destination, "output_") -%}
{%- if type_spec and type_spec.annotations.get("map-entry") -%}{#- Handle map case. -#}
{{ destination }}->clear();
for (const auto& {{ input_item }} : {{ source }}) {
Copy link
Contributor Author

@mhidalgo-bdai mhidalgo-bdai Sep 13, 2024

Choose a reason for hiding this comment

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

Handling map fields was particularly hard. Python APIs for Protobuf messages expose the underlying sequence of key-value messages. C++ APIs hide them, and that forces all this special casing 🤦

LIBRARY DESTINATION lib
RUNTIME DESTINATION bin
)
ament_export_targets(export_${target}_conversions)
Copy link
Contributor Author

@mhidalgo-bdai mhidalgo-bdai Sep 13, 2024

Choose a reason for hiding this comment

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

Note for myself: this is likely incomplete, and will need a revisit when we try to re-build https://github.com/bdaiinstitute/bosdyn_msgs with this.

@mhidalgo-bdai
Copy link
Contributor Author

Hmm, something's off with generated Protobuf C++ code. It sometimes fails to preprocess some of it, but only in CI, I cannot reproduce it anywhere else 🤔

@mhidalgo-bdai mhidalgo-bdai merged commit e93bfc9 into main Sep 17, 2024
3 checks passed
@mhidalgo-bdai mhidalgo-bdai deleted the mhidalgo-bdai/proto2ros-cpp branch September 17, 2024 20:00
khughes-bdai pushed a commit that referenced this pull request Sep 24, 2024
Follow-up to #118. This patch makes `proto2ros` packages' C++ code comply with stricter `clang-tidy` configurations. It liberally disables some opinionated checks where appropriate.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants