Re: [protobuf] Builders containing builders
> I wish I could pass a builder object to a method and have the method > modify either a value of the builder or a value of a sub-message in > the builder! > > I came across this thread, which described exactly the problem I have. > The Car/Engine example in the thread is perfectly illustrative of my > scenario. > > http://groups.google.com/group/protobuf/browse_thread/thread/1699791071e92c83/fc77205a755721f0 > > Has anyone else been in this same situation? What have you done to > ameliorate the problem? Generally speaking, I use non-PB model objects as my primary in-memory representation, and then I serialize them on demand to get the PB representation when I need it. For instance, something like: public class Engine { private String make; private double volumeLiters; public EnginePb serialize() { return EnginePb.newBuilder().setMake(make).setVolumeLiters(volumeLiters).build(); } } public class Car { private Engine engine; private String make; private String name; public CarPb serialize() { return CarPb.newBuilder().setMake(make).setName(name).setEngine(engine.serialize()).build(); } } - Adam -- 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.
Re: [protobuf] Builders containing builders
You should be able to pass a builder to some method, and have the method modify some value of the builder just fine. Modifying a value in a sub-message is a bit more inconvenient, but still doable. If you have some type Bar in type Foo like: message Bar { optional int32 a = 1; optional int32 b = 2; } message Foo { optional Bar bar = 1; } Foo.Builder builder; builder.setBar(builder.getBar().toBuilder().setA(...).build()); Would that work for you? On Wed, Dec 16, 2009 at 9:24 AM, Mark wrote: > I wish I could pass a builder object to a method and have the method > modify either a value of the builder or a value of a sub-message in > the builder! > > I came across this thread, which described exactly the problem I have. > The Car/Engine example in the thread is perfectly illustrative of my > scenario. > > > http://groups.google.com/group/protobuf/browse_thread/thread/1699791071e92c83/fc77205a755721f0 > > Has anyone else been in this same situation? What have you done to > ameliorate the problem? > > -- > > 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.
[protobuf] Builders containing builders
I wish I could pass a builder object to a method and have the method modify either a value of the builder or a value of a sub-message in the builder! I came across this thread, which described exactly the problem I have. The Car/Engine example in the thread is perfectly illustrative of my scenario. http://groups.google.com/group/protobuf/browse_thread/thread/1699791071e92c83/fc77205a755721f0 Has anyone else been in this same situation? What have you done to ameliorate the problem? -- 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.