#include<chrono>#include<memory>#include<string>#include"rclcpp/rclcpp.hpp"#include"my_msgs/msg/num.hpp"usingnamespacestd::chrono_literals;classPubNode:publicrclcpp::Node{public:PubNode():Node("string_loan_check"){publisher_=this->create_publisher<my_msgs::msg::Num>("numbers",10);constboolloan_supported=publisher_->can_loan_messages();RCLCPP_INFO(this->get_logger(),"Topic: %s",publisher_->get_topic_name());RCLCPP_INFO(this->get_logger(),"can_loan_messages() = %s",loan_supported?"true":"false");if(!loan_supported){RCLCPP_WARN(this->get_logger(),"Loaned messages are not supported for this publisher/RMW/type. ""Will publish with normal copy-based message.");}timer_=this->create_wall_timer(1s,std::bind(&PubNode::on_timer,this));}private:voidon_timer(){my_msgs::msg::Nummsg;msg.data=42;RCLCPP_INFO(this->get_logger(),"Publishing: '%d'",msg.data);publisher_->publish(msg);automsg=publisher_->borrow_loaned_message();msg.get().data=42;publisher_->publish(std::move(msg));}rclcpp::Publisher<my_msgs::msg::Num>::SharedPtrpublisher_;rclcpp::TimerBase::SharedPtrtimer_;};intmain(intargc,char*argv[]){rclcpp::init(argc,argv);rclcpp::spin(std::make_shared<PubNode>());rclcpp::shutdown();return0;}