summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorVegard Storheil Eriksen <zyp@sakuya.local>2010-11-07 22:08:48 +0100
committerVegard Storheil Eriksen <zyp@sakuya.local>2010-11-07 22:08:48 +0100
commit64fdd300fe671292db68b9a94e4df0321f08ae07 (patch)
treeb2af38ba54b166f0f7969bcd4e41d3f815939f41 /common
parent7c660aeee9763a6baf4a45ebcc1c029e3a43222e (diff)
Add a temporary payload to messages.
Diffstat (limited to 'common')
-rw-r--r--common/message.cpp20
-rw-r--r--common/message.h5
2 files changed, 21 insertions, 4 deletions
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<uint8_t*, std::size_t> Message::serialize() {
- return std::pair<uint8_t*, std::size_t>(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<uint8_t*, std::size_t>(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 <boost/shared_ptr.hpp>
+#include <string>
+
class Message {
private:
Message();
@@ -14,6 +16,9 @@ class Message {
static p create();
+ //! Temporary payload.
+ std::string payload;
+
//! Serialize message.
std::pair<uint8_t*, std::size_t> serialize();