Luna/libluna/include/luna/Buffer.h

64 lines
995 B
C
Raw Normal View History

#pragma once
#include <luna/Result.h>
#include <luna/Types.h>
class Buffer
{
public:
Buffer();
~Buffer();
Buffer(Buffer&& other);
Buffer(const Buffer& other) = delete; // For now.
static Result<Buffer> create_sized(usize size);
Result<void> try_resize(usize new_size);
Result<u8*> slice_at_end(usize size);
Result<u8*> slice(usize offset, usize size);
Result<void> append_data(const u8* data, usize size);
2023-03-23 20:20:57 +00:00
usize dequeue_data(u8* data, usize size);
u8* data()
{
return m_data;
}
const u8* data() const
{
return m_data;
}
u8* release_data();
u8* end()
{
return m_data + m_size;
}
const u8* end() const
{
return m_data + m_size;
}
usize size() const
{
return m_size;
}
2023-04-18 14:40:37 +00:00
bool is_empty() const
{
return m_size == 0;
}
private:
Buffer(u8* data, usize size);
u8* m_data { nullptr };
usize m_size { 0 };
};