feat: working on the client-server connection

This commit is contained in:
Sara Gerretsen 2025-10-11 23:04:45 +02:00
parent dc1aed487e
commit 13f9e8479c
11 changed files with 114 additions and 101 deletions

View file

@ -1,39 +1,30 @@
#include "ydi_networking.h"
#include <zmq.hpp>
#include <zmq_addon.hpp>
namespace ydi {
MessageType to_message_type(std::string const &msg) {
int as_int{ std::stoi(msg) };
if (as_int >= 0 && as_int < MESSAGE_TYPE_MAX) {
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 NONE;
return MESSAGE_TYPE_INVALID;
}
}
MessageType message_type(zmq::multipart_t const &msg, size_t *type_idx) {
MessageType type{ to_message_type(msg[0].to_string()) };
size_t idx{ 0 };
if (!type) {
++idx;
type = to_message_type(msg[0].to_string());
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;
}
if (!type) {
idx = std::numeric_limits<size_t>::max();
}
if (type_idx) {
*type_idx = idx;
}
return type;
}
bool decompose_connect(zmq::multipart_t &msg, int *code) {
size_t start{};
MessageType actual_type{ message_type(msg, &start) };
if (actual_type) {
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;
}
}
@ -67,4 +58,4 @@ void extend_multipart(zmq::multipart_t &mpart, zmq::multipart_t const &right) {
}
void extend_multipart(zmq::multipart_t &mpart) {}
}
} //namespace ydi