From 5df35700a19e4a7854afdcaad0fc3944d8b38b67 Mon Sep 17 00:00:00 2001 From: jared Date: Sat, 10 Oct 2020 22:42:53 +0800 Subject: [PATCH] update 3rdparty --- 3rdparty/TaoCommon/Common/package.h | 36 +++++++++++++++++++++++ 3rdparty/TaoCommon/Common/singleton.h | 42 --------------------------- 3rdparty/TaoCommon/TaoCommon.pri | 1 + 3 files changed, 37 insertions(+), 42 deletions(-) create mode 100644 3rdparty/TaoCommon/Common/package.h delete mode 100644 3rdparty/TaoCommon/Common/singleton.h diff --git a/3rdparty/TaoCommon/Common/package.h b/3rdparty/TaoCommon/Common/package.h new file mode 100644 index 0000000..fc452d1 --- /dev/null +++ b/3rdparty/TaoCommon/Common/package.h @@ -0,0 +1,36 @@ +#pragma once +#include +#include +#include + +const int static headerLength = sizeof(quint32); + +static QByteArray pack(const QByteArray &data) +{ + QByteArray header(headerLength, 0); + QDataStream os(&header, QIODevice::WriteOnly); + os << static_cast(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; +} diff --git a/3rdparty/TaoCommon/Common/singleton.h b/3rdparty/TaoCommon/Common/singleton.h deleted file mode 100644 index 9319e94..0000000 --- a/3rdparty/TaoCommon/Common/singleton.h +++ /dev/null @@ -1,42 +0,0 @@ -#pragma once -namespace TaoCommon -{ - //单例模板 - template - 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 -{ - friend class Singleton; -public: - void loadData(); -protected: - DataManager(); - -private: - -}; - -调用: - DataManager::instance().loadData(); -*/ - -} // namespace TaoCommon diff --git a/3rdparty/TaoCommon/TaoCommon.pri b/3rdparty/TaoCommon/TaoCommon.pri index 59f19f2..23b5acd 100644 --- a/3rdparty/TaoCommon/TaoCommon.pri +++ b/3rdparty/TaoCommon/TaoCommon.pri @@ -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 \