|
|
|
|
@@ -13,7 +13,8 @@
|
|
|
|
|
namespace adc
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
namespace utils {
|
|
|
|
|
namespace utils
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <typename ByteStorageT, typename T, typename... Ts>
|
|
|
|
|
@@ -42,7 +43,8 @@ void convertToBytes(ByteStorageT &res, const T &v, const Ts &...vs)
|
|
|
|
|
} // namespace utils
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace traits {
|
|
|
|
|
namespace traits
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
|
concept adc_netmessage_c = requires(const T t) { // const methods
|
|
|
|
|
@@ -62,7 +64,6 @@ template<traits::adc_output_char_range ByteStorageT = std::string, traits::adc_c
|
|
|
|
|
class AdcNetMessageTrivialInterface
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
virtual ~AdcNetMessageTrivialInterface() = default;
|
|
|
|
|
|
|
|
|
|
bool empty() const { return std::ranges::distance(_bytes.begin(), _bytes.end()) == 0; }
|
|
|
|
|
@@ -165,7 +166,8 @@ public:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < _bytes.size(); ++i) {
|
|
|
|
|
std::ranges::for_each(storageViewByIndex(i), [&r](const auto &el) { r.emplace_back(el.begin(), el.end()); });
|
|
|
|
|
std::ranges::for_each(storageViewByIndex(i),
|
|
|
|
|
[&r](const auto& el) { r.emplace_back(el.begin(), el.end()); });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return r;
|
|
|
|
|
@@ -190,9 +192,6 @@ protected:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Generic message class
|
|
|
|
|
template <traits::adc_output_char_range ByteStorageT = std::string, traits::adc_char_view ByteViewT = std::string_view>
|
|
|
|
|
class AdcGenericNetMessage : public AdcNetMessageTrivialInterface<ByteStorageT, ByteViewT>
|
|
|
|
|
@@ -266,8 +265,8 @@ class AdcTokenNetMessage : public AdcNetMessageSeqInterface<ByteStorageT, ByteVi
|
|
|
|
|
public:
|
|
|
|
|
static constexpr std::string_view tokenDelimiter{TOKEN_DELIM};
|
|
|
|
|
|
|
|
|
|
using base_t::bytesView;
|
|
|
|
|
using base_t::bytes;
|
|
|
|
|
using base_t::bytesView;
|
|
|
|
|
using base_t::empty;
|
|
|
|
|
|
|
|
|
|
AdcTokenNetMessage() = default;
|
|
|
|
|
@@ -302,6 +301,27 @@ public:
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <traits::adc_output_char_range R>
|
|
|
|
|
R tokensBytes(size_t start = 0, size_t N = std::numeric_limits<size_t>::max()) const
|
|
|
|
|
{
|
|
|
|
|
R r;
|
|
|
|
|
|
|
|
|
|
if (empty() || (start >= this->_bytes.size()) || !N) {
|
|
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
utils::AdcJoinRange(this->_bytes | std::views::drop(start) | std::views::take(N), tokenDelimiter, r);
|
|
|
|
|
|
|
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ByteStorageT tokensBytes(size_t start = 0, size_t N = std::numeric_limits<size_t>::max()) const
|
|
|
|
|
{
|
|
|
|
|
return tokensBytes<ByteStorageT>(start, N);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T, typename... Ts>
|
|
|
|
|
void appendTokens(const T& v, const Ts&... vs)
|
|
|
|
|
{
|
|
|
|
|
@@ -392,13 +412,13 @@ class AdcKeyTokenNetMessage : public AdcTokenNetMessage<TOKEN_DELIM, ByteStorage
|
|
|
|
|
public:
|
|
|
|
|
static constexpr std::string_view keytokenDelimiter{KEY_TOKEN_DELIM};
|
|
|
|
|
|
|
|
|
|
using base_t::appendFromBytes; // append only tokens not keyword
|
|
|
|
|
using base_t::appendTokens;
|
|
|
|
|
using base_t::bytes;
|
|
|
|
|
using base_t::bytesView;
|
|
|
|
|
using base_t::empty;
|
|
|
|
|
using base_t::setTokens;
|
|
|
|
|
using base_t::tokens;
|
|
|
|
|
using base_t::appendFromBytes; // append only tokens not keyword
|
|
|
|
|
using base_t::bytesView;
|
|
|
|
|
using base_t::bytes;
|
|
|
|
|
using base_t::empty;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AdcKeyTokenNetMessage() = default;
|
|
|
|
|
@@ -472,6 +492,20 @@ public:
|
|
|
|
|
return tokens<std::vector<ByteStorageT>>(start, N);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <traits::adc_output_char_range R>
|
|
|
|
|
R tokensBytes(size_t start = 0, size_t N = std::numeric_limits<size_t>::max()) const
|
|
|
|
|
{
|
|
|
|
|
// "+1" since the first element is keyword
|
|
|
|
|
return base_t::template tokensBytes<ByteStorageT>(start + 1, N);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ByteStorageT tokensBytes(size_t start = 0, size_t N = std::numeric_limits<size_t>::max()) const
|
|
|
|
|
{
|
|
|
|
|
return tokensBytes<ByteStorageT>(start, N);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <typename KT, typename T, typename... Ts>
|
|
|
|
|
void setKeyTokens(const KT& key, const T& tok, const Ts&... toks)
|
|
|
|
|
@@ -509,7 +543,6 @@ public:
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
|
|
virtual std::vector<ByteViewT> storageViewByIndex(size_t idx) const override
|
|
|
|
|
{
|
|
|
|
|
if (idx == 0) { // the first element is keyword
|
|
|
|
|
|