mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-18 22:35:39 +01:00
Use spans of std::byte in serialize
This switches .read() and .write() to take spans of bytes.
This commit is contained in:
@@ -22,20 +22,23 @@ public:
|
||||
m_remaining(txToLen)
|
||||
{}
|
||||
|
||||
void read(char* pch, size_t nSize)
|
||||
void read(Span<std::byte> dst)
|
||||
{
|
||||
if (nSize > m_remaining)
|
||||
if (dst.size() > m_remaining) {
|
||||
throw std::ios_base::failure(std::string(__func__) + ": end of data");
|
||||
}
|
||||
|
||||
if (pch == nullptr)
|
||||
if (dst.data() == nullptr) {
|
||||
throw std::ios_base::failure(std::string(__func__) + ": bad destination buffer");
|
||||
}
|
||||
|
||||
if (m_data == nullptr)
|
||||
if (m_data == nullptr) {
|
||||
throw std::ios_base::failure(std::string(__func__) + ": bad source buffer");
|
||||
}
|
||||
|
||||
memcpy(pch, m_data, nSize);
|
||||
m_remaining -= nSize;
|
||||
m_data += nSize;
|
||||
memcpy(dst.data(), m_data, dst.size());
|
||||
m_remaining -= dst.size();
|
||||
m_data += dst.size();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
|
||||
@@ -1303,12 +1303,12 @@ public:
|
||||
it = itBegin;
|
||||
while (scriptCode.GetOp(it, opcode)) {
|
||||
if (opcode == OP_CODESEPARATOR) {
|
||||
s.write((char*)&itBegin[0], it-itBegin-1);
|
||||
s.write(AsBytes(Span{&itBegin[0], size_t(it - itBegin - 1)}));
|
||||
itBegin = it;
|
||||
}
|
||||
}
|
||||
if (itBegin != scriptCode.end())
|
||||
s.write((char*)&itBegin[0], it-itBegin);
|
||||
s.write(AsBytes(Span{&itBegin[0], size_t(it - itBegin)}));
|
||||
}
|
||||
|
||||
/** Serialize an input of txTo */
|
||||
|
||||
Reference in New Issue
Block a user