Skip to content

Commit 16b117c

Browse files
committed
deploy: 445b6c0
1 parent 0834868 commit 16b117c

95 files changed

Lines changed: 65 additions & 103272 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

chapters/custom_messages.html

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ <h1 id="custom-messages"><a class="header" href="#custom-messages">Custom Messag
199199
</pre>
200200
<hr />
201201
<h2 id="rust-native-messages"><a class="header" href="#rust-native-messages">Rust-Native Messages</a></h2>
202-
<p><strong>Define messages directly in Rust by implementing required traits.</strong> This approach is fast for prototyping but only works between ros-z nodes.</p>
202+
<p><strong>Define messages directly in Rust and derive their schema metadata.</strong> This approach is fast for prototyping but only works between ros-z nodes.</p>
203203
<div id="admonition-warning" class="admonition admonish-warning" role="note" aria-labelledby="admonition-warning-title">
204204
<div class="admonition-title">
205205
<div id="admonition-warning-title">
@@ -213,42 +213,37 @@ <h2 id="rust-native-messages"><a class="header" href="#rust-native-messages">Rus
213213
</div>
214214
<h3 id="workflow-of-rust-native-messages"><a class="header" href="#workflow-of-rust-native-messages">Workflow of Rust-Native Messages</a></h3>
215215
<pre class="mermaid">graph LR
216-
A[Define Struct] --&gt; B[Impl MessageTypeInfo]
216+
A[Define Struct] --&gt; B[Derive MessageTypeInfo]
217217
B --&gt; C[Add Serde Traits]
218-
C --&gt; D[Impl WithTypeInfo]
218+
C --&gt; D[Impl ZMessage]
219219
D --&gt; E[Use in Pub/Sub]
220220
</pre>
221221
<h3 id="required-traits"><a class="header" href="#required-traits">Required Traits</a></h3>
222222
<div class="table-wrapper"><table><thead><tr><th>Trait</th><th>Purpose</th><th>Key Method</th></tr></thead><tbody>
223-
<tr><td><strong>MessageTypeInfo</strong></td><td>Type identification</td><td><code>type_name()</code>, <code>type_hash()</code></td></tr>
224-
<tr><td><strong>WithTypeInfo</strong></td><td>ros-z integration</td><td><code>type_info()</code></td></tr>
223+
<tr><td><strong>MessageTypeInfo</strong></td><td>Type identification + runtime schema</td><td><code>type_name()</code>, <code>type_hash()</code>, <code>message_schema()</code></td></tr>
225224
<tr><td><strong>Serialize/Deserialize</strong></td><td>Data encoding</td><td>From <code>serde</code></td></tr>
225+
<tr><td><strong>ZMessage</strong></td><td>ros-z serialization path</td><td><code>type Serdes = SerdeCdrSerdes&lt;Self&gt;</code></td></tr>
226226
</tbody></table>
227227
</div>
228228
<h3 id="message-example"><a class="header" href="#message-example">Message Example</a></h3>
229-
<pre><code class="language-rust ignore">use ros_z::{MessageTypeInfo, entity::TypeHash};
230-
use ros_z::ros_msg::WithTypeInfo;
229+
<pre><code class="language-rust ignore">use ros_z::MessageTypeInfo;
231230
use serde::{Serialize, Deserialize};
232231

233-
#[derive(Debug, Clone, Serialize, Deserialize)]
232+
#[derive(Debug, Clone, Serialize, Deserialize, MessageTypeInfo)]
233+
#[ros_msg(type_name = "my_msgs/msg/RobotStatus")]
234234
struct RobotStatus {
235235
battery_level: f32,
236236
position_x: f32,
237237
position_y: f32,
238238
is_moving: bool,
239239
}
240240

241-
impl MessageTypeInfo for RobotStatus {
242-
fn type_name() -&gt; &amp;'static str {
243-
"my_msgs::msg::dds_::RobotStatus_"
244-
}
245-
246-
fn type_hash() -&gt; TypeHash {
247-
TypeHash::zero() // ros-z-to-ros-z only
248-
}
249-
}
250-
251-
impl WithTypeInfo for RobotStatus {}</code></pre>
241+
impl ros_z::msg::ZMessage for RobotStatus {
242+
type Serdes = ros_z::msg::SerdeCdrSerdes&lt;Self&gt;;
243+
}</code></pre>
244+
<p><code>MessageTypeInfo</code> derive currently supports named structs with deterministic ROS field mappings:
245+
primitive numeric/bool types, <code>String</code>, <code>Vec&lt;T&gt;</code>, fixed arrays <code>[T; N]</code>, and nested message structs.
246+
Tuple structs, unit structs, enums, <code>Option</code>, maps, and other richer Rust-only shapes are not yet supported.</p>
252247
<h3 id="service-example"><a class="header" href="#service-example">Service Example</a></h3>
253248
<pre><code class="language-rust ignore">use ros_z::{ServiceTypeInfo, TypeInfo, TypeHash, msg::ZService};
254249

@@ -276,6 +271,8 @@ <h3 id="service-example"><a class="header" href="#service-example">Service Examp
276271
type Response = NavigateToResponse;
277272
}</code></pre>
278273
<p>See the <code>z_custom_message</code> example:</p>
274+
<p>When a publisher node enables the type description service, derived custom message types
275+
automatically register their runtime schema so dynamic subscribers can discover them.</p>
279276
<pre><code class="language-bash"># Terminal 1: Router
280277
cargo run --example zenoh_router
281278

chapters/python.html

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -380,14 +380,11 @@ <h3 id="service-client"><a class="header" href="#service-client">Service Client<
380380
print(f"CLIENT:REQUEST:{a}+{b}", flush=True)
381381

382382
req = example_interfaces.AddTwoIntsRequest(a=a, b=b)
383-
client.send_request(req)
384-
385-
resp = client.take_response(timeout=timeout)
386-
387-
if resp is not None:
383+
try:
384+
resp = client.call(req, timeout=timeout)
388385
print(f"CLIENT:RESPONSE:{resp.sum}", flush=True)
389-
else:
390-
print("CLIENT:ERROR:no response", flush=True)
386+
except RuntimeError as e:
387+
print(f"CLIENT:ERROR:{e}", flush=True)
391388
sys.exit(1)
392389

393390

chapters/services.html

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -249,19 +249,23 @@ <h2 id="service-server-example"><a class="header" href="#service-server-example"
249249

250250
loop {
251251
// Wait for a request
252-
let (key, req) = service.take_request()?;
253-
println!("Incoming request\na: {} b: {}", req.a, req.b);
252+
let req = service.take_request()?;
253+
println!(
254+
"Incoming request\na: {} b: {}",
255+
req.message().a,
256+
req.message().b
257+
);
254258

255259
// Compute the sum
256-
let sum = req.a + req.b;
260+
let sum = req.message().a + req.message().b;
257261

258262
// Create the response
259263
let resp = AddTwoIntsResponse { sum };
260264

261265
println!("Sending response: {}", resp.sum);
262266

263267
// Send the response
264-
service.send_response(&amp;resp, &amp;key)?;
268+
req.reply_blocking(&amp;resp)?;
265269

266270
request_count += 1;
267271

@@ -319,15 +323,13 @@ <h2 id="service-client-example"><a class="header" href="#service-client-example"
319323

320324
// Wait for the response
321325
let resp = if async_mode {
322-
tokio::runtime::Runtime::new().unwrap().block_on(async {
323-
client.send_request(&amp;req).await?;
324-
client.async_take_response().await
325-
})?
326+
tokio::runtime::Runtime::new()
327+
.unwrap()
328+
.block_on(async { client.call(&amp;req).await })?
326329
} else {
327330
tokio::runtime::Runtime::new()
328331
.unwrap()
329-
.block_on(async { client.send_request(&amp;req).await })?;
330-
client.take_response_timeout(Duration::from_secs(5))?
332+
.block_on(async { client.call_with_timeout(&amp;req, Duration::from_secs(5)).await })?
331333
};
332334

333335
println!("Received response: {}", resp.sum);

0 commit comments

Comments
 (0)