summaryrefslogtreecommitdiff
path: root/gui
diff options
context:
space:
mode:
authorJose Fonseca <jfonseca@vmware.com>2015-05-19 16:52:10 +0100
committerJose Fonseca <jfonseca@vmware.com>2015-05-20 14:17:50 +0100
commit46b887754299d493f52653eba3c97b58be8855e1 (patch)
tree219557aa10a31b9a35d84dba9ade48e34e4aaf48 /gui
parent9653f95f75863870a9e6b1ffad8c0ab48fa3fa4d (diff)
gui: Use QDataStream for big endian conversion.
Diffstat (limited to 'gui')
-rw-r--r--gui/qubjson.cpp45
1 files changed, 24 insertions, 21 deletions
diff --git a/gui/qubjson.cpp b/gui/qubjson.cpp
index 2004f298..a0652cd2 100644
--- a/gui/qubjson.cpp
+++ b/gui/qubjson.cpp
@@ -48,57 +48,59 @@ readMarker(QDataStream &stream)
static int8_t
readInt8(QDataStream &stream)
{
- quint8 byte;
- stream >> byte;
- return byte;
+ qint8 i;
+ stream >> i;
+ return i;
}
static uint8_t
readUInt8(QDataStream &stream)
{
- quint8 byte;
- stream >> byte;
- return byte;
+ quint8 u;
+ stream >> u;
+ return u;
}
static int16_t
readInt16(QDataStream &stream)
{
- uint16_t i;
- stream.readRawData((char *)&i, sizeof i);
- return bigEndian16(i);
+ qint16 i;
+ stream >> i;
+ return i;
}
static int32_t
readInt32(QDataStream &stream)
{
- uint32_t i;
- stream.readRawData((char *)&i, sizeof i);
- return bigEndian32(i);
+ qint32 i;
+ stream >> i;
+ return i;
}
static int64_t
readInt64(QDataStream &stream)
{
- uint64_t i;
- stream.readRawData((char *)&i, sizeof i);
- return bigEndian64(i);
+ qint64 i;
+ stream >> i;
+ return i;
}
static float
readFloat32(QDataStream &stream)
{
- Float32 u;
- u.i = readInt32(stream);
- return u.f;
+ float f;
+ stream.setFloatingPointPrecision(QDataStream::SinglePrecision);
+ stream >> f;
+ return f;
}
static float
readFloat64(QDataStream &stream)
{
- Float64 u;
- u.i = readInt64(stream);
- return u.f;
+ double f;
+ stream.setFloatingPointPrecision(QDataStream::DoublePrecision);
+ stream >> f;
+ return f;
}
@@ -239,6 +241,7 @@ readVariant(QDataStream &stream, Marker type)
QVariantMap decodeUBJSONObject(QDataStream &stream)
{
+ stream.setByteOrder(QDataStream::BigEndian);
Marker marker = readMarker(stream);
Q_ASSERT(marker == MARKER_OBJECT_BEGIN);
return readObject(stream);