diff options
author | Gluzskiy Alexandr <sss@sss.chaoslab.ru> | 2015-07-28 05:33:02 +0300 |
---|---|---|
committer | Gluzskiy Alexandr <sss@sss.chaoslab.ru> | 2015-07-28 05:33:02 +0300 |
commit | a076f8228ff6fe8a2f9b7ac6634b46fb598fd711 (patch) | |
tree | 9686790893da36f6155696dfa3204dd81153a63e /server/src | |
parent | 7aade009f69a149ca28f7dd0af5db78d1caab00e (diff) |
a bit of implementation of client<->server protocol
Diffstat (limited to 'server/src')
-rw-r--r-- | server/src/utilities.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/server/src/utilities.cpp b/server/src/utilities.cpp index 1cebd16..5ea14c1 100644 --- a/server/src/utilities.cpp +++ b/server/src/utilities.cpp @@ -19,6 +19,7 @@ */ #include "utilities.h" +#include "../../protocol/udm.pb.h" std::string replace_home_var(const std::string &path) { @@ -28,3 +29,28 @@ std::string replace_home_var(const std::string &path) return tmp_path; } + + +std::shared_ptr<char*> pack_data(const std::string &buf, int *size_) +{ +// BOOST_LOG_TRIVIAL(debug)<<__FILE__<<":"<<__LINE__<<"\t"<<__func__; + std::shared_ptr<char*> ptr = std::make_shared<char*>(new char[buf.length() + 4]); + int32_t size = buf.length(); + *size_ = size + 4; + (*ptr)[3] = size & 0xff; + (*ptr)[2] = (size>>8) & 0xff; + (*ptr)[1] = (size>>16) & 0xff; + (*ptr)[0] = (size>>24) & 0xff; + char *fck = (*ptr)+4; + memcpy(fck, buf.data(), buf.length()); + return ptr; +} + +std::shared_ptr<char*> pack_msg(server_msg *msg, int *size_) +{ +// BOOST_LOG_TRIVIAL(debug)<<__FILE__<<":"<<__LINE__<<"\t"<<__func__; +// BOOST_LOG_TRIVIAL(trace)<<"packing message:\n"<<cmd.DebugString(); + std::string msg_buf; + msg->SerializeToString(&msg_buf); + return pack_data(msg_buf, size_); +} |