59 lines
1.4 KiB
C++
59 lines
1.4 KiB
C++
#include <list>
|
|
#include <print>
|
|
|
|
#include <snipplib/network/snplib_netproto.h>
|
|
|
|
|
|
int main()
|
|
{
|
|
snplib::snplib_netproto_stopseq_t<> proto;
|
|
|
|
std::string bytes{"SET VAL1 10\n"};
|
|
std::vector bytes_vec{std::from_range, bytes};
|
|
std::list bytes_lst{std::from_range, bytes};
|
|
|
|
std::println("BYTES VEC: {}", bytes_vec);
|
|
|
|
auto msg = proto.fromBytes(bytes_vec);
|
|
|
|
if (msg) {
|
|
std::println("MSG (from std::vector): {}", msg.value());
|
|
} else {
|
|
std::println("MSG ERR: {}", msg.error().message());
|
|
}
|
|
|
|
auto msg_l = proto.fromBytes(bytes_lst);
|
|
|
|
if (msg_l) {
|
|
std::println("MSG (from std::list): {}", msg_l.value());
|
|
} else {
|
|
std::println("MSG ERR: {}", msg_l.error().message());
|
|
}
|
|
|
|
auto vmsg = proto.fromBytes<std::vector<char>>(bytes_lst);
|
|
if (vmsg) {
|
|
std::println("VMSG (from std::list): {}", vmsg.value());
|
|
} else {
|
|
std::println("VMSG ERR: {}", vmsg.error().message());
|
|
}
|
|
|
|
|
|
std::println("\n\n");
|
|
|
|
bytes = "GET VAL2 1";
|
|
bytes_vec = {std::from_range, bytes};
|
|
bytes_lst = {std::from_range, bytes};
|
|
|
|
std::println("MSG: ", bytes_vec);
|
|
|
|
auto bs = proto.toBytes(bytes_vec);
|
|
std::println("BYTES (from std::vector): {}", bs);
|
|
|
|
auto bs1 = proto.toBytes(bytes_lst);
|
|
std::println("BYTES (from std::list): {}", bs1);
|
|
|
|
bytes_vec = proto.toBytes<decltype(bytes_vec)>(bytes_lst);
|
|
std::println("BYTES: {}", bytes_vec);
|
|
|
|
return 0;
|
|
} |