Skip to content

Commit de54b87

Browse files
kwvgPastaPastaPasta
authored andcommitted
partial bitcoin#23438: Use spans of std::byte in serialize
includes: - fa65bbf
1 parent 8c2d480 commit de54b87

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/span.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,16 +237,21 @@ T& SpanPopBack(Span<T>& span)
237237
return back;
238238
}
239239

240+
//! Convert a data pointer to a std::byte data pointer.
241+
//! Where possible, please use the safer AsBytes helpers.
242+
inline const std::byte* BytePtr(const void* data) { return reinterpret_cast<const std::byte*>(data); }
243+
inline std::byte* BytePtr(void* data) { return reinterpret_cast<std::byte*>(data); }
244+
240245
// From C++20 as_bytes and as_writeable_bytes
241246
template <typename T>
242247
Span<const std::byte> AsBytes(Span<T> s) noexcept
243248
{
244-
return {reinterpret_cast<const std::byte*>(s.data()), s.size_bytes()};
249+
return {BytePtr(s.data()), s.size_bytes()};
245250
}
246251
template <typename T>
247252
Span<std::byte> AsWritableBytes(Span<T> s) noexcept
248253
{
249-
return {reinterpret_cast<std::byte*>(s.data()), s.size_bytes()};
254+
return {BytePtr(s.data()), s.size_bytes()};
250255
}
251256

252257
template <typename V>

0 commit comments

Comments
 (0)