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

Builder for assembling a complete advertising payload. More...

#include <advertisement_data.hpp>

Collaboration diagram for c7222::AdvertisementDataBuilder:
Collaboration graph

Public Member Functions

 AdvertisementDataBuilder ()
 Create an empty builder.
 
 AdvertisementDataBuilder (const std::list< AdvertisementData > &ads)
 Create a builder from a list of AD structures.
 
bool Set (const std::list< AdvertisementData > &ads)
 ReplaceOrAdd the payload with a list of AD structures.
 
bool Set (const uint8_t *data, size_t size)
 ReplaceOrAdd the payload from a raw advertising buffer.
 
bool Pop ()
 Remove the last AD structure from the payload.
 
bool Push (const AdvertisementData &ad)
 Add an AD structure to the payload.
 
void ReplaceOrAdd (const AdvertisementData &ad)
 ReplaceOrAdd the AD structure with the same type.
 
void ReplaceOrAdd (AdvertisementData &&ad)
 ReplaceOrAdd the AD structure with the same type (move).
 
bool Add (const std::list< AdvertisementData > &ads)
 Add a list of AD structures to the payload.
 
bool Add (const AdvertisementData &ad)
 Add an AD structure to the payload.
 
const std::vector< uint8_t > & data () const
 Return the raw advertising payload bytes.
 
const uint8_t * bytes () const
 Return a raw pointer to the advertising payload bytes.
 
size_t size () const
 Return the total payload size in bytes.
 
void Clear ()
 Clear all stored AD structures.
 
AdvertisementDataBuilderoperator+= (const AdvertisementData &ad)
 Add an AD structure and enforce uniqueness.
 
AdvertisementDataBuilder operator+ (const AdvertisementData &ad)
 Return a builder with an additional AD structure.
 
AdvertisementDataBuilderoperator+= (const AdvertisementDataBuilder &adb)
 Merge another builder into this one, enforcing uniqueness.
 
AdvertisementDataBuilder operator+ (const AdvertisementDataBuilder &adb)
 Return a builder that is the merge of two builders.
 
bool operator== (const AdvertisementDataBuilder &other) const
 Compare two builders by payload or list contents.
 
bool Validate () const
 Validate the assembled payload.
 
bool Build ()
 Build the raw payload from stored AD structures.
 
const std::list< AdvertisementData > & advertisement_data_list () const
 Decode the payload into a list of AD structures.
 

Static Public Member Functions

static std::list< AdvertisementDataDecodeBufferToAdvertisementDataList (const uint8_t *adv_data, size_t adv_data_size)
 Decode a raw advertising payload buffer into a list of AD structures.
 

Friends

std::ostream & operator<< (std::ostream &os, const AdvertisementDataBuilder &adb)
 Stream the builder payload for logging/debugging.
 

Detailed Description

Builder for assembling a complete advertising payload.

Use this class when you want to compose multiple AD structures into a single legacy advertising payload. The builder enforces the 31-byte limit on insert.

Constructor & Destructor Documentation

◆ AdvertisementDataBuilder() [1/2]

c7222::AdvertisementDataBuilder::AdvertisementDataBuilder ( )

Create an empty builder.

◆ AdvertisementDataBuilder() [2/2]

c7222::AdvertisementDataBuilder::AdvertisementDataBuilder ( const std::list< AdvertisementData > &  ads)
explicit

Create a builder from a list of AD structures.

The builder validates the resulting payload.

Parameters
adsList of AD structures to add.

Member Function Documentation

◆ Add() [1/2]

bool c7222::AdvertisementDataBuilder::Add ( const AdvertisementData ad)

Add an AD structure to the payload.

Fails if the addition would exceed 31 bytes.

Parameters
adAD structure to add.
Returns
true if added, false if the payload would overflow.

◆ Add() [2/2]

bool c7222::AdvertisementDataBuilder::Add ( const std::list< AdvertisementData > &  ads)

Add a list of AD structures to the payload.

Parameters
adsList of AD structures to add.
Returns
true if all structures were added, false if a structure would overflow.

◆ advertisement_data_list()

const std::list< AdvertisementData > & c7222::AdvertisementDataBuilder::advertisement_data_list ( ) const
inline

Decode the payload into a list of AD structures.

◆ Build()

bool c7222::AdvertisementDataBuilder::Build ( )

Build the raw payload from stored AD structures.

Sorts by type, assembles the payload, and validates the result.

Returns
true if the payload is valid, false otherwise.
Here is the caller graph for this function:

◆ bytes()

const uint8_t * c7222::AdvertisementDataBuilder::bytes ( ) const

Return a raw pointer to the advertising payload bytes.

◆ Clear()

void c7222::AdvertisementDataBuilder::Clear ( )

Clear all stored AD structures.

◆ data()

const std::vector< uint8_t > & c7222::AdvertisementDataBuilder::data ( ) const

Return the raw advertising payload bytes.

Here is the caller graph for this function:

◆ DecodeBufferToAdvertisementDataList()

static std::list< AdvertisementData > c7222::AdvertisementDataBuilder::DecodeBufferToAdvertisementDataList ( const uint8_t *  adv_data,
size_t  adv_data_size 
)
static

Decode a raw advertising payload buffer into a list of AD structures.

Parameters
adv_dataPointer to raw advertising bytes.
adv_data_sizeTotal buffer size in bytes.
Returns
List of decoded AD structures.

◆ operator+() [1/2]

AdvertisementDataBuilder c7222::AdvertisementDataBuilder::operator+ ( const AdvertisementData ad)

Return a builder with an additional AD structure.

Parameters
adAD structure to add.
Returns
Builder copy with the AD structure added.

◆ operator+() [2/2]

AdvertisementDataBuilder c7222::AdvertisementDataBuilder::operator+ ( const AdvertisementDataBuilder adb)

Return a builder that is the merge of two builders.

Parameters
adbBuilder to merge in.
Returns
Merged builder copy.

◆ operator+=() [1/2]

AdvertisementDataBuilder & c7222::AdvertisementDataBuilder::operator+= ( const AdvertisementData ad)

Add an AD structure and enforce uniqueness.

If an identical AD structure already exists, this asserts.

Parameters
adAD structure to add.
Returns
Reference to this builder.

◆ operator+=() [2/2]

AdvertisementDataBuilder & c7222::AdvertisementDataBuilder::operator+= ( const AdvertisementDataBuilder adb)

Merge another builder into this one, enforcing uniqueness.

Parameters
adbBuilder to merge in.
Returns
Reference to this builder.

◆ operator==()

bool c7222::AdvertisementDataBuilder::operator== ( const AdvertisementDataBuilder other) const

Compare two builders by payload or list contents.

◆ Pop()

bool c7222::AdvertisementDataBuilder::Pop ( )

Remove the last AD structure from the payload.

Returns
true if an AD structure was removed, false if the payload is empty or invalid.

◆ Push()

bool c7222::AdvertisementDataBuilder::Push ( const AdvertisementData ad)

Add an AD structure to the payload.

Parameters
adAD structure to add.
Returns
true if added, false if the payload would overflow.

◆ ReplaceOrAdd() [1/2]

void c7222::AdvertisementDataBuilder::ReplaceOrAdd ( AdvertisementData &&  ad)

ReplaceOrAdd the AD structure with the same type (move).

Parameters
adAD structure to replace in the list (moved).

◆ ReplaceOrAdd() [2/2]

void c7222::AdvertisementDataBuilder::ReplaceOrAdd ( const AdvertisementData ad)

ReplaceOrAdd the AD structure with the same type.

Parameters
adAD structure to replace in the list.

◆ Set() [1/2]

bool c7222::AdvertisementDataBuilder::Set ( const std::list< AdvertisementData > &  ads)

ReplaceOrAdd the payload with a list of AD structures.

Parameters
adsList of AD structures to set.
Returns
true if all structures were added, false if a structure would overflow.

◆ Set() [2/2]

bool c7222::AdvertisementDataBuilder::Set ( const uint8_t *  data,
size_t  size 
)

ReplaceOrAdd the payload from a raw advertising buffer.

Parameters
dataRaw advertising bytes.
sizeTotal buffer size in bytes.
Returns
true if decoded and built successfully, false otherwise.

◆ size()

size_t c7222::AdvertisementDataBuilder::size ( ) const

Return the total payload size in bytes.

◆ Validate()

bool c7222::AdvertisementDataBuilder::Validate ( ) const

Validate the assembled payload.

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  os,
const AdvertisementDataBuilder adb 
)
friend

Stream the builder payload for logging/debugging.


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