From 0130420f90ba6408b6ce5723d76aa529e275684f Mon Sep 17 00:00:00 2001 From: "Timur A. Fatkhullin" Date: Wed, 22 Jul 2026 00:16:31 +0300 Subject: [PATCH] ... --- include/snipplib/network/snplib_netproto.h | 40 ++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/include/snipplib/network/snplib_netproto.h b/include/snipplib/network/snplib_netproto.h index 9e5d492..ba0845c 100644 --- a/include/snipplib/network/snplib_netproto.h +++ b/include/snipplib/network/snplib_netproto.h @@ -54,9 +54,45 @@ struct snplib_netproto_stopseq_t { } } - template - OR fromBytes(IR&& bytes) + template + std::expected fromBytes(IR&& bytes) { + auto found = std::ranges::search(std::forward(bytes), NETPROTO_STOP_SEQ); + if (found.empty()) { + return std::unexpected(std::errc::invalid_argument); + } + + if constexpr (std::ranges::contiguous_range) { + if constexpr (std::ranges::view) { + return OR(bytes.begin(), found.begin()); // return without stop-sequence!!! + } else if constexpr (snplib_output_char_range_c) { + OR res; + std::ranges::copy( + std::forward(bytes) | std::views::take(std::distance(bytes.begin(), found.begin())), + std::back_inserter(res)); + + return res; + } else { + static_assert(false, "Unsupported output byte sequence type!"); + } + } else { + } + + if constexpr (snplib_output_char_range_c) { + OR res; + std::ranges::copy(std::forward(bytes) | std::views::take(std::distance(bytes.begin(), found.begin())), + std::back_inserter(res)); // return without stop-sequence!!! + + return res; + } else if constexpr (snplib_char_view_c) { + if constexpr (std::ranges::contiguous_range) { + return OR(bytes.begin(), found.begin()); // return without stop-sequence!!! + } else { + static_assert(false, "Unsupported output byte sequence type!"); + } + } else { + static_assert(false, "Unsupported output byte sequence type!"); + } } };