Void Sentry
An AI-driven, real-time Sentry Turret platform leveraging asynchronous I/O and computer vision to deliver high-precision autonomous motion tracking on resource-constrained embedded hardware.
Loading...
Searching...
No Matches
nvs_blob.h
Go to the documentation of this file.
1
6#pragma once
7
8#include <Preferences.h>
9#include <cstddef>
10#include <cstdint>
11#include <span>
12
13namespace nvs_blob
14{
16enum class ReadStatus {
17 Absent,
18 Mismatch,
19 Ok
20};
21
26inline ReadStatus read(Preferences& prefs, const char* key, std::span<uint8_t> out)
27{
28 const size_t stored = prefs.getBytesLength(key);
29 if (stored == 0)
30 {
31 return ReadStatus::Absent;
32 }
33 if (stored != out.size() || prefs.getBytes(key, out.data(), out.size()) != out.size())
34 {
35 return ReadStatus::Mismatch;
36 }
37 return ReadStatus::Ok;
38}
39} // namespace nvs_blob
ReadStatus
Outcome of read().
Definition nvs_blob.h:16
@ Mismatch
stored with a different length than expected, or the read came back short
@ Ok
out holds exactly the stored bytes
@ Absent
the key does not exist (stored length 0)
ReadStatus read(Preferences &prefs, const char *key, std::span< uint8_t > out)
Reads the blob under key into out, requiring the stored length to equal out.size().
Definition nvs_blob.h:26