Reputation: 361
Far as I understand there when compiling a *.proto file the generated class does not have a constructor nor a copy/move constructor. For example if I have
message Float3Vector{
optional float x = 1;
optional float y = 2;
optional float z = 3;
}
I can't call Float3Vector(my_x, my_y, my_z)
. This is clear also from the documentation.
So far so good. There are other ways provided. My question is, is there a particular reason for doing this? I mean, there is a technical reason (i.e. dictated by serialising, generating code, etc) that makes this impossible?
Upvotes: 5
Views: 6695
Reputation: 1549
There seems to be an undocumented way of doing this. I find it rather annoying how hard constructing protobuf Messages is.
Float3Vector(x=my_x, y=my_y, z=my_z)
This means you can also do things like:
pb_args = {'x':1, 'y':2, 'z':3}
Float3Vector(**pb_args)
see this for more info.
Upvotes: 4
Reputation: 1164
Copy was disabled on purpose. For big protobufs copy is expensive and to prevent accidental copy it was chosen to make CopyFrom() explicit.
Move was not needed and was neglected when C++ 11 arrived. The next protobuf release likely have move included.
Upvotes: 1