add file interface
This commit is contained in:
37
test/test_file.cpp
Normal file
37
test/test_file.cpp
Normal 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;
|
||||
}
|
||||
Reference in New Issue
Block a user