Mbed OS Reference
Loading...
Searching...
No Matches
MessageBuilder Class Reference

Construct a NDEF Message. More...

#include <MessageBuilder.h>

Data Structures

struct  PayloadBuilder
 Build a record payload. More...
 

Public Member Functions

 MessageBuilder (const Span< uint8_t > &buffer)
 Create a new MessageBuilder that can be used to construct valid NDEF messages. More...
 
bool append_record (const RecordType &type, const RecordPayload &payload=RecordPayload(), bool is_last_record=false)
 Append a new record to the message being built. More...
 
bool append_record (const RecordType &type, const PayloadBuilder &builder, bool is_last_record=false)
 Append a new record to the message being built. More...
 
bool append_record (const Record &record, const PayloadBuilder *builder=NULL)
 Append a new record to the message being built. More...
 
void reset ()
 Reset the builder state. More...
 
void reset (const Span< uint8_t > &buffer)
 Reset the builder state and assign a new buffer to it. More...
 
bool is_message_complete () const
 Return true if the message stored is complete and false otherwise. More...
 
Span< const uint8_t > get_message () const
 Return the buffer storing the data if the message is complete or an empty buffer if the message is not complete. More...
 

Static Public Member Functions

static size_t compute_record_size (const Record &record, const PayloadBuilder *builder=NULL)
 Compute the size of a record. More...
 

Detailed Description

Construct a NDEF Message.

Definition at line 38 of file MessageBuilder.h.

Constructor & Destructor Documentation

◆ MessageBuilder()

MessageBuilder ( const Span< uint8_t > &  buffer)

Create a new MessageBuilder that can be used to construct valid NDEF messages.

Parameters
bufferThe data buffer that will contain the NDEF message.

Member Function Documentation

◆ append_record() [1/3]

bool append_record ( const RecordType type,
const RecordPayload payload = RecordPayload(),
bool  is_last_record = false 
)

Append a new record to the message being built.

Parameters
typeThe type of the record to insert.
payloadThe payload of the record (optional).
is_last_recordtrue if the record to insert is the last record of the payload or false otherwise.
Returns
true if the record has been successfully inserted or false otherwise.
Note
insertion can fail if the message is already complete or if the size remaining in the message buffer is not large enough to makes the record inserted fit.

◆ append_record() [2/3]

bool append_record ( const RecordType type,
const PayloadBuilder builder,
bool  is_last_record = false 
)

Append a new record to the message being built.

Parameters
typeThe type of the record to insert.
builderThe builder of the payload.
is_last_recordtrue if the record to insert is the last record of the payload or false otherwise.
Returns
true if the record has been successfully inserted or false otherwise.
Note
insertion can fail if the message is already complete or if the size remaining in the message buffer is not large enough to makes the record inserted fit.

◆ append_record() [3/3]

bool append_record ( const Record record,
const PayloadBuilder builder = NULL 
)

Append a new record to the message being built.

Parameters
recordThe record to insert.
builderThe builder that will construct the payload.
Returns
true if the record has been successfully inserted or false otherwise.
Note
insertion can fail if the message is already complete or if the size remaining in the message buffer is not large enough to makes the record inserted fit.

◆ compute_record_size()

static size_t compute_record_size ( const Record record,
const PayloadBuilder builder = NULL 
)
static

Compute the size of a record.

Parameters
recordThe record used to compute the size.
builderThe payload builder if any.
Returns
The size of the payload for the record in input.

◆ reset() [1/2]

void reset ( )

Reset the builder state.

◆ reset() [2/2]

void reset ( const Span< uint8_t > &  buffer)

Reset the builder state and assign a new buffer to it.

◆ is_message_complete()

bool is_message_complete ( ) const

Return true if the message stored is complete and false otherwise.

Returns
true if the message is complete or false.

◆ get_message()

Span< const uint8_t > get_message ( ) const

Return the buffer storing the data if the message is complete or an empty buffer if the message is not complete.

Returns
The message built.