mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-05-19 16:30:50 +02:00
scripted-diff: Rename nReadPos to m_read_pos in streams.h
-BEGIN VERIFY SCRIPT- sed -i 's/nReadPos/m_read_pos/g' ./src/streams.h -END VERIFY SCRIPT-
This commit is contained in:
parent
fa56c79df9
commit
fa1b89a6bd
@ -187,7 +187,7 @@ class CDataStream
|
|||||||
protected:
|
protected:
|
||||||
using vector_type = SerializeData;
|
using vector_type = SerializeData;
|
||||||
vector_type vch;
|
vector_type vch;
|
||||||
vector_type::size_type nReadPos{0};
|
vector_type::size_type m_read_pos{0};
|
||||||
|
|
||||||
int nType;
|
int nType;
|
||||||
int nVersion;
|
int nVersion;
|
||||||
@ -230,37 +230,37 @@ public:
|
|||||||
//
|
//
|
||||||
// Vector subset
|
// Vector subset
|
||||||
//
|
//
|
||||||
const_iterator begin() const { return vch.begin() + nReadPos; }
|
const_iterator begin() const { return vch.begin() + m_read_pos; }
|
||||||
iterator begin() { return vch.begin() + nReadPos; }
|
iterator begin() { return vch.begin() + m_read_pos; }
|
||||||
const_iterator end() const { return vch.end(); }
|
const_iterator end() const { return vch.end(); }
|
||||||
iterator end() { return vch.end(); }
|
iterator end() { return vch.end(); }
|
||||||
size_type size() const { return vch.size() - nReadPos; }
|
size_type size() const { return vch.size() - m_read_pos; }
|
||||||
bool empty() const { return vch.size() == nReadPos; }
|
bool empty() const { return vch.size() == m_read_pos; }
|
||||||
void resize(size_type n, value_type c = value_type{}) { vch.resize(n + nReadPos, c); }
|
void resize(size_type n, value_type c = value_type{}) { vch.resize(n + m_read_pos, c); }
|
||||||
void reserve(size_type n) { vch.reserve(n + nReadPos); }
|
void reserve(size_type n) { vch.reserve(n + m_read_pos); }
|
||||||
const_reference operator[](size_type pos) const { return vch[pos + nReadPos]; }
|
const_reference operator[](size_type pos) const { return vch[pos + m_read_pos]; }
|
||||||
reference operator[](size_type pos) { return vch[pos + nReadPos]; }
|
reference operator[](size_type pos) { return vch[pos + m_read_pos]; }
|
||||||
void clear() { vch.clear(); nReadPos = 0; }
|
void clear() { vch.clear(); m_read_pos = 0; }
|
||||||
value_type* data() { return vch.data() + nReadPos; }
|
value_type* data() { return vch.data() + m_read_pos; }
|
||||||
const value_type* data() const { return vch.data() + nReadPos; }
|
const value_type* data() const { return vch.data() + m_read_pos; }
|
||||||
|
|
||||||
inline void Compact()
|
inline void Compact()
|
||||||
{
|
{
|
||||||
vch.erase(vch.begin(), vch.begin() + nReadPos);
|
vch.erase(vch.begin(), vch.begin() + m_read_pos);
|
||||||
nReadPos = 0;
|
m_read_pos = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Rewind(std::optional<size_type> n = std::nullopt)
|
bool Rewind(std::optional<size_type> n = std::nullopt)
|
||||||
{
|
{
|
||||||
// Total rewind if no size is passed
|
// Total rewind if no size is passed
|
||||||
if (!n) {
|
if (!n) {
|
||||||
nReadPos = 0;
|
m_read_pos = 0;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// Rewind by n characters if the buffer hasn't been compacted yet
|
// Rewind by n characters if the buffer hasn't been compacted yet
|
||||||
if (*n > nReadPos)
|
if (*n > m_read_pos)
|
||||||
return false;
|
return false;
|
||||||
nReadPos -= *n;
|
m_read_pos -= *n;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -282,32 +282,32 @@ public:
|
|||||||
if (dst.size() == 0) return;
|
if (dst.size() == 0) return;
|
||||||
|
|
||||||
// Read from the beginning of the buffer
|
// Read from the beginning of the buffer
|
||||||
auto next_read_pos{CheckedAdd(nReadPos, dst.size())};
|
auto next_read_pos{CheckedAdd(m_read_pos, dst.size())};
|
||||||
if (!next_read_pos.has_value() || next_read_pos.value() > vch.size()) {
|
if (!next_read_pos.has_value() || next_read_pos.value() > vch.size()) {
|
||||||
throw std::ios_base::failure("CDataStream::read(): end of data");
|
throw std::ios_base::failure("CDataStream::read(): end of data");
|
||||||
}
|
}
|
||||||
memcpy(dst.data(), &vch[nReadPos], dst.size());
|
memcpy(dst.data(), &vch[m_read_pos], dst.size());
|
||||||
if (next_read_pos.value() == vch.size()) {
|
if (next_read_pos.value() == vch.size()) {
|
||||||
nReadPos = 0;
|
m_read_pos = 0;
|
||||||
vch.clear();
|
vch.clear();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
nReadPos = next_read_pos.value();
|
m_read_pos = next_read_pos.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ignore(size_t num_ignore)
|
void ignore(size_t num_ignore)
|
||||||
{
|
{
|
||||||
// Ignore from the beginning of the buffer
|
// Ignore from the beginning of the buffer
|
||||||
auto next_read_pos{CheckedAdd(nReadPos, num_ignore)};
|
auto next_read_pos{CheckedAdd(m_read_pos, num_ignore)};
|
||||||
if (!next_read_pos.has_value() || next_read_pos.value() > vch.size()) {
|
if (!next_read_pos.has_value() || next_read_pos.value() > vch.size()) {
|
||||||
throw std::ios_base::failure("CDataStream::ignore(): end of data");
|
throw std::ios_base::failure("CDataStream::ignore(): end of data");
|
||||||
}
|
}
|
||||||
if (next_read_pos.value() == vch.size()) {
|
if (next_read_pos.value() == vch.size()) {
|
||||||
nReadPos = 0;
|
m_read_pos = 0;
|
||||||
vch.clear();
|
vch.clear();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
nReadPos = next_read_pos.value();
|
m_read_pos = next_read_pos.value();
|
||||||
}
|
}
|
||||||
|
|
||||||
void write(Span<const value_type> src)
|
void write(Span<const value_type> src)
|
||||||
@ -591,7 +591,7 @@ private:
|
|||||||
|
|
||||||
FILE *src; //!< source file
|
FILE *src; //!< source file
|
||||||
uint64_t nSrcPos; //!< how many bytes have been read from source
|
uint64_t nSrcPos; //!< how many bytes have been read from source
|
||||||
uint64_t nReadPos; //!< how many bytes have been read from this
|
uint64_t m_read_pos; //!< how many bytes have been read from this
|
||||||
uint64_t nReadLimit; //!< up to which position we're allowed to read
|
uint64_t nReadLimit; //!< up to which position we're allowed to read
|
||||||
uint64_t nRewind; //!< how many bytes we guarantee to rewind
|
uint64_t nRewind; //!< how many bytes we guarantee to rewind
|
||||||
std::vector<std::byte> vchBuf; //!< the buffer
|
std::vector<std::byte> vchBuf; //!< the buffer
|
||||||
@ -601,7 +601,7 @@ protected:
|
|||||||
bool Fill() {
|
bool Fill() {
|
||||||
unsigned int pos = nSrcPos % vchBuf.size();
|
unsigned int pos = nSrcPos % vchBuf.size();
|
||||||
unsigned int readNow = vchBuf.size() - pos;
|
unsigned int readNow = vchBuf.size() - pos;
|
||||||
unsigned int nAvail = vchBuf.size() - (nSrcPos - nReadPos) - nRewind;
|
unsigned int nAvail = vchBuf.size() - (nSrcPos - m_read_pos) - nRewind;
|
||||||
if (nAvail < readNow)
|
if (nAvail < readNow)
|
||||||
readNow = nAvail;
|
readNow = nAvail;
|
||||||
if (readNow == 0)
|
if (readNow == 0)
|
||||||
@ -616,7 +616,7 @@ protected:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
CBufferedFile(FILE* fileIn, uint64_t nBufSize, uint64_t nRewindIn, int nTypeIn, int nVersionIn)
|
CBufferedFile(FILE* fileIn, uint64_t nBufSize, uint64_t nRewindIn, int nTypeIn, int nVersionIn)
|
||||||
: nType(nTypeIn), nVersion(nVersionIn), nSrcPos(0), nReadPos(0), nReadLimit(std::numeric_limits<uint64_t>::max()), nRewind(nRewindIn), vchBuf(nBufSize, std::byte{0})
|
: nType(nTypeIn), nVersion(nVersionIn), nSrcPos(0), m_read_pos(0), nReadLimit(std::numeric_limits<uint64_t>::max()), nRewind(nRewindIn), vchBuf(nBufSize, std::byte{0})
|
||||||
{
|
{
|
||||||
if (nRewindIn >= nBufSize)
|
if (nRewindIn >= nBufSize)
|
||||||
throw std::ios_base::failure("Rewind limit must be less than buffer size");
|
throw std::ios_base::failure("Rewind limit must be less than buffer size");
|
||||||
@ -645,33 +645,33 @@ public:
|
|||||||
|
|
||||||
//! check whether we're at the end of the source file
|
//! check whether we're at the end of the source file
|
||||||
bool eof() const {
|
bool eof() const {
|
||||||
return nReadPos == nSrcPos && feof(src);
|
return m_read_pos == nSrcPos && feof(src);
|
||||||
}
|
}
|
||||||
|
|
||||||
//! read a number of bytes
|
//! read a number of bytes
|
||||||
void read(Span<std::byte> dst)
|
void read(Span<std::byte> dst)
|
||||||
{
|
{
|
||||||
if (dst.size() + nReadPos > nReadLimit) {
|
if (dst.size() + m_read_pos > nReadLimit) {
|
||||||
throw std::ios_base::failure("Read attempted past buffer limit");
|
throw std::ios_base::failure("Read attempted past buffer limit");
|
||||||
}
|
}
|
||||||
while (dst.size() > 0) {
|
while (dst.size() > 0) {
|
||||||
if (nReadPos == nSrcPos)
|
if (m_read_pos == nSrcPos)
|
||||||
Fill();
|
Fill();
|
||||||
unsigned int pos = nReadPos % vchBuf.size();
|
unsigned int pos = m_read_pos % vchBuf.size();
|
||||||
size_t nNow = dst.size();
|
size_t nNow = dst.size();
|
||||||
if (nNow + pos > vchBuf.size())
|
if (nNow + pos > vchBuf.size())
|
||||||
nNow = vchBuf.size() - pos;
|
nNow = vchBuf.size() - pos;
|
||||||
if (nNow + nReadPos > nSrcPos)
|
if (nNow + m_read_pos > nSrcPos)
|
||||||
nNow = nSrcPos - nReadPos;
|
nNow = nSrcPos - m_read_pos;
|
||||||
memcpy(dst.data(), &vchBuf[pos], nNow);
|
memcpy(dst.data(), &vchBuf[pos], nNow);
|
||||||
nReadPos += nNow;
|
m_read_pos += nNow;
|
||||||
dst = dst.subspan(nNow);
|
dst = dst.subspan(nNow);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//! return the current reading position
|
//! return the current reading position
|
||||||
uint64_t GetPos() const {
|
uint64_t GetPos() const {
|
||||||
return nReadPos;
|
return m_read_pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! rewind to a given reading position
|
//! rewind to a given reading position
|
||||||
@ -679,22 +679,22 @@ public:
|
|||||||
size_t bufsize = vchBuf.size();
|
size_t bufsize = vchBuf.size();
|
||||||
if (nPos + bufsize < nSrcPos) {
|
if (nPos + bufsize < nSrcPos) {
|
||||||
// rewinding too far, rewind as far as possible
|
// rewinding too far, rewind as far as possible
|
||||||
nReadPos = nSrcPos - bufsize;
|
m_read_pos = nSrcPos - bufsize;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (nPos > nSrcPos) {
|
if (nPos > nSrcPos) {
|
||||||
// can't go this far forward, go as far as possible
|
// can't go this far forward, go as far as possible
|
||||||
nReadPos = nSrcPos;
|
m_read_pos = nSrcPos;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
nReadPos = nPos;
|
m_read_pos = nPos;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! prevent reading beyond a certain position
|
//! prevent reading beyond a certain position
|
||||||
//! no argument removes the limit
|
//! no argument removes the limit
|
||||||
bool SetLimit(uint64_t nPos = std::numeric_limits<uint64_t>::max()) {
|
bool SetLimit(uint64_t nPos = std::numeric_limits<uint64_t>::max()) {
|
||||||
if (nPos < nReadPos)
|
if (nPos < m_read_pos)
|
||||||
return false;
|
return false;
|
||||||
nReadLimit = nPos;
|
nReadLimit = nPos;
|
||||||
return true;
|
return true;
|
||||||
@ -711,12 +711,12 @@ public:
|
|||||||
void FindByte(uint8_t ch)
|
void FindByte(uint8_t ch)
|
||||||
{
|
{
|
||||||
while (true) {
|
while (true) {
|
||||||
if (nReadPos == nSrcPos)
|
if (m_read_pos == nSrcPos)
|
||||||
Fill();
|
Fill();
|
||||||
if (vchBuf[nReadPos % vchBuf.size()] == std::byte{ch}) {
|
if (vchBuf[m_read_pos % vchBuf.size()] == std::byte{ch}) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
nReadPos++;
|
m_read_pos++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user