:children[] — enumerate a parent’s members (L4 graph)

The : control plane, read. :children[] is addressed whole: the read serves a structured (PL=1) reply whose children are the parent’s registered members — members, not creation SPECs (the write-spec / read-members asymmetry, reference 05 §SPEC). It is the enumeration half of “observing structural change”; the other half is an ordinary subscription to the parent (reference 02 §Observing structural change).

What to notice

  • One level, and each vertex answers for itself. /zone:children[] lists soil and air; the grandchild /zone/air/humidity is enumerated from /zone/air, because a child is its own identity carrying its own facets (CONTEXT.md §Schema).

  • A leaf enumerates an empty list, not an error. An empty member list is a legitimate answer, in the same spirit as the bare :settings read serving an empty container.

  • A composed reply is a rope. :children[] is synthesized rather than stored, so the reply may arrive as several links; the example calls materialize() before decoding — zero copy when single-link, one flatten copy otherwise (ADR-0053 §6).

  • This is not a notification. The : plane is silent by design: no field read or write wakes await or propagates (CONTEXT.md §Announce write). A consumer watching for structural change subscribes to the parent and re-enumerates — and a retired child simply stops appearing, with no tombstone (reference 02 §Retirement notification).

Source

 1/*
 2 * SPDX-License-Identifier: Apache-2.0
 3 * SPDX-FileCopyrightText: Copyright 2026 avatarsd LLC
 4 */
 5
 6/**
 7 * @file
 8 * @brief ONE CONCEPT — enumerate a parent's members with the `:children[]` field read.
 9 *
10 * `:children[]` is the `:` control plane, addressed WHOLE: the read serves a structured
11 * (`PL=1`) reply whose children are the parent's registered members — members, not creation
12 * SPECs (`docs/reference/02-graph-model.md` §Observing structural change). It enumerates one
13 * level; a grandchild is read from its own parent, because each vertex answers for itself.
14 *
15 * The `:` plane is silent by design, so nothing here is a notification: a consumer watching
16 * for structural change subscribes to the parent and re-enumerates (`CONTEXT.md`
17 * §Announce write).
18 *
19 * Runs under ctest as `example_graph_children`; returns non-zero on any failed check.
20 */
21
22#include <cstddef>
23#include <cstdio>
24
25#include "libtracer/tracer.hpp"
26
27namespace {
28
29using tr::graph::path_t;
30using tr::graph::role_t;
31
32/** @brief The member count of a `:children[]` read, or `SIZE_MAX` when it did not resolve. */
33std::size_t members(tr::graph::graph_t& g, const char* where) {
34    const auto r = g.read(path_t(where));
35    if (!r) return static_cast<std::size_t>(-1);
36    // A composed reply is a rope, not one contiguous view: materialize before decoding
37    // (single-link ⇒ a refcount bump, multi-link ⇒ the one flatten copy, ADR-0053 §6).
38    const auto tlv = tr::wire::decode((*r)->materialize());
39    return tlv ? tlv->children.size() : static_cast<std::size_t>(-1);
40}
41
42/** @brief Report expectation @p what and record a failure on @p ok. */
43void check(bool& ok, bool cond, const char* what) {
44    std::printf("  [%s] %s\n", cond ? "ok" : "FAIL", what);
45    ok = ok && cond;
46}
47
48}  // namespace
49
50int main() {
51    tr::graph::graph_t g;
52    bool ok = true;
53
54    (void)g.register_vertex(path_t("/zone"), role_t::STORED_VALUE);
55    (void)g.register_vertex(path_t("/zone/soil"), role_t::STORED_VALUE);
56    (void)g.register_vertex(path_t("/zone/air"), role_t::STORED_VALUE);
57    (void)g.register_vertex(path_t("/zone/air/humidity"), role_t::STORED_VALUE);
58
59    std::printf("/zone:children[] lists %zu members\n", members(g, "/zone:children[]"));
60    check(ok, members(g, "/zone:children[]") == 2, ":children[] enumerates ONE level (soil, air)");
61    check(ok, members(g, "/zone/air:children[]") == 1,
62          "a grandchild is enumerated from its own parent");
63    check(ok, members(g, "/zone/soil:children[]") == 0,
64          "a leaf enumerates an empty member list, not an error");
65    return ok ? 0 : 1;
66}

See also: graph module · addressing reference · vertex roles and aggregation.