Class NDEFRecord

Class Documentation

class NDEFRecord

NDEF Record struct.

Public Functions

NDEFRecord()

Default constructor creates empty NDEF record.

NDEFRecord(const std::vector<uint8_t> &payload, const NDEFRecordType &type, size_t offset = 0, bool chunked = false)
NDEFRecord(const std::vector<uint8_t> &payload, const NDEFRecordType &type, const std::string &id, size_t offset = 0, bool chunked = false)
~NDEFRecord()
void validate()

Validates that if the payload has changed size then the type is no longer empty.

vector<uint8_t> as_bytes(uint8_t flags = 0x00) const

Creates the bytes representation of the Record object passed.

Return

vector of uint8 byte values

Parameters
  • flags: 8 bit value of header flags to combine with internal flags

void set_id(const std::string &new_id)
std::string id() const
void set_type(const NDEFRecordType &type)
NDEFRecordType type() const
void set_chunked(bool flag)
bool constexpr is_chunked() const
void set_payload(const std::vector<uint8_t> &data)

Update the payload stored in this NDEFRecord object, validating the record after doing so.

std::vector<uint8_t> payload() const
size_t payload_length() const

Access number of bytes in the payload

Return

size_t number of bytes in the payload

uint8_t header() const

Creates header byte from information known to NDEF Record. Other values will be set by NDEFMessage.

bool is_short() const
bool constexpr is_empty() const
bool constexpr is_valid() const
string get_text_locale() const

Extracts the text locale in string from the record object.

Return

ASCII string representation of record’s locale

string get_text() const

Extracts stored text from record.

Return

UTF-8 encoded string of record’s contents

std::string get_uri_protocol() const

Gets string form of URI protocol from URI Record.

Return

UTF-8 encoded string of record’s URI protocol

std::string get_uri() const

Gets string form of actual URI from URI Record.

Return

UTF-8 encoded string of record’s URI

Public Static Functions

NDEFRecord from_bytes(uint8_t bytes[], size_t len, size_t offset = 0)

Wrapper around from_byte(vector<uint8_t>) that converts the array to a vector.

Return

Record object created from bytes

Parameters
  • bytes: array of bytes (uint8_t) that will be used to attempt to create an NDEFRecord object

  • len: number of elements in bytes array

  • offset: byte offset to start from

static NDEFRecord from_bytes(std::vector<uint8_t> bytes, size_t offset = 0, size_t &bytes_used = default_bytes_used)

Return

NDEFRecord object created from bytes

Parameters
  • bytes: vector of bytes (uint8_t) that will be used to attempt to create an NDEFRecord object

  • offset: byte offset to start from

static NDEFRecord create_text_record(const std::u16string &text, const std::string &locale)

Return

NDEFRecord object with text encoded in UTF-16

Parameters
  • text: std::u16string to be converted

  • locale: string’s locale. Should be kept <= 5 characters, which is the max limit set by the NDEF standard

static NDEFRecord create_text_record(const std::string &text, const std::string &locale, RecordTextCodec codec = RecordTextCodec::UTF8)

Return

NDEFRecord object with text encoded in whatever is specified by codec

Parameters
  • text: string to be converted

  • locale: string’s locale. Should be kept <= 5 characters, which is the max limit set by the NDEF standard

  • codec: RecordTextCodec enum variant representing whether this is a UTF-8 or UTF-16 encoded string

static std::string get_text_locale(const std::vector<uint8_t> &payload)

Return

ASCII string representation of locale in payload

Parameters
  • payload: vector of bytes to have locale extracted from

static std::string get_text(const std::vector<uint8_t> &payload)

Return

UTF-8 encoded string of record in byte’s contents

Parameters
  • payload: vector of bytes to have locale extracted from

NDEFRecord create_uri_record(const std::string &uri)

Creates URI record from URI provided.

Return

NDEFRecord object with URI encoded

Parameters
  • uri: string of URI to encode

std::string get_uri_protocol(const std::vector<uint8_t> &payload)

Gets string form of URI protocol from URI Record payload.

Return

UTF-8 encoded string of record in byte’s URI protocol

Parameters
  • payload: vector of bytes to have URI protocol extracted from

std::string get_uri(const std::vector<uint8_t> &payload)

Gets string form of actual URI from URI Record payload.

Return

UTF-8 encoded string of record in byte’s URI

Parameters
  • payload: vector of bytes to have URI extracted from