mirror of
https://github.com/bitcoin/bitcoin.git
synced 2024-11-20 10:38:42 +01:00
streams: Base BufferedFile on AutoFile instead of CAutoFile
This commit is contained in:
parent
98b0acda0f
commit
e63f643079
@ -529,7 +529,7 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
/** Wrapper around a CAutoFile& that implements a ring buffer to
|
||||
/** Wrapper around an AutoFile& that implements a ring buffer to
|
||||
* deserialize from. It guarantees the ability to rewind a given number of bytes.
|
||||
*
|
||||
* Will automatically close the file when it goes out of scope if not null.
|
||||
@ -538,7 +538,7 @@ public:
|
||||
class BufferedFile
|
||||
{
|
||||
private:
|
||||
CAutoFile& m_src;
|
||||
AutoFile& m_src;
|
||||
uint64_t nSrcPos{0}; //!< how many bytes have been read from source
|
||||
uint64_t m_read_pos{0}; //!< how many bytes have been read from this
|
||||
uint64_t nReadLimit; //!< up to which position we're allowed to read
|
||||
@ -585,15 +585,13 @@ private:
|
||||
}
|
||||
|
||||
public:
|
||||
BufferedFile(CAutoFile& file, uint64_t nBufSize, uint64_t nRewindIn)
|
||||
BufferedFile(AutoFile& file, uint64_t nBufSize, uint64_t nRewindIn)
|
||||
: m_src{file}, nReadLimit{std::numeric_limits<uint64_t>::max()}, nRewind{nRewindIn}, vchBuf(nBufSize, std::byte{0})
|
||||
{
|
||||
if (nRewindIn >= nBufSize)
|
||||
throw std::ios_base::failure("Rewind limit must be less than buffer size");
|
||||
}
|
||||
|
||||
int GetVersion() const { return m_src.GetVersion(); }
|
||||
|
||||
//! check whether we're at the end of the source file
|
||||
bool eof() const {
|
||||
return m_read_pos == nSrcPos && m_src.feof();
|
||||
|
@ -20,9 +20,8 @@ FUZZ_TARGET(buffered_file)
|
||||
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
|
||||
FuzzedFileProvider fuzzed_file_provider{fuzzed_data_provider};
|
||||
std::optional<BufferedFile> opt_buffered_file;
|
||||
CAutoFile fuzzed_file{
|
||||
AutoFile fuzzed_file{
|
||||
fuzzed_file_provider.open(),
|
||||
0,
|
||||
ConsumeRandomLengthByteVector<std::byte>(fuzzed_data_provider),
|
||||
};
|
||||
try {
|
||||
@ -65,6 +64,5 @@ FUZZ_TARGET(buffered_file)
|
||||
});
|
||||
}
|
||||
opt_buffered_file->GetPos();
|
||||
opt_buffered_file->GetVersion();
|
||||
}
|
||||
}
|
||||
|
@ -271,9 +271,6 @@ BOOST_AUTO_TEST_CASE(streams_buffered_file)
|
||||
BufferedFile bf{file, 25, 10};
|
||||
BOOST_CHECK(!bf.eof());
|
||||
|
||||
// This member has no functional effect.
|
||||
BOOST_CHECK_EQUAL(bf.GetVersion(), 333);
|
||||
|
||||
uint8_t i;
|
||||
bf >> i;
|
||||
BOOST_CHECK_EQUAL(i, 0);
|
||||
|
Loading…
Reference in New Issue
Block a user