NVS base. More...
#include <base.hpp>
Classes | |
struct | Iterator |
Wrapper around C-style NVS iterators More... | |
struct | Sentinel |
Sentinel type for Iterator. More... | |
Public Member Functions | |
auto | begin () const |
auto | cbegin () const |
auto | end () const |
auto | cend () const |
esp_err_t | find (std::string const &key) const |
Lookup key-value pair with given key name. | |
esp_err_t | erase (std::string const &key) |
Erase key-value pair with given key name. | |
esp_err_t | eraseAll () |
Erase all key-value pairs in a namespace. | |
Protected Member Functions | |
Base (char const *namespace_name, nvs_open_mode_t open_mode) | |
Ctor. | |
~Base () | |
Dtor. | |
std::string | getBlob (std::string const &key) const |
Get blob value for given key. | |
esp_err_t | setBlob (std::string const &key, std::string_view str) |
Set blob value for given key. | |
uint8_t | getU8 (std::string const &key) const |
Get uint8_t value for given key. | |
esp_err_t | setU8 (std::string const &key, uint8_t value) |
Set uint8_t value for given key. | |
uint8_t | getU16 (std::string const &key) const |
Get uint16_t value for given key. | |
esp_err_t | setU16 (std::string const &key, uint16_t value) |
Set uint16_t value for given key. | |
Private Attributes | |
char const * | _namespace_name {} |
Store namespace name (mainly for iterator) | |
nvs_handle_t | _handle {} |
Opaque pointer type representing non-volatile storage handle. | |
bool | _commit_pending {} |
Flag to indicate commit pending. | |
Base is a convenience wrapper over the NVS C-API and forms the basis of all NVS classes. The RAII idiom ensures that the desired namespace is opened in the constructor and that any write operations are committed in the destructor and the namespace is closed again.
A nested iterator type (Base::Iterator) ensures that the keys of the namespace can be iterated over.
|
protected |
Open non-volatile storage with a given namespace from the default NVS partition.
namespace_name | Namespace to open |
open_mode | Mode of opening the non-volatile storage |
|
protected |
Write any pending changes to non-volatile storage, then close the storage handle and free any allocated resources.
|
inline |
|
inline |
|
inline |
|
inline |
esp_err_t mem::nvs::Base::erase | ( | std::string const & | key | ) |
key | Key name |
ESP_OK | Erase operation was successful |
ESP_FAIL | Internal error |
ESP_ERR_NVS_NOT_FOUND | Requested key doesn't exist |
esp_err_t mem::nvs::Base::eraseAll | ( | ) |
ESP_OK | Erase operation was successful |
ESP_FAIL | Internal error |
esp_err_t mem::nvs::Base::find | ( | std::string const & | key | ) | const |
key | Key name |
ESP_OK | Key found |
ESP_ERR_NVS_NOT_FOUND | Key not found |
ESP_FAIL | Internal error |
|
protected |
key | Key name |
std::string
|
protected |
key | Key name |
|
protected |
key | Key name |
|
protected |
key | Key name |
str | Blob value |
ESP_OK | Value was set successfully |
ESP_FAIL | Internal error |
ESP_ERR_NVS_INVALID_NAME | Key name doesn't satisfy constraints |
ESP_ERR_NVS_NOT_ENOUGH_SPACE | Not enough space |
ESP_ERR_NVS_REMOVE_FAILED | Value wasn't updated because flash write operation has failed |
ESP_ERR_NVS_VALUE_TOO_LONG | String value is too long |
|
protected |
key | Key name |
value | uint16_t value |
ESP_OK | Value was set successfully |
ESP_FAIL | Internal error |
ESP_ERR_NVS_INVALID_NAME | Key name doesn't satisfy constraints |
ESP_ERR_NVS_NOT_ENOUGH_SPACE | Not enough space |
ESP_ERR_NVS_REMOVE_FAILED | Value wasn't updated because flash write operation has failed |
|
protected |
key | Key name |
value | uint8_t value |
ESP_OK | Value was set successfully |
ESP_FAIL | Internal error |
ESP_ERR_NVS_INVALID_NAME | Key name doesn't satisfy constraints |
ESP_ERR_NVS_NOT_ENOUGH_SPACE | Not enough space |
ESP_ERR_NVS_REMOVE_FAILED | Value wasn't updated because flash write operation has failed |
|
private |
|
private |
|
private |