From 1fae63de23320a1663b7c591e247ad81852ab6dc Mon Sep 17 00:00:00 2001 From: Roland Reichwein Date: Sun, 22 Nov 2020 13:00:06 +0100 Subject: Support 16-bit short --- byteorder.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 byteorder.cpp (limited to 'byteorder.cpp') diff --git a/byteorder.cpp b/byteorder.cpp new file mode 100644 index 0000000..16f7537 --- /dev/null +++ b/byteorder.cpp @@ -0,0 +1,40 @@ +#include "byteorder.h" + +#include + +std::vector endian::to_little(uint16_t value) +{ + std::vector result(sizeof(uint16_t)); + *(reinterpret_cast(result.data())) = boost::endian::native_to_little(value); + return result; +} + +uint16_t endian::from_little16(const std::vector& value) +{ + return boost::endian::little_to_native(*(reinterpret_cast(value.data()))); +} + +std::vector endian::to_little(uint32_t value) +{ + std::vector result(sizeof(uint32_t)); + *(reinterpret_cast(result.data())) = boost::endian::native_to_little(value); + return result; +} + +uint32_t endian::from_little32(const std::vector& value) +{ + return boost::endian::little_to_native(*(reinterpret_cast(value.data()))); +} + +std::vector endian::to_little(uint64_t value) +{ + std::vector result(sizeof(uint64_t)); + *(reinterpret_cast(result.data())) = boost::endian::native_to_little(value); + return result; +} + +uint64_t endian::from_little64(const std::vector& value) +{ + return boost::endian::little_to_native(*(reinterpret_cast(value.data()))); +} + -- cgit v1.2.3