Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 10:08:25

0001 /* Copyright (c) 2018-2024 Marcelo Zimbres Silva (mzimbres@gmail.com)
0002  *
0003  * Distributed under the Boost Software License, Version 1.0. (See
0004  * accompanying file LICENSE.txt)
0005  */
0006 
0007 #ifndef BOOST_REDIS_RESPONSE_HPP
0008 #define BOOST_REDIS_RESPONSE_HPP
0009 
0010 #include <boost/redis/resp3/node.hpp>
0011 #include <boost/redis/adapter/result.hpp>
0012 #include <boost/system.hpp>
0013 
0014 #include <vector>
0015 #include <string>
0016 #include <tuple>
0017 
0018 namespace boost::redis
0019 {
0020 
0021 /** @brief Response with compile-time size.
0022  *  @ingroup high-level-api
0023  */
0024 template <class... Ts>
0025 using response = std::tuple<adapter::result<Ts>...>;
0026 
0027 /** @brief A generic response to a request
0028  *  @ingroup high-level-api
0029  *
0030  *  This response type can store any type of RESP3 data structure.  It
0031  *  contains the
0032  *  [pre-order](https://en.wikipedia.org/wiki/Tree_traversal#Pre-order,_NLR)
0033  *  view of the response tree.
0034  */
0035 using generic_response = adapter::result<std::vector<resp3::node>>;
0036 
0037 /** @brief Consume on response from a generic response
0038  *
0039  *  This function rotates the elements so that the start of the next
0040  *  response becomes the new front element. For example the output of
0041  *  the following code
0042  *
0043  * @code
0044  * request req;
0045  * req.push("PING", "one");
0046  * req.push("PING", "two");
0047  * req.push("PING", "three");
0048  *
0049  * generic_response resp;
0050  * co_await conn->async_exec(req, resp, asio::deferred);
0051  *
0052  * std::cout << "PING: " << resp.value().front().value << std::endl;
0053  * consume_one(resp);
0054  * std::cout << "PING: " << resp.value().front().value << std::endl;
0055  * consume_one(resp);
0056  * std::cout << "PING: " << resp.value().front().value << std::endl;
0057  * @endcode
0058  *
0059  * is
0060  *
0061  * @code
0062  * PING: one
0063  * PING: two
0064  * PING: three
0065  * @endcode
0066  *
0067  * Given that this function rotates elements, it won't be very
0068  * efficient for responses with a large number of elements. It was
0069  * introduced mainly to deal with buffers server pushes as shown in
0070  * the cpp20_subscriber.cpp example. In the future queue-like
0071  * responses might be introduced to consume in O(1) operations. 
0072  */
0073 void consume_one(generic_response& r, system::error_code& ec);
0074 
0075 /// Throwing overload of `consume_one`.
0076 void consume_one(generic_response& r);
0077 
0078 } // boost::redis
0079 
0080 #endif // BOOST_REDIS_RESPONSE_HPP