1 #include "utilities/dequeue_buffer.h" 7 assert(sentinel_ == kSentinel);
12 assert(sentinel_ == kSentinel);
13 return written_bytes_;
17 assert(sentinel_ == kSentinel);
22 if (written_bytes_ < bytes) {
23 throw std::logic_error(
"Attempt to DequeueBuffer::Consume() more bytes than are valid");
26 auto* next_unconsumed_byte = buffer_.begin() + bytes;
27 auto* end_of_written_area = buffer_.begin() + written_bytes_;
28 std::copy(next_unconsumed_byte, end_of_written_area, buffer_.begin());
29 written_bytes_ -= bytes;
33 assert(sentinel_ == kSentinel);
35 return buffer_.data() + written_bytes_;
39 assert(sentinel_ == kSentinel);
40 return buffer_.size() - written_bytes_;
47 assert(sentinel_ == kSentinel);
48 if (buffer_.size() < written_bytes_ + bytes) {
49 throw std::logic_error(
"Wrote bytes beyond the end of the buffer");
51 written_bytes_ += bytes;
void HaveEnqueued(size_t bytes)
Call to indicate that bytes have been written in the range Tail() ...
char * Head()
A pointer to the first element that has not been Consumed().
size_t Size() const
The number of elements that are valid (have been written) after Head()
void Consume(size_t bytes)
Called after bytes have been read from Head().
size_t TailSpace()
The number of bytes beyond Tail() that are allocated and may be written to.
char * Tail()
A pointer to the next place to write data to.