M5Unit-NFC 0.1.0 git rev:93745b5
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
36 {
37 }
42 explicit TLV(const Tag t) : _tag{t}
43 {
44 }
47 {
48 }
49
54 inline Tag tag() const
55 {
56 return _tag;
57 }
62 inline bool isTerminatorTLV() const
63 {
64 return _tag == Tag::Terminator;
65 }
70 inline bool isMessageTLV() const
71 {
72 return _tag == Tag::Message;
73 }
78 inline bool isNullTLV() const
79 {
80 return _tag == Tag::Null;
81 }
87 inline const container_type& records() const
88 {
89 return _records;
90 }
96 inline const std::vector<uint8_t>& payload() const
97 {
98 return _payload;
99 }
105 inline std::vector<uint8_t>& payload()
106 {
107 return _payload;
108 }
109
114 uint32_t required() const;
115
122 bool push_back(const Record& r);
123
128 void pop_back();
129
137 uint32_t encode(uint8_t* buf, const uint32_t blen) const;
145 uint32_t decode(const uint8_t* buf, const uint32_t len);
146
151 void clear();
152
154 void dump();
155
156private:
157 Tag _tag{};
158 container_type _records{};
159 std::vector<uint8_t> _payload{};
160};
161} // namespace ndef
162} // namespace nfc
163} // namespace m5
164#endif
NDEF Record.
Definition ndef_record.hpp:166
NDEF TLV container.
Definition ndef_tlv.hpp:27
std::vector< uint8_t > & payload()
Get the payload.
Definition ndef_tlv.hpp:105
bool push_back(const Record &r)
Push back the record.
Definition ndef_tlv.cpp:111
Tag tag() const
Tag.
Definition ndef_tlv.hpp:54
void clear()
Clear internal buffers.
Definition ndef_tlv.cpp:329
void dump()
Dump internal state for debugging.
Definition ndef_tlv.cpp:336
const std::vector< uint8_t > & payload() const
Get the payload.
Definition ndef_tlv.hpp:96
bool isMessageTLV() const
Is Message?
Definition ndef_tlv.hpp:70
static const TLV Terminator
Terminator instance.
Definition ndef_tlv.hpp:32
void pop_back()
Removes the last record.
Definition ndef_tlv.cpp:139
TLV(const Tag t)
Construct with the given Tag.
Definition ndef_tlv.hpp:42
uint32_t required() const
Size required for encoding.
Definition ndef_tlv.cpp:105
bool isNullTLV() const
Is Null TLV?
Definition ndef_tlv.hpp:78
bool isTerminatorTLV() const
Is terminator.
Definition ndef_tlv.hpp:62
~TLV()
Destructor.
Definition ndef_tlv.hpp:46
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
TLV()
Default ctor (Tag::Null)
Definition ndef_tlv.hpp:35
const container_type & records() const
Get the records.
Definition ndef_tlv.hpp:87
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.