| 187 | } |
| 188 | |
| 189 | uint64_t ReadByte(std::streambuf& buffer, |
| 190 | std::vector<uint8_t> &dest, |
| 191 | uint64_t size) { |
| 192 | if (size == 0) { |
| 193 | dest.clear(); |
| 194 | return 0; |
| 195 | } |
| 196 | |
| 197 | dest.resize(static_cast<size_t>(size), 0); |
| 198 | const auto ret = buffer.sgetn( |
| 199 | reinterpret_cast<char*>(dest.data()), |
| 200 | static_cast<std::streamsize>(size)); |
| 201 | if (ret != size) { |
| 202 | throw std::ios_base::failure("End of stream reached (EOF)."); |
| 203 | } |
| 204 | return static_cast<uint64_t>(ret); |
| 205 | } |
| 206 | |
| 207 | uint64_t WriteByte(std::streambuf& buffer, const std::vector<uint8_t> &source) { |
| 208 | const auto ret = buffer.sputn( |