mirror of
https://github.com/h2zero/esp-nimble-cpp.git
synced 2024-11-21 20:50:55 +01:00
Fix 16 and 32 bit UUID comparison.
This commit is contained in:
parent
209f70a083
commit
d22db6ef8c
1 changed files with 15 additions and 3 deletions
|
@ -272,6 +272,10 @@ const NimBLEUUID& NimBLEUUID::reverseByteOrder() {
|
||||||
* @brief Convenience operator to check if this UUID is equal to another.
|
* @brief Convenience operator to check if this UUID is equal to another.
|
||||||
*/
|
*/
|
||||||
bool NimBLEUUID::operator==(const NimBLEUUID& rhs) const {
|
bool NimBLEUUID::operator==(const NimBLEUUID& rhs) const {
|
||||||
|
if (!this->bitSize() || !rhs.bitSize()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (this->bitSize() != rhs.bitSize()) {
|
if (this->bitSize() != rhs.bitSize()) {
|
||||||
uint8_t uuid128[sizeof(ble_base_uuid)];
|
uint8_t uuid128[sizeof(ble_base_uuid)];
|
||||||
memcpy(uuid128, &ble_base_uuid, sizeof(ble_base_uuid));
|
memcpy(uuid128, &ble_base_uuid, sizeof(ble_base_uuid));
|
||||||
|
@ -287,11 +291,19 @@ bool NimBLEUUID::operator==(const NimBLEUUID& rhs) const {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->bitSize() != BLE_UUID_TYPE_128) {
|
if (this->bitSize() == BLE_UUID_TYPE_16) {
|
||||||
return this->getValue() == rhs.getValue();
|
return *reinterpret_cast<const uint16_t*>(this->getValue()) == *reinterpret_cast<const uint16_t*>(rhs.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
return memcmp(this->getValue(), rhs.getValue(), 16) == 0;
|
if (this->bitSize() == BLE_UUID_TYPE_32) {
|
||||||
|
return *reinterpret_cast<const uint32_t*>(this->getValue()) == *reinterpret_cast<const uint32_t*>(rhs.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this->bitSize() == BLE_UUID_TYPE_128) {
|
||||||
|
return memcmp(this->getValue(), rhs.getValue(), 16) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
} // operator==
|
} // operator==
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue