Correct usage of google::protobuf::StringValue

33 views
Skip to first unread message

martin...@versasec.com

unread,
Nov 20, 2019, 11:25:57 AM11/20/19
to grpc.io
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 there are no examples for StringValue. Also the official c++ documentation of protobuf is using string instead of StringValue.

Esun Kim

unread,
Nov 20, 2019, 4:30:55 PM11/20/19
to grpc.io
First of all, this doesn't seem relevant to gRPC. I think protobuf user group would be the best place. (https://groups.google.com/forum/#!forum/protobuf)
AFAIK, set_allocated_* method is for arena-usage (ref: https://developers.google.com/protocol-buffers/docs/reference/arenas) and using regular accessors would be encouraged in general.
Reply all
Reply to author
Forward
0 new messages