ESPHome 2025.5.0
Loading...
Searching...
No Matches
ndef_record.h
Go to the documentation of this file.
1#pragma once
2
3#include "esphome/core/log.h"
5
6#include <vector>
7
8namespace esphome {
9namespace nfc {
10
11static const uint8_t TNF_EMPTY = 0x00;
12static const uint8_t TNF_WELL_KNOWN = 0x01;
13static const uint8_t TNF_MIME_MEDIA = 0x02;
14static const uint8_t TNF_ABSOLUTE_URI = 0x03;
15static const uint8_t TNF_EXTERNAL_TYPE = 0x04;
16static const uint8_t TNF_UNKNOWN = 0x05;
17static const uint8_t TNF_UNCHANGED = 0x06;
18static const uint8_t TNF_RESERVED = 0x07;
19
21 public:
23 NdefRecord(std::vector<uint8_t> payload_data);
24 void set_tnf(uint8_t tnf) { this->tnf_ = tnf; };
25 void set_type(const std::string &type) { this->type_ = type; };
26 void set_payload(const std::string &payload) { this->payload_ = payload; };
27 void set_id(const std::string &id) { this->id_ = id; };
28 NdefRecord(const NdefRecord &) = default;
29 virtual ~NdefRecord() {}
30 virtual std::unique_ptr<NdefRecord> clone() const { // To allow copying polymorphic classes
31 return make_unique<NdefRecord>(*this);
32 };
33
34 uint32_t get_encoded_size();
35
36 std::vector<uint8_t> encode(bool first, bool last);
37
38 uint8_t create_flag_byte(bool first, bool last, size_t payload_size);
39
40 const std::string &get_type() const { return this->type_; };
41 const std::string &get_id() const { return this->id_; };
42 virtual const std::string &get_payload() const { return this->payload_; };
43
44 virtual std::vector<uint8_t> get_encoded_payload() {
45 std::vector<uint8_t> payload(this->payload_.begin(), this->payload_.end());
46 return payload;
47 };
48
49 protected:
50 uint8_t tnf_;
51 std::string type_;
52 std::string id_;
53 std::string payload_;
54};
55
56} // namespace nfc
57} // namespace esphome
virtual std::unique_ptr< NdefRecord > clone() const
Definition ndef_record.h:30
void set_id(const std::string &id)
Definition ndef_record.h:27
void set_type(const std::string &type)
Definition ndef_record.h:25
NdefRecord(const NdefRecord &)=default
const std::string & get_id() const
Definition ndef_record.h:41
void set_tnf(uint8_t tnf)
Definition ndef_record.h:24
std::vector< uint8_t > encode(bool first, bool last)
virtual std::vector< uint8_t > get_encoded_payload()
Definition ndef_record.h:44
uint8_t create_flag_byte(bool first, bool last, size_t payload_size)
virtual const std::string & get_payload() const
Definition ndef_record.h:42
const std::string & get_type() const
Definition ndef_record.h:40
void set_payload(const std::string &payload)
Definition ndef_record.h:26
uint8_t type
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
std::unique_ptr< T > make_unique(Args &&...args)
Definition helpers.h:85
T id(T value)
Helper function to make id(var) known from lambdas work in custom components.
Definition helpers.h:798
uint32_t payload_size()