M5Unit-NFC 0.0.3 git rev:59f5362
Loading...
Searching...
No Matches
ndef_tlv.hpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD
3 *
4 * SPDX-License-Identifier: MIT
5 */
10#ifndef M5_UNIT_UNIFIED_NFC_NDEF_NDEF_TLV_HPP
11#define M5_UNIT_UNIFIED_NFC_NDEF_NDEF_TLV_HPP
12
13#include "ndef.hpp"
14#include "ndef_record.hpp"
15#include <vector>
16
17namespace m5 {
18namespace nfc {
19namespace ndef {
20
21class Record;
22
27class TLV {
28public:
29 using container_type = std::vector<Record>;
30
32 static const TLV Terminator;
33
34 TLV() : TLV(Tag::Null)
35 {
36 }
37 explicit TLV(const Tag t) : _tag{t}
38 {
39 }
40 ~TLV()
41 {
42 }
43
45 inline Tag tag() const
46 {
47 return _tag;
48 }
50 inline bool isTerminatorTLV() const
51 {
52 return _tag == Tag::Terminator;
53 }
55 inline bool isMessageTLV() const
56 {
57 return _tag == Tag::Message;
58 }
60 inline bool isNullTLV() const
61 {
62 return _tag == Tag::Null;
63 }
68 inline const container_type& records() const
69 {
70 return _records;
71 }
76 inline const std::vector<uint8_t>& payload() const
77 {
78 return _payload;
79 }
84 inline std::vector<uint8_t>& payload()
85 {
86 return _payload;
87 }
88
90 uint32_t required() const;
91
98 bool push_back(const Record& r);
99
101 void pop_back();
102
110 uint32_t encode(uint8_t* buf, const uint32_t blen) const;
118 uint32_t decode(const uint8_t* buf, const uint32_t len);
119
124 void clear();
125
126 void dump();
127
128private:
129 Tag _tag{};
130 container_type _records{};
131 std::vector<uint8_t> _payload{};
132};
133} // namespace ndef
134} // namespace nfc
135} // namespace m5
136#endif
NDEF Record.
Definition ndef_record.hpp:117
NDEF TLV container.
Definition ndef_tlv.hpp:27
std::vector< uint8_t > & payload()
Get the payload.
Definition ndef_tlv.hpp:84
bool push_back(const Record &r)
Push back the record.
Definition ndef_tlv.cpp:111
Tag tag() const
Tag.
Definition ndef_tlv.hpp:45
void clear()
Clear internal buffers.
Definition ndef_tlv.cpp:328
const std::vector< uint8_t > & payload() const
Get the payload.
Definition ndef_tlv.hpp:76
bool isMessageTLV() const
Is Message?
Definition ndef_tlv.hpp:55
static const TLV Terminator
Terminator instance.
Definition ndef_tlv.hpp:32
void pop_back()
Removes the last record.
Definition ndef_tlv.cpp:139
uint32_t required() const
Size required for encoding.
Definition ndef_tlv.cpp:105
bool isNullTLV() const
Is Null TLV?
Definition ndef_tlv.hpp:60
bool isTerminatorTLV() const
Is termibator.
Definition ndef_tlv.hpp:50
uint32_t decode(const uint8_t *buf, const uint32_t len)
Decode.
Definition ndef_tlv.cpp:217
uint32_t encode(uint8_t *buf, const uint32_t blen) const
Encode.
Definition ndef_tlv.cpp:160
const container_type & records() const
Get the records.
Definition ndef_tlv.hpp:68
Top level namespace of M5stack.
For NDEF.
NFC related definitions.
NDEF related.
Tag
TLV(Tag,Length,Value) tag for type2/5.
Definition ndef.hpp:42
NDEF record.