1
0
Fork 0

consider native byte order when interpreting data

This commit is contained in:
Kevin Matz 2023-05-18 14:38:32 -04:00
parent 14e4bdc5b5
commit 13981ff727
1 changed files with 5 additions and 13 deletions

View File

@ -125,16 +125,12 @@ public:
else else
{ {
auto bytes = reinterpret_cast<uint8_t*>(&ret); auto bytes = reinterpret_cast<uint8_t*>(&ret);
switch (order_) { if (order_ == endian::native)
case LittleEndian:
for (int_fast8_t i = 0; i < width; i++) for (int_fast8_t i = 0; i < width; i++)
bytes[i] = get(); bytes[i] = get();
break; else
case BigEndian: for (int_fast8_t i = width; --i >= 0;)
for (int_fast8_t i = width; --i >= 0;)
bytes[i] = get(); bytes[i] = get();
break;
}
} }
if (!in_avail()) if (!in_avail())
setstate(std::ios_base::eofbit); setstate(std::ios_base::eofbit);
@ -153,16 +149,12 @@ public:
return; return;
} }
auto bytes = reinterpret_cast<const uint8_t*>(&val); auto bytes = reinterpret_cast<const uint8_t*>(&val);
switch (order_) { if (order_ == endian::native)
case LittleEndian:
for (int_fast8_t i = 0; i < width; i++) for (int_fast8_t i = 0; i < width; i++)
put(bytes[i]); put(bytes[i]);
break; else
case BigEndian:
for (int_fast8_t i = width; --i >= 0;) for (int_fast8_t i = width; --i >= 0;)
put(bytes[i]); put(bytes[i]);
break;
}
} }
private: private: