2
0
mirror of https://github.com/boostorg/redis.git synced 2026-01-19 04:42:09 +00:00

First steps with using adapters to process a generic_response.

This commit is contained in:
Marcelo Zimbres
2023-09-04 14:00:12 +02:00
parent 44a608c0ba
commit 4547e1ac07
4 changed files with 49 additions and 18 deletions

View File

@@ -92,7 +92,8 @@ private:
public:
explicit general_aggregate(Result* c = nullptr): result_(c) {}
void operator()(resp3::basic_node<std::string_view> const& nd, system::error_code&)
template <class String>
void operator()(resp3::basic_node<String> const& nd, system::error_code&)
{
BOOST_ASSERT_MSG(!!result_, "Unexpected null pointer");
switch (nd.data_type) {
@@ -114,7 +115,8 @@ private:
public:
explicit general_simple(Node* t = nullptr) : result_(t) {}
void operator()(resp3::basic_node<std::string_view> const& nd, system::error_code&)
template <class String>
void operator()(resp3::basic_node<String> const& nd, system::error_code&)
{
BOOST_ASSERT_MSG(!!result_, "Unexpected null pointer");
switch (nd.data_type) {
@@ -136,10 +138,11 @@ class simple_impl {
public:
void on_value_available(Result&) {}
template <class String>
void
operator()(
Result& result,
resp3::basic_node<std::string_view> const& n,
resp3::basic_node<String> const& n,
system::error_code& ec)
{
if (is_aggregate(n.data_type)) {
@@ -160,10 +163,11 @@ public:
void on_value_available(Result& result)
{ hint_ = std::end(result); }
template <class String>
void
operator()(
Result& result,
resp3::basic_node<std::string_view> const& nd,
resp3::basic_node<String> const& nd,
system::error_code& ec)
{
if (is_aggregate(nd.data_type)) {
@@ -195,10 +199,11 @@ public:
void on_value_available(Result& result)
{ current_ = std::end(result); }
template <class String>
void
operator()(
Result& result,
resp3::basic_node<std::string_view> const& nd,
resp3::basic_node<String> const& nd,
system::error_code& ec)
{
if (is_aggregate(nd.data_type)) {
@@ -233,10 +238,11 @@ class vector_impl {
public:
void on_value_available(Result& ) { }
template <class String>
void
operator()(
Result& result,
resp3::basic_node<std::string_view> const& nd,
resp3::basic_node<String> const& nd,
system::error_code& ec)
{
if (is_aggregate(nd.data_type)) {
@@ -257,10 +263,11 @@ private:
public:
void on_value_available(Result& ) { }
template <class String>
void
operator()(
Result& result,
resp3::basic_node<std::string_view> const& nd,
resp3::basic_node<String> const& nd,
system::error_code& ec)
{
if (is_aggregate(nd.data_type)) {
@@ -292,10 +299,11 @@ struct list_impl {
void on_value_available(Result& ) { }
template <class String>
void
operator()(
Result& result,
resp3::basic_node<std::string_view> const& nd,
resp3::basic_node<String> const& nd,
system::error_code& ec)
{
if (!is_aggregate(nd.data_type)) {
@@ -365,7 +373,8 @@ private:
response_type* result_;
typename impl_map<Result>::type impl_;
bool set_if_resp3_error(resp3::basic_node<std::string_view> const& nd) noexcept
template <class String>
bool set_if_resp3_error(resp3::basic_node<String> const& nd) noexcept
{
switch (nd.data_type) {
case resp3::type::null:
@@ -387,9 +396,10 @@ public:
}
}
template <class String>
void
operator()(
resp3::basic_node<std::string_view> const& nd,
resp3::basic_node<String> const& nd,
system::error_code& ec)
{
BOOST_ASSERT_MSG(!!result_, "Unexpected null pointer");
@@ -414,7 +424,8 @@ private:
response_type* result_;
typename impl_map<T>::type impl_{};
bool set_if_resp3_error(resp3::basic_node<std::string_view> const& nd) noexcept
template <class String>
bool set_if_resp3_error(resp3::basic_node<String> const& nd) noexcept
{
switch (nd.data_type) {
case resp3::type::blob_error:
@@ -429,9 +440,10 @@ private:
public:
explicit wrapper(response_type* o = nullptr) : result_(o) {}
template <class String>
void
operator()(
resp3::basic_node<std::string_view> const& nd,
resp3::basic_node<String> const& nd,
system::error_code& ec)
{
BOOST_ASSERT_MSG(!!result_, "Unexpected null pointer");

View File

@@ -23,8 +23,9 @@ namespace boost::redis::adapter::detail
class ignore_adapter {
public:
template <class String>
void
operator()(std::size_t, resp3::basic_node<std::string_view> const& nd, system::error_code& ec)
operator()(std::size_t, resp3::basic_node<String> const& nd, system::error_code& ec)
{
switch (nd.data_type) {
case resp3::type::simple_error: ec = redis::error::resp3_simple_error; break;
@@ -59,10 +60,11 @@ public:
auto get_supported_response_size() const noexcept
{ return size;}
template <class String>
void
operator()(
std::size_t i,
resp3::basic_node<std::string_view> const& nd,
resp3::basic_node<String> const& nd,
system::error_code& ec)
{
using std::visit;
@@ -88,10 +90,11 @@ public:
get_supported_response_size() const noexcept
{ return static_cast<std::size_t>(-1);}
template <class String>
void
operator()(
std::size_t,
resp3::basic_node<std::string_view> const& nd,
resp3::basic_node<String> const& nd,
system::error_code& ec)
{
adapter_(nd, ec);
@@ -142,7 +145,8 @@ class wrapper {
public:
explicit wrapper(Adapter adapter) : adapter_{adapter} {}
void operator()(resp3::basic_node<std::string_view> const& nd, system::error_code& ec)
template <class String>
void operator()(resp3::basic_node<String> const& nd, system::error_code& ec)
{ return adapter_(0, nd, ec); }
[[nodiscard]]

View File

@@ -116,7 +116,8 @@ public:
}
}
void count(resp3::basic_node<std::string_view> const& nd)
template <class String>
void count(resp3::basic_node<String> const& nd)
{
if (nd.depth == 1) {
if (is_aggregate(nd.data_type))
@@ -131,7 +132,8 @@ public:
++i_;
}
void operator()(resp3::basic_node<std::string_view> const& nd, system::error_code& ec)
template <class String>
void operator()(resp3::basic_node<String> const& nd, system::error_code& ec)
{
using std::visit;

View File

@@ -589,3 +589,16 @@ BOOST_AUTO_TEST_CASE(adapter)
BOOST_CHECK_EQUAL(std::get<1>(resp).value(), 42);
BOOST_TEST(!ec);
}
// TODO: This was an experiment, I will resume implementing this
// later.
BOOST_AUTO_TEST_CASE(adapter_as)
{
result<std::set<std::string>> set;
auto adapter = adapt2(set);
for (auto const& e: set_expected1a.value()) {
error_code ec;
adapter(e, ec);
}
}