Correct usage of StringValue in C++

14 views
Skip to first unread message

Martin Scholz

unread,
Nov 21, 2019, 3:07:20 AM11/21/19
to Protocol Buffers
What is the correct usage of StringValue in C++.

google::protobuf::StringValue* test = new google::protobuf::StringValue();
test->set_value("some string");

someRequest.set_allocated_value(test);

Do i have to delete the StringValue manually at the end? Why this isn't possible?
std::unique_ptr<google::protobuf::StringValue> test (new google::protobuf::StringValue());
test.get()->set_value("some string");

someRequest.set_allocated_value(test.get());

When i use a smartpointer i got errors when the destructor of the request is called. And why in the request i only have these "set_allocated_value" functions and not just "set_value"?

And one more thing, why there are no examples for StringValue. Also the official c++ documentation of protobuf is using string instead of StringValue.
Reply all
Reply to author
Forward
0 new messages