Unverified Commit b8fceab6 authored by kladko's avatar kladko

Adding ZMQ

parent 2f0bafe8
//
// Created by kladko on 14.12.20.
//
#include "common.h"
#include "ZMQMessage.h"
#include "ServerWorker.h"
......@@ -15,6 +16,13 @@ void ServerWorker::work() {
zmq::message_t msg;
zmq::message_t copied_msg;
worker_.recv(&msg);
vector<uint8_t> msgData(msg.size() + 1, 0);
memcpy(msgData.data(), msg.data(), msg.size());
auto parseMsg = ZMQMessage::parse(msgData);
copied_msg.copy(&msg);
worker_.send(copied_msg);
}
......
......@@ -22,6 +22,7 @@
*/
#include "common.h"
#include "ZMQMessage.h"
......@@ -39,3 +40,18 @@ string ZMQMessage::getStringRapid(const char *_name) {
CHECK_STATE((*d)[_name].IsString());
return (*d)[_name].GetString();
};
shared_ptr<ZMQMessage> ZMQMessage::parse(vector<uint8_t>& _msg) {
CHECK_STATE(_msg.at(_msg.size() - 1) == 0);
auto d = make_shared<rapidjson::Document>();
d->Parse((const char*) _msg.data());
CHECK_STATE(!d->HasParseError());
CHECK_STATE(d->IsObject())
return make_shared<ZMQMessage>(d);
}
......@@ -39,12 +39,13 @@ protected:
public:
explicit ZMQMessage(string& _jsonMessage);
explicit ZMQMessage(shared_ptr<rapidjson::Document>& _d) : d(_d) {};
virtual ~ZMQMessage();
string getStringRapid(const char *_name);
uint64_t getUint64Rapid(const char *_name);
static shared_ptr<ZMQMessage> parse(vector<uint8_t>& _msg);
};
\ No newline at end of file
......@@ -31,6 +31,7 @@ using namespace std;
#include <iostream>
#include <map>
#include <memory>
#include <vector>
#include <boost/throw_exception.hpp>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment