moddef-c
Loading...
Searching...
No Matches
doc.h
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2
3/* Zero-copy views over a binary `.moddef` document (spec §4, §27).
4 *
5 * The document is never copied or materialized: md_doc_t wraps the
6 * serialized bytes wherever they live (memory-mapped flash, a RAM buffer,
7 * an array baked into the firmware) and navigation walks the protobuf
8 * frames. YAML/JSON parsing is host-side only — convert with any other
9 * ModDef implementation or the CLI. */
10#ifndef MODDEF_DOC_H
11#define MODDEF_DOC_H
12
13#include <stddef.h>
14
15#include "moddef/err.h"
16#include "moddef/str.h"
17
18/* A whole ModDefDocument. */
19typedef struct md_doc {
22
23/* A DeviceProfile submessage. */
28
29/* A RegisterBlock submessage with its decoded envelope fields. */
30typedef struct md_block {
33 uint8_t space; /* md_space_t */
35 md_bytes_t discovery; /* Discovery submessage when has_discovery */
36 int8_t discovery_slot; /* index among the profile's discovery blocks, -1 */
38
39/* A Point submessage plus its owning block. */
44
45/* Wrap a buffer; verifies the outer frame walks cleanly. */
46md_err_t md_doc_init(md_doc_t *doc, const void *buf, size_t len);
47
49
50/* Find a device profile by id; an empty id selects the first profile. */
52
53/* Find a point by id across the profile's blocks. */
55
56/* Iterate all points of a profile (catalog walks, generators):
57 * md_point_iter_t it = md_point_iter(prof);
58 * md_point_t pt;
59 * while (md_point_next(&it, &pt)) { ... } */
60typedef struct md_point_iter {
62 const uint8_t *block_pos; /* cursor in the profile message */
64 const uint8_t *point_pos; /* cursor in the current block, NULL = advance */
65 int8_t next_slot;
67
70
71/* Point envelope accessors used by callers (id lives in the wire). */
73
74#endif /* MODDEF_DOC_H */
struct md_devprof md_devprof_t
md_err_t md_doc_device(const md_doc_t *doc, md_str_t device_id, md_devprof_t *out)
md_str_t md_doc_id(const md_doc_t *doc)
md_err_t md_doc_init(md_doc_t *doc, const void *buf, size_t len)
struct md_point_iter md_point_iter_t
bool md_point_next(md_point_iter_t *it, md_point_t *out)
md_str_t md_point_id(const md_point_t *pt)
struct md_doc md_doc_t
struct md_point md_point_t
struct md_block md_block_t
md_err_t md_devprof_find_point(const md_devprof_t *prof, md_str_t point_id, md_point_t *out)
enum md_err md_err_t
Definition doc.h:30
md_bytes_t discovery
Definition doc.h:35
md_str_t block_id
Definition doc.h:32
bool has_discovery
Definition doc.h:34
md_bytes_t raw
Definition doc.h:31
int8_t discovery_slot
Definition doc.h:36
uint8_t space
Definition doc.h:33
Definition str.h:33
Definition doc.h:24
md_bytes_t raw
Definition doc.h:25
md_str_t device_id
Definition doc.h:26
Definition doc.h:19
md_bytes_t raw
Definition doc.h:20
Definition doc.h:60
md_bytes_t prof
Definition doc.h:61
const uint8_t * block_pos
Definition doc.h:62
int8_t next_slot
Definition doc.h:65
md_block_t block
Definition doc.h:63
const uint8_t * point_pos
Definition doc.h:64
Definition doc.h:40
md_bytes_t raw
Definition doc.h:41
md_block_t block
Definition doc.h:42
Definition str.h:13