io/BufferedReader: use std::size_t

This commit is contained in:
Max Kellermann 2021-12-07 11:49:59 +01:00
parent 8c6bc02bf7
commit 4074db5f50
4 changed files with 12 additions and 11 deletions

View File

@ -31,6 +31,7 @@
#include "Reader.hxx"
#include "util/TextFile.hxx"
#include <cassert>
#include <cstdint>
#include <stdexcept>
@ -52,7 +53,7 @@ BufferedReader::Fill(bool need_more)
assert(!w.empty());
}
size_t nbytes = reader.Read(w.data, w.size);
std::size_t nbytes = reader.Read(w.data, w.size);
if (nbytes == 0) {
eof = true;
return !need_more;
@ -63,7 +64,7 @@ BufferedReader::Fill(bool need_more)
}
void *
BufferedReader::ReadFull(size_t size)
BufferedReader::ReadFull(std::size_t size)
{
while (true) {
auto r = Read();
@ -75,11 +76,11 @@ BufferedReader::ReadFull(size_t size)
}
}
size_t
std::size_t
BufferedReader::ReadFromBuffer(WritableBuffer<void> dest) noexcept
{
auto src = Read();
size_t nbytes = std::min(src.size, dest.size);
std::size_t nbytes = std::min(src.size, dest.size);
memcpy(dest.data, src.data, nbytes);
Consume(nbytes);
return nbytes;
@ -92,7 +93,7 @@ BufferedReader::ReadFull(WritableBuffer<void> _dest)
assert(dest.size == _dest.size);
while (true) {
size_t nbytes = ReadFromBuffer(dest.ToVoid());
std::size_t nbytes = ReadFromBuffer(dest.ToVoid());
dest.skip_front(nbytes);
if (dest.size == 0)
break;

View File

@ -37,7 +37,7 @@
class Reader;
class BufferedReader {
static constexpr size_t MAX_SIZE = 512 * 1024;
static constexpr std::size_t MAX_SIZE = 512 * 1024;
Reader &reader;
@ -73,9 +73,9 @@ public:
* it). Throws std::runtime_error if not enough data is
* available.
*/
void *ReadFull(size_t size);
void *ReadFull(std::size_t size);
void Consume(size_t n) noexcept {
void Consume(std::size_t n) noexcept {
buffer.Consume(n);
}
@ -83,7 +83,7 @@ public:
* Read (and consume) data from the input buffer into the
* given buffer. Does not attempt to refill the buffer.
*/
size_t ReadFromBuffer(WritableBuffer<void> dest) noexcept;
std::size_t ReadFromBuffer(WritableBuffer<void> dest) noexcept;
/**
* Read data into the given buffer and consume it from our

View File

@ -40,7 +40,7 @@ public:
/**
* Throws std::exception on error.
*/
virtual void Write(const void *data, size_t size) = 0;
virtual void Write(const void *data, std::size_t size) = 0;
};
#endif

View File

@ -51,7 +51,7 @@ public:
* on end-of-stream
*/
[[gnu::nonnull]]
virtual size_t Read(void *data, size_t size) = 0;
virtual std::size_t Read(void *data, std::size_t size) = 0;
};
#endif