summaryrefslogtreecommitdiff
path: root/daemon/unpacker.h
diff options
context:
space:
mode:
authorJavier <dev.git@javispedro.com>2014-11-30 20:58:57 +0100
committerJavier <dev.git@javispedro.com>2014-11-30 20:58:57 +0100
commitf7c8244641a4242f6a8c706bd918494b23e48075 (patch)
treef84b5ead8f4d621cf47e10489889fb9fef8b1f61 /daemon/unpacker.h
parent4527ab9a4147a8f15bf8ca5613341df9d0029d0c (diff)
introduce the AppMsgManager and the JsKitManager
will be used to handle application messages (push, etc) while the JSKitManager will run PebbleKit JS scripts. also add the ability to unpack PebbleDicts
Diffstat (limited to 'daemon/unpacker.h')
-rw-r--r--daemon/unpacker.h29
1 files changed, 17 insertions, 12 deletions
diff --git a/daemon/unpacker.h b/daemon/unpacker.h
index 94908cb..000c3e8 100644
--- a/daemon/unpacker.h
+++ b/daemon/unpacker.h
@@ -5,19 +5,30 @@
#include <QByteArray>
#include <QString>
#include <QUuid>
+#include <QVariantMap>
+#include <Log4Qt/Logger>
class Unpacker
{
+ LOG4QT_DECLARE_STATIC_LOGGER(logger, Unpacker)
+
public:
Unpacker(const QByteArray &data);
template <typename T>
T read();
+ template <typename T>
+ T readLE();
+
+ QByteArray readBytes(int n);
+
QString readFixedString(int n);
QUuid readUuid();
+ QMap<int, QVariant> readDict();
+
void skip(int n);
bool bad() const;
@@ -45,19 +56,13 @@ inline T Unpacker::read()
return qFromBigEndian<T>(u);
}
-inline QString Unpacker::readFixedString(int n)
-{
- if (checkBad(n)) return QString();
- const char *u = &_buf.constData()[_offset];
- _offset += n;
- return QString::fromUtf8(u, strnlen(u, n));
-}
-
-inline QUuid Unpacker::readUuid()
+template <typename T>
+inline T Unpacker::readLE()
{
- if (checkBad(16)) return QString();
- _offset += 16;
- return QUuid::fromRfc4122(_buf.mid(_offset - 16, 16));
+ if (checkBad(sizeof(T))) return 0;
+ const uchar *u = p();
+ _offset += sizeof(T);
+ return qFromLittleEndian<T>(u);
}
inline void Unpacker::skip(int n)