From c3a54d8e5b59f1df48360382af7f0a0701b30dd7 Mon Sep 17 00:00:00 2001 From: Persson-dev Date: Thu, 6 Feb 2025 16:14:11 +0100 Subject: [PATCH] cleaner example --- include/examples/KeepAlivePacket.h | 21 +++++++++++++++++++++ include/examples/PacketExample.h | 16 +--------------- src/main.cpp | 14 +++++++++++++- 3 files changed, 35 insertions(+), 16 deletions(-) create mode 100644 include/examples/KeepAlivePacket.h diff --git a/include/examples/KeepAlivePacket.h b/include/examples/KeepAlivePacket.h new file mode 100644 index 0000000..980ffa1 --- /dev/null +++ b/include/examples/KeepAlivePacket.h @@ -0,0 +1,21 @@ +#pragma once + +#include +#include +#include + +enum PacketId { + KeepAlive = 0, +}; + +enum KeepAlivePacketFields { + KeepAliveId = 0 +}; + +using KeepAliveFields = std::tuple>; + +class KeepAlivePacket : public sp::MessageBase, // provide idImpl() if needed + sp::option::DispatchImpl, // provide dispatchImpl() if needed + sp::option::FieldsImpl // provide access to fields + > {}; \ No newline at end of file diff --git a/include/examples/PacketExample.h b/include/examples/PacketExample.h index da9fbec..c4f068d 100644 --- a/include/examples/PacketExample.h +++ b/include/examples/PacketExample.h @@ -1,20 +1,6 @@ #pragma once -#include -#include -#include - -enum PacketId { - KeepAlive = 0, -}; - -using KeepAliveFields = std::tuple>; - -class KeepAlivePacket : public sp::MessageBase, // provide idImpl() if needed - sp::option::DispatchImpl, // provide dispatchImpl() if needed - sp::option::FieldsImpl // provide access to fields - > {}; +#include using AllPackets = std::tuple; diff --git a/src/main.cpp b/src/main.cpp index 7f2a44a..9c0f3e3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -10,8 +10,20 @@ class KeepAliveHandler : public sp::PacketHandler { }; int main() { - std::unique_ptr msg = std::make_unique(); + auto keepAlive = std::make_unique(); + sp::PacketMessage* msg = keepAlive.get(); + KeepAliveHandler handler; msg->Dispatch(handler); + + keepAlive->GetField() = 69; + sp::DataBuffer buffer; + msg->Write(buffer); + + auto keepAlive2 = std::make_unique(); + keepAlive2->Read(buffer); + + std::cout << "KeepAlive2 : " << keepAlive2->GetField() << "\n"; + return 0; } \ No newline at end of file