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 #ifndef BOOST_REDIS_RESP3_NODE_HPP
0008 #define BOOST_REDIS_RESP3_NODE_HPP
0009 
0010 #include <boost/redis/resp3/type.hpp>
0011 
0012 namespace boost::redis::resp3 {
0013 
0014 /** \brief A node in the response tree.
0015  *  \ingroup high-level-api
0016  *
0017  *  RESP3 can contain recursive data structures: A map of sets of
0018  *  vector of etc. As it is parsed each element is passed to user
0019  *  callbacks (push parser). The signature of this
0020  *  callback is `f(resp3::node<std::string_view)`. This class is called a node
0021  *  because it can be seen as the element of the response tree. It
0022  *  is a template so that users can use it with owing strings e.g.
0023  *  `std::string` or `boost::static_string` etc.
0024  *
0025  *  @tparam String A `std::string`-like type.
0026  */
0027 template <class String>
0028 struct basic_node {
0029    /// The RESP3 type of the data in this node.
0030    type data_type = type::invalid;
0031 
0032    /// The number of elements of an aggregate.
0033    std::size_t aggregate_size{};
0034 
0035    /// The depth of this node in the response tree.
0036    std::size_t depth{};
0037 
0038    /// The actual data. For aggregate types this is usually empty.
0039    String value{};
0040 };
0041 
0042 /** @brief Compares a node for equality.
0043  *  @relates basic_node
0044  *
0045  *  @param a Left hand side node object.
0046  *  @param b Right hand side node object.
0047  */
0048 template <class String>
0049 auto operator==(basic_node<String> const& a, basic_node<String> const& b)
0050 {
0051    return a.aggregate_size == b.aggregate_size
0052        && a.depth == b.depth
0053        && a.data_type == b.data_type
0054        && a.value == b.value;
0055 };
0056 
0057 /** @brief A node in the response tree that owns its data
0058  *  @ingroup high-level-api
0059  */
0060 using node = basic_node<std::string>;
0061 
0062 /** @brief A node view in the response tree
0063  *  @ingroup high-level-api
0064  */
0065 using node_view = basic_node<std::string_view>;
0066 
0067 } // boost::redis::resp3
0068 
0069 #endif // BOOST_REDIS_RESP3_NODE_HPP