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};
55 inline bool messageBegin()
const
59 inline bool messageEnd()
const
63 inline bool chunk()
const
67 inline bool shortRecord()
const
71 inline bool idLength()
const
75 inline TNF tnf()
const
83 inline void messageBegin(
const bool b)
85 value = (value & ~MB) | (
b ?
MB : 0);
87 inline void messageEnd(
const bool b)
89 value = (value & ~ME) | (
b ?
ME : 0);
91 inline void chunk(
const bool b)
93 value = (value & ~CF) | (
b ?
CF : 0);
95 inline void shortRecord(
const bool b)
97 value = (value & ~SR) | (
b ?
SR : 0);
99 inline void idLength(
const bool b)
101 value = (value & ~IL) | (
b ?
IL : 0);
103 inline void tnf(
const TNF t)
105 value = (value & ~TNF_MASK) | (m5::stl::to_underlying(t) &
TNF_MASK);
137 inline const Attribute& attribute()
const
141 inline TNF tnf()
const
178 inline const char* type()
const
180 return _type.c_str();
182 inline void setType(
const char* s)
198 return !_id.empty() ? _id.data() :
nullptr;
207 if (_attr.tnf() != TNF::Empty &&
id && len) {
208 _id = std::vector<uint8_t>(
id,
id + len);
209 _attr.idLength(
true);
212 _attr.idLength(
false);
230 return _payload.size();
235 return !_payload.empty() ? _payload.data() :
nullptr;
242 inline void setPayload(
const uint8_t* data,
const uint32_t len)
244 if (_attr.tnf() != TNF::Empty && data && len) {
245 _payload = std::vector<uint8_t>(data, data + len);
246 _attr.shortRecord(_payload.size() < 256);
281 uint32_t
encode(uint8_t* buf,
const uint32_t blen)
const;
289 uint32_t
decode(
const uint8_t* buf,
const uint32_t blen);
298 bool apply_nested_message();
299 void set_text_payload(
const char* str,
const char* lang);
300 void set_uri_payload(
const char* uri,
URIProtocol protocol);
305 std::vector<uint8_t> _payload{};
306 std::vector<uint8_t> _id{};
308 friend bool operator==(
const Record&
a,
const Record&
b);
314 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:117
bool setURIPayload(const char *uri, URIProtocol protocol)
Set URI to the payload.
Definition ndef_record.cpp:67
uint32_t payloadSize() const
Gets the payload size.
Definition ndef_record.hpp:228
const uint8_t * payload() const
Gets the payload pointer.
Definition ndef_record.hpp:233
void clearIdentifier()
Clear the identifier.
Definition ndef_record.hpp:216
friend bool operator==(const Record &a, const Record &b)
Equal?
Definition ndef_record.hpp:312
uint32_t encode(uint8_t *buf, const uint32_t blen) const
Encode.
Definition ndef_record.cpp:79
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:286
void dump() const
Dump record for debug.
Definition ndef_record.cpp:294
std::string payloadAsString() const
Obtain the payload as a string.
Definition ndef_record.cpp:216
const uint8_t * identifier() const
Gets the identifier pointer.
Definition ndef_record.hpp:196
uint32_t decode(const uint8_t *buf, const uint32_t blen)
Decode.
Definition ndef_record.cpp:146
void setIdentifier(const uint8_t *id, const uint32_t len)
Set the identifier.
Definition ndef_record.hpp:205
void setPayload(const uint8_t *data, const uint32_t len)
Set the payload data.
Definition ndef_record.hpp:242
uint32_t identifierSize() const
Gets the identifier size.
Definition ndef_record.hpp:191
Top level namespace of M5stack.
URIProtocol
URI Identifier Code.
Definition ndef.hpp:132
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
static constexpr uint8_t CF
Chunked Flag.
Definition ndef_record.hpp:47
static constexpr uint8_t ME
Message End.
Definition ndef_record.hpp:46
static constexpr uint8_t MB
Message Begin.
Definition ndef_record.hpp:45
static constexpr uint8_t IL
ID Length (If disabled (specified as 0), ID LENGTH and ID can be omitted)
Definition ndef_record.hpp:49
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