add file interface

This commit is contained in:
2025-02-26 00:01:51 +01:00
parent 132c3c3c8d
commit a2eb10ec6d
3 changed files with 75 additions and 0 deletions

37
test/test_file.cpp Normal file
View File

@@ -0,0 +1,37 @@
#include <iostream>
#include <examples/PacketExample.h>
#include <sp/io/FileIO.h>
class CustomPacketHandler : public sp::PacketHandler {
void Handle(const KeepAlivePacket& packet) {
std::cout << "KeepAlive handled ! " << packet.GetKeepAliveId() << "\n";
}
void Handle(const DisconnectPacket& packet) {
std::cout << "Disconnect handled ! " << packet.GetReason() << "\n";
}
void Handle(const UpgradeTowerPacket& packet) {
std::cout << "UpgradeTower handled !\n";
}
};
using FileStream = sp::IOStream<sp::FileTag, sp::PacketDispatcher, sp::PacketFactory>;
int main() {
auto handler = std::make_shared<CustomPacketHandler>();
FileStream stream(sp::FileIO{"test.txt"});
stream.GetDispatcher().RegisterHandler(PacketId::Disconnect, handler);
stream.GetDispatcher().RegisterHandler(PacketId::KeepAlive, handler);
stream.SendMessage(KeepAlivePacket{96});
stream.SendMessage(KeepAlivePacket{69});
stream.SendMessage(DisconnectPacket{"This is in the file !"});
stream.RecieveMessages();
return 0;
}