From b252b3c6e3e99ead44e8af99101828c083d65cc0 Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Thu, 27 Jun 2024 16:48:10 +0200 Subject: libutil: allow draining Generator into sinks Change-Id: I442d03a5399096d4baca9a2618b4c4b64db36c4b --- src/libutil/serialise.hh | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/libutil/serialise.hh') diff --git a/src/libutil/serialise.hh b/src/libutil/serialise.hh index 0632e3109..491b1987d 100644 --- a/src/libutil/serialise.hh +++ b/src/libutil/serialise.hh @@ -1,8 +1,10 @@ #pragma once ///@file +#include #include +#include "generator.hh" #include "strings.hh" #include "types.hh" #include "file-descriptor.hh" @@ -340,6 +342,13 @@ std::unique_ptr sourceToSink(std::function fun); */ std::unique_ptr sinkToSource(std::function fun); +inline Sink & operator<<(Sink & sink, Generator && g) +{ + while (auto buffer = g.next()) { + sink(std::string_view(buffer->data(), buffer->size())); + } + return sink; +} void writePadding(size_t len, Sink & sink); void writeString(std::string_view s, Sink & sink); -- cgit v1.2.3