98 lines
2.9 KiB
C++
98 lines
2.9 KiB
C++
#include <algorithm>
|
|
#include <list>
|
|
#include <print>
|
|
|
|
#include <snipplib/network/snplib_netproto.h>
|
|
|
|
|
|
int main()
|
|
{
|
|
std::println("{:*^80}\n", " STOP-SEQ PROTOCOL ");
|
|
|
|
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.fromNetwork(bytes_vec);
|
|
|
|
if (msg.flag == snplib::net_repr_proto_result_flag_e::OK) {
|
|
std::println("MSG (from std::vector): {}", msg.result);
|
|
} else {
|
|
std::println("MSG ERR: {}", std::to_underlying(msg.flag));
|
|
}
|
|
|
|
auto msg_l = proto.fromNetwork(bytes_lst);
|
|
|
|
if (msg_l.flag == snplib::net_repr_proto_result_flag_e::OK) {
|
|
std::println("MSG (from std::list): {}", msg_l.result);
|
|
} else {
|
|
std::println("MSG ERR: {}", std::to_underlying(msg_l.flag));
|
|
}
|
|
|
|
auto vmsg = proto.fromNetwork<std::vector<char>>(bytes_lst);
|
|
if (vmsg.flag == snplib::net_repr_proto_result_flag_e::OK) {
|
|
std::println("VMSG (from std::list): {}", vmsg.result);
|
|
} else {
|
|
std::println("VMSG ERR: {}", std::to_underlying(vmsg.flag));
|
|
}
|
|
|
|
|
|
std::println("\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.toNetwork(bytes_vec);
|
|
std::println("BYTES (from std::vector): {}", bs.result);
|
|
|
|
// auto bs1 = proto.toNetwork(bytes_lst);
|
|
// std::println("BYTES (from std::list): {}", bs1.result);
|
|
|
|
auto bs11 = proto.toNetwork<decltype(bytes_vec)>(bytes_lst);
|
|
std::println("BYTES: {}", bs11.result);
|
|
|
|
|
|
std::println("\n\n{:*^80}\n", " BINARY-BLOB PROTOCOL ");
|
|
|
|
snplib::netproto_binary_blob_t<> bb_proto;
|
|
|
|
snplib::random_string_generator_t<> rstr_gen;
|
|
|
|
bytes = rstr_gen.generate(15);
|
|
bytes_vec = {std::from_range, bytes};
|
|
bytes_lst = {std::from_range, bytes};
|
|
|
|
std::println("BLOB: {}", bytes);
|
|
|
|
auto bs21 = bb_proto.toNetwork(bytes_vec);
|
|
std::println("BYTES (from std::vector): {}", bs21.result);
|
|
|
|
auto bs2 = bb_proto.toNetwork(bytes_lst);
|
|
std::println("BYTES (from std::list): {}", bs2.result);
|
|
|
|
// auto blob = std::vector(std::from_range, bs.result | std::views::join);
|
|
// auto blob = std::ranges::views::concat(std::get<0>(bs2.result), std::get<1>(bs2.result));
|
|
std::vector<char> blob;
|
|
std::ranges::copy(std::get<0>(bs2.result), std::back_inserter(blob));
|
|
std::ranges::copy(std::get<1>(bs2.result), std::back_inserter(blob));
|
|
|
|
std::println("\nBYTES: {}", blob);
|
|
|
|
vmsg = bb_proto.fromNetwork<std::vector<char>>(blob);
|
|
if (vmsg.flag == snplib::net_repr_proto_result_flag_e::OK) {
|
|
std::println("BLOB (from std::vector): {}", vmsg.result);
|
|
} else {
|
|
std::println("VMSG ERR: {}", std::to_underlying(vmsg.flag));
|
|
}
|
|
|
|
// std::array<char, 30> arr = bb_proto.toNetwork<decltype(arr)>(bytes_lst);
|
|
|
|
return 0;
|
|
} |