diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2022-11-18 12:50:12 -0800 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2023-02-13 18:11:22 -0800 |
commit | 7fb69fe7b3a02fb712c82a482a26a77e5176b464 (patch) | |
tree | 16b125f2c1769fd22e582a13e2d3b29e630be7d4 /src | |
parent | 4157fc80e498a0a534728f711d908af96b5a39ba (diff) | |
download | qtconnectivity-7fb69fe7b3a02fb712c82a482a26a77e5176b464.tar.gz |
Bluez LE: improve detection of 16-bit UUID
minimumSize() and toUInt16() need to perform the same check, so do it
only once. And make one function call the other, to avoid repeating
oneself.
Change-Id: Id8e48e8f498c4a029619fffd1728c8f415f36045
Reviewed-by: Juha Vuolle <juha.vuolle@qt.io>
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/bluetooth/qlowenergycontroller_bluez.cpp | 31 |
1 files changed, 12 insertions, 19 deletions
diff --git a/src/bluetooth/qlowenergycontroller_bluez.cpp b/src/bluetooth/qlowenergycontroller_bluez.cpp index 9489aa1b..68f191d1 100644 --- a/src/bluetooth/qlowenergycontroller_bluez.cpp +++ b/src/bluetooth/qlowenergycontroller_bluez.cpp @@ -155,16 +155,16 @@ template<typename T> static void putDataAndIncrement(const T &src, char *&dst) } template<> void putDataAndIncrement(const QBluetoothUuid &uuid, char *&dst) { - const int uuidSize = getUuidSize(uuid); - if (uuidSize == 2) { - putBtData(uuid.toUInt16(), dst); + bool ok; + quint16 uuid16 = uuid.toUInt16(&ok); + if (ok) { + putBtData(uuid16, dst); + dst += sizeof(uuid16); } else { - QUuid::Id128Bytes hostOrder; - QUuid::Id128Bytes qtUuidOrder = uuid.toBytes(); - ntoh128(&qtUuidOrder, &hostOrder); - putBtData(hostOrder, dst); + QUuid::Id128Bytes btOrder = uuid.toBytes(QSysInfo::LittleEndian); + memcpy(dst, btOrder.data, sizeof(btOrder)); + dst += sizeof(btOrder); } - dst += uuidSize; } template<> void putDataAndIncrement(const QByteArray &value, char *&dst) { @@ -3221,17 +3221,10 @@ QString QLowEnergyControllerPrivateBluez::keySettingsFilePath() const static QByteArray uuidToByteArray(const QBluetoothUuid &uuid) { - QByteArray ba; - if (uuid.minimumSize() == 2) { - ba.resize(2); - putBtData(uuid.toUInt16(), ba.data()); - } else { - ba.resize(16); - QUuid::Id128Bytes hostOrder; - QUuid::Id128Bytes qtUuidOrder = uuid.toBytes(); - ntoh128(&qtUuidOrder, &hostOrder); - putBtData(hostOrder, ba.data()); - } + QByteArray ba(sizeof(uuid), Qt::Uninitialized); + char *ptr = ba.data(); + putDataAndIncrement(uuid, ptr); + ba.resize(ptr - ba.constData()); return ba; } |