Skip to content

Commit 1b429be

Browse files
Fix code example in main README.md (#74)
Signed-off-by: Simon Hoinkis <simon.hoinkis@apex.ai>
1 parent b48e453 commit 1b429be

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,12 @@ An application using these new features is shown in the code snippet below.
9191
For a fully working implementation, please have a look at [this demo node](https://github.com/ros2/demos/blob/master/demo_nodes_cpp/src/topics/talker_loaned_message.cpp).
9292

9393
```c++
94-
auto pub = node->create_publisher<std_msgs::msg::String>("/chatter", 1);
94+
auto non_pod_pub_ = node->create_publisher<std_msgs::msg::String>("/chatter", 1);
9595
// Ask the publisher to loan a String message
96-
auto pod_loaned_msg = pub_->borrow_loaned_message();
97-
pod_loaned_msg.get().data = "Hello World";
96+
auto non_pod_loaned_msg = non_pod_pub_->borrow_loaned_message();
97+
non_pod_loaned_msg.get().data = "Hello World";
9898
// Return ownership of that string message
99-
pod_pub_->publish(std::move(pod_loaned_msg));
99+
non_pod_pub_->publish(std::move(non_pod_loaned_msg));
100100
```
101101
102102
The code above has one problem though: How can the middleware allocate enough memory for the string message?
@@ -112,9 +112,9 @@ The message definition shown on the right size is not made for zero copy transpo
112112
Thus, in order to make our demo work with zero copy, we can alternatively send a float64, as its size is clearly defined.
113113
114114
```c++
115-
auto pub = node->create_publisher<std_msgs::msg::Float64>("/float", 1);
115+
auto pod_pub_ = node->create_publisher<std_msgs::msg::Float64>("/float", 1);
116116
// Ask the publisher to loan a Float64 message
117-
auto pod_loaned_msg = pub_->borrow_loaned_message();
117+
auto pod_loaned_msg = pod_pub_->borrow_loaned_message();
118118
pod_loaned_msg.get().data = 123.456f;
119119
// Return ownership of that Float64 message
120120
pod_pub_->publish(std::move(pod_loaned_msg));

0 commit comments

Comments
 (0)