From 9129656082890abcef660768e5133cbb0dfe74a7 Mon Sep 17 00:00:00 2001 From: Oren Leiman Date: Wed, 7 Aug 2024 11:21:21 -0700 Subject: [PATCH] serde: Require T::serde_fields OR arity <= 1 for all envelopes Applies only if a field tuple is actually needed by a particular envelope. For example, if a struct T implements both serde_read and serde_write, the field tuple is not needed, so T::serde_fields is not required. --- src/v/serde/envelope_for_each_field.h | 159 +------------------------- 1 file changed, 4 insertions(+), 155 deletions(-) diff --git a/src/v/serde/envelope_for_each_field.h b/src/v/serde/envelope_for_each_field.h index 935a2d8ab7907..57d6e288da0dd 100644 --- a/src/v/serde/envelope_for_each_field.h +++ b/src/v/serde/envelope_for_each_field.h @@ -36,167 +36,16 @@ constexpr inline auto envelope_to_tuple(T& t) { static_assert(std::is_standard_layout_v); static_assert(!std::is_polymorphic_v); + // TODO(oren): template error here is not very clear. an assert is probably + // the best we can do, but in practice the error is not much easier to + // understand + constexpr auto const a = reflection::arity() - 1; if constexpr (a == 0) { return std::tie(); } else if constexpr (a == 1) { auto& [p1] = t; return std::tie(p1); - } else if constexpr (a == 2) { - auto& [p1, p2] = t; - return std::tie(p1, p2); - } else if constexpr (a == 3) { - auto& [p1, p2, p3] = t; - return std::tie(p1, p2, p3); - } else if constexpr (a == 4) { - auto& [p1, p2, p3, p4] = t; - return std::tie(p1, p2, p3, p4); - } else if constexpr (a == 5) { - auto& [p1, p2, p3, p4, p5] = t; - return std::tie(p1, p2, p3, p4, p5); - } else if constexpr (a == 6) { - auto& [p1, p2, p3, p4, p5, p6] = t; - return std::tie(p1, p2, p3, p4, p5, p6); - } else if constexpr (a == 7) { - auto& [p1, p2, p3, p4, p5, p6, p7] = t; - return std::tie(p1, p2, p3, p4, p5, p6, p7); - } else if constexpr (a == 8) { - auto& [p1, p2, p3, p4, p5, p6, p7, p8] = t; - return std::tie(p1, p2, p3, p4, p5, p6, p7, p8); - } else if constexpr (a == 9) { - auto& [p1, p2, p3, p4, p5, p6, p7, p8, p9] = t; - return std::tie(p1, p2, p3, p4, p5, p6, p7, p8, p9); - } else if constexpr (a == 10) { - auto& [p1, p2, p3, p4, p5, p6, p7, p8, p9, p10] = t; - return std::tie(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10); - } else if constexpr (a == 11) { - auto& [p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11] = t; - return std::tie(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11); - } else if constexpr (a == 12) { - auto& [p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12] = t; - return std::tie(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12); - } else if constexpr (a == 13) { - auto& [p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13] = t; - return std::tie(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13); - } else if constexpr (a == 14) { - auto& [p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14] = t; - return std::tie( - p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14); - } else if constexpr (a == 15) { - auto& [p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15] - = t; - return std::tie( - p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15); - } else if constexpr (a == 16) { - auto& [p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16] - = t; - return std::tie( - p1, - p2, - p3, - p4, - p5, - p6, - p7, - p8, - p9, - p10, - p11, - p12, - p13, - p14, - p15, - p16); - } else if constexpr (a == 17) { - auto& [p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16, p17] - = t; - return std::tie( - p1, - p2, - p3, - p4, - p5, - p6, - p7, - p8, - p9, - p10, - p11, - p12, - p13, - p14, - p15, - p16, - p17); - } else if constexpr (a == 18) { - auto& [p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16, p17, p18] - = t; - return std::tie( - p1, - p2, - p3, - p4, - p5, - p6, - p7, - p8, - p9, - p10, - p11, - p12, - p13, - p14, - p15, - p16, - p17, - p18); - } else if constexpr (a == 19) { - auto& [p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16, p17, p18, p19] - = t; - return std::tie( - p1, - p2, - p3, - p4, - p5, - p6, - p7, - p8, - p9, - p10, - p11, - p12, - p13, - p14, - p15, - p16, - p17, - p18, - p19); - } else if constexpr (a == 20) { - auto& [p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16, p17, p18, p19, p20] - = t; - return std::tie( - p1, - p2, - p3, - p4, - p5, - p6, - p7, - p8, - p9, - p10, - p11, - p12, - p13, - p14, - p15, - p16, - p17, - p18, - p19, - p20); } }