Mistake on this page?
Report an issue in GitHub or email us

MessageBuilder

Mbed OS provides this API to construct NDEF messages, the common data format exchange for NFC messages. The class mbed::nfc::ndef::MessageBuilder builds an NDEF message into a user-provided buffer. URI, Text and Mime types can be serialized in the builder with the help of the member function append_as_record.

MessageBuilder class reference

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...

MessageBuilder example

#include "nfc/ndef/MessageBuilder.h"

using mbed::nfc::ndef::MessageBuilder;
using mbed::nfc::ndef::common::Text;
using mbed::nfc::ndef::common::URI;

size_t build_ndef_message(const Span<uint8_t> &buffer) {
    MessageBuilder builder(buffer);

    URI uri(URI::HTTPS_WWW, span_from_cstr("mbed.com"));
    Text text(Text::UTF8, span_from_cstr("en-US"), span_from_cstr("Mbed website"));

    uri.append_as_record(builder);
    text.append_as_record(builder, /* last record */ true);

    return builder.get_message().size();
}
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.