26 #ifndef INCLUDE_OLA_IO_MEMORYBLOCK_H_
27 #define INCLUDE_OLA_IO_MEMORYBLOCK_H_
51 m_data_end(data + size),
77 unsigned int Capacity()
const {
return m_capacity; }
84 return static_cast<unsigned int>(m_data_end - m_last);
91 unsigned int Size()
const {
92 return static_cast<unsigned int>(m_last - m_first);
100 return m_last == m_first;
107 uint8_t *
Data()
const {
return m_first; }
116 unsigned int Append(
const uint8_t *data,
unsigned int length) {
117 unsigned int bytes_to_write = std::min(
118 length, static_cast<unsigned int>(m_data_end - m_last));
119 memcpy(m_last, data, bytes_to_write);
120 m_last += bytes_to_write;
121 return bytes_to_write;
131 unsigned int Prepend(
const uint8_t *data,
unsigned int length) {
132 unsigned int bytes_to_write = std::min(
133 length, static_cast<unsigned int>(m_first - m_data));
134 memcpy(m_first - bytes_to_write, data + length - bytes_to_write,
136 m_first -= bytes_to_write;
137 return bytes_to_write;
146 unsigned int Copy(uint8_t *data,
unsigned int length)
const {
147 unsigned int bytes_to_read = std::min(
148 length, static_cast<unsigned int>(m_last - m_first));
149 memcpy(data, m_first, bytes_to_read);
150 return bytes_to_read;
159 unsigned int bytes_to_pop = std::min(
160 length, static_cast<unsigned int>(m_last - m_first));
161 m_first += bytes_to_pop;
163 if (m_first == m_last) {
171 uint8_t*
const m_data;
172 uint8_t*
const m_data_end;
173 unsigned int m_capacity;
180 #endif // INCLUDE_OLA_IO_MEMORYBLOCK_H_