20#ifndef RIPPLE_OVERLAY_ZEROCOPYSTREAM_H_INCLUDED
21#define RIPPLE_OVERLAY_ZEROCOPYSTREAM_H_INCLUDED
23#include <xrpl/beast/utility/instrumentation.h>
25#include <boost/asio/buffer.hpp>
27#include <google/protobuf/io/zero_copy_stream.h>
36template <
class Buffers>
40 using iterator =
typename Buffers::const_iterator;
52 Next(
void const** data,
int* size)
override;
55 BackUp(
int count)
override;
58 Skip(
int count)
override;
60 google::protobuf::int64
69template <
class Buffers>
71 : last_(buffers.end())
72 , first_(buffers.begin())
73 , pos_((first_ != last_) ? *first_ :
const_buffer(nullptr, 0))
77template <
class Buffers>
82 *size = boost::asio::buffer_size(pos_);
86 pos_ = (++first_ != last_) ? *first_ :
const_buffer(
nullptr, 0);
90template <
class Buffers>
95 pos_ = *first_ + (boost::asio::buffer_size(*first_) - count);
99template <
class Buffers>
107 auto const size = boost::asio::buffer_size(pos_);
115 if (++first_ == last_)
129template <
class Streambuf>
134 using iterator =
typename buffers_type::const_iterator;
150 Next(
void** data,
int* size)
override;
153 BackUp(
int count)
override;
155 google::protobuf::int64
164template <
class Streambuf>
166 Streambuf& streambuf,
168 : streambuf_(streambuf)
169 , blockSize_(blockSize)
170 , buffers_(streambuf_.prepare(blockSize_))
171 , pos_(buffers_.begin())
175template <
class Streambuf>
179 streambuf_.commit(commit_);
182template <
class Streambuf>
188 streambuf_.commit(commit_);
192 if (pos_ == buffers_.end())
194 buffers_ = streambuf_.prepare(blockSize_);
195 pos_ = buffers_.begin();
198 *data = *pos_.data();
199 *size = boost::asio::buffer_size(*pos_);
205template <
class Streambuf>
210 count <= commit_,
"ripple::ZeroCopyOutputStream::BackUp : valid input");
211 auto const n = commit_ - count;
212 streambuf_.commit(n);
Implements ZeroCopyOutputStream around a Streambuf.
google::protobuf::int64 ByteCount() const override
google::protobuf::int64 count_
typename Streambuf::mutable_buffers_type buffers_type
void BackUp(int count) override
ZeroCopyOutputStream(Streambuf &streambuf, std::size_t blockSize)
typename buffers_type::const_iterator iterator
boost::asio::mutable_buffer mutable_buffer
bool Next(void **data, int *size) override
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.