A remote write is one FWD frame (Rust)

The Rust crate is a codec, so a write to another node is a frame you build: FWD{ op=WRITE, dst, src, VALUE } (RFC-0004 §B). The receiving node reads the same children back with decode_fwd.

What to notice

  • Four children, in a fixed order. op, the dst route, the src reply route, then the payload. encode_fwd assembles them and decode_fwd reads them back by position.

  • There is no correlation id. The frame carries src = /client, the route its reply travels home on, and that is all a reply needs (the way home).

  • The value is an ordinary VALUE TLV. value_u32(21_500) is the same four little-endian bytes any core writes.

Source

 1// SPDX-License-Identifier: Apache-2.0
 2// SPDX-FileCopyrightText: Copyright 2026 avatarsd LLC
 3
 4/*!
 5 * @brief One concept: a remote write is one FWD frame — `op`, the `dst` route, the
 6 * `src` reply route, then the VALUE (RFC-0004 §B).
 7 *
 8 * Run: `cargo run --example fwd_write` (from `bindings/rust/`).
 9 */
10
11use libtracer::fwd::{fwd_dst_path, fwd_op};
12use libtracer::{decode_fwd, encode_fwd_bytes, value_u32, FwdRequest};
13
14fn main() {
15    // Write 21500 (a temperature in milli-degrees) to /sensor/temp on a remote node.
16    let mut req = FwdRequest::new(fwd_op::WRITE, &["sensor", "temp"], &["client"]);
17    req.payload = Some(value_u32(21_500));
18    let frame = encode_fwd_bytes(&req).expect("a valid request");
19    println!("FWD{{WRITE}} ({} bytes): {:02x?}", frame.len(), frame);
20
21    // The receiving node reads the same four children back, positionally.
22    let parsed = decode_fwd(&frame).expect("a well-formed FWD");
23    assert_eq!(parsed.op, fwd_op::WRITE);
24    let dst = fwd_dst_path(&parsed).unwrap();
25    assert_eq!(dst, "/sensor/temp");
26    let value = parsed.payload.as_ref().expect("a WRITE carries its value");
27    assert_eq!(value.payload_uint(), 21_500);
28    println!("dst {dst} <- {}", value.payload_uint());
29
30    // The frame carries no correlation id: the reply finds its way home along `src`.
31    assert_eq!(parsed.src.payload, [6, b'c', b'l', b'i', b'e', b'n', b't']);
32}

Run it from bindings/rust/:

$ cargo run --example fwd_write

See also: read and write (C++) · protocol TLVs reference.