Given a message
message My_msg{
repeated double my_arr = 1;
}
How can one append elements into the field?
There is an answer for copying/moving already allocated full arrays by overwriting the current contents, but what if there is already some data in the filed, which needs to be kept as it is?
Is using the below code to do it safe?
void set_data(std::vector<double> table, My_msg* message){ /* suppose message is valid */
message->mutable_my_arr()->Resize(message->my_arr_size() + table.size(),0);
message->mutable_my_arr()[message->my_arr_size() - table.size()] = {table.begin(),table.end()};
}