alignment #1
@@ -4,10 +4,15 @@
|
|||||||
#include <sp/protocol/Field.h>
|
#include <sp/protocol/Field.h>
|
||||||
#include <sp/protocol/MessageBase.h>
|
#include <sp/protocol/MessageBase.h>
|
||||||
|
|
||||||
enum DisconnectPacketFields {
|
enum DisconnectPacketFields { Reason = 0 };
|
||||||
Reason = 0
|
|
||||||
};
|
|
||||||
|
|
||||||
using DisconnectFields = std::tuple<std::string /*Reason*/>;
|
using DisconnectFields = std::tuple<std::string /*Reason*/>;
|
||||||
|
|
||||||
DeclarePacket(Disconnect);
|
DeclarePacket(Disconnect){
|
||||||
|
public:
|
||||||
|
PacketConstructor(Disconnect)
|
||||||
|
|
||||||
|
const std::string& GetReason() const {
|
||||||
|
return GetField<Reason>();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
@@ -15,6 +15,21 @@ using KeepAliveFields = std::tuple<
|
|||||||
sp::Field<std::uint16_t, 12>, //<- m_Tower
|
sp::Field<std::uint16_t, 12>, //<- m_Tower
|
||||||
sp::Field<std::uint8_t, 4> //<- m_Upgrade
|
sp::Field<std::uint8_t, 4> //<- m_Upgrade
|
||||||
>
|
>
|
||||||
>;
|
>;
|
||||||
|
|
||||||
DeclarePacket(KeepAlive);
|
DeclarePacket(KeepAlive){
|
||||||
|
public:
|
||||||
|
PacketConstructor(KeepAlive)
|
||||||
|
|
||||||
|
std::uint64_t GetKeepAliveId() const {
|
||||||
|
return GetField<KeepAlive>();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::uint16_t GetTowerId() const {
|
||||||
|
return GetField<TestAlignField>().GetField<0>();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::uint8_t GetTowerUpgrade() const {
|
||||||
|
return GetField<TestAlignField>().GetField<1>();
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -13,15 +13,17 @@ using PacketMessage = Message<option::MsgIdType<std::uint8_t>, // add id() opera
|
|||||||
option::Handler<PacketHandler> // add dispatch() operation
|
option::Handler<PacketHandler> // add dispatch() operation
|
||||||
>;
|
>;
|
||||||
|
|
||||||
#define DeclarePacket(packetName) \
|
#define PacketConstructor(packetName) \
|
||||||
class packetName##Packet : public sp::MessageBase<sp::PacketMessage, sp::option::StaticNumIdImpl<packetName>, \
|
|
||||||
sp::option::DispatchImpl<packetName##Packet>, sp::option::FieldsImpl<packetName##Fields>> { \
|
|
||||||
public: \
|
|
||||||
packetName##Packet() {} \
|
packetName##Packet() {} \
|
||||||
template <typename... Args> \
|
template <typename... Args> \
|
||||||
packetName##Packet(Args... args) { \
|
packetName##Packet(Args... args) { \
|
||||||
Construct(args...); \
|
Construct(args...); \
|
||||||
} \
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define DeclarePacket(packetName) \
|
||||||
|
class packetName##Packet : public sp::MessageBase<sp::PacketMessage, sp::option::StaticNumIdImpl<packetName>, \
|
||||||
|
sp::option::DispatchImpl<packetName##Packet>, sp::option::FieldsImpl<packetName##Fields>>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace sp
|
} // namespace sp
|
||||||
|
|||||||
@@ -40,6 +40,11 @@ class BitField {
|
|||||||
return std::get<FIndex>(this->GetFields()).GetValue();
|
return std::get<FIndex>(this->GetFields()).GetValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <std::size_t FIndex>
|
||||||
|
const auto& GetField() const {
|
||||||
|
return std::get<FIndex>(this->GetFields()).GetValue();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
template <int IOffset, typename... T, std::enable_if_t<IOffset >= sizeof...(T), bool> = true>
|
template <int IOffset, typename... T, std::enable_if_t<IOffset >= sizeof...(T), bool> = true>
|
||||||
void Apply(const std::tuple<T...>& args) {}
|
void Apply(const std::tuple<T...>& args) {}
|
||||||
|
|||||||
@@ -114,6 +114,11 @@ class MessageImplFieldsBase : public TBase {
|
|||||||
return std::get<FIndex>(GetFields()).GetValue();
|
return std::get<FIndex>(GetFields()).GetValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <std::size_t FIndex>
|
||||||
|
const auto& GetField() const {
|
||||||
|
return std::get<FIndex>(GetFields()).GetValue();
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
AllFields m_Fields;
|
AllFields m_Fields;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -30,7 +30,10 @@ int main() {
|
|||||||
auto keepAlive2 = std::make_unique<KeepAlivePacket>();
|
auto keepAlive2 = std::make_unique<KeepAlivePacket>();
|
||||||
keepAlive2->Read(buffer);
|
keepAlive2->Read(buffer);
|
||||||
|
|
||||||
std::cout << "KeepAlive2 : " << keepAlive2->GetField<KeepAliveId>() << "\n";
|
std::cout << "KeepAlive2 : " << keepAlive2->GetKeepAliveId() << "\n";
|
||||||
|
|
||||||
|
keepAlive2->GetField<TestAlignField>().GetField<0>();
|
||||||
|
std::cout << "Test : " << (unsigned) keepAlive2->GetTowerId() << "\n";
|
||||||
|
|
||||||
sp::PacketFactory factory;
|
sp::PacketFactory factory;
|
||||||
auto packet = factory.CreateMessage(msgId);
|
auto packet = factory.CreateMessage(msgId);
|
||||||
|
|||||||
Reference in New Issue
Block a user