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
27 operator()(std::size_t, resp3::basic_node<std::string_view>
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
65 resp3::basic_node<std::string_view>
const& nd,
66 system::error_code& ec)
70 BOOST_ASSERT(i < adapters_.size());
71 visit([&](
auto& arg){arg(nd, ec);}, adapters_.at(i));
75template <
class Vector>
78 using adapter_type =
typename result_traits<Vector>::adapter_type;
79 adapter_type adapter_;
82 explicit vector_adapter(Vector& v)
83 : adapter_{internal_adapt(v)}
88 get_supported_response_size() const noexcept
89 {
return static_cast<std::size_t
>(-1);}
94 resp3::basic_node<std::string_view>
const& nd,
95 system::error_code& ec)
102struct response_traits;
107 using adapter_type = detail::ignore_adapter;
109 static auto adapt(response_type&)
noexcept
110 {
return detail::ignore_adapter{}; }
115 using response_type = result<ignore_t>;
116 using adapter_type = detail::ignore_adapter;
118 static auto adapt(response_type&)
noexcept
119 {
return detail::ignore_adapter{}; }
122template <
class String,
class Allocator>
123struct response_traits<
result<std::vector<resp3::basic_node<String>, Allocator>>> {
124 using response_type = result<std::vector<resp3::basic_node<String>, Allocator>>;
125 using adapter_type = vector_adapter<response_type>;
127 static auto adapt(response_type& v)
noexcept
128 {
return adapter_type{v}; }
131template <
class ...Ts>
132struct response_traits<
response<Ts...>> {
133 using response_type =
response<Ts...>;
134 using adapter_type = static_adapter<response_type>;
136 static auto adapt(response_type& r)
noexcept
137 {
return adapter_type{r}; }
140template <
class Adapter>
143 explicit wrapper(Adapter adapter) : adapter_{adapter} {}
145 void operator()(resp3::basic_node<std::string_view>
const& nd, system::error_code& ec)
146 {
return adapter_(0, nd, ec); }
149 auto get_supported_response_size() const noexcept
150 {
return adapter_.get_supported_response_size();}
156template <
class Adapter>
157auto make_adapter_wrapper(Adapter adapter)
159 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.