From b252b3c6e3e99ead44e8af99101828c083d65cc0 Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Thu, 27 Jun 2024 16:48:10 +0200 Subject: [PATCH] libutil: allow draining Generator into sinks Change-Id: I442d03a5399096d4baca9a2618b4c4b64db36c4b --- perl/meson.build | 1 + src/libutil/serialise.hh | 9 +++++++++ 2 files changed, 10 insertions(+) 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 #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);