summaryrefslogtreecommitdiff
path: root/AK
diff options
context:
space:
mode:
authorAnotherTest <ali.mpfard@gmail.com>2020-04-03 06:22:31 +0430
committerAndreas Kling <kling@serenityos.org>2020-04-03 09:42:13 +0200
commitdf7062aac52efb15fe63d34cdbec388e44f8b501 (patch)
tree083b5e1cf9bc4b48156d3c7d227ae6a50bb99d73 /AK
parent3fae4cb0548d515e016c6eef065f1b9fad4065d6 (diff)
downloadserenity-df7062aac52efb15fe63d34cdbec388e44f8b501.zip
AK: Add an overwrite API to ByteBuffer
Since ByteBuffer is a Buffer, it should allow us to overwrite parts of it that we have allocated. This comes in useful in handling unsequenced writes like handling fragmented ip packets :^)
Diffstat (limited to 'AK')
-rw-r--r--AK/ByteBuffer.h7
1 files changed, 7 insertions, 0 deletions
diff --git a/AK/ByteBuffer.h b/AK/ByteBuffer.h
index 179cba936c..3f8a245fdd 100644
--- a/AK/ByteBuffer.h
+++ b/AK/ByteBuffer.h
@@ -216,6 +216,13 @@ public:
__builtin_memcpy(this->data() + old_size, data, data_size);
}
+ void overwrite(size_t offset, const void* data, size_t data_size)
+ {
+ // make sure we're not told to write past the end
+ ASSERT(offset + data_size < size());
+ __builtin_memcpy(this->data() + offset, data, data_size);
+ }
+
private:
explicit ByteBuffer(RefPtr<ByteBufferImpl>&& impl)
: m_impl(move(impl))