io/BufferedReader: use std::size_t
This commit is contained in:
parent
8c6bc02bf7
commit
4074db5f50
|
@ -31,6 +31,7 @@
|
||||||
#include "Reader.hxx"
|
#include "Reader.hxx"
|
||||||
#include "util/TextFile.hxx"
|
#include "util/TextFile.hxx"
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
|
@ -52,7 +53,7 @@ BufferedReader::Fill(bool need_more)
|
||||||
assert(!w.empty());
|
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) {
|
if (nbytes == 0) {
|
||||||
eof = true;
|
eof = true;
|
||||||
return !need_more;
|
return !need_more;
|
||||||
|
@ -63,7 +64,7 @@ BufferedReader::Fill(bool need_more)
|
||||||
}
|
}
|
||||||
|
|
||||||
void *
|
void *
|
||||||
BufferedReader::ReadFull(size_t size)
|
BufferedReader::ReadFull(std::size_t size)
|
||||||
{
|
{
|
||||||
while (true) {
|
while (true) {
|
||||||
auto r = Read();
|
auto r = Read();
|
||||||
|
@ -75,11 +76,11 @@ BufferedReader::ReadFull(size_t size)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t
|
std::size_t
|
||||||
BufferedReader::ReadFromBuffer(WritableBuffer<void> dest) noexcept
|
BufferedReader::ReadFromBuffer(WritableBuffer<void> dest) noexcept
|
||||||
{
|
{
|
||||||
auto src = Read();
|
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);
|
memcpy(dest.data, src.data, nbytes);
|
||||||
Consume(nbytes);
|
Consume(nbytes);
|
||||||
return nbytes;
|
return nbytes;
|
||||||
|
@ -92,7 +93,7 @@ BufferedReader::ReadFull(WritableBuffer<void> _dest)
|
||||||
assert(dest.size == _dest.size);
|
assert(dest.size == _dest.size);
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
size_t nbytes = ReadFromBuffer(dest.ToVoid());
|
std::size_t nbytes = ReadFromBuffer(dest.ToVoid());
|
||||||
dest.skip_front(nbytes);
|
dest.skip_front(nbytes);
|
||||||
if (dest.size == 0)
|
if (dest.size == 0)
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -37,7 +37,7 @@
|
||||||
class Reader;
|
class Reader;
|
||||||
|
|
||||||
class BufferedReader {
|
class BufferedReader {
|
||||||
static constexpr size_t MAX_SIZE = 512 * 1024;
|
static constexpr std::size_t MAX_SIZE = 512 * 1024;
|
||||||
|
|
||||||
Reader &reader;
|
Reader &reader;
|
||||||
|
|
||||||
|
@ -73,9 +73,9 @@ public:
|
||||||
* it). Throws std::runtime_error if not enough data is
|
* it). Throws std::runtime_error if not enough data is
|
||||||
* available.
|
* 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);
|
buffer.Consume(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ public:
|
||||||
* Read (and consume) data from the input buffer into the
|
* Read (and consume) data from the input buffer into the
|
||||||
* given buffer. Does not attempt to refill the buffer.
|
* 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
|
* Read data into the given buffer and consume it from our
|
||||||
|
|
|
@ -40,7 +40,7 @@ public:
|
||||||
/**
|
/**
|
||||||
* Throws std::exception on error.
|
* 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
|
#endif
|
||||||
|
|
|
@ -51,7 +51,7 @@ public:
|
||||||
* on end-of-stream
|
* on end-of-stream
|
||||||
*/
|
*/
|
||||||
[[gnu::nonnull]]
|
[[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
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue