Subscribing is a write (Rust)¶
A consumer subscribes by writing a SUBSCRIBER that names its own endpoint into the
producer’s :subscribers[] field. Every later delivery is an ordinary FWD{WRITE} addressed
to that endpoint (RFC-0004 §C/§D).
What to notice¶
One operation, two uses. The subscribe and the delivery are both
op=WRITE. The first carries the:subscribers[]field selector; the second is addressed to the consumer.The SUBSCRIBER carries the target.
subscriber_target_pathreads/clientout of the payload, and the producer delivers there.A delivery is pushed. The producer sends it when it is written, and the consumer handles it like any other inbound write.
Source¶
1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright 2026 avatarsd LLC
3
4/*!
5 * @brief One concept: subscribing is a write. A consumer writes a SUBSCRIBER naming its
6 * own endpoint into the producer's `:subscribers[]`, and each later delivery arrives as
7 * an ordinary FWD{WRITE} addressed to that endpoint (RFC-0004 §C/§D).
8 *
9 * Run: `cargo run --example fwd_subscribe` (from `bindings/rust/`).
10 */
11
12use libtracer::fwd::{fwd_dst_path, fwd_op};
13use libtracer::structured::subscriber_target_path;
14use libtracer::{decode_fwd, encode_fwd_bytes, subscriber, value_u32, FieldSel, FwdRequest};
15
16fn main() {
17 // Consumer -> producer: WRITE /sensor/temp:subscribers[] <- SUBSCRIBER{target=/client}.
18 let mut req = FwdRequest::new(fwd_op::WRITE, &["sensor", "temp"], &["client"]);
19 req.field = Some(FieldSel::Str(":subscribers[]"));
20 req.payload = Some(subscriber(&["client"]).unwrap());
21 let frame = encode_fwd_bytes(&req).unwrap();
22 println!("subscribe ({} bytes): {:02x?}", frame.len(), frame);
23
24 // The producer sees a field-write whose payload names where to deliver.
25 let seen = decode_fwd(&frame).unwrap();
26 assert!(seen.field.is_some(), "a subscribe is addressed to a field");
27 let target = subscriber_target_path(seen.payload.as_ref().unwrap()).unwrap();
28 assert_eq!(target.as_deref(), Some("/client"));
29 println!("producer will deliver to {}", target.unwrap());
30
31 // Producer -> consumer: a delivery is a WRITE of the new VALUE to that target.
32 let mut push = FwdRequest::new(fwd_op::WRITE, &["client"], &["sensor", "temp"]);
33 push.payload = Some(value_u32(21_750));
34 let delivery = decode_fwd(&encode_fwd_bytes(&push).unwrap()).unwrap();
35 assert_eq!(delivery.op, fwd_op::WRITE);
36 assert_eq!(fwd_dst_path(&delivery).unwrap(), "/client");
37 assert_eq!(delivery.payload.unwrap().payload_uint(), 21_750);
38 println!("delivery: WRITE /client <- 21750");
39}
Run it from bindings/rust/:
$ cargo run --example fwd_subscribe
See also: subscribe to one vertex (C++) · graph model reference.