Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get writeable buffer #120

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either I miss something, or this is a bug.
Instead of

    _currOffset = newOffset;
    return _beginIt + static_cast<diff_t>(_currOffset);

You should probably do like this:

    auto res = _beginIt + static_cast<diff_t>(_currOffset);
    _currOffset = newOffset;
    return res;

}


Buffer* _buffer;
TIterator _beginIt;
size_t _currOffset{ 0 };
Expand Down
9 changes: 9 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