path — addressing (L4)

In one paragraph

A path_t parses /sensor/temp (with an optional :field.sub[N] tail) into the canonical PATH-TLV payload bytes — the concatenated packed segment records. Those bytes, not the string, are the vertex-map key: dispatch is a byte compare, never a string parse on the hot path.

What it does

path_t::parse validates and canonicalizes per the addressing rules (reference/03): strip a trailing /, reject empty segments (//) and unrooted paths, enforce the limits (≤64 B/segment, ≤1024 B total, ≤255 segments, ≤8 field steps). It emits the canonical key — e.g. /sensor/temp → 06 'sensor' 04 'temp' (12 bytes; each record is [u8 len][utf8], RFC-0018) — and parses the :-tail into a field_path_t (settings.app.setpoint, subscribers[], subscribers[3]) for the field-write surface. The graph resolves those bytes one record at a time down its vertex tree (ADR-0057).

Interface

struct field_step_t { std::string_view name; bool indexed, append, wildcard; std::uint16_t index; };
struct field_path_t { field_steps_t steps; };        // ≤ kMaxFieldDepth steps in place, no growth

class path_t {
    explicit path_t(std::string_view);               // known-good LITERAL: parses once, aborts if malformed
    static result_t<path_t> parse(std::string_view);  // RUNTIME string; result_t = expected<T, status_t>
    static result_t<path_t> parse(std::string_view, mem::block_source_t&);  // block from that source
    std::span<const std::byte> key() const;          // canonical PATH payload bytes
    const field_path_t& field() const;               // the :field.sub[N] tail
    std::size_t segment_count() const;
};

The two entry points differ in what failure means. path_t::parse is for a string whose validity is itself a runtime condition, and returns status_t::INVALID_PATH (core/src/path.cpp:result_t<path_t> path_t::parse(std::string_view text, tr::mem). The explicit constructor is for a compile-site literal, where a malformed path is a source bug: it hard-aborts rather than yielding a result_t the caller would only *-deref unchecked (path.hpp:explicit path_t(std::string_view, defined path.hpp:p). Neither uses exceptions, so both hold under -fno-exceptions.

A path owns no standard container (#2286): its key, its field steps and their names are one block sized exactly at parse, drawn from the source given to parse (else the table source), and a step’s name views that block. The root path with no field tail draws nothing.

String → bytes, once

        flowchart LR
    S["/sensor/temp:settings.app.setpoint"] --> P[path_t::parse]
    P --> K["key bytes<br/>06 &quot;sensor&quot; · 04 &quot;temp&quot;"]
    P --> F["field<br/>settings → app → setpoint"]
    K --> M{{"vertex map<br/>(byte-keyed)"}}
    classDef e fill:#dbeafe,stroke:#1e40af
    class M e
    

Consequences

  • No string work reaches dispatch. A path parses at one visible construction site and the graph API takes const path_t&, so a held handle cannot re-parse; every subsequent read, write and subscribe on that path is a byte compare against the map key. The cost of the parse is paid once, at registration or at the literal, not per call.

  • Local and remote addressing are the same bytes. key() returns the PATH-TLV payload that travels on the wire, so a forwarded frame carries the key it was matched on and a remote address needs no translation into a local one.

  • A malformed address fails at the boundary. Empty segments (//), unrooted paths, reserved characters and every limit overrun reject at parse with a typed status_t rather than surfacing as a miss deep in dispatch.

  • The limits are a receiver’s buffer budget. ≤64 B per segment, ≤1024 B total, ≤255 segments (RFC-0023; the byte cap binds first under the current encoding, at 204) and ≤8 field steps (core/include/libtracer/path.hpp:kMaxSegmentBytes, core/include/libtracer/path.hpp:kMaxPathBytes, core/include/libtracer/path.hpp:kMaxSegments, core/include/libtracer/path.hpp:kMaxFieldDepth) let a component size fixed scratch instead of allocating per frame — the mount-prefix walk’s stitch buffer is two segments’ worth, std::array<std::byte, kMaxSegmentBytes * 2> (core/src/fwd_router.cpp), and no longer scales with how wide a mount is (#523).

  • A name costs its bytes and nothing else. A vertex keeps only a reference to its own segment record (#2672); the bytes live in the graph’s name block, chunks drawn from the graph’s table source and kept until the graph goes, so no name takes a heap block of its own and an 8-character name costs 9 bytes plus its share of a chunk header.

API reference

Generated from core/include/libtracer/path.hpp by Doxygen.

class path_t

A parsed, canonical path: the PATH-TLV payload bytes (packed records) plus the optional field_path_t tail. The payload bytes are the vertex-map key.

Dispatch keys on the parsed bytes (key), never the string form — parse once, hold the value, and every read/write compares bytes (docs/reference/02 §dispatch).

It is a value type that carries no route: a learned chain is held by the graph-owned path object (path_object.hpp), never by this handle, so copying a path copies only its parse and neither copy can outlive anything.

Storage (#2286)

No standard container: the canonical bytes, the field steps and their names live in ONE block sized exactly at parse and drawn from a tr::mem::block_source_t: the one given to parse, else the process table source (ADR-0083). The root path with no field tail owns no block at all. A copy draws its block from the source of the path it copies and stops with a sizing message if that source cannot serve it. A move takes the block. Nothing here grows after the parse.

Public Functions

path_t() noexcept = default

An empty path (no segments, no field tail).

inline explicit path_t(std::string_view text)

Construct from a compile-site / known-good path LITERAL, parsing ONCE.

A path_t is two pointers and eight bytes of lengths: 24 B on a 64-bit host, 16 B on rv32.

path_t p("/sensor/temp"); write(p, a); write(p, b); — parse the string a single time, then hold the value and reuse the handle; the graph API takes const path_t& so a held path never re-parses on the hot path (docs/reference/02 §dispatch keys on the parsed PATH-TLV bytes, never the string). A malformed literal is a source bug, so this hard-aborts rather than yielding a fallible result_t the caller would only *-deref unchecked. For a RUNTIME string whose validity is a genuine runtime condition, use parse (fallible). explicit — construction is always a visible, deliberate parse, never an implicit per-call one. No exceptions (usable under -fno-exceptions).

Pinned, not observed. A path is a parse-once VALUE the API takes by const&, and an origin holds them per subscription and per vertex, so its size is multiplied RAM. #2286 moved its three remaining owning standard containers into source-drawn blocks: 9 pointer-widths → 3 plus the lengths (72 → 40 B on a 64-bit host, 36 → 24 B on rv32), and #2436 dropped the learned-chain slot no caller used (the graph-owned path object holds the chain): 40 → 24 B, 24 → 16 B. A change here is a deliberate edit, and it is the moment to ask whether the new member wants to be a slot at all.

path_t(const path_t &o)

Copy o into a block from o's source (see Storage (#2286)).

path_t &operator=(const path_t &o)

Copy-assign (see the copy constructor).

inline path_t(path_t &&o) noexcept

Take o's block; o is left the empty path.

inline path_t &operator=(path_t &&o) noexcept

Move-assign (see the move constructor).

inline ~path_t()

Return the block to its source.

inline std::span<const std::byte> key() const noexcept

The vertex-map key: the canonical PATH-TLV payload bytes (packed records).

const field_path_t &field() const noexcept

The parsed :field tail (empty when the path addresses the vertex value).

Its step names view this path’s block, and so does a copy of it: hold the path for as long as the field path is used (auto f = path_t::parse(t)->field(); dangles).

inline std::size_t segment_count() const noexcept

The number of segments in the path.

Public Static Functions

static result_t<path_t> parse(std::string_view text)

Parse and canonicalize a path string (fallible — for a RUNTIME string).

Accepts "/sensor/temp" or "/sensor/temp:settings.deadline_ns". Canonicalizes: strip a trailing /, reject empty segments (//) and unrooted paths, enforce the kMaxSegmentBytes / kMaxPathBytes / kMaxSegments / kMaxFieldDepth limits. A known-good literal uses the parse-once path_t(std::string_view) constructor instead.

Parameters:

text – The path string to parse.

Returns:

The parsed path_t, or a status_t error (e.g. INVALID_PATH).

static result_t<path_t> parse(std::string_view text, tr::mem::block_source_t &src)

parse, drawing the path’s block from src.

Returns:

As parse; BACKPRESSURE when src refuses the block.

struct field_path_t

The parsed :field.sub[N] tail of a path — a sequence of field_step_t.

Empty when the path addresses the vertex value itself (no : tail). Drives the field-write / field-read control surface (docs/reference/04). A value type with no allocation: its steps are in place and their names are views.

Public Functions

inline bool empty() const noexcept

True when there is no field tail (addresses the vertex value).

bool operator==(const field_path_t&) const = default

Value equality over the step sequence.

Public Members

field_steps_t steps

The .-separated steps; empty ⇒ the vertex value itself.

struct field_step_t

One step of a field path: a NAME and an optional [index] / [] append / [*] wildcard selector.

The parsed form of one .-separated component of a :field.sub[N] tail (docs/reference/03 §addressing). Exactly one of indexed (with index), append, or wildcard is meaningful when a [...] selector is present.

A step owns nothing (ADR-0083 Q15: no owning standard type crosses core’s API): name views bytes that whoever built the step keeps alive — a path_t’s own block, the request frame a resolver is reading, or a string literal.

Public Functions

bool operator==(const field_step_t&) const = default

Value equality over every field (the name by content).

Public Members

std::string_view name

The step’s NAME (the text before any [...]).

bool indexed = false

True if a [...] selector was present.

bool append = false

True for [] — append to a sequence.

bool wildcard = false

True for [*] — FIELD index_mode=WILDCARD (RFC-0004 §C).

std::uint16_t index = 0

The [N] index; valid when indexed && !append && !wildcard.

The delivery-target key

target_key_t is the delivery-target key try_make_target_key builds. A vertex’s own name is not a key type any more: since #2672 the vertex references its record in the graph’s name block (vertex_t::name()).

class target_key_t

A subscription edge’s canonical PATH key — immutable and refcount-shared, held in one block of the graph’s table source (#1912).

Shared rather than owned because the dispatch snapshot must outlive a concurrent unsubscribe: vertex_t::snapshot_edges copies each active slot out under an edge pin so the graph can dispatch after releasing it, and the slot may be cleared in between. A deep copy satisfied that and cost a malloc + free per edge per delivery. Refcounting satisfies it for one count update instead, exactly as edge_view_t::remote does one field over for the same hazard (#1448).

The remote_ptr_t shape with the key’s length carried in the handle: the count and the owning source head the block and the key bytes follow them, so admission is ONE draw from the source the edge’s other state uses, and a refused draw is a value (null), never an abort. Until #1912 this was a std::shared_ptr around a std::vector: two platform-heap draws per admission, outside the seam. The handle is 16 B on a 64-bit host and 8 B on rv32, the std::shared_ptr’s width, so subscriber_t, edge_view_t and pub_edge_t keep their pinned sizes. The count is tr::view::detail::ref_count_t, which skips the locked RMW while the process is single-threaded, as std::shared_ptr does.

Null ⇒ no local re-dispatch target (the callback-only or remote-only edge). The key is built once at admission and never mutated, so sharing it needs no synchronization beyond the count.

Public Functions

target_key_t() noexcept = default

An empty handle — no local target.

inline target_key_t(std::nullptr_t) noexcept

An empty handle, spelled as the null it tests equal to.

inline target_key_t(const target_key_t &other) noexcept

Clone — one more reference to the same immutable key.

inline target_key_t(target_key_t &&other) noexcept

Transfer other's reference, leaving it empty.

inline target_key_t &operator=(target_key_t other) noexcept

Copy-and-swap assignment — one operator covers copy- and move-assign.

inline ~target_key_t()

Release this reference; the last one out returns the block.

inline void reset() noexcept

Drop this reference and empty the handle. Always inlined for the reason remote_ptr_t::reset gives: the fan-out runs it once per edge per delivery.

inline std::span<const std::byte> operator*() const noexcept

The key bytes; empty for a null handle.

inline explicit operator bool() const noexcept

True iff this handle names a key.

Friends

friend target_key_t try_make_target_key(mem::block_source_t &src, std::span<const std::byte> key) noexcept

The one way to make a key: try_make_target_key.

Admission is reachable from a peer’s bytes (RFC-0014 made registration wire-driven), so a refused draw answers by value and the caller refuses the admission as BACKPRESSURE.

Parameters:
  • src – The graph’s table source; the block returns to it when the last holder drops.

  • key – The canonical PATH key bytes; an empty span yields null (no target).

inline friend bool operator==(const target_key_t &h, std::nullptr_t) noexcept

Null test.

inline target_key_t tr::graph::try_make_target_key(mem::block_source_t &src, std::span<const std::byte> key) noexcept

Copy key into one block of src as a shared target_key_t, NOTHROW — null on refusal or empty input (#1912).

The one way to make a key: try_make_target_key.

Admission is reachable from a peer’s bytes (RFC-0014 made registration wire-driven), so a refused draw answers by value and the caller refuses the admission as BACKPRESSURE.

Parameters:
  • src – The graph’s table source; the block returns to it when the last holder drops.

  • key – The canonical PATH key bytes; an empty span yields null (no target).

inline bool tr::graph::valid_segment(std::string_view seg) noexcept

True iff seg is valid as ONE segment of the addressing grammar.

THE segment predicate (ADR-0073 §1): every boundary where a name enters the graph — the local string parser, a wire SPEC creation carrying a child name, a module registration — calls this ONE function, so the tiers cannot drift (#688; the drift, not any single missing check, is the recurring defect — cf. #681). A name that fails here answers INVALID_PATH wherever it is rejected.

Checks: non-empty, at most kMaxSegmentBytes, and none of the SEVEN reserved characters of reference/03 §Reserved characters — / and : are separators, . separates field levels, [ / ] delimit the grammar’s index suffix (which sits OUTSIDE name: segment = name [ index ]), * is the wildcard selector, ? is reserved for the future. Rejecting the brackets is the normative MUST (reference/03 §Reserved characters, incorporated by spec v1 §3); the pre-#996 five-character subset admitted them on the theory that frame[7] travels inside the NAME bytes — ruled the other way: address-index addressing, if it lands, lives outside the NAME bytes (#996, cf. .out-of-scope/range-slice-addressing.md). The character set is pinned cross-tier by the path/path-reserved-brackets conformance vector.

constexpr std::size_t tr::graph::kMaxPathBytes = 1024

Max bytes in a whole canonical PATH payload (docs/reference/03 §limits).

constexpr std::size_t tr::graph::kMaxSegments = 255

Max segments in a path (reference/03 §limits; RFC-0023: min(255, byte cap)).

constexpr std::size_t tr::graph::kMaxSegmentBytes = 64

Max bytes in one path segment (docs/reference/03 §limits; the packed record’s u8 length field caps it at 255 forever, RFC-0018 §5).

constexpr std::size_t tr::graph::kMaxFieldDepth = 8

Max steps in a :field tail (docs/reference/03 §limits).

See: graph, wire-format-bits, reference §addressing.