Hi all,
In Go, protos can be constructed using struct literals. For instance:
p := pb.Person{
Id: 1234,
Name: "John Doe",
Email: "[email protected]",
Phones: []*pb.Person_PhoneNumber{
{Number: "555-4321", Type: pb.PhoneType_PHONE_TYPE_HOME},
},
}
On the other hand, in C++, you have to instantiate the proto then use
setter fields:
Person p;
person.set_id(1234);
person.set_name("John Doe");
person.set_email("[email protected]");
Person::PhoneNumber* phone_number = person.add_phones();
phone_number->set_number("555-4321");
phone_number->set_type(PhoneType::PHONE_TYPE_NONE);
It would be nice if the generated C++ code generated some structs, which
could be used to construct protos using initializer lists, which IMO would
be cleaner. Perhaps something like:
PersonSpec spec = {
.id = 1234,
.name = "John Doe",
.email = "[email protected]",
.phones = {
{.number = "555-4321",
.type = PhoneType::PHONE_TYPE_NONE},
},
};
Person proto(spec);
Has the team considered something like this? I think it would make
constructing protos in C++ look cleaner and clearer.
Best,
David
--
You received this message because you are subscribed to the Google Groups
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/protobuf/af69c050-719f-4906-bd7b-bc836b1d7006n%40googlegroups.com.