diff --git a/ntcore/src/main/native/cpp/net3/WireEncoder3.cpp b/ntcore/src/main/native/cpp/net3/WireEncoder3.cpp index d1e4c784358..7f587c9f604 100644 --- a/ntcore/src/main/native/cpp/net3/WireEncoder3.cpp +++ b/ntcore/src/main/native/cpp/net3/WireEncoder3.cpp @@ -4,6 +4,7 @@ #include "WireEncoder3.h" +#include #include #include #include @@ -19,28 +20,21 @@ static void Write8(wpi::raw_ostream& os, uint8_t val) { } static void Write16(wpi::raw_ostream& os, uint16_t val) { - os << std::span{{static_cast((val >> 8) & 0xff), - static_cast(val & 0xff)}}; + uint8_t buf[2]; + wpi::support::endian::write16be(buf, val); + os << buf; } static void Write32(wpi::raw_ostream& os, uint32_t val) { - os << std::span{{static_cast((val >> 24) & 0xff), - static_cast((val >> 16) & 0xff), - static_cast((val >> 8) & 0xff), - static_cast(val & 0xff)}}; + uint8_t buf[4]; + wpi::support::endian::write32be(buf, val); + os << buf; } static void WriteDouble(wpi::raw_ostream& os, double val) { - // The highest performance way to do this, albeit non-portable. - uint64_t v = wpi::bit_cast(val); - os << std::span{{static_cast((v >> 56) & 0xff), - static_cast((v >> 48) & 0xff), - static_cast((v >> 40) & 0xff), - static_cast((v >> 32) & 0xff), - static_cast((v >> 24) & 0xff), - static_cast((v >> 16) & 0xff), - static_cast((v >> 8) & 0xff), - static_cast(v & 0xff)}}; + uint8_t buf[8]; + wpi::support::endian::write64be(buf, wpi::bit_cast(val)); + os << buf; } static void WriteString(wpi::raw_ostream& os, std::string_view str) {