ProtoCore v0.0.2
Deterministic, zero-heap network stack for embedded targets
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 (PC_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 PROTOCORE_CONFIG_IO_H
20#define PROTOCORE_CONFIG_IO_H
21
22#include "protocore_config.h"
23#include <stddef.h>
24#include <stdint.h>
25
26#if PC_ENABLE_CONFIG_IO
27
28/** @brief Type of a config field (selects the typed get/set used). */
29enum class pc_cfg_type : uint8_t
30{
31 PC_CFG_STR = 0, ///< null-terminated string.
32 PC_CFG_U32 = 1, ///< unsigned 32-bit integer (serialized as decimal).
33};
34
35/** @brief One field in an export/restore schema. */
36struct pc_cfg_field
37{
38 const char *key; ///< config-store key (<= 15 chars).
39 pc_cfg_type 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 pc_config_export(const char *ns, const pc_cfg_field *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 pc_config_import(const char *ns, const pc_cfg_field *fields, size_t n, const char *text, size_t len);
56
57#endif // PC_ENABLE_CONFIG_IO
58#endif // PROTOCORE_CONFIG_IO_H
User-facing configuration for ProtoCore.