...
This commit is contained in:
parent
2acb97e973
commit
9e13bf0d74
@ -23,7 +23,9 @@ set(ADC_DEVICE_HEADERS
|
||||
|
||||
|
||||
set(ADC_NETWORK_HEADERS
|
||||
net/adc_netmessage.h)
|
||||
net/adc_netmessage.h
|
||||
net/adc_netproto.h
|
||||
)
|
||||
|
||||
option(BUILD_TESTS "Build tests" ON)
|
||||
|
||||
|
||||
@ -32,7 +32,8 @@ concept adc_char_range =
|
||||
|
||||
// output range of char/const char
|
||||
template <typename R, typename CharT = char>
|
||||
concept adc_output_char_range = std::ranges::output_range<R, CharT>;
|
||||
concept adc_output_char_range =
|
||||
std::ranges::output_range<R, CharT> && std::same_as<std::remove_cv_t<std::ranges::range_value_t<R>>, CharT>;
|
||||
|
||||
|
||||
// range of char/const char
|
||||
|
||||
@ -76,7 +76,7 @@ public:
|
||||
if constexpr (traits::adc_input_char_range<T>) {
|
||||
std::ranges::copy(v, std::back_inserter(_storageSequence.emplace_back()));
|
||||
} else if constexpr (traits::formattable<T>) {
|
||||
std::format_to(std::back_inserter(_storageSequence.emplace_back()), v);
|
||||
std::format_to(std::back_inserter(_storageSequence.emplace_back()), "{}", v);
|
||||
} else {
|
||||
static_assert(false, "UNSUPPORTED TYPE!!!");
|
||||
}
|
||||
@ -133,7 +133,7 @@ public:
|
||||
}
|
||||
|
||||
|
||||
template <traits::adc_output_char_range R>
|
||||
template <traits::adc_output_char_range<char> R>
|
||||
size_t bytes(R& r)
|
||||
{
|
||||
if (_outputSequence.empty()) {
|
||||
@ -154,7 +154,7 @@ protected:
|
||||
|
||||
output_seq_t _outputSequence;
|
||||
|
||||
AdcNetMessageInterface() : _storageSequence(), _outputSequence() {};
|
||||
AdcNetMessageInterface() : _storageSequence(), _outputSequence(){};
|
||||
|
||||
template <typename T, typename... Ts>
|
||||
AdcNetMessageInterface(const T& v, const Ts&... vs) : AdcNetMessageInterface()
|
||||
@ -240,6 +240,10 @@ public:
|
||||
template <typename T, typename... Ts>
|
||||
void appendTokens(const T& v, const Ts&... vs)
|
||||
{
|
||||
if (_storageSequence.size()) { // some tokens are already in storage
|
||||
_outputSequence.emplace_back(tokenDelimiter); // add delimiter in output sequence
|
||||
}
|
||||
|
||||
if constexpr (traits::adc_input_char_range<T> || traits::formattable<T>) {
|
||||
this->appendBytes(v);
|
||||
} else if constexpr (std::ranges::input_range<T>) {
|
||||
@ -254,7 +258,7 @@ public:
|
||||
}
|
||||
|
||||
} else {
|
||||
static_assert(false, "INVALID TYPE OF INPUT TOKENS!!!");
|
||||
static_assert(false, "UNSUPPORTED (CANNOT BE SERIALIZED TO BYTES) TYPE OF INPUT TOKENS!!!");
|
||||
}
|
||||
|
||||
if constexpr (sizeof...(Ts)) {
|
||||
@ -347,13 +351,13 @@ public:
|
||||
|
||||
|
||||
protected:
|
||||
void updateState() override
|
||||
{
|
||||
if (_outputSequence.size()) {
|
||||
_outputSequence.emplace_back(tokenDelimiter); // add delimiter in output sequence
|
||||
}
|
||||
_outputSequence.emplace_back(_storageSequence.back());
|
||||
}
|
||||
// void updateState() override
|
||||
// {
|
||||
// if (_outputSequence.size()) { // some tokens are already in storage
|
||||
// _outputSequence.emplace_back(tokenDelimiter); // add delimiter in output sequence
|
||||
// }
|
||||
// _outputSequence.emplace_back(_storageSequence.back());
|
||||
// }
|
||||
};
|
||||
|
||||
|
||||
@ -404,7 +408,8 @@ public:
|
||||
this->_outputSequence.emplace_back(_key);
|
||||
|
||||
if constexpr (sizeof...(ParamTs)) {
|
||||
this->setTokens(params...);
|
||||
this->_outputSequence.emplace_back(keyparamDelimiter); // add key-param delimiter in output sequence
|
||||
this->appendTokens(params...);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
1
net/adc_netproto.h
Normal file
1
net/adc_netproto.h
Normal file
@ -0,0 +1 @@
|
||||
#pragma once
|
||||
@ -39,4 +39,19 @@ TEST_CASE("[ADC NET MESSAGE]")
|
||||
std::cout << "MESSAGE: [" << bb << "]\n";
|
||||
|
||||
REQUIRE_EQ(bb, bytes);
|
||||
|
||||
// msg.setKeyParam("GET", "IMAGE", std::string_view("CROP"), 4, 7, std::make_pair(10, 20));
|
||||
msg.setKeyParam("GET", "IMAGE", std::string_view("CROP"), 4, 7);
|
||||
bb.clear();
|
||||
msg.bytes(bb);
|
||||
|
||||
std::cout << "MSG: [" << bb << "]\n";
|
||||
key.clear();
|
||||
msg.key(key);
|
||||
std::cout << "KEY: [" << key << "]\n";
|
||||
ls.clear();
|
||||
msg.params(ls, 1, 3);
|
||||
for (auto& el : ls) {
|
||||
std::cout << "PAR: [" << el << "]\n";
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user