alignment #1

Merged
Persson-dev merged 19 commits from alignment into main 2025-02-23 09:40:46 +00:00
5 changed files with 20 additions and 8 deletions
Showing only changes of commit 66835554f1 - Show all commits

View File

@@ -4,7 +4,7 @@
#include <sp/protocol/Field.h>
#include <sp/protocol/MessageBase.h>
enum DisconnectPacketFields {
enum class DisconnectFieldsE {
Reason = 0
};
@@ -15,6 +15,6 @@ DeclarePacket(Disconnect){
PacketConstructor(Disconnect)
const std::string& GetReason() const {
return GetField<Reason>();
return GetField<DisconnectFieldsE, DisconnectFieldsE::Reason>();
}
};

View File

@@ -4,9 +4,8 @@
#include <sp/protocol/Field.h>
#include <sp/protocol/MessageBase.h>
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<KeepAlive>();
return GetField<KeepAliveFieldsE, KeepAliveFieldsE::KeepAliveId>();
}
};

View File

@@ -4,7 +4,8 @@
#include <sp/protocol/Field.h>
#include <sp/protocol/MessageBase.h>
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<m_Tower>();
return GetField<0>().GetField<UpgradeTowerFieldsE, UpgradeTowerFieldsE::m_Tower>();
}
std::uint8_t GetTowerUpgrade() const {
return GetField<0>().GetField<m_Upgrade>();
return GetField<0>().GetField<UpgradeTowerFieldsE, UpgradeTowerFieldsE::m_Upgrade>();
}
};

View File

@@ -45,6 +45,12 @@ class BitField {
return std::get<FIndex>(this->GetFields()).GetValue();
}
// allow use of enums
template <typename E, E FIndex>
const auto& GetField() const {
return std::get<static_cast<std::size_t>(FIndex)>(this->GetFields()).GetValue();
}
private:
template <int IOffset, typename... T, std::enable_if_t<IOffset >= sizeof...(T), bool> = true>
void Apply(const std::tuple<T...>& args) {}

View File

@@ -119,6 +119,12 @@ class MessageImplFieldsBase : public TBase {
return std::get<FIndex>(GetFields()).GetValue();
}
// allow use of enums
template <typename E, E FIndex>
const auto& GetField() const {
return std::get<static_cast<std::size_t>(FIndex)>(this->GetFields()).GetValue();
}
private:
AllFields m_Fields;
};