Back to home page

EIC code displayed by LXR

 
 

    


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

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 #include <boost/redis/response.hpp>
0008 #include <boost/redis/error.hpp>
0009 #include <boost/assert.hpp>
0010 
0011 namespace boost::redis
0012 {
0013 
0014 void consume_one(generic_response& r, system::error_code& ec)
0015 {
0016    if (r.has_error())
0017       return; // Nothing to consume.
0018 
0019    if (std::empty(r.value()))
0020       return; // Nothing to consume.
0021 
0022    auto const depth = r.value().front().depth;
0023 
0024    // To simplify we will refuse to consume any data-type that is not
0025    // a root node. I think there is no use for that and it is complex
0026    // since it requires updating parent nodes.
0027    if (depth != 0) {
0028       ec = error::incompatible_node_depth;
0029       return;
0030    }
0031 
0032    auto f = [depth](auto const& e)
0033       { return e.depth == depth; };
0034 
0035    auto match = std::find_if(std::next(std::cbegin(r.value())), std::cend(r.value()), f);
0036 
0037    r.value().erase(std::cbegin(r.value()), match);
0038 }
0039 
0040 void consume_one(generic_response& r)
0041 {
0042    system::error_code ec;
0043    consume_one(r, ec);
0044    if (ec)
0045       throw system::system_error(ec);
0046 }
0047 
0048 } // boost::redis::resp3