Consider enum values when computing protocol hash

This commit is contained in:
Guillaume Meunier
2026-07-26 21:15:22 +02:00
parent 66a2ffda82
commit b33de5ef4b
2 changed files with 23 additions and 0 deletions
+15
View File
@@ -29,6 +29,7 @@
#include <cstdint>
#include <cstring>
#include <limits>
#include <magic_enum.hpp>
#include <optional>
#include <span>
#include <stdexcept>
@@ -495,6 +496,20 @@ struct serialization_traits<T, std::enable_if_t<std::is_enum_v<T>>>
{
h.feed("enum");
h.feed(sizeof(T) * 8);
h.feed("{");
bool first = true;
for (auto [value, name]: magic_enum::enum_entries<T>())
{
if (not first)
h.feed(",");
first = false;
h.feed(name);
h.feed("=");
h.feed((std::underlying_type_t<T>)value);
}
h.feed("}");
}
static void serialize(T value, serialization_packet & packet)
+8
View File
@@ -51,4 +51,12 @@ struct test
float y;
};
static_assert(serialization_type_hash<test>(0) == hash("structure{int32,float32}"));
enum test_enum : uint32_t
{
foo,
bar,
foobar = 42
};
static_assert(serialization_type_hash<test_enum>(0) == hash("enum32{foo=0,bar=1,foobar=42}"));
} // namespace