1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

refactor(settings): remove unused serialization methods

Conversion should be re-done with QVariant - if required at all.
This commit is contained in:
Nils Fenner 2016-06-26 11:33:41 +02:00
parent 31c154293b
commit f1642e6f3e
No known key found for this signature in database
GPG Key ID: 9591A163FF9BE04C
2 changed files with 0 additions and 200 deletions

View File

@ -25,66 +25,6 @@ Most of functions in this file are unsafe unless otherwise specified.
@warning Do not use them on untrusted data (e.g. check a signature first).
*/
QByteArray doubleToData(double num)
{
union
{
char tab[8];
double n;
} castUnion;
//char n[8];
//*((double*) n) = num;
castUnion.n=num;
return QByteArray(castUnion.tab,8);
}
QByteArray floatToData(float num)
{
union
{
char tab[4];
float n;
} castUnion;
castUnion.n=num;
return QByteArray(castUnion.tab,4);
}
float dataToFloat(QByteArray data)
{
union
{
char tab[4];
float n;
} castUnion;
castUnion.tab[0]=data.data()[0];
castUnion.tab[1]=data.data()[1];
castUnion.tab[2]=data.data()[2];
castUnion.tab[3]=data.data()[3];
return castUnion.n;
}
// Converts a string into PNet string data
QByteArray stringToData(const QString& str)
{
QByteArray data(4,0);
// Write the size in a Uint of variable lenght (8-32 bits)
int i=0;
int num1 = str.toUtf8().size();
while (num1 >= 0x80)
{
data[i] = static_cast<char>(num1 | 0x80);
i++;
num1 = num1 >> 7;
}
data[i] = static_cast<char>(num1);
data.resize(i+1);
data+=str.toUtf8();
return data;
}
QString dataToString(QByteArray data)
{
char num3;
@ -108,96 +48,6 @@ QString dataToString(QByteArray data)
return QString(data);
}
float dataToRangedSingle(float min, float max, int numberOfBits, QByteArray data)
{
uint endvalue=0;
uint value=0;
if (numberOfBits <= 8)
{
endvalue = static_cast<uchar>(data[0]);
goto done;
}
value = static_cast<uchar>(data[0]);
numberOfBits -= 8;
if (numberOfBits <= 8)
{
endvalue = value | (static_cast<uint>(data[1]) << 8);
goto done;
}
value |= static_cast<uint>(data[1]) << 8;
numberOfBits -= 8;
if (numberOfBits <= 8)
{
uint num2 = static_cast<uint>(data[2]) << 0x10;
endvalue = (value | num2);
goto done;
}
value |= static_cast<uint>(data[2]) << 0x10;
numberOfBits -= 8;
endvalue = value | (static_cast<uint>(data[3]) << 0x18);
goto done;
done:
float num = max - min;
int num2 = (static_cast<int>(1) << numberOfBits) - 1;
float num3 = endvalue;
float num4 = num3 / num2;
return (min + (num4 * num));
}
QByteArray rangedSingleToData(float value, float min, float max, int numberOfBits)
{
QByteArray data;
float num = max - min;
float num2 = (value - min) / num;
int num3 = (static_cast<int>(1) << numberOfBits) - 1;
uint source = static_cast<uint>(num3 * num2);
if (numberOfBits <= 8)
{
data += static_cast<char>(source);
return data;
}
data += static_cast<char>(source);
numberOfBits -= 8;
if (numberOfBits <= 8)
{
data += static_cast<char>(source >> 8);
return data;
}
data += static_cast<char>(source >> 8);
numberOfBits -= 8;
if (numberOfBits <= 8)
{
data += static_cast<char>(source >> 16);
return data;
}
data += static_cast<char>(source >> 16);
data += static_cast<char>(source >> 24);
return data;
}
uint8_t dataToUint8(const QByteArray& data)
{
return static_cast<uint8_t>(data[0]);
}
uint16_t dataToUint16(const QByteArray& data)
{
return static_cast<uint16_t>(data[0])
| static_cast<uint16_t>(data[1] << 8);
}
uint32_t dataToUint32(const QByteArray& data)
{
return static_cast<uint32_t>(data[0])
| (static_cast<uint32_t>(data[1]) << 8)
| (static_cast<uint32_t>(data[2]) << 16)
| (static_cast<uint32_t>(data[3]) << 24);
}
uint64_t dataToUint64(const QByteArray& data)
{
return static_cast<uint64_t>(data[0])
@ -253,43 +103,6 @@ unsigned getVUint32Size(QByteArray data)
return lensize;
}
QByteArray uint8ToData(uint8_t num)
{
return QByteArray(1, static_cast<char>(num));
}
QByteArray uint16ToData(uint16_t num)
{
QByteArray data(2,0);
data[0] = static_cast<char>(num & 0xFF);
data[1] = static_cast<char>((num>>8) & 0xFF);
return data;
}
QByteArray uint32ToData(uint32_t num)
{
QByteArray data(4,0);
data[0] = static_cast<char>(num & 0xFF);
data[1] = static_cast<char>((num>>8) & 0xFF);
data[2] = static_cast<char>((num>>16) & 0xFF);
data[3] = static_cast<char>((num>>24) & 0xFF);
return data;
}
QByteArray uint64ToData(uint64_t num)
{
QByteArray data(8,0);
data[0] = static_cast<char>(num & 0xFF);
data[1] = static_cast<char>((num>>8) & 0xFF);
data[2] = static_cast<char>((num>>16) & 0xFF);
data[3] = static_cast<char>((num>>24) & 0xFF);
data[4] = static_cast<char>((num>>32) & 0xFF);
data[5] = static_cast<char>((num>>40) & 0xFF);
data[6] = static_cast<char>((num>>48) & 0xFF);
data[7] = static_cast<char>((num>>56) & 0xFF);
return data;
}
QByteArray vintToData(int num)
{
QByteArray data(sizeof(int), 0);

View File

@ -25,24 +25,11 @@
#include <QByteArray>
#include <QString>
QByteArray doubleToData(double num);
QByteArray floatToData(float num);
float dataToFloat(const QByteArray& data);
QByteArray stringToData(const QString& str);
QString dataToString(QByteArray data);
float dataToRangedSingle(float min, float max, int numberOfBits, QByteArray data);
QByteArray rangedSingleToData(float value, float min, float max, int numberOfBits);
uint8_t dataToUint8(const QByteArray& data);
uint16_t dataToUint16(const QByteArray& data);
uint32_t dataToUint32(const QByteArray& data);
uint64_t dataToUint64(const QByteArray& data);
int dataToVInt(const QByteArray& data);
size_t dataToVUint(const QByteArray& data);
unsigned getVUint32Size(QByteArray data);
QByteArray uint8ToData(uint8_t num);
QByteArray uint16ToData(uint16_t num);
QByteArray uint32ToData(uint32_t num);
QByteArray uint64ToData(uint64_t num);
QByteArray vintToData(int num);
QByteArray vuintToData(size_t num);