Skip to content

Commit

Permalink
get writeable buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
victorstewart committed Jan 9, 2025
1 parent ee992d8 commit 037c846
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
9 changes: 9 additions & 0 deletions include/bitsery/adapter/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<diff_t>(_currOffset);
}


Buffer* _buffer;
TIterator _beginIt;
size_t _currOffset{ 0 };
Expand Down
19 changes: 19 additions & 0 deletions include/bitsery/details/adapter_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,15 @@ struct OutputAdapterBaseCRTP
writeSwappedBuffer(buf, count, ShouldSwap<typename Adapter::TConfig, T>{});
}

template<size_t SIZE, typename T>
T* writeBuffer(size_t count)
{
static_assert(std::is_integral<T>(), "");
static_assert(sizeof(T) == SIZE, "");

return static_cast<Adapter*>(this)->writeInternalBuffer(count * sizeof(T));
}

template<typename T>
void writeBits(const T&, size_t)
{
Expand Down Expand Up @@ -375,6 +384,16 @@ struct InputAdapterBaseCRTP
swapDataBits(buf, count, ShouldSwap<typename Adapter::TConfig, T>{});
}

template<size_t SIZE, typename T>
T* readBuffer(T* buf, size_t count)
{
static_assert(std::is_integral<T>(), "");
static_assert(sizeof(T) == SIZE, "");
static_cast<Adapter*>(this)->readInternalBuffer(
reinterpret_cast<typename Adapter::TValue*>(buf), sizeof(T) * count);
swapDataBits(buf, count, ShouldSwap<typename Adapter::TConfig, T>{});
}

template<typename T>
void readBits(T&, size_t)
{
Expand Down

0 comments on commit 037c846

Please sign in to comment.