Luna/libluna/include/luna/Buffer.h
apio 498e20561f
libluna: Add release_data() overloads to Buffer and Vector
This can be used to transfer the underlying data to a String object without copying.
2023-07-02 19:29:04 +02:00

62 lines
948 B
C++

#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);
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;
}
bool is_empty() const
{
return m_size == 0;
}
private:
Buffer(u8* data, usize size);
u8* m_data { nullptr };
usize m_size { 0 };
};