At first I have this simple protobuf file
message messagetest
{
...
repeated float samples = 6;
....
}
Which creates a headerfi
Since this isn't here yet and I like one-liners:
*fMessage.mutable_samples() = {fData.begin(), fData.end()};
I found the shortest way to copy vector into repeated field as this:
google::protobuf::RepeatedField<float> data(fData.begin(), fData.end());
fMessage.mutable_samples()->Swap(&data);
It is probably also faster than yours since it avoids initial iteration and setting values to 0.
fMessage.mutable_samples()
return an array of pointer of samples : [*sample1, *sample2, sample3, ...].
&fData[0]
is the address of first element of fData.
memcpy(fMessage.mutable_samples()->mutable_data(),
&fData[0],
sizeof(float)*fData.size());
So I do not think the code above can successfully fill data from fData to fMessage. It's totally wrong!