diff options
author | MarcoFalke <falke.marco@gmail.com> | 2022-01-02 11:31:25 +0100 |
---|---|---|
committer | MarcoFalke <falke.marco@gmail.com> | 2022-01-02 11:40:31 +0100 |
commit | fa24493d6394b3a477535f480664c9596f18e3c5 (patch) | |
tree | 56fb2f98aba2055c959c57ffb8022dbcd21f8d27 /src/script/bitcoinconsensus.cpp | |
parent | fa65bbf217b725ada35107b4ad646d250228355c (diff) |
Use spans of std::byte in serialize
This switches .read() and .write() to take spans of bytes.
Diffstat (limited to 'src/script/bitcoinconsensus.cpp')
-rw-r--r-- | src/script/bitcoinconsensus.cpp | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/src/script/bitcoinconsensus.cpp b/src/script/bitcoinconsensus.cpp index dd15e6104c..f7f9dfc262 100644 --- a/src/script/bitcoinconsensus.cpp +++ b/src/script/bitcoinconsensus.cpp @@ -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> |