I cannot seem to find any explicit mention of how protobuf maps that use non-scalar values can be manipulated in C++. For example consider this proto file:
syntax = "proto3"
message X{
uint32 name = 1;
}
message Y{
map<string, X> values = 1;
}
Notice that X is non-scalar. How would I go about inserting something into this map in C++? Do I need to dynamically allocate a X object or that is not necessary? For example are both pieces of code below correct? For the dynamically allocated one, would I need to explicitly deallocate the pointer after the insertion in the map? If yes what is the proper way to deallocate the pointer after copying the data in the map?
code 1:
Y y;
X * x = new X();
x->set_name(123);
auto map = y.mutable_values();
(*map)["key value"] = *x;
code 2:
Y y;
X x;
x.set_name(123);
auto map = y.mutable_values();
(*map)["key value"] = x;
Aucun commentaire:
Enregistrer un commentaire