Skip to content

Commit

Permalink
serde: Require (serde_fields) XOR (explicit read and/or write)
Browse files Browse the repository at this point in the history
More precisely, if a serde envelope implements either serde_read
or serde_write, that envelope may not implement serde_fields.
  • Loading branch information
oleiman committed Sep 9, 2024
1 parent 9c47f75 commit 10e3f43
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/v/serde/rw/envelope.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ concept has_serde_read = requires(T t, iobuf_parser& in, const header& h) {
t.serde_read(in, h);
};

template<typename T>
concept has_serde_fields = requires(T t) { t.serde_fields(); };

template<typename T>
requires is_envelope<std::decay_t<T>>
void tag_invoke(
Expand Down Expand Up @@ -61,6 +64,7 @@ void tag_invoke(
}

if constexpr (has_serde_read<Type>) {
static_assert(!has_serde_fields<Type>);
t.serde_read(in, h);
} else {
envelope_for_each_field(t, [&](auto& f) {
Expand Down Expand Up @@ -104,6 +108,7 @@ void tag_invoke(tag_t<write_tag>, iobuf& out, T t) {

auto const size_before = out.size_bytes();
if constexpr (has_serde_write<Type>) {
static_assert(!has_serde_fields<Type>);
t.serde_write(out);
} else {
envelope_for_each_field(
Expand Down

0 comments on commit 10e3f43

Please sign in to comment.