ELEC-C7222
Libraries for ELEC C7222 Course Work
Loading...
Searching...
No Matches
c7222::AdvertisementData Class Reference

Generic advertisement data structure builder. More...

#include <advertisement_data.hpp>

Collaboration diagram for c7222::AdvertisementData:
Collaboration graph

Public Types

enum class  Flags : uint8_t {
  kLeLimitedDiscoverableMode = 0x01 , kLeGeneralDiscoverableMode = 0x02 , kBrEdrNotSupported = 0x04 , kSimultaneousLeAndBrEdrController = 0x08 ,
  kSimultaneousLeAndBrEdrHost = 0x10 , kAll = 0x1f
}
 

Public Member Functions

 AdvertisementData (AdvertisementDataType type, const std::vector< uint8_t > &data)
 Build an AD structure from a byte vector.
 
template<typename T >
 AdvertisementData (AdvertisementDataType type, const T *object_ptr)
 Build an AD structure from a typed object pointer.
 
template<typename T >
 AdvertisementData (AdvertisementDataType type, const T *object_ptr, size_t elem_count)
 Build an AD structure from an array of typed objects.
 
template<typename T >
 AdvertisementData (AdvertisementDataType type, const T &object_ref)
 Build an AD structure from a typed object reference.
 
const std::vector< uint8_t > & GetData () const
 Return the full AD structure bytes.
 
const uint8_t * GetBytes () const
 Return a raw pointer to the AD structure bytes.
 
size_t GetSize () const
 Return the total size of the AD structure (length + type + value).
 
AdvertisementDataType GetType () const
 Return the AD structure type.
 
uint8_t GetLength () const
 Return the length field (type + value bytes).
 
std::vector< uint8_t > operator+= (const AdvertisementData &other) const
 Concatenate two AD structures into a raw byte vector.
 
bool operator== (const AdvertisementData &other) const
 Compare AD structure bytes for equality.
 

Static Public Member Functions

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.
 

Friends

std::ostream & operator<< (std::ostream &os, const AdvertisementData &ad)
 Stream an AD structure for logging/debugging.
 
std::ostream & operator<< (std::ostream &os, const AdvertisementData::Flags &flag)
 Stream AD Flags for logging/debugging.
 

Detailed Description

Generic advertisement data structure builder.

Stores a single AD structure (length + type + value) in a vector.

Member Enumeration Documentation

◆ Flags

enum class c7222::AdvertisementData::Flags : uint8_t
strong
Enumerator
kLeLimitedDiscoverableMode 
kLeGeneralDiscoverableMode 
kBrEdrNotSupported 
kSimultaneousLeAndBrEdrController 
kSimultaneousLeAndBrEdrHost 
kAll 

Constructor & Destructor Documentation

◆ 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
typeAdvertisement data type.
dataValue bytes.

◆ AdvertisementData() [2/4]

template<typename T >
c7222::AdvertisementData::AdvertisementData ( AdvertisementDataType  type,
const T *  object_ptr 
)
inline

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
TConcrete (non-pointer) type.
Parameters
typeAdvertisement data type.
object_ptrPointer 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
TConcrete (non-pointer) type.
Parameters
typeAdvertisement data type.
object_ptrPointer to the first element.
elem_countNumber of elements to copy.

◆ AdvertisementData() [4/4]

template<typename T >
c7222::AdvertisementData::AdvertisementData ( AdvertisementDataType  type,
const T &  object_ref 
)
inline

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
TConcrete type.
Parameters
typeAdvertisement data type.
object_refReference to a concrete object.

Member Function Documentation

◆ 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()

AdvertisementDataType c7222::AdvertisementData::GetType ( ) const
inline

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
otherAD structure to append.
Returns
Combined byte vector (no re-validation of 31-byte limit).

◆ operator==()

bool c7222::AdvertisementData::operator== ( const AdvertisementData other) const
inline

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_dataRaw advertising payload bytes.
Returns
true if the buffer is well-formed, false otherwise.
Here is the call graph for this function:

◆ 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_dataPointer to raw advertising bytes.
adv_data_sizeTotal buffer size in bytes.
Returns
true if the buffer is well-formed, false otherwise.
Here is the caller graph for this function:

◆ ValidateLength()

static bool c7222::AdvertisementData::ValidateLength ( AdvertisementDataType  type,
size_t  length 
)
static

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
typeAdvertisement data type.
lengthLength field value (type + value bytes).

Friends And Related Symbol Documentation

◆ operator<< [1/2]

std::ostream & operator<< ( std::ostream &  os,
const AdvertisementData ad 
)
friend

Stream an AD structure for logging/debugging.

◆ operator<< [2/2]

std::ostream & operator<< ( std::ostream &  os,
const AdvertisementData::Flags flag 
)
friend

Stream AD Flags for logging/debugging.


The documentation for this class was generated from the following file: