Skip to content

Commit

Permalink
replace int with size_t in stream methods
Browse files Browse the repository at this point in the history
Thus the read(...) and write(...) methods of all stream classes now have identical parameter lists.
This will bring these classes one step closer to a common interface.
  • Loading branch information
kdomanski committed Aug 18, 2014
1 parent a4f151f commit 8695a39
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/serialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ inline const T* end_ptr(const std::vector<T,TAl>& v)
/////////////////////////////////////////////////////////////////
//
// Templates for serializing to anything that looks like a stream,
// i.e. anything that supports .read(char*, int) and .write(char*, int)
// i.e. anything that supports .read(char*, size_t) and .write(char*, size_t)
//

enum
Expand Down Expand Up @@ -876,7 +876,7 @@ class CSizeComputer

CSizeComputer(int nTypeIn, int nVersionIn) : nSize(0), nType(nTypeIn), nVersion(nVersionIn) {}

CSizeComputer& write(const char *psz, int nSize)
CSizeComputer& write(const char *psz, size_t nSize)
{
this->nSize += nSize;
return *this;
Expand Down Expand Up @@ -1105,10 +1105,9 @@ class CDataStream
void ReadVersion() { *this >> nVersion; }
void WriteVersion() { *this << nVersion; }

CDataStream& read(char* pch, int nSize)
CDataStream& read(char* pch, size_t nSize)
{
// Read from the beginning of the buffer
assert(nSize >= 0);
unsigned int nReadPosNext = nReadPos + nSize;
if (nReadPosNext >= vch.size())
{
Expand Down Expand Up @@ -1145,10 +1144,9 @@ class CDataStream
return (*this);
}

CDataStream& write(const char* pch, int nSize)
CDataStream& write(const char* pch, size_t nSize)
{
// Write to the end of the buffer
assert(nSize >= 0);
vch.insert(vch.end(), pch, pch + nSize);
return (*this);
}
Expand Down

0 comments on commit 8695a39

Please sign in to comment.