summaryrefslogtreecommitdiff
path: root/common/message.cpp
diff options
context:
space:
mode:
authorVegard Storheil Eriksen <zyp@jvnv.net>2010-11-30 23:44:26 +0100
committerVegard Storheil Eriksen <zyp@jvnv.net>2010-11-30 23:44:26 +0100
commitbf3b20f58d400c3961ce4d162cf314ff3ed4895e (patch)
tree939511ef19f27cf73143c18e619d2fb333d5af49 /common/message.cpp
parent0599d5beb9d6d37394441fec55a592767a143be0 (diff)
Simplified Message API. All messages are now serialized by Boost.Serialize.
Diffstat (limited to 'common/message.cpp')
-rw-r--r--common/message.cpp148
1 files changed, 0 insertions, 148 deletions
diff --git a/common/message.cpp b/common/message.cpp
deleted file mode 100644
index 5c5ab50..0000000
--- a/common/message.cpp
+++ /dev/null
@@ -1,148 +0,0 @@
-#include "message.h"
-
-#include <boost/serialization/vector.hpp>
-#include <boost/serialization/string.hpp>
-#include <boost/serialization/shared_ptr.hpp>
-#include <boost/archive/binary_oarchive.hpp>
-#include <boost/archive/binary_iarchive.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) {
-
-}
-
-template<class Sub>
-Message::BoostBase<Sub>::BoostBase(Type t) : Base(t) {
-
-}
-
-template<class Sub>
-std::pair<uint8_t*, std::size_t> Message::BoostBase<Sub>::serialize() {
- std::ostringstream os;
- boost::archive::binary_oarchive oa(os);
-
- oa & *this;
-
- 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);
-}
-
-template<class Sub>
-void Message::BoostBase<Sub>::deserialize(uint8_t* data, std::size_t bytes) {
- std::istringstream is(std::string((char*)data, bytes));
- boost::archive::binary_iarchive ia(is);
-
- ia & *this;
-}
-
-Message::Hello::Hello() : Base(Types::Hello) {
-
-}
-
-Message::Hello::Hello(const std::string& v) : Base(Types::Hello), version(v) {
-
-}
-
-std::pair<uint8_t*, std::size_t> Message::Hello::serialize() {
- std::size_t s = version.size();
- uint8_t* buf = new uint8_t[s];
-
- memcpy(buf, version.c_str(), version.size());
-
- return std::pair<uint8_t*, std::size_t>(buf, s);
-}
-
-void Message::Hello::deserialize(uint8_t* data, std::size_t bytes) {
- version = std::string((char*)data, bytes);
-}
-
-Message::Login::Login() : Base(Types::Login) {
-
-}
-
-Message::Login::Login(const std::string& n) : Base(Types::Login), nick(n) {
-
-}
-
-std::pair<uint8_t*, std::size_t> Message::Login::serialize() {
- std::size_t s = nick.size();
- uint8_t* buf = new uint8_t[s];
-
- memcpy(buf, nick.c_str(), nick.size());
-
- return std::pair<uint8_t*, std::size_t>(buf, s);
-}
-
-void Message::Login::deserialize(uint8_t* data, std::size_t bytes) {
- nick = std::string((char*)data, bytes);
-}
-
-Message::LoginResponse::LoginResponse() : Base(Types::LoginResponse) {
-
-}
-
-Message::LoginResponse::LoginResponse(bool ok) : Base(Types::LoginResponse), login_ok(ok) {
-
-}
-
-std::pair<uint8_t*, std::size_t> Message::LoginResponse::serialize() {
- uint8_t* buf = new uint8_t[1];
-
- buf[0] = uint8_t(login_ok);
-
- return std::pair<uint8_t*, std::size_t>(buf, 1);
-}
-
-void Message::LoginResponse::deserialize(uint8_t* data, std::size_t bytes) {
- login_ok = bool(data[0]);
-}
-
-Message::GameStart::GameStart() : BoostBase<GameStart>(Types::GameStart) {
-
-}
-
-Message::Ready::Ready() : NullBase(Types::Ready) {
-
-}
-
-Message::RoundStart::RoundStart() : NullBase(Types::RoundStart) {
-
-}
-
-Message::RoundState::RoundState() : BoostBase<RoundState>(Types::RoundState) {
-
-}
-
-Message::RoundState::RoundState(const Player& pl_d, const Player& pl_r, const Player& pl_u, const Player& pl_l, const Tiles& d, const Actions& a)
- : BoostBase<RoundState>(Types::RoundState), dora(d), possible_actions(a) {
- players[0] = pl_d;
- players[1] = pl_r;
- players[2] = pl_u;
- players[3] = pl_l;
-}
-
-Message::RoundAction::RoundAction() : BoostBase<RoundAction>(Types::RoundAction) {
-
-}
-
-Message::RoundEnd::RoundEnd() : NullBase(Types::RoundEnd) {
-
-}