summaryrefslogtreecommitdiff
path: root/common/message.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'common/message.cpp')
-rw-r--r--common/message.cpp65
1 files changed, 51 insertions, 14 deletions
diff --git a/common/message.cpp b/common/message.cpp
index 526a3fd..a72bac9 100644
--- a/common/message.cpp
+++ b/common/message.cpp
@@ -1,6 +1,51 @@
#include "message.h"
+#include <boost/serialization/vector.hpp>
+#include <boost/serialization/string.hpp>
+
#include <cstring>
+#include <sstream>
+
+Message::Base::Base(Type t) : type(t) {
+
+}
+
+Message::NullBase::NullBase(Type t) : Base(t) {
+
+}
+
+std::pair<uint8_t*, std::size_t> Message::NullBase::serialize() {
+ return std::pair<uint8_t*, std::size_t>(0, 0);
+}
+
+void Message::NullBase::deserialize(uint8_t* data, std::size_t bytes) {
+
+}
+
+Message::BoostBase::BoostBase(Type t) : Base(t) {
+
+}
+
+std::pair<uint8_t*, std::size_t> Message::BoostBase::serialize() {
+ std::ostringstream os;
+ boost::archive::text_oarchive oa(os);
+
+ serialize(oa);
+
+ std::size_t s = os.str().size();
+ uint8_t* buf = new uint8_t[s];
+
+ memcpy(buf, os.str().c_str(), s);
+
+ return std::pair<uint8_t*, std::size_t>(buf, s);
+}
+
+void Message::BoostBase::deserialize(uint8_t* data, std::size_t bytes) {
+ std::istringstream is(std::string((char*)data, bytes));
+ boost::archive::text_iarchive ia(is);
+
+ deserialize(ia);
+}
Message::Hello::Hello() : Base(Types::Hello) {
@@ -64,26 +109,18 @@ void Message::LoginResponse::deserialize(uint8_t* data, std::size_t bytes) {
login_ok = bool(data[0]);
}
-Message::GameStart::GameStart() : Base(Types::GameStart) {
+Message::GameStart::GameStart() : BoostBase(Types::GameStart) {
}
-std::pair<uint8_t*, std::size_t> Message::GameStart::serialize() {
- return std::pair<uint8_t*, std::size_t>(0, 0);
-}
-
-void Message::GameStart::deserialize(uint8_t* data, std::size_t bytes) {
-
+void Message::GameStart::serialize(boost::archive::text_oarchive& ar) {
+ ar & players;
}
-Message::Ready::Ready() : Base(Types::Ready) {
-
-}
-
-std::pair<uint8_t*, std::size_t> Message::Ready::serialize() {
- return std::pair<uint8_t*, std::size_t>(0, 0);
+void Message::GameStart::deserialize(boost::archive::text_iarchive& ar) {
+ ar & players;
}
-void Message::Ready::deserialize(uint8_t* data, std::size_t bytes) {
+Message::Ready::Ready() : NullBase(Types::Ready) {
}