aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoreldritch horrors <pennae@lix.systems>2024-06-27 16:48:10 +0200
committereldritch horrors <pennae@lix.systems>2024-07-03 11:46:53 +0000
commitb252b3c6e3e99ead44e8af99101828c083d65cc0 (patch)
tree6346d530ec690b1780b8c439a9b8cd8ca2127960 /src
parent4857feb9101ca4479f922040be17f27ee1486455 (diff)
libutil: allow draining Generator<Bytes> into sinks
Change-Id: I442d03a5399096d4baca9a2618b4c4b64db36c4b
Diffstat (limited to 'src')
-rw-r--r--src/libutil/serialise.hh9
1 files changed, 9 insertions, 0 deletions
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 <concepts>
#include <memory>
+#include "generator.hh"
#include "strings.hh"
#include "types.hh"
#include "file-descriptor.hh"
@@ -340,6 +342,13 @@ std::unique_ptr<FinishSink> sourceToSink(std::function<void(Source &)> fun);
*/
std::unique_ptr<Source> sinkToSource(std::function<void(Sink &)> fun);
+inline Sink & operator<<(Sink & sink, Generator<Bytes> && 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);