From 64fdd300fe671292db68b9a94e4df0321f08ae07 Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Sun, 7 Nov 2010 22:08:48 +0100 Subject: Add a temporary payload to messages. --- common/message.cpp | 20 ++++++++++++++++---- common/message.h | 5 +++++ 2 files changed, 21 insertions(+), 4 deletions(-) (limited to 'common') diff --git a/common/message.cpp b/common/message.cpp index 78731e2..53209ed 100644 --- a/common/message.cpp +++ b/common/message.cpp @@ -12,15 +12,27 @@ Message::p Message::create() { } std::pair Message::serialize() { - return std::pair(0, 0); + std::size_t s = payload.size(); + + uint8_t* buf = new uint8_t[4 + s]; + + *(uint32_t*)buf = (uint32_t)s; + + memcpy(buf + 4, payload.c_str(), payload.size()); + + return std::pair(buf, 4 + s); } std::size_t Message::deserialize(uint8_t* data, std::size_t bytes) { - std::cout << "Fikk data (" << bytes << "): " << std::string((char*)data, bytes) << std::endl; - if(deserialize_size == 0 && bytes == 0) { - return 8; + return 4; + } + + if(deserialize_size == 0 && bytes == 4) { + return (std::size_t)(*(int32_t*)data); } + payload = std::string((char*)data, bytes); + return 0; } diff --git a/common/message.h b/common/message.h index 57258c1..eee5ac7 100644 --- a/common/message.h +++ b/common/message.h @@ -3,6 +3,8 @@ #include +#include + class Message { private: Message(); @@ -14,6 +16,9 @@ class Message { static p create(); + //! Temporary payload. + std::string payload; + //! Serialize message. std::pair serialize(); -- cgit v1.2.3