read a number of bytes
| 650 | |
| 651 | //! read a number of bytes |
| 652 | void read(Span<std::byte> dst) |
| 653 | { |
| 654 | if (dst.size() + m_read_pos > nReadLimit) { |
| 655 | throw std::ios_base::failure("Read attempted past buffer limit"); |
| 656 | } |
| 657 | while (dst.size() > 0) { |
| 658 | if (m_read_pos == nSrcPos) |
| 659 | Fill(); |
| 660 | unsigned int pos = m_read_pos % vchBuf.size(); |
| 661 | size_t nNow = dst.size(); |
| 662 | if (nNow + pos > vchBuf.size()) |
| 663 | nNow = vchBuf.size() - pos; |
| 664 | if (nNow + m_read_pos > nSrcPos) |
| 665 | nNow = nSrcPos - m_read_pos; |
| 666 | memcpy(dst.data(), &vchBuf[pos], nNow); |
| 667 | m_read_pos += nNow; |
| 668 | dst = dst.subspan(nNow); |
| 669 | } |
| 670 | } |
| 671 | |
| 672 | //! return the current reading position |
| 673 | uint64_t GetPos() const { |