diff --git a/src/io/BufferedOutputStream.hxx b/src/io/BufferedOutputStream.hxx index 65548d963..68d0c0c4f 100644 --- a/src/io/BufferedOutputStream.hxx +++ b/src/io/BufferedOutputStream.hxx @@ -51,7 +51,7 @@ public: */ template void WriteT(const T &value) { - Write(std::as_bytes(std::span{&value, 1})); + Write(ReferenceAsBytes(value)); } /** diff --git a/src/output/plugins/snapcast/Client.cxx b/src/output/plugins/snapcast/Client.cxx index 805cc6784..1b9d72822 100644 --- a/src/output/plugins/snapcast/Client.cxx +++ b/src/output/plugins/snapcast/Client.cxx @@ -105,7 +105,7 @@ template 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 diff --git a/src/util/SpanCast.hxx b/src/util/SpanCast.hxx index 90cc39aae..e6dc5e665 100644 --- a/src/util/SpanCast.hxx +++ b/src/util/SpanCast.hxx @@ -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. + */ +template +constexpr auto +ReferenceAsBytes(const T &value) noexcept +{ + return std::as_bytes(std::span{&value, 1}); +} + constexpr std::string_view ToStringView(std::span s) noexcept {