21 #ifndef INCLUDE_OLA_IO_MEMORYBLOCK_H_
22 #define INCLUDE_OLA_IO_MEMORYBLOCK_H_
40 m_data_end(data + size),
58 unsigned int Capacity()
const {
return m_capacity; }
61 unsigned int Size()
const {
62 return static_cast<unsigned int>(m_last - m_first);
66 return m_last == m_first;
70 uint8_t *Data()
const {
return m_first; }
74 unsigned int Append(
const uint8_t *data,
unsigned int length) {
75 unsigned int bytes_to_write = std::min(
76 length, static_cast<unsigned int>(m_data_end - m_last));
77 memcpy(m_last, data, bytes_to_write);
78 m_last += bytes_to_write;
79 return bytes_to_write;
85 unsigned int Prepend(
const uint8_t *data,
unsigned int length) {
86 unsigned int bytes_to_write = std::min(
87 length, static_cast<unsigned int>(m_first - m_data));
88 memcpy(m_first - bytes_to_write, data + length - bytes_to_write,
90 m_first -= bytes_to_write;
91 return bytes_to_write;
96 unsigned int Copy(uint8_t *data,
unsigned int length)
const {
97 unsigned int bytes_to_read = std::min(
98 length, static_cast<unsigned int>(m_last - m_first));
99 memcpy(data, m_first, bytes_to_read);
100 return bytes_to_read;
104 unsigned int PopFront(
unsigned int length) {
105 unsigned int bytes_to_pop = std::min(
106 length, static_cast<unsigned int>(m_last - m_first));
107 m_first += bytes_to_pop;
112 uint8_t*
const m_data;
113 uint8_t*
const m_data_end;
114 unsigned int m_capacity;
121 #endif // INCLUDE_OLA_IO_MEMORYBLOCK_H_