Consider enum values when computing protocol hash
This commit is contained in:
@@ -29,6 +29,7 @@
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
#include <magic_enum.hpp>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <span>
|
#include <span>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
@@ -495,6 +496,20 @@ struct serialization_traits<T, std::enable_if_t<std::is_enum_v<T>>>
|
|||||||
{
|
{
|
||||||
h.feed("enum");
|
h.feed("enum");
|
||||||
h.feed(sizeof(T) * 8);
|
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)
|
static void serialize(T value, serialization_packet & packet)
|
||||||
|
|||||||
@@ -51,4 +51,12 @@ struct test
|
|||||||
float y;
|
float y;
|
||||||
};
|
};
|
||||||
static_assert(serialization_type_hash<test>(0) == hash("structure{int32,float32}"));
|
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
|
} // namespace
|
||||||
|
|||||||
Reference in New Issue
Block a user