aboutsummaryrefslogtreecommitdiff
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
parent4857feb9101ca4479f922040be17f27ee1486455 (diff)
libutil: allow draining Generator<Bytes> into sinks
Change-Id: I442d03a5399096d4baca9a2618b4c4b64db36c4b
-rw-r--r--perl/meson.build1
-rw-r--r--src/libutil/serialise.hh9
2 files changed, 10 insertions, 0 deletions
diff --git a/perl/meson.build b/perl/meson.build
index b542f3e8a..6f078f8e6 100644
--- a/perl/meson.build
+++ b/perl/meson.build
@@ -65,5 +65,6 @@ if cxx.get_linker_id() in ['ld.bfd', 'ld.gold']
endif
libstore = dependency('lixstore', 'lix-store', required : true)
+libutil = dependency('lixutil', 'lix-util', required : true)
subdir('lib/Nix')
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);