mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-16 15:36:12 -04:00
Force bluetooth connection info mac address to be 6 bytes.
PiperOrigin-RevId: 491977342
This commit is contained in:
committed by
Copybara-Service
parent
fb544f7900
commit
50de23b42c
@@ -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) {
|
||||
|
||||
@@ -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_;
|
||||
};
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user