Skip to content

Conversation

@pgeier
Copy link
Contributor

@pgeier pgeier commented Nov 18, 2025

Description

This PR is using the recently added CodesHandle in the CodesContent to avoid using eccodes headers directly.

The MallocCodesContent has been removed as it had wrong behaviour - after a modification to the handle in returned the old data array.
Depending downstream dependencies are fdb - a separate PR (ecmwf/fdb#198) - unfortunately we can not test the CI using both.

Contributor Declaration

By opening this pull request, I affirm the following:

  • All authors agree to the Contributor License Agreement.
  • The code follows the project's coding standards.
  • I have performed self-review and added comments where needed.
  • I have added or updated tests to verify that my changes are effective and functional.
  • I have run all existing tests and confirmed they pass.

@codecov-commenter
Copy link

codecov-commenter commented Nov 18, 2025

Codecov Report

❌ Patch coverage is 48.21429% with 29 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.84%. Comparing base (b618639) to head (9eb32f2).

Files with missing lines Patch % Lines
src/metkit/codes/CodesContent.cc 27.27% 16 Missing ⚠️
src/metkit/codes/BUFRDecoder.cc 0.00% 4 Missing ⚠️
src/metkit/codes/api/CodesAPI.cc 55.55% 4 Missing ⚠️
src/metkit/codes/GRIBDecoder.cc 25.00% 3 Missing ⚠️
src/metkit/codes/BufrContent.cc 33.33% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #128      +/-   ##
===========================================
+ Coverage    70.51%   70.84%   +0.32%     
===========================================
  Files          132      133       +1     
  Lines         8107     8058      -49     
  Branches       781      779       -2     
===========================================
- Hits          5717     5709       -8     
+ Misses        2390     2349      -41     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Ozaq Ozaq self-requested a review November 20, 2025 08:01
@pgeier pgeier force-pushed the feature/METK-145-Refactor-CodesContent branch 3 times, most recently from 330cf6c to 4329de1 Compare November 20, 2025 11:08
using Type = std::decay_t<decltype(v)>;
if constexpr (std::is_same_v<Type, std::string> || std::is_arithmetic_v<Type>) {
gather.setValue(name, std::forward<decltype(v)>(v));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Please emit an error message if an unexpected type is encountered.

Comment on lines 276 to 278
/// Return the pointer to the underlying buffer
/// @return Contiguous array to the underlying buffer.
/// @see messageSize()
Copy link
Contributor

Choose a reason for hiding this comment

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

Please mention the lifetime of Span

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

virtual Span<const uint8_t> messageData() const = 0;

/// Retrieve binary size of the handled message.
/// @return Offset of the message in the underlying buffer.
Copy link
Contributor

Choose a reason for hiding this comment

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

offset in bytes...

int err = 0;
void* data = wmo_read_any_from_stream_malloc(&handle_, &readcb, &size, &err);
int err = 0;
auto deleter = [&](uint8_t* ptr) { ::free(ptr); };
Copy link
Contributor

@Ozaq Ozaq Nov 20, 2025

Choose a reason for hiding this comment

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

Please use named captures and capture by value. Capturing by reference is save in this case but it leaves a bit of a refactoring trap if data is ever returned from the function you get a dangling reference from inside the lambda.

On a second look: remove the ampersand, you are not capturing anything.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.


return eckit::message::Message(new MallocCodesContent(data, size, 0));
return eckit::message::Message(
new CodesContent(codesHandleFromMessageCopy({static_cast<const uint8_t*>(data.get()), size})));
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to run this past @simondsmart because we might impact performance due to the additional copy.

@pgeier pgeier force-pushed the feature/METK-145-Refactor-CodesContent branch 2 times, most recently from 7e50702 to 86f2a5a Compare November 20, 2025 14:02
@pgeier pgeier force-pushed the feature/METK-145-Refactor-CodesContent branch from 86f2a5a to 9eb32f2 Compare November 20, 2025 14:03
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.

4 participants