diff options
| author | Javier <dev.git@javispedro.com> | 2014-11-30 20:58:57 +0100 |
|---|---|---|
| committer | Javier <dev.git@javispedro.com> | 2014-11-30 20:58:57 +0100 |
| commit | f7c8244641a4242f6a8c706bd918494b23e48075 (patch) | |
| tree | f84b5ead8f4d621cf47e10489889fb9fef8b1f61 /daemon/unpacker.cpp | |
| parent | 4527ab9a4147a8f15bf8ca5613341df9d0029d0c (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.cpp')
| -rw-r--r-- | daemon/unpacker.cpp | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/daemon/unpacker.cpp b/daemon/unpacker.cpp new file mode 100644 index 0000000..fc38020 --- /dev/null +++ b/daemon/unpacker.cpp @@ -0,0 +1,88 @@ +#include "unpacker.h" +#include "watchconnector.h" + +QByteArray Unpacker::readBytes(int n) +{ + if (checkBad(n)) return QByteArray(); + const char *u = &_buf.constData()[_offset]; + _offset += n; + return QByteArray(u, n); +} + +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)); +} + +QUuid Unpacker::readUuid() +{ + if (checkBad(16)) return QString(); + _offset += 16; + return QUuid::fromRfc4122(_buf.mid(_offset - 16, 16)); +} + +QMap<int, QVariant> Unpacker::readDict() +{ + QMap<int, QVariant> d; + if (checkBad(1)) return d; + + const int n = read<quint8>(); + + for (int i = 0; i < n; i++) { + if (checkBad(4 + 1 + 2)) return d; + const int key = readLE<qint32>(); // For some reason, this is little endian. + const int type = readLE<quint8>(); + const int width = readLE<quint16>(); + + switch (type) { + case WatchConnector::typeBYTES: + d.insert(key, QVariant::fromValue(readBytes(width))); + break; + case WatchConnector::typeSTRING: + d.insert(key, QVariant::fromValue(readFixedString(width))); + break; + case WatchConnector::typeUINT: + switch (width) { + case sizeof(quint8): + d.insert(key, QVariant::fromValue(readLE<quint8>())); + break; + case sizeof(quint16): + d.insert(key, QVariant::fromValue(readLE<quint16>())); + break; + case sizeof(quint32): + d.insert(key, QVariant::fromValue(readLE<quint32>())); + break; + default: + _bad = true; + return d; + } + + break; + case WatchConnector::typeINT: + switch (width) { + case sizeof(qint8): + d.insert(key, QVariant::fromValue(readLE<qint8>())); + break; + case sizeof(qint16): + d.insert(key, QVariant::fromValue(readLE<qint16>())); + break; + case sizeof(qint32): + d.insert(key, QVariant::fromValue(readLE<qint32>())); + break; + default: + _bad = true; + return d; + } + + break; + default: + _bad = true; + return d; + } + } + + return d; +} |
