oveRTOS C++ API
C++20 RAII wrappers for the oveRTOS C API
Loading...
Searching...
No Matches
nvs.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2026 Kamil Lulko <kamil.lulko@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 *
6 * This file is part of oveRTOS.
7 */
8
14#pragma once
15
16#include <ove/nvs.h>
17#include <ove/types.hpp>
18#include <ove/error.hpp>
19
20#ifdef CONFIG_OVE_NVS
21
22namespace ove::nvs
23{
24
38[[nodiscard]] inline Result<void> init() noexcept
39{
40 return from_rc(ove_nvs_init());
41}
42
46inline void deinit()
47{
48 ove_nvs_deinit();
49}
50
60[[nodiscard]] inline Result<size_t> read(const char *key, void *buf, size_t len) noexcept
61{
62 size_t out = 0;
63 const int rc = ove_nvs_read(key, buf, len, &out);
64 return from_rc(rc, out);
65}
66
75[[nodiscard]] inline Result<void> write(const char *key, const void *data, size_t len) noexcept
76{
77 return from_rc(ove_nvs_write(key, data, len));
78}
79
86[[nodiscard]] inline Result<void> erase(const char *key) noexcept
87{
88 return from_rc(ove_nvs_erase(key));
89}
90
91} /* namespace ove::nvs */
92
93#endif /* CONFIG_OVE_NVS */
Strong ove::Error type, Result<T> alias, and std::error_code interop for the oveRTOS C++ binding.
Thin C++ wrappers around the oveRTOS non-volatile storage API.
Definition nvs.hpp:23
void deinit()
Deinitialises the NVS subsystem and frees associated resources.
Definition nvs.hpp:46
Result< void > init() noexcept
Initialises the NVS subsystem.
Definition nvs.hpp:38
Result< void > erase(const char *key) noexcept
Erases the value associated with a key from NVS.
Definition nvs.hpp:86
Result< size_t > read(const char *key, void *buf, size_t len) noexcept
Reads the value associated with a key from NVS.
Definition nvs.hpp:60
Result< void > write(const char *key, const void *data, size_t len) noexcept
Writes a value associated with a key to NVS.
Definition nvs.hpp:75
Result< void > from_rc(int rc) noexcept
Lifts a substrate rc-code into a Result<void>.
Definition error.hpp:254
std::expected< T, Error > Result
std::expected-based result alias.
Definition error.hpp:139
Common type definitions and concepts for the C++ wrapper layer.