blob: 3060382203d9ddda4851d719c76f27911d871613 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
#ifndef ENDIANHELPERS_H
#define ENDIANHELPERS_H
#include <QtCore/QtEndian>
namespace
{
template<typename T>
inline T read(const QByteArray &data, int &offset)
{
T unswapped;
memcpy(&unswapped, &data.constData()[offset], sizeof(T)); // Unaligned access warning!
offset += sizeof(T);
return qFromBigEndian<T>(unswapped);
}
template<typename T>
inline void append(QByteArray &data, const T &value)
{
T swapped = qToBigEndian<T>(value);
data.append(reinterpret_cast<const char*>(&swapped), sizeof(T));
}
}
#endif // ENDIANHELPERS_H
|