From 83492339ec3ee05877bb944893b3dedeba5760dc Mon Sep 17 00:00:00 2001 From: apio Date: Thu, 23 Mar 2023 21:20:57 +0100 Subject: [PATCH] Buffer: Add an append_data() method --- libluna/include/luna/Buffer.h | 2 ++ libluna/src/Buffer.cpp | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/libluna/include/luna/Buffer.h b/libluna/include/luna/Buffer.h index bb2796b3..6d6f89c0 100644 --- a/libluna/include/luna/Buffer.h +++ b/libluna/include/luna/Buffer.h @@ -19,6 +19,8 @@ class Buffer Result slice(usize offset, usize size); + Result append_data(u8* data, usize size); + u8* data() { return m_data; diff --git a/libluna/src/Buffer.cpp b/libluna/src/Buffer.cpp index 1b331e2e..6c385db5 100644 --- a/libluna/src/Buffer.cpp +++ b/libluna/src/Buffer.cpp @@ -1,4 +1,5 @@ #include +#include #include Buffer::Buffer() @@ -44,3 +45,10 @@ Result Buffer::slice(usize offset, usize size) if (offset + size > m_size) { TRY(try_resize(offset + size)); } return m_data + offset; } + +Result Buffer::append_data(u8* data, usize size) +{ + memcpy(TRY(slice_at_end(size)), data, size); + + return {}; +}