ByteBuffer: Add slice_view(). Works like slice() but makes a wrapper only.

So we already have ByteBuffer::wrap() which is like a StringView for random
data. This might not be the best abstraction actually, but this will be
immediately useful so let's add it.
This commit is contained in:
Andreas Kling 2019-07-27 15:26:51 +02:00
parent c7a4c8f93b
commit 6f397e23f1
Notes: sideshowbarker 2024-07-19 13:01:46 +09:00

View File

@ -155,6 +155,17 @@ public:
m_impl->trim(size);
}
ByteBuffer slice_view(int offset, int size) const
{
if (is_null())
return {};
if (offset >= this->size())
return {};
if (offset + size >= this->size())
size = this->size() - offset;
return wrap(offset_pointer(offset), size);
}
ByteBuffer slice(int offset, int size) const
{
if (is_null())