From 037c8463da134dbcce57961b27e1e6492a0e5c99 Mon Sep 17 00:00:00 2001 From: Victor Stewart Date: Thu, 9 Jan 2025 04:35:48 +0000 Subject: [PATCH] get writeable buffer --- include/bitsery/adapter/buffer.h | 9 +++++++++ include/bitsery/details/adapter_common.h | 19 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/include/bitsery/adapter/buffer.h b/include/bitsery/adapter/buffer.h index 1e05b23..010cd96 100644 --- a/include/bitsery/adapter/buffer.h +++ b/include/bitsery/adapter/buffer.h @@ -261,6 +261,15 @@ class OutputBufferAdapter writeInternalImpl(data, size); } + TValue* writeInternalBuffer(size_t size) + { + const size_t newOffset = _currOffset + size; + maybeResize(newOffset, TResizable{}); + _currOffset = newOffset; + return _beginIt + static_cast(_currOffset); + } + + Buffer* _buffer; TIterator _beginIt; size_t _currOffset{ 0 }; diff --git a/include/bitsery/details/adapter_common.h b/include/bitsery/details/adapter_common.h index dda97c1..d58d462 100644 --- a/include/bitsery/details/adapter_common.h +++ b/include/bitsery/details/adapter_common.h @@ -300,6 +300,15 @@ struct OutputAdapterBaseCRTP writeSwappedBuffer(buf, count, ShouldSwap{}); } + template + T* writeBuffer(size_t count) + { + static_assert(std::is_integral(), ""); + static_assert(sizeof(T) == SIZE, ""); + + return static_cast(this)->writeInternalBuffer(count * sizeof(T)); + } + template void writeBits(const T&, size_t) { @@ -375,6 +384,16 @@ struct InputAdapterBaseCRTP swapDataBits(buf, count, ShouldSwap{}); } + template + T* readBuffer(T* buf, size_t count) + { + static_assert(std::is_integral(), ""); + static_assert(sizeof(T) == SIZE, ""); + static_cast(this)->readInternalBuffer( + reinterpret_cast(buf), sizeof(T) * count); + swapDataBits(buf, count, ShouldSwap{}); + } + template void readBits(T&, size_t) {