ESPHome 2026.4.0-dev
Loading...
Searching...
No Matches
preference_backend.h
Go to the documentation of this file.
1#pragma once
2#ifdef USE_ZEPHYR
3#ifdef CONFIG_SETTINGS
4
5#include <cstddef>
6#include <cstdint>
7#include <cinttypes>
8#include <cstdio>
9#include <cstring>
10#include <vector>
11
12namespace esphome::zephyr {
13
14static constexpr const char *ESPHOME_SETTINGS_KEY = "esphome";
15
16// Buffer size for key: "esphome/" (8) + max hex uint32 (8) + null terminator (1) = 17; use 20 for safety margin
17static constexpr size_t KEY_BUFFER_SIZE = 20;
18
20 public:
22 ZephyrPreferenceBackend(uint32_t type, std::vector<uint8_t> &&data) : data(std::move(data)), type_(type) {}
23
24 bool save(const uint8_t *data, size_t len);
25 bool load(uint8_t *data, size_t len);
26
27 uint32_t get_type() const { return this->type_; }
28 void format_key(char *buf, size_t size) const {
29 snprintf(buf, size, "%s/%" PRIx32, ESPHOME_SETTINGS_KEY, this->type_);
30 }
31
32 std::vector<uint8_t> data;
33
34 protected:
36};
37
40
41} // namespace esphome::zephyr
42
43namespace esphome {
45} // namespace esphome
46
47#endif // CONFIG_SETTINGS
48#endif // USE_ZEPHYR
bool load(uint8_t *data, size_t len)
void format_key(char *buf, size_t size) const
ZephyrPreferenceBackend(uint32_t type, std::vector< uint8_t > &&data)
bool save(const uint8_t *data, size_t len)
uint16_t type
ZephyrPreferences * get_preferences()
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
std::string size_t len
Definition helpers.h:1045
size_t size
Definition helpers.h:1082
static void uint32_t