1
0
mirror of https://github.com/jaredtao/TaoQuick.git synced 2025-01-19 20:22:56 +08:00

update 3rdparty

This commit is contained in:
jared 2020-10-10 22:42:53 +08:00
parent 8d63eac60d
commit 5df35700a1
3 changed files with 37 additions and 42 deletions

36
3rdparty/TaoCommon/Common/package.h vendored Normal file
View File

@ -0,0 +1,36 @@
#pragma once
#include <QByteArray>
#include <QByteArrayList>
#include <QDataStream>
const int static headerLength = sizeof(quint32);
static QByteArray pack(const QByteArray &data)
{
QByteArray header(headerLength, 0);
QDataStream os(&header, QIODevice::WriteOnly);
os << static_cast<quint32>(data.length());
return header + data;
}
static QByteArrayList unpack(const QByteArray &data)
{
QByteArrayList list;
QDataStream inStream(data);
quint32 sum = data.size();
quint32 pos = 0;
quint32 packageLen = 0;
while (pos + headerLength < sum)
{
packageLen = 0;
inStream >> packageLen;
if (packageLen <= 0 || packageLen + headerLength > sum - pos)
{
break;
}
QByteArray subPackage = data.mid(pos + headerLength, packageLen);
inStream.skipRawData(packageLen);
list.append(subPackage);
pos += headerLength + packageLen;
}
return list;
}

View File

@ -1,42 +0,0 @@
#pragma once
namespace TaoCommon
{
//单例模板
template <typename T>
class Singleton
{
public:
static T &instance()
{
static T t;
return t;
}
virtual ~Singleton() {}
Singleton(const Singleton &) = delete;
Singleton &operator=(const Singleton &) = delete;
protected:
Singleton() {}
};
/*
使
:
class DataManager : public Singleton<DataManager>
{
friend class Singleton<DataManager>;
public:
void loadData();
protected:
DataManager();
private:
};
:
DataManager::instance().loadData();
*/
} // namespace TaoCommon

View File

@ -12,6 +12,7 @@ HEADERS += \
$$PWD/Common/objectmap.h \
$$PWD/Common/singleton.h \
$$PWD/Common/subject.h \
$$PWD/Common/package.h \
$$PWD/Logger/loggertemplate.h \
$$PWD/Logger/logger.h \
$$PWD/Thread/threadcommon.h \