consider native byte order when interpreting data
This commit is contained in:
parent
14e4bdc5b5
commit
13981ff727
|
@ -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:
|
||||||
|
|
Loading…
Reference in New Issue