mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 20:12:57 +01:00
partial bitcoin#23438: Use spans of std::byte in serialize
includes: - fa65bbf217b725ada35107b4ad646d250228355c
This commit is contained in:
parent
8c2d480f1a
commit
de54b8784c
@ -237,16 +237,21 @@ T& SpanPopBack(Span<T>& span)
|
|||||||
return back;
|
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
|
// From C++20 as_bytes and as_writeable_bytes
|
||||||
template <typename T>
|
template <typename T>
|
||||||
Span<const std::byte> AsBytes(Span<T> s) noexcept
|
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>
|
template <typename T>
|
||||||
Span<std::byte> AsWritableBytes(Span<T> s) noexcept
|
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>
|
template <typename V>
|
||||||
|
Loading…
Reference in New Issue
Block a user