#ifndef CORE_INTERNAL_BLE_ADVERTISEMENT_H_ #define CORE_INTERNAL_BLE_ADVERTISEMENT_H_ #include #include "core/internal/pcp.h" #include "platform/byte_array.h" #include "platform/port/string.h" #include "platform/ptr.h" namespace location { namespace nearby { namespace connections { // Represents the format of the Connections BLE Advertisement used in // Advertising + Discovery. // //

[VERSION][PCP][SERVICE_ID_HASH][ENDPOINT_ID][ENDPOINT_NAME_SIZE] // [ENDPOINT_NAME][BLUETOOTH_MAC] // //

See go/connections-ble-advertisement for more information. class BLEAdvertisement { public: // Versions of the BLEAdvertisement. struct Version { enum Value { V1 = 1, // Version is only allocated 3 bits in the BLEAdvertisement, so this // can never go beyond V7. }; }; static Ptr fromBytes( ConstPtr ble_advertisement_bytes); static ConstPtr toBytes(Version::Value version, PCP::Value pcp, ConstPtr service_id_hash, const std::string& endpoint_id, const std::string& endpoint_name, const std::string& bluetooth_mac_address); static const std::uint32_t kServiceIdHashLength; static const std::uint32_t kMinAdvertisementLength; // TODO(ahlee): Make sure names match for both Java and C++ implementations. static const std::uint32_t kMaxEndpointNameLength; ~BLEAdvertisement(); Version::Value getVersion() const; PCP::Value getPCP() const; ConstPtr getServiceIdHash() const; std::string getEndpointId() const; std::string getEndpointName() const; std::string getBluetoothMacAddress() const; private: static std::string hexBytesToColonDelimitedString( ConstPtr hex_bytes); // TODO(ahlee): Rename to bluetoothMacAddressHexStringToBytes static ConstPtr bluetoothMacAddressToHexBytes( const std::string& bluetooth_mac_address); static std::uint32_t computeEndpointNameLength( ConstPtr ble_advertisement_bytes); static std::uint32_t computeAdvertisementLength( const std::string& endpoint_name); static bool isBluetoothMacAddressUnset( ConstPtr bluetooth_mac_address_bytes); static const std::uint32_t kVersionAndPcpLength; static const std::uint32_t kEndpointIdLength; static const std::uint32_t kEndpointNameSizeLength; static const std::uint32_t kBluetoothMacAddressLength; static const std::uint16_t kVersionBitmask; static const std::uint16_t kPCPBitmask; static const std::uint16_t kEndpointNameLengthBitmask; BLEAdvertisement(Version::Value version, PCP::Value pcp, ConstPtr service_id_hash, const std::string& endpoint_id, const std::string& endpoint_name, const std::string& bluetooth_mac_address); const Version::Value version_; const PCP::Value pcp_; ScopedPtr > service_id_hash_; const std::string endpoint_id_; const std::string endpoint_name_; const std::string bluetooth_mac_address_; }; } // namespace connections } // namespace nearby } // namespace location #endif // CORE_INTERNAL_BLE_ADVERTISEMENT_H_