On Tue, Dec 29, 2009 at 11:11, Nigel Pickard <pickard.ni...@gmail.com> wrote: > I'm having a problem working out how to assign a nested object's value > in C++ (my Java version works fine). E.g. in the proto file for my > car object I define: > > 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
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 proto...@googlegroups.com. > To unsubscribe from this group, send email to > protobuf+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/protobuf?hl=en. > > > -- You received this message because you are subscribed to the Google Groups "Protocol Buffers" group. To post to this group, send email to proto...@googlegroups.com. To unsubscribe from this group, send email to protobuf+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/protobuf?hl=en.