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