Generic advertisement data structure builder.
More...
#include <advertisement_data.hpp>
|
| static bool | ValidateLength (AdvertisementDataType type, size_t length) |
| | Validate the AD length field for a given type.
|
| |
| static bool | ValidateBuffer (const uint8_t *adv_data, size_t adv_data_size) |
| | Validate a raw advertising payload buffer.
|
| |
| static bool | ValidateBuffer (const std::vector< uint8_t > &adv_data) |
| | Validate a raw advertising payload stored in a vector.
|
| |
Generic advertisement data structure builder.
Stores a single AD structure (length + type + value) in a vector.
◆ Flags
| Enumerator |
|---|
| kLeLimitedDiscoverableMode | |
| kLeGeneralDiscoverableMode | |
| kBrEdrNotSupported | |
| kSimultaneousLeAndBrEdrController | |
| kSimultaneousLeAndBrEdrHost | |
| kAll | |
◆ AdvertisementData() [1/4]
| c7222::AdvertisementData::AdvertisementData |
( |
AdvertisementDataType |
type, |
|
|
const std::vector< uint8_t > & |
data |
|
) |
| |
|
inline |
Build an AD structure from a byte vector.
Use this when your payload is already stored in a std::vector.
- Parameters
-
| type | Advertisement data type. |
| data | Value bytes. |
◆ AdvertisementData() [2/4]
Build an AD structure from a typed object pointer.
This overload deduces the payload size as sizeof(T) and copies the raw bytes of the object into the AD structure.
Use this for POD/struct payloads that match the AD format.
- Template Parameters
-
| T | Concrete (non-pointer) type. |
- Parameters
-
| type | Advertisement data type. |
| object_ptr | Pointer to a concrete object. |
◆ AdvertisementData() [3/4]
template<typename T >
| c7222::AdvertisementData::AdvertisementData |
( |
AdvertisementDataType |
type, |
|
|
const T * |
object_ptr, |
|
|
size_t |
elem_count |
|
) |
| |
|
inline |
Build an AD structure from an array of typed objects.
Copies elem_count items of type T into the payload.
- Template Parameters
-
| T | Concrete (non-pointer) type. |
- Parameters
-
| type | Advertisement data type. |
| object_ptr | Pointer to the first element. |
| elem_count | Number of elements to copy. |
◆ AdvertisementData() [4/4]
Build an AD structure from a typed object reference.
This overload deduces the payload size as sizeof(T) and copies the raw bytes of the object into the AD structure.
Use this for POD/struct payloads that match the AD format.
- Template Parameters
-
- Parameters
-
| type | Advertisement data type. |
| object_ref | Reference to a concrete object. |
◆ GetBytes()
| const uint8_t * c7222::AdvertisementData::GetBytes |
( |
| ) |
const |
|
inline |
Return a raw pointer to the AD structure bytes.
The pointer remains valid until the object is modified or destroyed.
◆ GetData()
| const std::vector< uint8_t > & c7222::AdvertisementData::GetData |
( |
| ) |
const |
|
inline |
Return the full AD structure bytes.
The returned vector includes the length and type header bytes.
◆ GetLength()
| uint8_t c7222::AdvertisementData::GetLength |
( |
| ) |
const |
|
inline |
Return the length field (type + value bytes).
◆ GetSize()
| size_t c7222::AdvertisementData::GetSize |
( |
| ) |
const |
|
inline |
Return the total size of the AD structure (length + type + value).
◆ GetType()
Return the AD structure type.
◆ operator+=()
| std::vector< uint8_t > c7222::AdvertisementData::operator+= |
( |
const AdvertisementData & |
other | ) |
const |
Concatenate two AD structures into a raw byte vector.
Use this when you want to build a single advertising payload from multiple AD structures.
- Parameters
-
| other | AD structure to append. |
- Returns
- Combined byte vector (no re-validation of 31-byte limit).
◆ operator==()
Compare AD structure bytes for equality.
◆ ValidateBuffer() [1/2]
| static bool c7222::AdvertisementData::ValidateBuffer |
( |
const std::vector< uint8_t > & |
adv_data | ) |
|
|
inlinestatic |
Validate a raw advertising payload stored in a vector.
- Parameters
-
| adv_data | Raw advertising payload bytes. |
- Returns
- true if the buffer is well-formed, false otherwise.
◆ ValidateBuffer() [2/2]
| static bool c7222::AdvertisementData::ValidateBuffer |
( |
const uint8_t * |
adv_data, |
|
|
size_t |
adv_data_size |
|
) |
| |
|
static |
Validate a raw advertising payload buffer.
Iterates over each AD structure in the buffer, validates the length and type rules, and ensures the payload fully consumes the buffer without trailing bytes.
- Parameters
-
| adv_data | Pointer to raw advertising bytes. |
| adv_data_size | Total buffer size in bytes. |
- Returns
- true if the buffer is well-formed, false otherwise.
◆ ValidateLength()
Validate the AD length field for a given type.
Enforces the BLE specification rules for specific data types (e.g., Flags must be 1 byte, UUID lists must be 16-bit aligned).
- Parameters
-
| type | Advertisement data type. |
| length | Length field value (type + value bytes). |
◆ operator<< [1/2]
Stream an AD structure for logging/debugging.
◆ operator<< [2/2]
Stream AD Flags for logging/debugging.
The documentation for this class was generated from the following file: