aboutsummaryrefslogtreecommitdiff
path: root/src/libutil/serialise.hh
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2020-12-02 14:10:56 +0100
committerEelco Dolstra <edolstra@gmail.com>2020-12-02 14:17:27 +0100
commit1b79b5b983a6c775766bd0d1c7881042188998b8 (patch)
treef695f8298291fccb6db02bc705445909ba729039 /src/libutil/serialise.hh
parentfaa31f40846f7a4dbc2487d000b112a6aef69d1b (diff)
read(): Use char * instead of unsigned char *
This gets rid of some pointless casts.
Diffstat (limited to 'src/libutil/serialise.hh')
-rw-r--r--src/libutil/serialise.hh44
1 files changed, 22 insertions, 22 deletions
diff --git a/src/libutil/serialise.hh b/src/libutil/serialise.hh
index f9ab79997..5bbbc7ce3 100644
--- a/src/libutil/serialise.hh
+++ b/src/libutil/serialise.hh
@@ -51,12 +51,12 @@ struct Source
/* Store exactly ‘len’ bytes in the buffer pointed to by ‘data’.
It blocks until all the requested data is available, or throws
an error if it is not going to be available. */
- void operator () (unsigned char * data, size_t len);
+ void operator () (char * data, size_t len);
/* Store up to ‘len’ in the buffer pointed to by ‘data’, and
return the number of bytes stored. It blocks until at least
one byte is available. */
- virtual size_t read(unsigned char * data, size_t len) = 0;
+ virtual size_t read(char * data, size_t len) = 0;
virtual bool good() { return true; }
@@ -71,18 +71,18 @@ struct Source
struct BufferedSource : Source
{
size_t bufSize, bufPosIn, bufPosOut;
- std::unique_ptr<unsigned char[]> buffer;
+ std::unique_ptr<char[]> buffer;
BufferedSource(size_t bufSize = 32 * 1024)
: bufSize(bufSize), bufPosIn(0), bufPosOut(0), buffer(nullptr) { }
- size_t read(unsigned char * data, size_t len) override;
+ size_t read(char * data, size_t len) override;
bool hasData();
protected:
/* Underlying read call, to be overridden. */
- virtual size_t readUnbuffered(unsigned char * data, size_t len) = 0;
+ virtual size_t readUnbuffered(char * data, size_t len) = 0;
};
@@ -138,7 +138,7 @@ struct FdSource : BufferedSource
bool good() override;
protected:
- size_t readUnbuffered(unsigned char * data, size_t len) override;
+ size_t readUnbuffered(char * data, size_t len) override;
private:
bool _good = true;
};
@@ -163,7 +163,7 @@ struct StringSource : Source
const string & s;
size_t pos;
StringSource(const string & _s) : s(_s), pos(0) { }
- size_t read(unsigned char * data, size_t len) override;
+ size_t read(char * data, size_t len) override;
};
@@ -187,10 +187,10 @@ struct TeeSource : Source
Sink & sink;
TeeSource(Source & orig, Sink & sink)
: orig(orig), sink(sink) { }
- size_t read(unsigned char * data, size_t len)
+ size_t read(char * data, size_t len)
{
size_t n = orig.read(data, len);
- sink({(char *) data, n});
+ sink({data, n});
return n;
}
};
@@ -202,7 +202,7 @@ struct SizedSource : Source
size_t remain;
SizedSource(Source & orig, size_t size)
: orig(orig), remain(size) { }
- size_t read(unsigned char * data, size_t len)
+ size_t read(char * data, size_t len)
{
if (this->remain <= 0) {
throw EndOfFile("sized: unexpected end-of-file");
@@ -216,7 +216,7 @@ struct SizedSource : Source
/* Consume the original source until no remain data is left to consume. */
size_t drainAll()
{
- std::vector<unsigned char> buf(8192);
+ std::vector<char> buf(8192);
size_t sum = 0;
while (this->remain > 0) {
size_t n = read(buf.data(), buf.size());
@@ -256,13 +256,13 @@ struct LambdaSink : Sink
/* Convert a function into a source. */
struct LambdaSource : Source
{
- typedef std::function<size_t(unsigned char *, size_t)> lambda_t;
+ typedef std::function<size_t(char *, size_t)> lambda_t;
lambda_t lambda;
LambdaSource(const lambda_t & lambda) : lambda(lambda) { }
- size_t read(unsigned char * data, size_t len) override
+ size_t read(char * data, size_t len) override
{
return lambda(data, len);
}
@@ -278,7 +278,7 @@ struct ChainSource : Source
: source1(s1), source2(s2)
{ }
- size_t read(unsigned char * data, size_t len) override;
+ size_t read(char * data, size_t len) override;
};
@@ -322,7 +322,7 @@ template<typename T>
T readNum(Source & source)
{
unsigned char buf[8];
- source(buf, sizeof(buf));
+ source((char *) buf, sizeof(buf));
uint64_t n =
((uint64_t) buf[0]) |
@@ -354,7 +354,7 @@ inline uint64_t readLongLong(Source & source)
void readPadding(size_t len, Source & source);
-size_t readString(unsigned char * buf, size_t max, Source & source);
+size_t readString(char * buf, size_t max, Source & source);
string readString(Source & source, size_t max = std::numeric_limits<size_t>::max());
template<class T> T readStrings(Source & source);
@@ -386,9 +386,9 @@ struct StreamToSourceAdapter : Source
: istream(istream)
{ }
- size_t read(unsigned char * data, size_t len) override
+ size_t read(char * data, size_t len) override
{
- if (!istream->read((char *) data, len)) {
+ if (!istream->read(data, len)) {
if (istream->eof()) {
if (istream->gcount() == 0)
throw EndOfFile("end of file");
@@ -411,7 +411,7 @@ struct FramedSource : Source
{
Source & from;
bool eof = false;
- std::vector<unsigned char> pending;
+ std::vector<char> pending;
size_t pos = 0;
FramedSource(Source & from) : from(from)
@@ -423,13 +423,13 @@ struct FramedSource : Source
while (true) {
auto n = readInt(from);
if (!n) break;
- std::vector<unsigned char> data(n);
+ std::vector<char> data(n);
from(data.data(), n);
}
}
}
- size_t read(unsigned char * data, size_t len) override
+ size_t read(char * data, size_t len) override
{
if (eof) throw EndOfFile("reached end of FramedSource");
@@ -439,7 +439,7 @@ struct FramedSource : Source
eof = true;
return 0;
}
- pending = std::vector<unsigned char>(len);
+ pending = std::vector<char>(len);
pos = 0;
from(pending.data(), len);
}