...
This commit is contained in:
@@ -54,9 +54,45 @@ struct snplib_netproto_stopseq_t {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <std::ranges::range OR, std::ranges::range IR>
|
template <std::ranges::range OR, snplib_input_char_range_c IR>
|
||||||
OR fromBytes(IR&& bytes)
|
std::expected<OR, std::error_code> fromBytes(IR&& bytes)
|
||||||
{
|
{
|
||||||
|
auto found = std::ranges::search(std::forward<IR>(bytes), NETPROTO_STOP_SEQ);
|
||||||
|
if (found.empty()) {
|
||||||
|
return std::unexpected(std::errc::invalid_argument);
|
||||||
|
}
|
||||||
|
|
||||||
|
if constexpr (std::ranges::contiguous_range<IR>) {
|
||||||
|
if constexpr (std::ranges::view<OR>) {
|
||||||
|
return OR(bytes.begin(), found.begin()); // return without stop-sequence!!!
|
||||||
|
} else if constexpr (snplib_output_char_range_c<OR>) {
|
||||||
|
OR res;
|
||||||
|
std::ranges::copy(
|
||||||
|
std::forward<IR>(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>) {
|
||||||
|
OR res;
|
||||||
|
std::ranges::copy(std::forward<IR>(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<OR>) {
|
||||||
|
if constexpr (std::ranges::contiguous_range<IR>) {
|
||||||
|
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!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user