diff --git a/utils/seekable_source.hh b/utils/seekable_source.hh new file mode 100644 index 0000000000..acddcb2b52 --- /dev/null +++ b/utils/seekable_source.hh @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2025-present ScyllaDB + */ + +/* + * SPDX-License-Identifier: LicenseRef-ScyllaDB-Source-Available-1.0 + */ + +#pragma once + +#include +#include + +class seekable_data_source_impl : public seastar::data_source_impl { +public: + virtual seastar::future> get(size_t limit) = 0; + virtual seastar::future<> seek(uint64_t pos) = 0; + virtual seastar::future size() { + return seastar::make_ready_future(0); + } + virtual seastar::future timestamp() { + return seastar::make_ready_future(); + } +}; + +class seekable_data_source : public seastar::data_source { +public: + seekable_data_source(std::unique_ptr src) + : seastar::data_source(std::move(src)) + {} + seastar::future> get(size_t limit) noexcept { + try { + return static_cast(impl())->get(limit); + } catch (...) { + return seastar::current_exception_as_future>(); + } + } + seastar::future<> seek(uint64_t pos) noexcept { + try { + return static_cast(impl())->seek(pos); + } catch (...) { + return seastar::current_exception_as_future<>(); + } + } + seastar::future size() noexcept { + try { + return static_cast(impl())->size(); + } catch (...) { + return seastar::current_exception_as_future(); + } + } + seastar::future timestamp() noexcept { + try { + return static_cast(impl())->timestamp(); + } catch (...) { + return seastar::current_exception_as_future(); + } + } +};