10#ifndef M5_UNIT_UNIFIED_NFC_NDEF_NDEF_RECORD_HPP
11#define M5_UNIT_UNIFIED_NFC_NDEF_NDEF_RECORD_HPP
27enum class TNF : uint8_t {
45 static constexpr uint8_t
MB{0x80};
46 static constexpr uint8_t
ME{0x40};
47 static constexpr uint8_t
CF{0x20};
48 static constexpr uint8_t
SR{0x10};
49 static constexpr uint8_t
IL{0x08};
114 value = (value & ~MB) | (
b ?
MB : 0);
122 value = (value & ~ME) | (
b ?
ME : 0);
130 value = (value & ~CF) | (
b ?
CF : 0);
138 value = (value & ~SR) | (
b ?
SR : 0);
146 value = (value & ~IL) | (
b ?
IL : 0);
154 value = (value & ~TNF_MASK) | (m5::stl::to_underlying(t) &
TNF_MASK);
243 inline const char*
type()
const
245 return _type.c_str();
255 M5_LIB_LOGW(
"Ignoring a null type string");
279 return !_id.empty() ? _id.data() :
nullptr;
288 if (_attr.
tnf() != TNF::Empty &&
id && len) {
289 _id = std::vector<uint8_t>(
id,
id + len);
317 return _payload.size();
325 return !_payload.empty() ? _payload.data() :
nullptr;
332 inline void setPayload(
const uint8_t* data,
const uint32_t len)
334 if (_attr.
tnf() == TNF::Empty || !data || !len) {
339 _payload = std::vector<uint8_t>(data, data + len);
379 uint32_t
encode(uint8_t* buf,
const uint32_t blen)
const;
387 uint32_t
decode(
const uint8_t* buf,
const uint32_t blen);
396 bool apply_nested_message();
397 bool set_text_payload(
const char* str,
const char* lang);
398 bool set_uri_payload(
const char* uri,
URIProtocol protocol);
403 std::vector<uint8_t> _payload{};
404 std::vector<uint8_t> _id{};
406 friend bool operator==(
const Record&
a,
const Record&
b);
412 return a._attr.value ==
b._attr.value &&
a._type ==
b._type &&
a._payload ==
b._payload &&
a._id ==
b._id;
NDEF Record.
Definition ndef_record.hpp:166
bool setURIPayload(const char *uri, URIProtocol protocol)
Set URI to the payload.
Definition ndef_record.cpp:66
uint32_t payloadSize() const
Gets the payload size.
Definition ndef_record.hpp:315
const uint8_t * payload() const
Gets the payload pointer.
Definition ndef_record.hpp:323
void clearIdentifier()
Clear the identifier.
Definition ndef_record.hpp:297
friend bool operator==(const Record &a, const Record &b)
Equal?
Definition ndef_record.hpp:410
TNF tnf() const
Gets Type Name Format.
Definition ndef_record.hpp:202
uint32_t encode(uint8_t *buf, const uint32_t blen) const
Encode.
Definition ndef_record.cpp:77
uint32_t required() const
Size required for encoding.
Definition ndef_record.cpp:42
bool setTextPayload(const char *str, const char *lang)
Set text to the payload.
Definition ndef_record.cpp:55
void clear()
Clear.
Definition ndef_record.cpp:303
Attribute & attribute()
Gets mutable attribute.
Definition ndef_record.hpp:186
void setType(const char *s)
Set the type string.
Definition ndef_record.hpp:252
void dump() const
Dump record for debug.
Definition ndef_record.cpp:311
std::string payloadAsString() const
Obtain the payload as a string.
Definition ndef_record.cpp:219
const char * type() const
Gets the type string.
Definition ndef_record.hpp:243
const uint8_t * identifier() const
Gets the identifier pointer.
Definition ndef_record.hpp:277
const Attribute & attribute() const
Gets attribute.
Definition ndef_record.hpp:194
uint32_t decode(const uint8_t *buf, const uint32_t blen)
Decode.
Definition ndef_record.cpp:145
void setIdentifier(const uint8_t *id, const uint32_t len)
Set the identifier.
Definition ndef_record.hpp:286
void setPayload(const uint8_t *data, const uint32_t len)
Set the payload data.
Definition ndef_record.hpp:332
uint32_t identifierSize() const
Gets the identifier size.
Definition ndef_record.hpp:269
Top level namespace of M5Stack.
URIProtocol
URI Identifier Code.
Definition ndef.hpp:133
TNF
Type Name Field for NDEF Record.
Definition ndef_record.hpp:27
@ Wellknown
NFC Forum well-known-type.
@ MIMEMedia
Media-type as define in RFC2046.
@ URI
Absolute URI as define in RFC3986.
@ External
NFC Forum external type.
NDEF Record attribute (1st byte)
Definition ndef_record.hpp:42
TNF tnf() const
Type Name Format.
Definition ndef_record.hpp:99
bool messageBegin() const
Message Begin flag.
Definition ndef_record.hpp:59
static constexpr uint8_t CF
Chunked Flag.
Definition ndef_record.hpp:47
void messageEnd(const bool b)
Set Message End flag.
Definition ndef_record.hpp:120
void messageBegin(const bool b)
Set Message Begin flag.
Definition ndef_record.hpp:112
bool chunk() const
Chunked flag.
Definition ndef_record.hpp:75
static constexpr uint8_t ME
Message End.
Definition ndef_record.hpp:46
static constexpr uint8_t MB
Message Begin.
Definition ndef_record.hpp:45
bool idLength() const
ID Length flag.
Definition ndef_record.hpp:91
bool shortRecord() const
Short Record flag.
Definition ndef_record.hpp:83
static constexpr uint8_t IL
ID Length (If disabled (specified as 0), ID LENGTH and ID can be omitted)
Definition ndef_record.hpp:49
void idLength(const bool b)
Set ID Length flag.
Definition ndef_record.hpp:144
void tnf(const TNF t)
Set Type Name Format.
Definition ndef_record.hpp:152
static constexpr uint8_t TNF_MASK
Type Name Format.
Definition ndef_record.hpp:50
static constexpr uint8_t SR
Short Flag.
Definition ndef_record.hpp:48
void shortRecord(const bool b)
Set Short Record flag.
Definition ndef_record.hpp:136
void chunk(const bool b)
Set Chunked flag.
Definition ndef_record.hpp:128
bool messageEnd() const
Message End flag.
Definition ndef_record.hpp:67