add check to not read more frames than available
Build on RHEL9 / build (push) Successful in 3m9s
Build on RHEL8 / build (push) Successful in 3m57s
Run tests using data on local RHEL8 / build (push) Successful in 4m47s

This commit is contained in:
mazzol_a committed 2026-10-27 16:26:10 +01:00
1 parent 33f360e218
commit 9738c6c19f
2 files changed
+18 -3

No files matched your search

+6 -1
View File
@@ -40,12 +40,17 @@ class MultiThreadedFileReader {
/**
* @brief Read one chunk per active worker into a caller-owned buffer.
*
* @param destination Pointer to the buffer where the data will be written.
* @param frames_to_read Optional number of frames to read. If not provided,
* the reader will read the next available frames.
*
* The buffer must hold at least next_read_bytes() bytes. The reader's
* position advances by the returned number of frames. At the end of the
* configured range this function returns zero and does not access the
* destination.
*/
size_t read_into(std::byte *destination);
size_t read_into(std::byte *destination,
std::optional<size_t> frames_to_read = std::nullopt);
/** @brief Read the next wave of chunks into an owned byte buffer. */
std::vector<std::byte> read();
+12 -2
View File
@@ -85,9 +85,19 @@ void MultiThreadedFileReader::ensure_open() const {
}
}
size_t MultiThreadedFileReader::read_into(std::byte *destination) {
size_t
MultiThreadedFileReader::read_into(std::byte *destination,
std::optional<size_t> frames_to_read_) {
ensure_open();
const size_t frames_to_read = next_read_frames();
const size_t next_frames_to_read = next_read_frames();
const size_t frames_to_read = frames_to_read_.value_or(next_frames_to_read);
if (frames_to_read > next_frames_to_read) {
throw std::invalid_argument(
fmt::format("MultiThreadedFileReader cannot read more frames than "
"available: requested {}, available {}",
frames_to_read, next_frames_to_read));
}
if (frames_to_read == 0) {
return 0;
}