diff --git a/src/libutil/serialise.cc b/src/libutil/serialise.cc index 11bc183cc..a8ebc8662 100644 --- a/src/libutil/serialise.cc +++ b/src/libutil/serialise.cc @@ -202,69 +202,6 @@ public: ~CoroutineContext() {}; }; -std::unique_ptr sourceToSink(std::function fun) -{ - struct SourceToSink : FinishSink - { - typedef boost::coroutines2::coroutine coro_t; - - std::function fun; - std::optional coro; - - SourceToSink(std::function fun) : fun(fun) - { - } - - std::string_view cur; - - void operator () (std::string_view in) override - { - if (in.empty()) return; - cur = in; - - if (!coro) { - CoroutineContext ctx; - coro = coro_t::push_type(VirtualStackAllocator{}, [&](coro_t::pull_type & yield) { - LambdaSource source([&](char *out, size_t out_len) { - if (cur.empty()) { - yield(); - if (yield.get()) { - throw EndOfFile("coroutine exhausted"); - } - } - - size_t n = std::min(cur.size(), out_len); - memcpy(out, cur.data(), n); - cur.remove_prefix(n); - return n; - }); - fun(source); - }); - } - - if (!*coro) { abort(); } - - if (!cur.empty()) { - CoroutineContext ctx; - (*coro)(false); - } - } - - void finish() override - { - if (!coro) return; - if (!*coro) abort(); - { - CoroutineContext ctx; - (*coro)(true); - } - if (*coro) abort(); - } - }; - - return std::make_unique(fun); -} - std::unique_ptr sinkToSource(std::function fun) { diff --git a/src/libutil/serialise.hh b/src/libutil/serialise.hh index 2a2568224..b9e16f6bd 100644 --- a/src/libutil/serialise.hh +++ b/src/libutil/serialise.hh @@ -359,8 +359,6 @@ private: Bytes buf{}; }; -std::unique_ptr sourceToSink(std::function fun); - /** * Convert a function that feeds data into a Sink into a Source. The * Source executes the function as a coroutine.