Buffer: Add an append_data() method

This commit is contained in:
apio 2023-03-23 21:20:57 +01:00
parent 89ad6869a4
commit 83492339ec
Signed by: apio
GPG Key ID: B8A7D06E42258954
2 changed files with 10 additions and 0 deletions

View File

@ -19,6 +19,8 @@ class Buffer
Result<u8*> slice(usize offset, usize size); Result<u8*> slice(usize offset, usize size);
Result<void> append_data(u8* data, usize size);
u8* data() u8* data()
{ {
return m_data; return m_data;

View File

@ -1,4 +1,5 @@
#include <luna/Buffer.h> #include <luna/Buffer.h>
#include <luna/CString.h>
#include <luna/Heap.h> #include <luna/Heap.h>
Buffer::Buffer() Buffer::Buffer()
@ -44,3 +45,10 @@ Result<u8*> Buffer::slice(usize offset, usize size)
if (offset + size > m_size) { TRY(try_resize(offset + size)); } if (offset + size > m_size) { TRY(try_resize(offset + size)); }
return m_data + offset; return m_data + offset;
} }
Result<void> Buffer::append_data(u8* data, usize size)
{
memcpy(TRY(slice_at_end(size)), data, size);
return {};
}