This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
#include <sp/protocol/ConcreteMessage.h>
|
||||
#include <sp/protocol/GenericHandler.h>
|
||||
#include <sp/protocol/MessageDispatcher.h>
|
||||
#include <sp/protocol/MessageFactory.h>
|
||||
#include <sp/protocol/MessageHandler.h>
|
||||
#include <sp/io/MessageStream.h>
|
||||
#include <sp/io/StdIo.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
@@ -24,12 +26,12 @@ using KeepAliveMessage = Message<KeepAlivePacket, PacketID::KeepAlive>;
|
||||
|
||||
using AllMessages = std::tuple<KeepAliveMessage>;
|
||||
|
||||
class PacketHandler : public sp::GenericHandler<AllMessages> {};
|
||||
class PacketHandler : public sp::MessageHandler<AllMessages> {};
|
||||
|
||||
class MyHandler : public PacketHandler {
|
||||
public:
|
||||
virtual void Handle(const KeepAliveMessage& msg) {
|
||||
std::cout << "yo !" << "\n";
|
||||
virtual void Handle(const KeepAlivePacket& msg) {
|
||||
std::cout << "I recieved a keep alive : " << msg.m_KeepAlive << "\n";
|
||||
}
|
||||
};
|
||||
|
||||
@@ -37,8 +39,10 @@ using PacketDispatcher = sp::MessageDispatcher<PacketBase>;
|
||||
|
||||
using PacketFactory = sp::MessageFactory<PacketBase, AllMessages>;
|
||||
|
||||
using PacketStream = sp::MessageStream<PacketFactory>;
|
||||
|
||||
int main() {
|
||||
KeepAliveMessage m{5UL};
|
||||
KeepAliveMessage m{69UL};
|
||||
|
||||
// dispatch tests
|
||||
|
||||
@@ -56,9 +60,23 @@ int main() {
|
||||
|
||||
std::ofstream file {"test.bin"};
|
||||
|
||||
message->Write(file);
|
||||
PacketStream p(std::make_shared<sp::StdOuput>(file));
|
||||
|
||||
p.WriteMessage(m);
|
||||
|
||||
file.flush();
|
||||
|
||||
std::ifstream file2 {"test.bin"};
|
||||
|
||||
PacketStream p2(std::make_shared<sp::StdInput>(file2));
|
||||
|
||||
auto message2 = p2.ReadMessage();
|
||||
|
||||
d.Dispatch(*message2);
|
||||
|
||||
// message->Write(file);
|
||||
// file << std::endl;
|
||||
m.Write(file);
|
||||
// m.Write(file);
|
||||
// file << std::endl;
|
||||
// message->Read(file);
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user