msg1.strings.push_back("Test1"); msg1.strings.push_back("Test2"); msg1.integers.push_back(13); msg1.integers.push_back(42); auto t = snake::DateTime::now(); msg1.stamps.push_back(t); msg1.stamps.push_back(t - snake::Days(1)); msg1.version_map["V1"] = version; msg1.version_map["V2"] = v2; msg1.time_map[1] = msg1.stamps[0]; msg1.time_map[10] = msg1.stamps[1]; REQUIRE(msg1.serialize(s)); REQUIRE(msg2.deserialize(s)); REQUIRE(msg1.group.size() == msg2.group.size()); REQUIRE(msg1.group[0].major_version == msg2.group[0].major_version); REQUIRE(msg1.group[0].minor_version == msg2.group[0].minor_version); REQUIRE(msg1.msg.minor_version == msg2.msg.minor_version); REQUIRE(msg1.types.size() == msg2.types.size()); REQUIRE(msg1.types[0] == msg2.types[0]); REQUIRE(msg1.types[1] == msg2.types[1]); REQUIRE(msg1.strings.size() == msg2.strings.size()); REQUIRE(msg1.strings[0] == msg2.strings[0]); REQUIRE(msg1.strings[1] == msg2.strings[1]); REQUIRE(msg1.integers.size() == msg2.integers.size()); REQUIRE(msg1.integers[0] == msg2.integers[0]); REQUIRE(msg1.integers[1] == msg2.integers[1]); REQUIRE(msg1.stamps.size() == msg2.stamps.size());
/** * Reply example */ int main() { // Set up the network binding zmq::context_t zmqContext(1); zmq::socket_t * pZmqSocket = new zmq::socket_t(zmqContext, ZMQ_REP); std::string listenAddress = "tcp://*:5555"; pZmqSocket->bind(listenAddress.c_str()); while (1) { if (pZmqSocket->connected()) { // Create a REQUEST message pointer zmq::message_t * pZmqMsgIn = new zmq::message_t(); char * buffer = nullptr; // Receive the REQUEST message { try { if (pZmqSocket->recv(pZmqMsgIn)) { std::cout << "REQUEST Message Received" << std::endl; buffer = (char *)(pZmqMsgIn->data()); std::istringstream iss(buffer); TestMessage recvData = TestMessage(); recvData.deserialize(iss); printData(recvData); } else { std::cout << "REQUEST Message NOT Received" << std::endl; } } catch (std::exception& e) { std::cerr << "Exception caught during socket.recv(): " << e.what() << std::endl; } } // Create the REPLY message and copy data from the REQUEST message zmq::message_t * pZmqMsgOut = new zmq::message_t(sizeof(pZmqMsgIn->data())); memcpy((void *)pZmqMsgOut->data(), pZmqMsgIn->data(), sizeof(pZmqMsgIn->data())); // Send the REPLY message { try { if (pZmqSocket->send(*pZmqMsgOut)) { std::cout << "REPLY Message Sent" << std::endl; } else { std::cerr << "REPLY Message NOT Sent." << std::endl; } } catch (std::exception& e) { std::cerr << "Exception caught during socket.send(): " << e.what() << std::endl; } } delete pZmqMsgIn; } } delete pZmqSocket; return 0; }