|
| 1 | +#include <spdlog/spdlog.h> |
| 2 | +#include <zmq.hpp> |
| 3 | + |
| 4 | +namespace Common { |
| 5 | +constexpr auto maxCount = 10; |
| 6 | + |
| 7 | +std::tuple<own::proto::Event, std::string> prepareMessage(const std::string &senderName, const zmq::message_t &request) |
| 8 | +{ |
| 9 | + own::proto::Event receivedEvent{}; |
| 10 | + std::string data; |
| 11 | + receivedEvent.ParseFromArray(request.data(), static_cast<int>(request.size())); |
| 12 | + |
| 13 | + own::proto::Event event{}; |
| 14 | + event.set_sender(senderName); |
| 15 | + event.SerializeToString(&data); |
| 16 | + return std::make_tuple(receivedEvent, data); |
| 17 | +} |
| 18 | + |
| 19 | +[[nodiscard]]std::string incrementPingPong(own::proto::Event& event, own::proto::Event_PingPong eventType) |
| 20 | +{ |
| 21 | + switch (eventType) { |
| 22 | + case own::proto::Event::PING: { |
| 23 | + event.set_action(own::proto::Event::PING); |
| 24 | + event.set_ping_count(event.ping_count() + 1); |
| 25 | + event.set_pong_count(event.pong_count()); |
| 26 | + } |
| 27 | + case own::proto::Event::PONG: { |
| 28 | + event.set_action(own::proto::Event::PONG); |
| 29 | + event.set_ping_count(event.ping_count()); |
| 30 | + event.set_pong_count(event.pong_count() + 1); |
| 31 | + break; |
| 32 | + } |
| 33 | + default: { |
| 34 | + break; |
| 35 | + } |
| 36 | + } |
| 37 | + std::string data; |
| 38 | + event.SerializeToString(&data); |
| 39 | + return data; |
| 40 | +} |
| 41 | + |
| 42 | +void logProtoEvent(const own::proto::Event &receivedEvent) |
| 43 | +{ |
| 44 | + spdlog::info("Received from: {} - Action: {} - Ping count: {} - Pong count: {}", |
| 45 | + receivedEvent.sender(), |
| 46 | + own::proto::Event_PingPong_Name(receivedEvent.action()), |
| 47 | + receivedEvent.ping_count(), |
| 48 | + receivedEvent.pong_count()); |
| 49 | +} |
| 50 | +}// namespace Common |
0 commit comments