ESPHome  2024.3.1
ndef_message.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <memory>
4 #include <vector>
5 
6 #include "esphome/core/helpers.h"
7 #include "esphome/core/log.h"
8 #include "ndef_record.h"
9 #include "ndef_record_text.h"
10 #include "ndef_record_uri.h"
11 
12 namespace esphome {
13 namespace nfc {
14 
15 static const uint8_t MAX_NDEF_RECORDS = 4;
16 
17 class NdefMessage {
18  public:
19  NdefMessage() = default;
20  NdefMessage(std::vector<uint8_t> &data);
21  NdefMessage(const NdefMessage &msg) {
22  records_.reserve(msg.records_.size());
23  for (const auto &r : msg.records_) {
24  records_.emplace_back(r->clone());
25  }
26  }
27 
28  const std::vector<std::shared_ptr<NdefRecord>> &get_records() { return this->records_; };
29 
30  bool add_record(std::unique_ptr<NdefRecord> record);
31  bool add_text_record(const std::string &text);
32  bool add_text_record(const std::string &text, const std::string &encoding);
33  bool add_uri_record(const std::string &uri);
34 
35  std::vector<uint8_t> encode();
36 
37  protected:
38  std::vector<std::shared_ptr<NdefRecord>> records_;
39 };
40 
41 } // namespace nfc
42 } // namespace esphome
const std::vector< std::shared_ptr< NdefRecord > > & get_records()
Definition: ndef_message.h:28
NdefMessage(const NdefMessage &msg)
Definition: ndef_message.h:21
bool add_text_record(const std::string &text)
bool add_record(std::unique_ptr< NdefRecord > record)
std::vector< std::shared_ptr< NdefRecord > > records_
Definition: ndef_message.h:38
std::vector< uint8_t > encode()
bool add_uri_record(const std::string &uri)
This is a workaround until we can figure out a way to get the tflite-micro idf component code availab...
Definition: a01nyub.cpp:7