Skip to content

Commit

Permalink
bytes: iostream wrappers for iobuf
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Pope <ben@redpanda.com>
  • Loading branch information
BenPope committed Jul 16, 2024
1 parent 0229940 commit aa569f8
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
40 changes: 40 additions & 0 deletions src/v/bytes/include/bytes/streambuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,43 @@ class iobuf_ostreambuf final : public std::streambuf {
private:
iobuf* _buf;
};

///\brief Wrap a std::istream around an iobuf
///
/// iobuf buf;
/// iobuf_istream is(std::move(buf));
/// std::string out;
/// is.istream() >> out;
class iobuf_istream {
public:
explicit iobuf_istream(iobuf buf)
: _buf(std::move(buf))
, _isb(_buf)
, _sis{&_isb} {}
std::istream& istream() { return _sis; }

private:
iobuf _buf;
iobuf_istreambuf _isb;
std::istream _sis;
};

///\brief Wrap a std::ostream around an iobuf
///
/// iobuf_ostream os;
/// os.ostream() << "Hello World";
/// iobuf buf = std::move(os).buf();
class iobuf_ostream {
public:
iobuf_ostream()
: _buf()
, _osb(_buf)
, _sos{&_osb} {}
std::ostream& ostream() { return _sos; }
iobuf buf() && { return std::move(_buf); }

private:
iobuf _buf;
iobuf_ostreambuf _osb;
std::ostream _sos;
};
1 change: 0 additions & 1 deletion src/v/pandaproxy/json/rjson_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include "json/reader.h"
#include "json/stream.h"
#include "json/stringbuffer.h"
#include "json/writer.h"
#include "pandaproxy/json/exceptions.h"
#include "pandaproxy/json/types.h"

Expand Down

0 comments on commit aa569f8

Please sign in to comment.