fix alignment + refactor
Reviewed-on: #1 Co-authored-by: Persson-dev <sim16.prib@gmail.com> Co-committed-by: Persson-dev <sim16.prib@gmail.com>
This commit was merged in pull request #1.
This commit is contained in:
@@ -4,10 +4,17 @@
|
||||
#include <sp/protocol/Field.h>
|
||||
#include <sp/protocol/MessageBase.h>
|
||||
|
||||
enum DisconnectPacketFields {
|
||||
Reason = 0
|
||||
enum class DisconnectFieldsE {
|
||||
Reason = 0
|
||||
};
|
||||
|
||||
using DisconnectFields = std::tuple<std::string /*Reason*/>;
|
||||
|
||||
DeclarePacket(Disconnect);
|
||||
DeclarePacket(Disconnect){
|
||||
public:
|
||||
PacketConstructor(Disconnect)
|
||||
|
||||
const std::string& GetReason() const {
|
||||
return GetField<DisconnectFieldsE, DisconnectFieldsE::Reason>();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -4,10 +4,19 @@
|
||||
#include <sp/protocol/Field.h>
|
||||
#include <sp/protocol/MessageBase.h>
|
||||
|
||||
enum KeepAlivePacketFields {
|
||||
KeepAliveId = 0
|
||||
enum class KeepAliveFieldsE {
|
||||
KeepAliveId = 0,
|
||||
};
|
||||
|
||||
using KeepAliveFields = std::tuple<std::uint64_t /*KeepAliveId*/>;
|
||||
using KeepAliveFields = std::tuple<
|
||||
std::uint64_t //<- KeepAliveId
|
||||
>;
|
||||
|
||||
DeclarePacket(KeepAlive);
|
||||
DeclarePacket(KeepAlive){
|
||||
public:
|
||||
PacketConstructor(KeepAlive)
|
||||
|
||||
std::uint64_t GetKeepAliveId() const {
|
||||
return GetField<KeepAliveFieldsE, KeepAliveFieldsE::KeepAliveId>();
|
||||
}
|
||||
};
|
||||
@@ -3,13 +3,15 @@
|
||||
enum PacketId {
|
||||
KeepAlive = 0,
|
||||
Disconnect,
|
||||
UpgradeTower,
|
||||
};
|
||||
|
||||
#include <examples/KeepAlivePacket.h>
|
||||
#include <examples/DisconnectPacket.h>
|
||||
#include <examples/UpgradeTowerPacket.h>
|
||||
|
||||
// they must be in the same order !
|
||||
using AllPackets = std::tuple<KeepAlivePacket, DisconnectPacket>;
|
||||
// they must be in the same order as in the enum !
|
||||
using AllPackets = std::tuple<KeepAlivePacket, DisconnectPacket, UpgradeTowerPacket>;
|
||||
|
||||
#include <sp/default/DefaultPacketHandler.h>
|
||||
#include <sp/default/DefaultPacketFactory.h>
|
||||
31
include/examples/UpgradeTowerPacket.h
Normal file
31
include/examples/UpgradeTowerPacket.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include <sp/default/DefaultPacket.h>
|
||||
#include <sp/protocol/Field.h>
|
||||
#include <sp/protocol/MessageBase.h>
|
||||
|
||||
|
||||
enum class UpgradeTowerFieldsE {
|
||||
m_Tower = 0,
|
||||
m_Upgrade,
|
||||
};
|
||||
|
||||
using UpgradeTowerFields = std::tuple<
|
||||
sp::BitField<std::uint16_t,
|
||||
sp::Field<std::uint16_t, 12>, //<- m_Tower
|
||||
sp::Field<std::uint8_t, 4> //<- m_Upgrade
|
||||
>
|
||||
>;
|
||||
|
||||
DeclarePacket(UpgradeTower){
|
||||
public:
|
||||
PacketConstructor(UpgradeTower)
|
||||
|
||||
std::uint16_t GetTowerId() const {
|
||||
return GetField<0>().GetField<UpgradeTowerFieldsE, UpgradeTowerFieldsE::m_Tower>();
|
||||
}
|
||||
|
||||
std::uint8_t GetTowerUpgrade() const {
|
||||
return GetField<0>().GetField<UpgradeTowerFieldsE, UpgradeTowerFieldsE::m_Upgrade>();
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user