Skip to content

Commit

Permalink
Merge pull request #24853 from dotnwat/cpp23-fixes
Browse files Browse the repository at this point in the history
serde: fix c++23 enum handling
  • Loading branch information
dotnwat authored Jan 17, 2025
2 parents 564fbb5 + 954ffe7 commit 5615542
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
7 changes: 6 additions & 1 deletion src/v/cluster/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ struct partition_assignment
= default;
};

enum incremental_update_operation : int8_t { none, set, remove };
enum class incremental_update_operation : int8_t { none, set, remove };

inline std::string_view
incremental_update_operation_as_string(incremental_update_operation op) {
Expand All @@ -498,6 +498,11 @@ incremental_update_operation_as_string(incremental_update_operation op) {
}
}

inline std::ostream&
operator<<(std::ostream& os, const incremental_update_operation& op) {
return os << incremental_update_operation_as_string(op);
}

template<typename T>
struct property_update
: serde::envelope<
Expand Down
6 changes: 6 additions & 0 deletions src/v/serde/rw/enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ namespace serde {
template<typename T>
requires(serde_is_enum_v<std::decay_t<T>>)
void tag_invoke(tag_t<write_tag>, iobuf& out, T t) {
#if defined(__cpp_lib_is_scoped_enum) && __cpp_lib_is_scoped_enum >= 202011L
static_assert(std::is_scoped_enum_v<std::decay_t<T>>);
#endif
using Type = std::decay_t<T>;
const auto val = static_cast<std::underlying_type_t<Type>>(t);
if (unlikely(!std::in_range<serde_enum_serialized_t>(val))) {
Expand All @@ -41,6 +44,9 @@ template<typename T>
requires serde_is_enum_v<std::decay_t<T>>
void tag_invoke(
tag_t<read_tag>, iobuf_parser& in, T& t, const std::size_t bytes_left_limit) {
#if defined(__cpp_lib_is_scoped_enum) && __cpp_lib_is_scoped_enum >= 202011L
static_assert(std::is_scoped_enum_v<std::decay_t<T>>);
#endif
using Type = std::decay_t<T>;

const auto val = read_nested<serde_enum_serialized_t>(in, bytes_left_limit);
Expand Down
11 changes: 3 additions & 8 deletions src/v/serde/serde_is_enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,8 @@ namespace serde {
using serde_enum_serialized_t = int32_t;

template<typename T>
inline constexpr bool serde_is_enum_v =
#if defined(__cpp_lib_is_scoped_enum) && __cpp_lib_is_scoped_enum >= 202011L
std::is_scoped_enum_v<T>
&& sizeof(std::decay_t<T>) <= sizeof(serde_enum_serialized_t);
#else
std::is_enum_v<T>
&& sizeof(std::decay_t<T>) <= sizeof(serde_enum_serialized_t);
#endif
inline constexpr bool serde_is_enum_v = std::is_enum_v<T>
&& sizeof(std::decay_t<T>)
<= sizeof(serde_enum_serialized_t);

} // namespace serde
6 changes: 3 additions & 3 deletions src/v/transform/rpc/tests/transform_rpc_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,13 @@ class fake_topic_metadata_cache : public topic_metadata_cache {
// tests.
const auto& prop_update = update.properties.batch_max_bytes;
switch (prop_update.op) {
case cluster::none:
case cluster::incremental_update_operation::none:
return;
case cluster::set:
case cluster::incremental_update_operation::set:
config.properties.batch_max_bytes
= update.properties.batch_max_bytes.value;
break;
case cluster::remove:
case cluster::incremental_update_operation::remove:
config.properties.batch_max_bytes.reset();
break;
}
Expand Down

0 comments on commit 5615542

Please sign in to comment.