util/SpanCast: add ReferenceAsBytes()
This commit is contained in:
parent
10940da381
commit
a073db1e52
@ -51,7 +51,7 @@ public:
|
||||
*/
|
||||
template<typename T>
|
||||
void WriteT(const T &value) {
|
||||
Write(std::as_bytes(std::span{&value, 1}));
|
||||
Write(ReferenceAsBytes(value));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -105,7 +105,7 @@ template<typename T>
|
||||
static bool
|
||||
SendT(SocketDescriptor s, const T &buffer) noexcept
|
||||
{
|
||||
return Send(s, std::as_bytes(std::span{&buffer, 1}));
|
||||
return Send(s, ReferenceAsBytes(buffer));
|
||||
}
|
||||
|
||||
static bool
|
||||
|
@ -59,6 +59,16 @@ AsBytes(std::string_view sv) noexcept
|
||||
return std::as_bytes(ToSpan(sv));
|
||||
}
|
||||
|
||||
/**
|
||||
* Cast a reference to a fixed-size std::span<const std::byte>.
|
||||
*/
|
||||
template<typename T>
|
||||
constexpr auto
|
||||
ReferenceAsBytes(const T &value) noexcept
|
||||
{
|
||||
return std::as_bytes(std::span<const T, 1>{&value, 1});
|
||||
}
|
||||
|
||||
constexpr std::string_view
|
||||
ToStringView(std::span<const char> s) noexcept
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user