import "mycustomengine.proto";
message MyCar {
optional string name = 1;
optional string model = 2;
optional MyCustomEngine customengine = 3;
Note I have assigned there to only be 0 or 1 MyCustomEngines to a Car
object. Now in my code, I've already created an instance of
MyCustomEngine, e.g.:
my::objects::MyCustomEngine myCustomEngine;
myCustomEngine.set_name("hey, this is my custom engine!");
Now I create my Car object....
my::objects::MyCar myCar;
myCar.set_name("Ford");
myCar.set_model("Fiesta");
But now I'm stuck on how to assign the myCustomEngine instance to the
myCar instance? There appears to be no method such as
"myCar.set_customengine(myCustomEngine)". So any ideas on how to do
this?
it is something along the lines of
myCar.mutable_customengine()->CopyFrom(myCustomEngine).
Since this copies data, you might want to consider setting things
directly in the customengine in the first place - if this is time
critical.
void InitCustomEngine(MyCustomEngine *engine) {
engine->set_name("My cool custom engine");
}
...
myCar.set_name("foo");
InitCustomEngine(myCar.mutable_customengine());
> this?
>
> --
>
> You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
> To post to this group, send email to prot...@googlegroups.com.
> To unsubscribe from this group, send email to protobuf+u...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/protobuf?hl=en.
>
>
>
excellent, that worked.... I knew someone must have done that
already!
Thanks again,
Nigel