| 2906 | Result<int64_t> IoRecordedRandomAccessFile::GetSize() { return file_size_; } |
| 2907 | |
| 2908 | Result<int64_t> IoRecordedRandomAccessFile::ReadAt(int64_t position, int64_t nbytes, |
| 2909 | void* out) { |
| 2910 | auto num_bytes_read = std::min(file_size_, position + nbytes) - position; |
| 2911 | |
| 2912 | if (!read_ranges_.empty() && |
| 2913 | position == read_ranges_.back().offset + read_ranges_.back().length) { |
| 2914 | // merge continuous IOs into one if possible |
| 2915 | read_ranges_.back().length += num_bytes_read; |
| 2916 | } else { |
| 2917 | // no real IO is performed, it is only saved into a vector for replaying later |
| 2918 | read_ranges_.emplace_back(io::ReadRange{position, num_bytes_read}); |
| 2919 | } |
| 2920 | return num_bytes_read; |
| 2921 | } |
| 2922 | |
| 2923 | Result<std::shared_ptr<Buffer>> IoRecordedRandomAccessFile::ReadAt(int64_t position, |
| 2924 | int64_t nbytes) { |