finish io
All checks were successful
Linux arm64 / Build (push) Successful in 19s

This commit is contained in:
2025-06-27 18:53:03 +02:00
parent 0d26879152
commit ed0b06f78d
11 changed files with 443 additions and 54 deletions

View File

@@ -5,6 +5,8 @@
#include <sp/io/MessageStream.h>
#include <sp/io/StdIo.h>
#include <sp/extensions/Compress.h>
#include <cstdint>
#include <iostream>
#include <fstream>
@@ -20,6 +22,7 @@ using Message = sp::ConcreteMessage<TData, PacketID, ID, PacketHandler>;
struct KeepAlivePacket {
std::uint64_t m_KeepAlive;
std::string mdc;
};
using KeepAliveMessage = Message<KeepAlivePacket, PacketID::KeepAlive>;
@@ -31,7 +34,7 @@ class PacketHandler : public sp::MessageHandler<AllMessages> {};
class MyHandler : public PacketHandler {
public:
virtual void Handle(const KeepAlivePacket& msg) {
std::cout << "I recieved a keep alive : " << msg.m_KeepAlive << "\n";
std::cout << "I recieved a keep alive : " << msg.m_KeepAlive << " : " << msg.mdc << "\n";
}
};
@@ -42,7 +45,7 @@ using PacketFactory = sp::MessageFactory<PacketBase, AllMessages>;
using PacketStream = sp::MessageStream<PacketFactory>;
int main() {
KeepAliveMessage m{69UL};
KeepAliveMessage m{69UL, "ceci est une mdc aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"};
// dispatch tests
@@ -58,9 +61,11 @@ int main() {
// write tests
auto compress = std::make_shared<sp::ZlibCompress>();
std::ofstream file {"test.bin"};
PacketStream p(std::make_shared<sp::StdOuput>(file));
PacketStream p(std::make_shared<sp::StdOuput>(file), compress);
p.WriteMessage(m);
@@ -68,7 +73,7 @@ int main() {
std::ifstream file2 {"test.bin"};
PacketStream p2(std::make_shared<sp::StdInput>(file2));
PacketStream p2(std::make_shared<sp::StdInput>(file2), compress);
auto message2 = p2.ReadMessage();