working commit

This commit is contained in:
2026-04-23 17:53:50 +02:00
parent cf45872d91
commit 37d9ee63cc
18 changed files with 1476 additions and 1170 deletions
+20 -20
View File
@@ -13,37 +13,37 @@ extern "C" {
#include <header.hpp>
Header::Header(const uint32_t ipSize) {
pSize = ipSize;
pSize = ipSize;
}
Header::Header(void) {
pSize = 0;
pSize = 0;
}
std::string Header::Encode() {
std::string buffer, tmp;
auto magic = htonl(MAGIC);
tmp = std::string(reinterpret_cast<const char*>(&magic), sizeof(magic));
buffer.append(tmp);
std::string buffer, tmp;
auto magic = htonl(MAGIC);
tmp = std::string(reinterpret_cast<const char*>(&magic), sizeof(magic));
buffer.append(tmp);
auto size = htonl(pSize);
tmp = std::string(reinterpret_cast<const char*>(&size), sizeof(size));
buffer.append(tmp);
return buffer;
auto size = htonl(pSize);
tmp = std::string(reinterpret_cast<const char*>(&size), sizeof(size));
buffer.append(tmp);
return buffer;
}
std::expected<void, std::string> Header::Decode(const std::string rawHeader) {
uint32_t tmp;
std::memcpy(&tmp, rawHeader.data(), sizeof(uint32_t));
auto magic = ntohl(tmp);
if (magic != MAGIC) {
return std::unexpected("Wrong magic code");
}
std::memcpy(&tmp, rawHeader.data() + sizeof(uint32_t), sizeof(uint32_t));
pSize = ntohl(tmp);
return {};
uint32_t tmp;
std::memcpy(&tmp, rawHeader.data(), sizeof(uint32_t));
auto magic = ntohl(tmp);
if (magic != MAGIC) {
return std::unexpected("Wrong magic code");
}
std::memcpy(&tmp, rawHeader.data() + sizeof(uint32_t), sizeof(uint32_t));
pSize = ntohl(tmp);
return {};
}
uint32_t Header::PacketSize() {
return pSize;
return pSize;
}