mirror of
https://github.com/WiVRn/WiVRn.git
synced 2026-11-29 05:13:07 -08:00
Consider enum values when computing protocol hash
This commit is contained in:
1 parent
66a2ffda82
commit
b33de5ef4b
2 files changed
+23
No files matched your search
@@ -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)
|
||||
|
||||
@@ -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
|
||||
Reference in new issue
Block a user