Loading [MathJax]/extensions/tex2jax.js
Loading...
Searching...
No Matches
any_adapter.hpp
1/* Copyright (c) 2018-2023 Marcelo Zimbres Silva (mzimbres@gmail.com)
2 *
3 * Distributed under the Boost Software License, Version 1.0. (See
4 * accompanying file LICENSE.txt)
5 */
6
7#ifndef BOOST_REDIS_ANY_ADAPTER_HPP
8#define BOOST_REDIS_ANY_ADAPTER_HPP
9
10
11#include <boost/redis/resp3/node.hpp>
12#include <boost/redis/adapter/adapt.hpp>
13#include <boost/system/error_code.hpp>
14#include <cstddef>
15#include <functional>
16#include <string_view>
17#include <type_traits>
18
19namespace boost::redis {
20
21namespace detail {
22
23// Forward decl
24template <class Executor>
25class basic_connection;
26
27}
28
43{
44 using fn_type = std::function<void(std::size_t, resp3::basic_node<std::string_view> const&, system::error_code&)>;
45
46 struct impl_t {
47 fn_type adapt_fn;
48 std::size_t supported_response_size;
49 } impl_;
50
51 template <class T>
52 static auto create_impl(T& resp) -> impl_t
53 {
54 using namespace boost::redis::adapter;
55 auto adapter = boost_redis_adapt(resp);
56 std::size_t size = adapter.get_supported_response_size();
57 return { std::move(adapter), size };
58 }
59
60 template <class Executor>
61 friend class basic_connection;
62
63public:
74 template <class T, class = std::enable_if_t<!std::is_same_v<T, any_adapter>>>
75 explicit any_adapter(T& resp) : impl_(create_impl(resp)) {}
76};
77
78}
79
80#endif
A type-erased reference to a response.
any_adapter(T &resp)
Constructor.
A SSL connection to the Redis server.
A node in the response tree.
Definition node.hpp:28