diff --git a/include/examples/DisconnectPacket.h b/include/examples/DisconnectPacket.h index ae61f43..013f7f0 100644 --- a/include/examples/DisconnectPacket.h +++ b/include/examples/DisconnectPacket.h @@ -4,7 +4,7 @@ #include #include -enum DisconnectPacketFields { +enum class DisconnectFieldsE { Reason = 0 }; @@ -15,6 +15,6 @@ DeclarePacket(Disconnect){ PacketConstructor(Disconnect) const std::string& GetReason() const { - return GetField(); + return GetField(); } }; diff --git a/include/examples/KeepAlivePacket.h b/include/examples/KeepAlivePacket.h index fe6c266..770b078 100644 --- a/include/examples/KeepAlivePacket.h +++ b/include/examples/KeepAlivePacket.h @@ -4,9 +4,8 @@ #include #include -enum KeepAlivePacketFields { +enum class KeepAliveFieldsE { KeepAliveId = 0, - TestAlignField = 1, }; using KeepAliveFields = std::tuple< @@ -18,6 +17,6 @@ DeclarePacket(KeepAlive){ PacketConstructor(KeepAlive) std::uint64_t GetKeepAliveId() const { - return GetField(); + return GetField(); } }; \ No newline at end of file diff --git a/include/examples/UpgradeTowerPacket.h b/include/examples/UpgradeTowerPacket.h index d54e692..de69cdf 100644 --- a/include/examples/UpgradeTowerPacket.h +++ b/include/examples/UpgradeTowerPacket.h @@ -4,7 +4,8 @@ #include #include -enum UpgradeTowerPacketFields { + +enum class UpgradeTowerFieldsE { m_Tower = 0, m_Upgrade, }; @@ -21,10 +22,10 @@ DeclarePacket(UpgradeTower){ PacketConstructor(UpgradeTower) std::uint16_t GetTowerId() const { - return GetField<0>().GetField(); + return GetField<0>().GetField(); } std::uint8_t GetTowerUpgrade() const { - return GetField<0>().GetField(); + return GetField<0>().GetField(); } }; \ No newline at end of file diff --git a/include/sp/protocol/Field.h b/include/sp/protocol/Field.h index dc1f702..f0a05dd 100644 --- a/include/sp/protocol/Field.h +++ b/include/sp/protocol/Field.h @@ -45,6 +45,12 @@ class BitField { return std::get(this->GetFields()).GetValue(); } + // allow use of enums + template + const auto& GetField() const { + return std::get(FIndex)>(this->GetFields()).GetValue(); + } + private: template = sizeof...(T), bool> = true> void Apply(const std::tuple& args) {} diff --git a/include/sp/protocol/MessageBase.h b/include/sp/protocol/MessageBase.h index ce9a798..61f4947 100644 --- a/include/sp/protocol/MessageBase.h +++ b/include/sp/protocol/MessageBase.h @@ -119,6 +119,12 @@ class MessageImplFieldsBase : public TBase { return std::get(GetFields()).GetValue(); } + // allow use of enums + template + const auto& GetField() const { + return std::get(FIndex)>(this->GetFields()).GetValue(); + } + private: AllFields m_Fields; };