mirror of
https://github.com/slsdetectorgroup/aare.git
synced 2026-11-23 15:57:53 +01:00
add check to not read more frames than available
This commit is contained in:
1 parent
33f360e218
commit
9738c6c19f
2 files changed
+18
-3
No files matched your search
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user