DeterministicESPAsyncWebServer v6.28.0
Zero-allocation, bounded-execution async HTTP server for ESP32
Loading...
Searching...
No Matches
config_io.h
Go to the documentation of this file.
1// Copyright (C) 2026 Douglas Quigg (dstroy0) <dquigg123@gmail.com>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4/**
5 * @file config_io.h
6 * @brief Schema-driven config export / restore (DETWS_ENABLE_CONFIG_IO).
7 *
8 * The app declares a fixed schema - an array of {key, type} fields - and this
9 * service serializes their current values from the config store to a portable
10 * `key=value` text blob (one field per line) for backup / migration, and parses
11 * such a blob back into the store for restore / bulk provisioning. Schema-driven
12 * (rather than enumerating NVS) keeps it deterministic and zero-heap; the
13 * serialize / parse round-trip is host-tested against the in-memory config store.
14 *
15 * @author Douglas Quigg (dstroy0)
16 * @date 2026
17 */
18
19#ifndef DETERMINISTICESPASYNCWEBSERVER_CONFIG_IO_H
20#define DETERMINISTICESPASYNCWEBSERVER_CONFIG_IO_H
21
22#include "ServerConfig.h"
23#include <stddef.h>
24#include <stdint.h>
25
26#if DETWS_ENABLE_CONFIG_IO
27
28/** @brief Type of a config field (selects the typed get/set used). */
29enum class DetwsCfgType : uint8_t
30{
31 DETWS_CFG_STR = 0, ///< null-terminated string.
32 DETWS_CFG_U32 = 1, ///< unsigned 32-bit integer (serialized as decimal).
33};
34
35/** @brief One field in an export/restore schema. */
36struct DetwsCfgField
37{
38 const char *key; ///< config-store key (<= 15 chars).
39 DetwsCfgType type; ///< the field's value type.
40};
41
42/**
43 * @brief Export the schema's current values from namespace @p ns as `key=value`
44 * lines into @p out.
45 * @return characters written, or 0 on a too-small buffer / failure (fail-closed).
46 */
47int detws_config_export(const char *ns, const DetwsCfgField *fields, size_t n, char *out, size_t cap);
48
49/**
50 * @brief Import `key=value` lines from @p text into namespace @p ns, writing each
51 * line whose key is in the schema with the schema's type. Unknown keys are
52 * skipped.
53 * @return number of fields written.
54 */
55int detws_config_import(const char *ns, const DetwsCfgField *fields, size_t n, const char *text, size_t len);
56
57#endif // DETWS_ENABLE_CONFIG_IO
58#endif // DETERMINISTICESPASYNCWEBSERVER_CONFIG_IO_H
User-facing configuration for DeterministicESPAsyncWebServer.