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#include <boost/redis/adapter/adapt.hpp>
11#include <boost/redis/resp3/node.hpp>
12
13#include <boost/system/error_code.hpp>
14
15#include <cstddef>
16#include <functional>
17#include <string_view>
18#include <type_traits>
19
20namespace boost::redis {
21
36public:
37 using fn_type = std::function<void(std::size_t, resp3::node_view const&, system::error_code&)>;
38
39 struct impl_t {
40 fn_type adapt_fn;
41 std::size_t supported_response_size;
42 } impl_;
43
44 template <class T>
45 static auto create_impl(T& resp) -> impl_t
46 {
47 using namespace boost::redis::adapter;
48 auto adapter = boost_redis_adapt(resp);
49 std::size_t size = adapter.get_supported_response_size();
50 return {std::move(adapter), size};
51 }
52
53 template <class Executor>
54 friend class basic_connection;
55
66 template <class T, class = std::enable_if_t<!std::is_same_v<T, any_adapter>>>
67 explicit any_adapter(T& resp)
68 : impl_(create_impl(resp))
69 { }
70};
71
72} // namespace boost::redis
73
74#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