...
This commit is contained in:
59
examples/net_exam.cpp
Normal file
59
examples/net_exam.cpp
Normal file
@@ -0,0 +1,59 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user