partial bitcoin#23438: Use spans of std::byte in serialize

includes:
- fa65bbf217b725ada35107b4ad646d250228355c
This commit is contained in:
Kittywhiskers Van Gogh 2022-01-02 11:19:01 +01:00 committed by PastaPastaPasta
parent 8c2d480f1a
commit de54b8784c

View File

@ -237,16 +237,21 @@ T& SpanPopBack(Span<T>& span)
return back;
}
//! Convert a data pointer to a std::byte data pointer.
//! Where possible, please use the safer AsBytes helpers.
inline const std::byte* BytePtr(const void* data) { return reinterpret_cast<const std::byte*>(data); }
inline std::byte* BytePtr(void* data) { return reinterpret_cast<std::byte*>(data); }
// From C++20 as_bytes and as_writeable_bytes
template <typename T>
Span<const std::byte> AsBytes(Span<T> s) noexcept
{
return {reinterpret_cast<const std::byte*>(s.data()), s.size_bytes()};
return {BytePtr(s.data()), s.size_bytes()};
}
template <typename T>
Span<std::byte> AsWritableBytes(Span<T> s) noexcept
{
return {reinterpret_cast<std::byte*>(s.data()), s.size_bytes()};
return {BytePtr(s.data()), s.size_bytes()};
}
template <typename V>