1 #include "hmbdc/Copyright.hpp" 3 #include <boost/endian/conversion.hpp> 9 static constexpr uint32_t i32 = 0x01020304;
10 static constexpr uint8_t i32_1stbyte = (
const uint8_t&)i32;
11 static_assert(i32_1stbyte == 0x04 || i32_1stbyte == 0x01,
"Cannot determine endianness!");
13 static constexpr
bool little = i32_1stbyte == 0x04;
14 #ifdef HMBDC_XMIT_BIG_ENDIAN 15 static constexpr
bool match_xmit = !little;
17 static constexpr
bool match_xmit = little;
19 template <
typename iType>
21 iType toXmit(iType v) {
25 return boost::endian::endian_reverse(v);
28 template <
typename iType>
30 iType toNative(iType v) {
38 static_assert(
sizeof(T) > 1,
"not effective or apply");
41 : vx_(Endian::match_xmit?v:boost::endian::endian_reverse(v)) {
45 return Endian::match_xmit?vx_:boost::endian::endian_reverse(vx_);
49 if (Endian::match_xmit) {
52 vx_ = boost::endian::endian_reverse(v);
58 if (Endian::match_xmit) {
61 auto tmp = boost::endian::endian_reverse(vx_) + v;
62 vx_ = boost::endian::endian_reverse(tmp);
68 friend std::istream& operator >> (std::istream& is,
XmitEndian& t) {
77 } __attribute__((packed));
79 template <
typename T,
size_t N>
82 static_assert(
sizeof(T) >= N,
"not effective or apply");
86 if (!Endian::match_xmit) {
87 for (
auto i = 0; i < N / 2; ++i)
88 std::swap(vb_[i], vb_[N - i - 1]);
93 return Endian::match_xmit?vx_:boost::endian::endian_reverse(
94 vx_ << (
sizeof(T) - N) * 8);
99 if (!Endian::match_xmit) {
100 for (
auto i = 0u; i < N / 2; ++i)
101 std::swap(vb_[i], vb_[N - i - 1]);
117 } __attribute__((packed));
118 } __attribute__((packed));
Definition: Endian.hpp:80
Definition: Endian.hpp:36