Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-17 09:00:18

0001 /* Copyright (c) 2018-2025 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_READ_BUFFER_HPP
0008 #define BOOST_REDIS_READ_BUFFER_HPP
0009 
0010 #include <boost/core/span.hpp>
0011 #include <boost/system/error_code.hpp>
0012 
0013 #include <cstddef>
0014 #include <string_view>
0015 #include <utility>
0016 #include <vector>
0017 
0018 namespace boost::redis::detail {
0019 
0020 class read_buffer {
0021 public:
0022    using span_type = span<char>;
0023 
0024    struct consume_result {
0025       std::size_t consumed;
0026       std::size_t rotated;
0027    };
0028 
0029    // See config.hpp for the meaning of these parameters.
0030    struct config {
0031       std::size_t read_buffer_append_size = 4096u;
0032       std::size_t max_read_size = static_cast<std::size_t>(-1);
0033    };
0034 
0035    // Prepare the buffer to receive more data.
0036    [[nodiscard]]
0037    auto prepare() -> system::error_code;
0038 
0039    [[nodiscard]]
0040    auto get_prepared() noexcept -> span_type;
0041 
0042    void commit(std::size_t read_size);
0043 
0044    [[nodiscard]]
0045    auto get_commited() const noexcept -> std::string_view;
0046 
0047    void clear();
0048 
0049    // Consumes committed data by rotating the remaining data to the
0050    // front of the buffer.
0051    auto consume(std::size_t size) -> consume_result;
0052 
0053    void reserve(std::size_t n);
0054 
0055    friend bool operator==(read_buffer const& lhs, read_buffer const& rhs);
0056 
0057    friend bool operator!=(read_buffer const& lhs, read_buffer const& rhs);
0058 
0059    void set_config(config const& cfg) noexcept { cfg_ = cfg; };
0060 
0061 private:
0062    config cfg_ = config{};
0063    std::vector<char> buffer_;
0064    std::size_t append_buf_begin_ = 0;
0065 };
0066 
0067 }  // namespace boost::redis::detail
0068 
0069 #endif  // BOOST_REDIS_READ_BUFFER_HPP