// SPDX-License-Identifier: BSD-2-Clause // author: Max Kellermann #ifndef READER_HXX #define READER_HXX #include #include #include /** * An interface that can read bytes from a stream until the stream * ends. * * This interface is simpler and less cumbersome to use than * #InputStream. */ class Reader { public: Reader() = default; Reader(const Reader &) = delete; /** * Read data from the stream. * * @return the number of bytes read into the given buffer or 0 * on end-of-stream */ virtual std::size_t Read(std::span dest) = 0; template requires std::is_standard_layout_v && std::is_trivially_copyable_v void ReadT(T &dest) { // TODO check return value Read(std::as_writable_bytes(std::span{&dest, 1})); } }; #endif