diff --git a/include/gp/ipc/envelope/cbor.hpp b/include/gp/ipc/envelope/cbor.hpp index 818ce19..d23bda6 100644 --- a/include/gp/ipc/envelope/cbor.hpp +++ b/include/gp/ipc/envelope/cbor.hpp @@ -126,19 +126,19 @@ namespace gp { } else if(norm_v < (1ll<<16ll)) { endian_wrapper wrapper = norm_v; src.push_back(header+25); - for(auto byte : wrapper.bytes) { + for(auto byte : wrapper.bytes()) { src.push_back(byte); } } else if(norm_v < (1ll<<32ll)) { endian_wrapper wrapper = norm_v; src.push_back(header+26); - for(auto byte : wrapper.bytes) { + for(auto byte : wrapper.bytes()) { src.push_back(byte); } } else { endian_wrapper wrapper = norm_v; src.push_back(header+27); - for(auto byte : wrapper.bytes) { + for(auto byte : wrapper.bytes()) { src.push_back(byte); } } @@ -477,4 +477,3 @@ namespace gp { } } } - diff --git a/include/gp/math/boolean/bitops.hpp b/include/gp/math/boolean/bitops.hpp index 9972742..5ffcf1b 100644 --- a/include/gp/math/boolean/bitops.hpp +++ b/include/gp/math/boolean/bitops.hpp @@ -29,35 +29,31 @@ T swap_endian(T value) noexcept { template struct endian_wrapper { + T value = 0; - union { - T value; - gp::array bytes; - }; - - endian_wrapper() noexcept - : value{0} {} + constexpr endian_wrapper() noexcept = default; endian_wrapper(T v) noexcept : value{adjust(v)} {} - endian_wrapper(const endian_wrapper& v) noexcept - : value{v.value} {} - endian_wrapper& operator=(T v) noexcept { value = adjust(v); return *this; } - endian_wrapper& operator=(const endian_wrapper& v) noexcept { - value = v.value; - return *this; - } - operator T() const noexcept { return adjust(value); } + auto bytes() const noexcept -> gp::array { + union { + T t; + gp::array bytes; + } tmp {.t = value}; + + return tmp.bytes; + } + // arithmetic assignment operators endian_wrapper& operator+=(T rhs) noexcept {