diff --git a/internal/platform/bluetooth_connection_info.cc b/internal/platform/bluetooth_connection_info.cc index b133ec6c..f8cdb2a1 100644 --- a/internal/platform/bluetooth_connection_info.cc +++ b/internal/platform/bluetooth_connection_info.cc @@ -21,7 +21,7 @@ namespace location { namespace nearby { ByteArray BluetoothConnectionInfo::ToBytes() const { - return ByteArray(absl::StrCat(mac_address_.AsStringView(), service_id_)); + return ByteArray(absl::StrCat(mac_address_, service_id_)); } BluetoothConnectionInfo BluetoothConnectionInfo::FromBytes(ByteArray bytes) { diff --git a/internal/platform/bluetooth_connection_info.h b/internal/platform/bluetooth_connection_info.h index 34aff091..1a7e9a5b 100644 --- a/internal/platform/bluetooth_connection_info.h +++ b/internal/platform/bluetooth_connection_info.h @@ -33,18 +33,20 @@ class BluetoothConnectionInfo : public ConnectionInfo { BluetoothConnectionInfo() = delete; explicit BluetoothConnectionInfo(const ByteArray& mac_address, absl::string_view service_id) - : mac_address_(mac_address), service_id_(std::string(service_id)) {} + : mac_address_(mac_address.data()), service_id_(std::string(service_id)) { + mac_address_.resize(kMacAddressLength); + } BluetoothConnectionInfo(BluetoothConnectionInfo const& info) { mac_address_ = info.mac_address_; service_id_ = info.service_id_; } static BluetoothConnectionInfo FromBytes(ByteArray bytes); - ByteArray GetMacAddress() const { return mac_address_; } + ByteArray GetMacAddress() const { return ByteArray(mac_address_); } absl::string_view GetServiceId() const { return service_id_; } private: - ByteArray mac_address_; + std::string mac_address_; std::string service_id_; }; diff --git a/internal/platform/bluetooth_connection_info_test.cc b/internal/platform/bluetooth_connection_info_test.cc index 64bcc790..822ec25d 100644 --- a/internal/platform/bluetooth_connection_info_test.cc +++ b/internal/platform/bluetooth_connection_info_test.cc @@ -27,7 +27,7 @@ namespace nearby { namespace { constexpr absl::string_view kMacAddr = "\x4C\x8B\x1D\xCE\xBA\xD1"; -constexpr absl::string_view kServiceId{"NearbyConnectTest12"}; +constexpr absl::string_view kServiceId{"test"}; TEST(BluetoothConnectionInfoTest, TestMediumType) { std::string macAddr(kMacAddr); @@ -59,6 +59,12 @@ TEST(BluetoothConnectionInfoTest, TestGetMacAddress) { EXPECT_EQ(info.GetMacAddress(), ByteArray(macAddr)); } +TEST(BluetoothConnectionInfoTest, TestGetLongMacAddr) { + std::string macAddr(kMacAddr); + BluetoothConnectionInfo info(ByteArray(macAddr + "\x56\x70\x89"), kServiceId); + EXPECT_EQ(info.GetMacAddress().AsStringView(), kMacAddr); +} + TEST(BluetoothConnectionInfoTest, TestGetServiceId) { std::string macAddr(kMacAddr); BluetoothConnectionInfo info(ByteArray(macAddr), kServiceId);