in src/native/io/sequential/chain_reader.h [72:129]
virtual size_t read_some(std::span<char> buffer)
{
size_t total_read{};
auto remaining_to_read = buffer.size();
while (remaining_to_read > 0)
{
if (m_current_reader_index >= m_readers.size())
{
break;
}
auto ¤t_reader = m_readers[m_current_reader_index];
std::span<char> reader_buffer{buffer.data() + total_read, buffer.size() - total_read};
auto actual_read = current_reader->read_some(reader_buffer);
if (actual_read == 0)
{
// shouldn't be possible
std::string msg = "chain_reader::read_some: Couldn't read any data. remaining_to_read: "
+ std::to_string(remaining_to_read);
throw errors::user_exception(errors::error_code::io_chain_read_too_much, msg);
}
if (actual_read > remaining_to_read)
{
// shouldn't be possible
std::string msg =
"chain_reader::read_some: More read than remaining. actual_read: " + std::to_string(actual_read)
+ ", remaining_to_read: " + std::to_string(remaining_to_read);
throw errors::user_exception(errors::error_code::io_chain_read_too_much, msg);
}
total_read += actual_read;
m_read_offset += actual_read;
m_offset_in_current_reader += actual_read;
remaining_to_read -= actual_read;
if (current_reader->tellg() > current_reader->size())
{
std::string msg =
"chain_reader::read_some: tellg() > size(). tellg: " + std::to_string(current_reader->tellg())
+ ", size(): " + std::to_string(current_reader->size());
throw errors::user_exception(errors::error_code::io_chain_bad_offset, msg);
}
// just move to next reader, we're done here.
if (current_reader->tellg() == current_reader->size())
{
m_offset_in_current_reader = 0;
m_current_reader_index++;
}
}
return total_read;
}