#include "device/bluetooth/public/cpp/bluetooth_uuid.h"
#include <stddef.h>
#include <ostream>
#include <string>
#include "base/check_op.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#if BUILDFLAG(IS_WIN)
#include <objbase.h>
#include "base/win/win_util.h"
#endif
namespace device {
namespace {
const char kCommonUuidPostfix[] = …;
const char kCommonUuidPrefix[] = …;
void GetCanonicalUuid(std::string uuid,
std::string* canonical,
std::string* canonical_128,
BluetoothUUID::Format* format) { … }
}
BluetoothUUID::BluetoothUUID(const std::string& uuid) { … }
BluetoothUUID::BluetoothUUID(base::span<const uint8_t> uuid_in_bytes) { … }
#if BUILDFLAG(IS_WIN)
BluetoothUUID::BluetoothUUID(GUID uuid) {
auto buffer = base::win::WStringFromGUID(uuid);
DCHECK_EQ('{', buffer[0]);
DCHECK_EQ('}', buffer[37]);
GetCanonicalUuid(base::WideToUTF8(buffer.substr(1, 36)), &value_,
&canonical_value_, &format_);
DCHECK_EQ(kFormat128Bit, format_);
}
#endif
BluetoothUUID::BluetoothUUID() : … { … }
BluetoothUUID::~BluetoothUUID() = default;
#if BUILDFLAG(IS_WIN)
GUID BluetoothUUID::GetCanonicalValueAsGUID(std::string_view uuid) {
DCHECK_EQ(36u, uuid.size());
std::u16string braced_uuid = u'{' + base::UTF8ToUTF16(uuid) + u'}';
GUID guid;
CHECK_EQ(NOERROR, ::CLSIDFromString(base::as_wcstr(braced_uuid), &guid));
return guid;
}
#endif
bool BluetoothUUID::IsValid() const { … }
std::vector<uint8_t> BluetoothUUID::GetBytes() const { … }
bool BluetoothUUID::operator<(const BluetoothUUID& uuid) const { … }
bool BluetoothUUID::operator==(const BluetoothUUID& uuid) const { … }
bool BluetoothUUID::operator!=(const BluetoothUUID& uuid) const { … }
std::ostream& operator<<(std::ostream& os, BluetoothUUID uuid) { … }
}