mountcontrol/mcc/tests/netmsg_test.cpp
2025-10-08 18:13:46 +03:00

55 lines
1.6 KiB
C++

#include <iostream>
#include <list>
#include "../mcc_netserver_proto.h"
int main()
{
using msg1_t = mcc::network::MccNetMessage<mcc::network::MccNetMessageValidKeywords, std::string_view>;
using msg2_t = mcc::network::MccNetMessage<mcc::network::MccNetMessageValidKeywords, std::string>;
std::string_view sv{"TARGET 11:22:33.212; -0.23876984; RADEC "};
std::vector<char> arr{sv.begin(), sv.end()};
msg1_t msg1;
msg1.fromCharRange(arr);
std::cout << "msg.key = <" << msg1.keyword() << ">\n";
std::cout << "msg.par[1] = <" << msg1.param(1) << ">\n";
std::vector<double> vd{1.1, 2.2, 3.3};
msg2_t msg2("ACK", 12.43298042, "EEE", std::chrono::seconds(10), vd);
std::cout << "msg.bytes = <" << msg2.byteRepr() << ">\n";
std::cout << "msg.key = <" << msg2.keyword() << ">\n";
std::cout << "msg.par[1] = <" << msg2.param(1) << ">\n";
std::cout << "msg.par[2] = <" << msg2.param(2) << ">\n";
auto p2 = msg2.paramValue<std::chrono::seconds>(2);
std::cout << "msg.par[2] = <" << p2.value_or({}) << ">\n";
std::cout << "msg.par[3] = <";
auto p3 = msg2.paramValue<decltype(vd)>(3);
if (p3.has_value()) {
for (auto const& el : p3.value()) {
std::cout << el << " ";
}
}
std::cout << ">\n";
std::cout << "msg.par[1-2] joined = <" << msg2.params(1, 2) << ">\n";
auto vv = msg2.params<std::list<std::string_view>>(1, 3);
std::cout << "msg.par[1-3] array = <";
for (auto const& el : vv) {
std::cout << el << " ";
}
std::cout << ">\n";
return 0;
}