Skip to content

Commit 0262982

Browse files
authored
Replace Protobuf DebugString with PrintToString (#703)
As of Protobuf 30, DebugString may contain some randomized content in order to redact sensitive information. This adapts gazebosim/gz-transport#685 for gz-gui. Signed-off-by: Addisu Z. Taddese <addisu@openrobotics.org>
1 parent 00b3e03 commit 0262982

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

src/plugins/publisher/Publisher.cc

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@
1515
*
1616
*/
1717

18-
#include <gz/utils/ImplPtr.hh>
19-
#include <iostream>
18+
#include "Publisher.hh"
19+
20+
#include <google/protobuf/text_format.h>
21+
2022
#include <gz/common/Console.hh>
2123
#include <gz/msgs/Utility.hh>
2224
#include <gz/plugin/Register.hh>
2325
#include <gz/transport/Node.hh>
24-
25-
#include "Publisher.hh"
26+
#include <gz/utils/ImplPtr.hh>
27+
#include <string>
2628

2729
namespace gz::gui::plugins
2830
{
@@ -107,7 +109,14 @@ void Publisher::OnPublish(const bool _checked)
107109

108110
// Check it's possible to create message
109111
auto msg = msgs::Factory::New(msgType, msgData);
110-
if (!msg || (msg->DebugString().empty() && !msgData.empty()))
112+
113+
std::string msgToText;
114+
using google::protobuf::TextFormat;
115+
if (msg)
116+
{
117+
TextFormat::PrintToString(*msg, &msgToText);
118+
}
119+
if (!msg || (msgToText.empty() && !msgData.empty()))
111120
{
112121
gzerr << "Unable to create message of type[" << msgType << "] "
113122
<< "with data[" << msgData << "].\n";

src/plugins/topic_echo/TopicEcho.cc

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,18 @@
1515
*
1616
*/
1717

18-
#include <gz/utils/ImplPtr.hh>
19-
#include <iostream>
18+
#include "TopicEcho.hh"
19+
20+
#include <google/protobuf/text_format.h>
21+
2022
#include <gz/common/Console.hh>
2123
#include <gz/plugin/Register.hh>
2224
#include <gz/transport/Node.hh>
25+
#include <gz/utils/ImplPtr.hh>
26+
#include <iostream>
27+
#include <string>
2328

2429
#include "gz/gui/Application.hh"
25-
#include "TopicEcho.hh"
2630

2731
namespace gz::gui::plugins
2832
{
@@ -109,8 +113,14 @@ void TopicEcho::OnMessage(const google::protobuf::Message &_msg)
109113
return;
110114

111115
std::lock_guard<std::mutex> lock(this->dataPtr->mutex);
112-
113-
emit this->AddMsg(QString::fromStdString(_msg.DebugString()));
116+
if (std::string str; google::protobuf::TextFormat::PrintToString(_msg, &str))
117+
{
118+
emit this->AddMsg(QString::fromStdString(str));
119+
}
120+
else
121+
{
122+
gzerr << "Error printing message" << std::endl;
123+
}
114124
}
115125

116126
/////////////////////////////////////////////////

0 commit comments

Comments
 (0)