diff --git a/src/core/enum_type.hpp b/src/core/enum_type.hpp index 10fa7c9485..9a3c8ae93c 100644 --- a/src/core/enum_type.hpp +++ b/src/core/enum_type.hpp @@ -193,6 +193,15 @@ public: return EnumBitSet{static_cast(this->data & other.data)}; } + /** + * Retrieve the raw value behind this EnumBitSet. + * @returns the raw value. + */ + inline constexpr Tstorage base() const noexcept + { + return this->data; + } + private: Tstorage data; ///< Bitmask of enum values. }; diff --git a/src/misc/endian_buffer.hpp b/src/misc/endian_buffer.hpp index 7662ad8d5f..ba59d4fd14 100644 --- a/src/misc/endian_buffer.hpp +++ b/src/misc/endian_buffer.hpp @@ -12,6 +12,7 @@ #include #include "../core/bitmath_func.hpp" +#include "../core/enum_type.hpp" #include "../core/overflowsafe_type.hpp" struct StrongTypedefBase; @@ -36,6 +37,9 @@ public: EndianBufferWriter &operator <<(std::string_view data) { this->Write(data); return *this; } EndianBufferWriter &operator <<(bool data) { return *this << static_cast(data ? 1 : 0); } + template + EndianBufferWriter &operator <<(const EnumBitSet &data) { return *this << data.base(); } + template EndianBufferWriter &operator <<(const OverflowSafeInt &data) { return *this << static_cast(data); }; @@ -130,6 +134,9 @@ public: EndianBufferReader &operator >>(std::string &data) { data = this->ReadStr(); return *this; } EndianBufferReader &operator >>(bool &data) { data = this->Read() != 0; return *this; } + template + EndianBufferReader &operator >>(EnumBitSet &data) { data = Tenum{this->Read()}; return *this; } + template EndianBufferReader &operator >>(OverflowSafeInt &data) { data = this->Read(); return *this; };