fields builder
This commit is contained in:
@@ -4,18 +4,10 @@
|
|||||||
#include <sp/protocol/Field.h>
|
#include <sp/protocol/Field.h>
|
||||||
#include <sp/protocol/MessageBase.h>
|
#include <sp/protocol/MessageBase.h>
|
||||||
|
|
||||||
enum PacketId {
|
|
||||||
KeepAlive = 0,
|
|
||||||
};
|
|
||||||
|
|
||||||
enum KeepAlivePacketFields {
|
enum KeepAlivePacketFields {
|
||||||
KeepAliveId = 0
|
KeepAliveId = 0
|
||||||
};
|
};
|
||||||
|
|
||||||
using KeepAliveFields = std::tuple<sp::Field<std::uint64_t>>;
|
using KeepAliveFields = sp::FieldsBuilder<std::uint64_t>::Type;
|
||||||
|
|
||||||
class KeepAlivePacket : public sp::MessageBase<sp::PacketMessage,
|
DeclarePacket(KeepAlive);
|
||||||
sp::option::StaticNumIdImpl<KeepAlive>, // provide idImpl() if needed
|
|
||||||
sp::option::DispatchImpl<KeepAlivePacket>, // provide dispatchImpl() if needed
|
|
||||||
sp::option::FieldsImpl<KeepAliveFields> // provide access to fields
|
|
||||||
> {};
|
|
||||||
@@ -1,5 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
enum PacketId {
|
||||||
|
KeepAlive
|
||||||
|
};
|
||||||
|
|
||||||
#include <examples/KeepAlivePacket.h>
|
#include <examples/KeepAlivePacket.h>
|
||||||
|
|
||||||
using AllPackets = std::tuple<KeepAlivePacket>;
|
using AllPackets = std::tuple<KeepAlivePacket>;
|
||||||
|
|||||||
@@ -13,4 +13,10 @@ using PacketMessage = Message<
|
|||||||
option::Handler<PacketHandler> // add dispatch() operation
|
option::Handler<PacketHandler> // add dispatch() operation
|
||||||
>;
|
>;
|
||||||
|
|
||||||
|
#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
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <sp/common/DataBuffer.h>
|
#include <sp/common/DataBuffer.h>
|
||||||
|
#include <sp/protocol/Templates.h>
|
||||||
|
|
||||||
namespace sp {
|
namespace sp {
|
||||||
|
|
||||||
@@ -62,4 +63,18 @@ class FieldWriter {
|
|||||||
DataBuffer& m_Buffer;
|
DataBuffer& m_Buffer;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <typename... TFields>
|
||||||
|
struct FieldsBuilder {};
|
||||||
|
|
||||||
|
template <>
|
||||||
|
struct FieldsBuilder<> {
|
||||||
|
using Type = std::tuple<>;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename TField, typename... TFields>
|
||||||
|
struct FieldsBuilder<TField, TFields...> {
|
||||||
|
using Type = sp::tuple_cat_t<std::tuple<Field<TField>>, typename FieldsBuilder<TFields...>::Type>;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
} // namespace sp
|
} // namespace sp
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ int main() {
|
|||||||
KeepAliveHandler handler;
|
KeepAliveHandler handler;
|
||||||
msg->Dispatch(handler);
|
msg->Dispatch(handler);
|
||||||
|
|
||||||
|
//TODO: constructor
|
||||||
keepAlive->GetField<KeepAliveId>() = 69;
|
keepAlive->GetField<KeepAliveId>() = 69;
|
||||||
sp::DataBuffer buffer;
|
sp::DataBuffer buffer;
|
||||||
msg->Write(buffer);
|
msg->Write(buffer);
|
||||||
|
|||||||
Reference in New Issue
Block a user