Skip to content
Discussion options

You must be logged in to vote

Under the hood of glz::write calls it is doing this:

size_t ix = 0; // overwrite index
to<Opts.format, std::remove_cvref_t<T>>::template op<Opts>(std::forward<T>(value), ctx, buffer, ix);
if constexpr (resizable<Buffer>) {
   buffer.resize(ix);
}

So, you can use this API yourself to figure out how many bytes have been written with ix

But, if you pass it an oversized raw buffer there is already an API that hands you back the number of bytes written:

template <auto Opts, class T, raw_buffer Buffer>
  requires write_supported<T, Opts.format>
[[nodiscard]] glz::expected<size_t, error_ctx> write(T&& value, Buffer&& buffer, is_context auto&& ctx)
{
  size_t ix = 0;
  to<Opts.format, std::remove…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by akm76
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants