37 #ifndef BOOST_BEAST_ZLIB_DETAIL_WINDOW_HPP 38 #define BOOST_BEAST_ZLIB_DETAIL_WINDOW_HPP 40 #include <boost/assert.hpp> 41 #include <boost/make_unique.hpp> 53 std::unique_ptr<std::uint8_t[]> p_;
55 std::uint16_t size_ = 0;
56 std::uint16_t capacity_ = 0;
57 std::uint8_t bits_ = 0;
82 read(std::uint8_t* out, std::size_t pos, std::size_t n);
84 template<
class =
void>
86 write(std::uint8_t
const* in, std::size_t n);
97 bits_ =
static_cast<std::uint8_t
>(
bits);
98 capacity_ = 1U << bits_;
107 read(std::uint8_t* out, std::size_t pos, std::size_t n)
112 std::memcpy(out, &p_[i_ - pos], n);
115 auto i = ((i_ - pos) + capacity_) % capacity_;
116 auto m = capacity_ - i;
119 std::memcpy(out, &p_[i], n);
122 std::memcpy(out, &p_[i], m);
124 std::memcpy(out, &p_[0], n - m);
130 write(std::uint8_t
const* in, std::size_t n)
133 p_ = boost::make_unique<
134 std::uint8_t[]>(capacity_);
139 std::memcpy(&p_[0], in + (n - size_), size_);
142 if(i_ + n <= capacity_)
144 std::memcpy(&p_[i_], in, n);
145 if(size_ >= capacity_ - n)
148 size_ =
static_cast<std::uint16_t
>(size_ + n);
150 i_ =
static_cast<std::uint16_t
>(
151 (i_ + n) % capacity_);
154 auto m = capacity_ - i_;
155 std::memcpy(&p_[i_], in, m);
157 i_ =
static_cast<std::uint16_t
>(n - m);
158 std::memcpy(&p_[0], in, i_);
unsigned capacity() const
Definition: window.hpp:67
Definition: async_result.hpp:20
void reset(int bits)
Definition: window.hpp:92
int bits() const
Definition: window.hpp:61
void write(std::uint8_t const *in, std::size_t n)
Definition: window.hpp:130
void read(std::uint8_t *out, std::size_t pos, std::size_t n)
Definition: window.hpp:107
unsigned size() const
Definition: window.hpp:73
Definition: window.hpp:51