7#ifndef BOOST_REDIS_ADAPTER_DETAIL_RESPONSE_TRAITS_HPP
8#define BOOST_REDIS_ADAPTER_DETAIL_RESPONSE_TRAITS_HPP
10#include <boost/redis/resp3/node.hpp>
11#include <boost/redis/response.hpp>
12#include <boost/redis/adapter/detail/result_traits.hpp>
13#include <boost/mp11.hpp>
14#include <boost/system.hpp>
21namespace boost::redis::adapter::detail
26 template <
class String>
27 void operator()(std::size_t, resp3::basic_node<String>
const& nd, system::error_code& ec)
29 switch (nd.data_type) {
38 auto get_supported_response_size() const noexcept
39 {
return static_cast<std::size_t
>(-1);}
42template <
class Response>
45 static constexpr auto size = std::tuple_size<Response>::value;
46 using adapter_tuple = mp11::mp_transform<adapter_t, Response>;
47 using variant_type = mp11::mp_rename<adapter_tuple, std::variant>;
48 using adapters_array_type = std::array<variant_type, size>;
50 adapters_array_type adapters_;
53 explicit static_adapter(Response& r)
55 assigner<size - 1>::assign(adapters_, r);
59 auto get_supported_response_size() const noexcept
62 template <
class String>
63 void operator()(std::size_t i, resp3::basic_node<String>
const& nd, system::error_code& ec)
67 BOOST_ASSERT(i < adapters_.size());
68 visit([&](
auto& arg){arg(nd, ec);}, adapters_.at(i));
72template <
class Vector>
75 using adapter_type =
typename result_traits<Vector>::adapter_type;
76 adapter_type adapter_;
79 explicit vector_adapter(Vector& v)
80 : adapter_{internal_adapt(v)}
85 get_supported_response_size() const noexcept
86 {
return static_cast<std::size_t
>(-1);}
88 template <
class String>
89 void operator()(std::size_t, resp3::basic_node<String>
const& nd, system::error_code& ec)
96struct response_traits;
101 using adapter_type = detail::ignore_adapter;
103 static auto adapt(response_type&)
noexcept
104 {
return detail::ignore_adapter{}; }
110 using adapter_type = detail::ignore_adapter;
112 static auto adapt(response_type&)
noexcept
113 {
return detail::ignore_adapter{}; }
116template <
class String,
class Allocator>
117struct response_traits<
result<std::vector<resp3::basic_node<String>, Allocator>>> {
119 using adapter_type = vector_adapter<response_type>;
121 static auto adapt(response_type& v)
noexcept
122 {
return adapter_type{v}; }
125template <
class ...Ts>
126struct response_traits<
response<Ts...>> {
127 using response_type =
response<Ts...>;
128 using adapter_type = static_adapter<response_type>;
130 static auto adapt(response_type& r)
noexcept
131 {
return adapter_type{r}; }
134template <
class Adapter>
137 explicit wrapper(Adapter adapter) : adapter_{adapter} {}
139 template <
class String>
140 void operator()(resp3::basic_node<String>
const& nd, system::error_code& ec)
141 {
return adapter_(0, nd, ec); }
144 auto get_supported_response_size() const noexcept
145 {
return adapter_.get_supported_response_size();}
151template <
class Adapter>
152auto make_adapter_wrapper(Adapter adapter)
154 return wrapper{adapter};
system::result< Value, error > result
Stores response to individual Redis commands.
std::decay_t< decltype(std::ignore)> ignore_t
Type used to ignore responses.
std::tuple< adapter::result< Ts >... > response
Response with compile-time size.
@ resp3_blob_error
Got RESP3 blob_error.
@ resp3_null
Got RESP3 null.
@ resp3_simple_error
Got RESP3 simple error.