|
1 | | -/* Copyright (c) 2018-2024 Marcelo Zimbres Silva (mzimbres@gmail.com) |
| 1 | +/* Copyright (c) 2018-2025 Marcelo Zimbres Silva (mzimbres@gmail.com) |
2 | 2 | * |
3 | 3 | * Distributed under the Boost Software License, Version 1.0. (See |
4 | 4 | * accompanying file LICENSE.txt) |
|
12 | 12 | #include <boost/redis/resp3/node.hpp> |
13 | 13 | #include <boost/redis/resp3/serialization.hpp> |
14 | 14 | #include <boost/redis/resp3/type.hpp> |
15 | | -#include <boost/redis/response.hpp> |
| 15 | +#include <boost/redis/resp3/flat_tree.hpp> |
16 | 16 |
|
17 | 17 | #include <boost/assert.hpp> |
18 | 18 |
|
19 | 19 | #include <array> |
20 | 20 | #include <charconv> |
21 | 21 | #include <deque> |
22 | 22 | #include <forward_list> |
23 | | -#include <iostream> |
24 | 23 | #include <list> |
25 | 24 | #include <map> |
26 | 25 | #include <optional> |
@@ -138,6 +137,8 @@ void boost_redis_from_bulk(T& t, resp3::basic_node<String> const& node, system:: |
138 | 137 | from_bulk_impl<T>::apply(t, node, ec); |
139 | 138 | } |
140 | 139 |
|
| 140 | +//================================================ |
| 141 | + |
141 | 142 | template <class Result> |
142 | 143 | class general_aggregate { |
143 | 144 | private: |
@@ -177,37 +178,54 @@ class general_aggregate { |
177 | 178 | }; |
178 | 179 |
|
179 | 180 | template <> |
180 | | -class general_aggregate<result<flat_response_value>> { |
| 181 | +class general_aggregate<resp3::tree> { |
181 | 182 | private: |
182 | | - result<flat_response_value>* result_; |
| 183 | + resp3::tree* tree_ = nullptr; |
183 | 184 |
|
184 | 185 | public: |
185 | | - explicit general_aggregate(result<flat_response_value>* c = nullptr) |
186 | | - : result_(c) |
| 186 | + explicit general_aggregate(resp3::tree* c = nullptr) |
| 187 | + : tree_(c) |
| 188 | + { } |
| 189 | + |
| 190 | + void on_init() { } |
| 191 | + void on_done() { } |
| 192 | + |
| 193 | + template <class String> |
| 194 | + void on_node(resp3::basic_node<String> const& nd, system::error_code&) |
| 195 | + { |
| 196 | + BOOST_ASSERT_MSG(!!tree_, "Unexpected null pointer"); |
| 197 | + |
| 198 | + resp3::node tmp; |
| 199 | + tmp.data_type = nd.data_type; |
| 200 | + tmp.aggregate_size = nd.aggregate_size; |
| 201 | + tmp.depth = nd.depth; |
| 202 | + tmp.value = std::string{std::cbegin(nd.value), std::cend(nd.value)}; |
| 203 | + |
| 204 | + tree_->push_back(std::move(tmp)); |
| 205 | + } |
| 206 | +}; |
| 207 | + |
| 208 | +template <> |
| 209 | +class general_aggregate<resp3::flat_tree> { |
| 210 | +private: |
| 211 | + resp3::flat_tree* tree_ = nullptr; |
| 212 | + |
| 213 | +public: |
| 214 | + explicit general_aggregate(resp3::flat_tree* c = nullptr) |
| 215 | + : tree_(c) |
187 | 216 | { } |
188 | 217 |
|
189 | 218 | void on_init() { } |
190 | 219 | void on_done() |
191 | 220 | { |
192 | | - if (result_->has_value()) { |
193 | | - result_->value().set_view(); |
194 | | - } |
| 221 | + tree_->notify_done(); |
195 | 222 | } |
196 | 223 |
|
197 | 224 | template <class String> |
198 | | - void operator()(resp3::basic_node<String> const& nd, system::error_code&) |
| 225 | + void on_node(resp3::basic_node<String> const& nd, system::error_code&) |
199 | 226 | { |
200 | | - BOOST_ASSERT_MSG(!!result_, "Unexpected null pointer"); |
201 | | - switch (nd.data_type) { |
202 | | - case resp3::type::blob_error: |
203 | | - case resp3::type::simple_error: |
204 | | - *result_ = error{ |
205 | | - nd.data_type, |
206 | | - std::string{std::cbegin(nd.value), std::cend(nd.value)} |
207 | | - }; |
208 | | - break; |
209 | | - default: result_->value().add_node(nd); |
210 | | - } |
| 227 | + BOOST_ASSERT_MSG(!!tree_, "Unexpected null pointer"); |
| 228 | + tree_->push(nd); |
211 | 229 | } |
212 | 230 | }; |
213 | 231 |
|
|
0 commit comments