61 lines
1.5 KiB
C++
61 lines
1.5 KiB
C++
#include "ydi_networking.h"
|
|
|
|
namespace ydi {
|
|
MessageType to_message_type(zmq::message_t const &msg) {
|
|
int as_int{ std::stoi(msg.str()) };
|
|
if (as_int >= 0 && as_int < MESSAGE_TYPE_INVALID) {
|
|
return (MessageType)as_int;
|
|
} else {
|
|
return MESSAGE_TYPE_INVALID;
|
|
}
|
|
}
|
|
|
|
NOKReason to_nok_reason(zmq::message_t const &msg) {
|
|
int as_int{ std::stoi(msg.str()) };
|
|
if (as_int >= 0 && as_int < NOK_REASON_INVALID) {
|
|
return (NOKReason)as_int;
|
|
} else {
|
|
return NOK_REASON_INVALID;
|
|
}
|
|
}
|
|
|
|
ClueID to_clue_id(zmq::message_t const &msg) {
|
|
int as_int{ std::stoi(msg.str()) };
|
|
if (as_int >= 0 && as_int < CLUE_MAX) {
|
|
return (ClueID)as_int;
|
|
} else {
|
|
return CLUE_MAX;
|
|
}
|
|
}
|
|
|
|
void extend_multipart(zmq::multipart_t &mpart, MessageType type) {
|
|
mpart.addstr(std::to_string(type));
|
|
}
|
|
|
|
void extend_multipart(zmq::multipart_t &mpart, ClueID id) {
|
|
mpart.addstr(std::to_string(id));
|
|
}
|
|
|
|
void extend_multipart(zmq::multipart_t &mpart, std::string const &string) {
|
|
mpart.addstr(string);
|
|
}
|
|
|
|
void extend_multipart(zmq::multipart_t &mpart, std::string_view const &strv) {
|
|
mpart.addmem(strv.data(), strv.size());
|
|
}
|
|
|
|
void extend_multipart(zmq::multipart_t &mpart, char const *cstr) {
|
|
mpart.addstr(cstr);
|
|
}
|
|
|
|
void extend_multipart(zmq::multipart_t &mpart, int const &arg) {
|
|
std::string as_string{ std::to_string(arg) };
|
|
mpart.addstr(as_string);
|
|
}
|
|
|
|
void extend_multipart(zmq::multipart_t &mpart, zmq::multipart_t const &right) {
|
|
mpart.append(right.clone());
|
|
}
|
|
|
|
void extend_multipart(zmq::multipart_t &mpart) {}
|
|
} //namespace ydi
|