5 #include "preferences.h" 10 namespace fs = std::filesystem;
12 static const char *
const TAG =
"host.preferences";
24 FILE *fp = fopen(this->
filename_.c_str(),
"rb");
29 if (fread(&key,
sizeof(key), 1, fp) != 1)
31 if (fread(&len,
sizeof(len), 1, fp) != 1)
34 if (fread(data,
sizeof(uint8_t), len, fp) !=
len)
36 std::vector vec(data, data + len);
37 this->data[key] = vec;
46 FILE *fp = fopen(this->
filename_.c_str(),
"wb");
47 std::map<uint32_t, std::vector<uint8_t>>::iterator it;
49 for (it = this->
data.begin(); it != this->
data.end(); ++it) {
50 fwrite(&it->first,
sizeof(uint32_t), 1, fp);
51 uint8_t
len = it->second.size();
52 fwrite(&len,
sizeof(len), 1, fp);
53 fwrite(it->second.data(),
sizeof(uint8_t), it->second.size(), fp);
std::map< uint32_t, std::vector< uint8_t > > data
bool load(uint32_t key, uint8_t *data, size_t len)
bool save(const uint8_t *data, size_t len) override
ESPPreferences * global_preferences
HostPreferences * host_preferences
ESPPreferenceObject make_preference(size_t length, uint32_t type, bool in_flash) override
Application App
Global storage of Application pointer - only one Application can exist.
const std::string & get_name() const
Get the name of this Application set by pre_setup().
bool load(uint8_t *data, size_t len) override
bool save(uint32_t key, const uint8_t *data, size_t len)
Implementation of SPI Controller mode.